parkdream1

googlefile.py

May 12th, 2012
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.27 KB | None | 0 0
  1. #!/usr/bin/python
  2. # TheHarvester used for inspiration
  3. # A many thanks to the Edge-Security team!          
  4. #
  5.  
  6. import string
  7. import httplib
  8. import sys
  9. import re
  10. import getopt
  11.  
  12.  
  13.  
  14.  
  15. print "\n-------------------------------------"
  16. print "|Goofile V1.0                        |"
  17. print "|Coded by Thomas (G13) Richards     |"
  18. print "|www.g13net.com                     |"
  19. print "|code.google.com/p/goofile          |"
  20. print "-------------------------------------\n\n"
  21.  
  22. global word
  23. global w
  24. global result
  25. result =[]
  26.  
  27. def usage():
  28.  print "Goofile 1.0\n"
  29.  print "usage: goofile options \n"
  30.  print "       -d: domain to search\n"
  31.  print "       -f: filetype (ex. pdf)\n"
  32.  print "example:./goofile.py -d test.com -f txt\n"
  33.  sys.exit()
  34.  
  35. def run(w,file):
  36.    
  37.     h = httplib.HTTP('www.google.com')
  38.     h.putrequest('GET',"/search?q=site:"+w+"+filetype:"+file)
  39.     h.putheader('Host', 'www.google.com')
  40.     h.putheader('User-agent', 'Internet Explorer 6.0 ')
  41.     h.putheader('Referrer', 'www.g13net.com')
  42.     h.endheaders()
  43.     returncode, returnmsg, headers = h.getreply()
  44.     data=h.getfile().read()
  45.     data=re.sub('<b>','',data)
  46.         for e in ('>','=','<','\\','(',')','"','http',':','//'):
  47.         data = string.replace(data,e,' ')
  48.     r1 = re.compile('[-_.a-zA-Z0-9.-_]*'+'\.'+file)
  49.     res = r1.findall(data)
  50.     return res
  51.    
  52.  
  53. def search(argv):
  54.     global limit
  55.     limit = 100
  56.     if len(sys.argv) < 2:
  57.         usage()
  58.     try :
  59.            opts, args = getopt.getopt(argv,"d:f:")
  60.  
  61.     except getopt.GetoptError:
  62.             usage()
  63.         sys.exit()
  64.    
  65.     for opt,arg in opts :
  66.             if opt == '-d' :
  67.             word=arg
  68.         elif opt == '-f':
  69.             file=arg
  70.    
  71.     print "Searching in "+word+" for "+ file
  72.     print "========================================"
  73.  
  74.  
  75.     cant = 0
  76.  
  77.     while cant < limit:
  78.         res = run(word,file)
  79.         for x in res:
  80.             if result.count(x) == 0:
  81.                     result.append(x)
  82.         cant+=100
  83.            
  84.  
  85.     print "\nFiles found:"
  86.     print "====================\n"
  87.     t=0
  88.     if result==[]:
  89.         print "No results were found"
  90.     else:
  91.         for x in result:
  92.             x= re.sub('<li class="first">','',x)
  93.             x= re.sub('</li>','',x)
  94.             print x
  95.             t+=1
  96.     print "====================\n"
  97.    
  98.  
  99. if __name__ == "__main__":
  100.         try: search(sys.argv[1:])
  101.     except KeyboardInterrupt:
  102.         print "Search interrupted by user.."
  103.     except:
  104.         sys.exit()
Add Comment
Please, Sign In to add comment