k3170makan

googledorker.py

Mar 14th, 2012
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.20 KB | None | 0 0
  1. #!/usr/bin/python
  2. from BeautifulSoup import BeautifulSoup as soup
  3. import httplib
  4. import sys
  5. """
  6.     A simple extension to goofile.py
  7.     features in this version:
  8.         *allows you to dork from the command line, and returns critical information
  9.             about the targets like
  10.                 >title text of the page
  11.                 >a short description
  12.                 >the URL to the target
  13.     TODO:
  14.         >server type detection
  15.         >dork presets for specifying targets with
  16.             *SQLi vulnerabilities in pages
  17.             *LFI/RFI vulnerabilities
  18.             *XSS vulnerabilities
  19.             *vulnerable files
  20.         I will implement this in such a way that you can localize a search to a given target
  21.         >CMS type detection
  22.         >I would like in the future to have googledorker learn from the searches you have performed and cache them
  23.             for faster results, and also use a lil machine learning to enhance the responsiveness to certain targets
  24.  
  25.     Depedencies:
  26.         are availble in the second line of the script!
  27.  
  28. This was inspired by googile.py
  29.  
  30. Author: Keith Makan
  31. Twitter: k3170makan
  32. site:k3170makan.blogspot.com   
  33. """
  34. class resultManager:
  35.     """
  36.         An object to manage results
  37.             *title
  38.             *URL
  39.             *server type
  40.             *script_type
  41.     """
  42.     def __init__(self):
  43.         return
  44.        
  45. class Dorker:
  46.     def __init__(self):
  47.         return
  48.     def get_page(self,dork):
  49.         h = httplib.HTTP('www.google.com')
  50.         h.putrequest('GET',"/search?num=100&q="+dork)
  51.         h.putheader('Host','www.google.com')
  52.         h.putheader('User-agent','Internet Explorer 6.0')
  53.         h.putheader('Referrer','www.g13net.com')
  54.         h.endheaders()
  55.         returncode,returnmsg,headers = h.getreply()
  56.         html=h.getfile().read()
  57.         #print html
  58.         return html
  59.     def stripURLs(self,page):
  60.         soop = soup(page)
  61.         resTag = soop.findAll("div",{"id":"res"}) #get the divider that wraps the results
  62.  
  63.         if len(resTag) == 0:
  64.             print page
  65.             print
  66.             print "Google is refusing you search query, please wait about 10mins before trying again"
  67.             return []
  68.         results_wrapperTag = soup(str(resTag)).findAll("ol")
  69.         results_list = soup(str(results_wrapperTag)).findAll("li",{"class":"g"})
  70.  
  71.         result_URLs = []
  72.         for res in results_list: #I'm using beautifull soup here, but a lot of this can be sped up by using regex!
  73.             string_res = str(res)
  74.             result_h3TAG = soup(string_res).findAll("h3",{"class":"r"})
  75.             results_anchorTAG = soup(str(result_h3TAG)).findAll("a")
  76.             URL = str(results_anchorTAG).split("/url?q=")[1].split(";")[0]
  77.             URL = URL[:len(URL)-4] #okay so we have the url
  78.             print "> %s " % (etc),
  79.             results_summaryTAG = soup(string_res).findAll("div",{"class":"s"}) 
  80.             for etc in results_summaryTAG:
  81.                 print "\t>>%s" % (etc)
  82.             print
  83.         return result_URLs
  84.     def dork(self,dork_term):
  85.         """
  86.             print the results for the dork_term supplied
  87.         """
  88.         html = self.get_page(dork_term)
  89.         self.stripURLs(html)
  90.         return
  91. if __name__ == "__main__":
  92.     dorky = Dorker()
  93.     if len(sys.argv) > 1:
  94.         dorky.dork(sys.argv[1])
  95.     else:
  96.         print ".::Google Dorker::."
  97.         print
  98.         print "Usage: ./googledorker.py [dork_term]"
  99.         print
  100.         print 'example: ./googledorker.py inurl:".php?*=*"'
  101.         print "*Please ensure that you're dork in all in a single line, use %20 for spaces and + to combine search operators"
  102.         print "See: http://k3170makan.blogspot.com/2012/01/science-of-google-dorking.html"
Add Comment
Please, Sign In to add comment