Advertisement
Guest User

MetaGooFil 1.4c (Unofficial revision by Derv)

a guest
Mar 19th, 2011
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 12.21 KB | None | 0 0
  1.  
  2. #!/usr/bin/python
  3. #Covered by GPL V2.0
  4. import time
  5. import string
  6. import httplib,sys
  7. from socket import *
  8. import re
  9. import getopt
  10. import urllib
  11. import time
  12. import os
  13.  
  14. """ Updated 3/19/2011 by Derv[eightytwo]@gmail.com to work with Google again """
  15.  
  16. print "\n*************************************"
  17. print "*MetaGooFil Ver. 1.4c (rev by derv) *"
  18. print "*Coded by Christian Martorella      *"
  19. print "*Edge-Security Research             *"
  20. print "*cmartorella@edge-security.com      *"
  21. print "*************************************\n\n"
  22.  
  23.  
  24. global word,w,limit,result,extcommand
  25. #Win
  26. ##extcommand='c:\extractor\\bin\extract.exe -l libextractor_ole2'
  27. #OSX
  28. #extcommand='/opt/local/bin/extract'
  29. #Cygwin
  30. #extcommand='/cygdrive/c/extractor/bin/extract.exe'
  31. extcommand='/usr/bin/extract'
  32.  
  33. result =[]
  34. global dir
  35. dir = "none"
  36.  
  37.  
  38. def usage():
  39.  print "MetaGooFil 1.4\n"
  40.  print "usage: metagoofil options \n"
  41.  print "    -d: domain to search"
  42.  print "    -f: filetype to download (all,pdf,doc,xls,ppt,odp,ods, etc)"
  43.  print "    -l: limit of results to work with (default 100)"
  44.  print "    -o: output file, html format."
  45.  print "    -t: target directory to download files.\n"
  46.  print "    Example: metagoofil.py -d microsoft.com -l 20 -f all -o micro.html -t micro-files\n"
  47.  sys.exit()
  48.  
  49.  
  50. #Mac address extractor#
  51. def get_mac(file,dir):
  52.         filename=dir+"/"+file  
  53.         line=open(filename,'r')
  54.         res=""
  55.         for l in line:
  56.             res+=l
  57.         macrex=re.compile('-[0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z]\}')   
  58.         macgetter=macrex.findall(res)
  59.         if macgetter==[]:
  60.             mac=''
  61.         else:
  62.             mac=macgetter[0]
  63.             mac=mac.strip("-")
  64.             mac=mac.strip("}")
  65.             mac=mac[:2]+":"+mac[2:4]+":"+mac[4:6]+":"+mac[6:8]+":"+mac[8:10]+":"+mac[10:12]
  66.         return mac
  67.  
  68. def get_pdf_meta(file,dir):
  69.     from pyPdf import PdfFileReader
  70.     filename=dir+"/"+file  
  71.     a=''
  72.     try:
  73.         input1 = pyPdf.PdfFileReader(file(filename, "rb"))
  74.         a=input1.getDocumentInfo()
  75.     except:
  76.         print "error opening pdf"
  77.     return a,a
  78.  
  79. def get_info_pdf(file,dir):
  80.         filename=dir+"/"+file  
  81.         line=open(filename,'r')
  82.         res=""
  83.         for l in line:
  84.             res+=l
  85.         arex=re.compile('xap:Author=.* ')  
  86.         getter=arex.findall(res)
  87.         if getter==[]:
  88.             aut3=''
  89.         else:
  90.             aut3=getter[0]
  91.             aut3=aut3.split(" ")[0]
  92.             aut3=aut3.replace("xap:Author='","")
  93.             aut3=aut3.replace("'","")
  94.             pat=""
  95.             return aut3,pat
  96.         rex=re.compile('xmpmeta')  
  97.         getter=rex.findall(res)
  98.         if getter==[]:
  99.             meta=''
  100.         else:
  101.             meta=getter[0]
  102.         if meta=='':
  103.             return meta,meta
  104.         else:
  105.             pass
  106.         arex=re.compile('Author\(.*\)[<|\/]')  
  107.         getter=arex.findall(res)
  108.         if getter==[]:
  109.             aut=''
  110.         else:
  111.             aut=getter[0].split("/")[0]
  112.             #print aut.split("/")[0]
  113.         ###
  114.         arex=re.compile('\<rdf:li\>(.*)\</rdf:li\>\</rdf:Seq\>')   
  115.         getter=arex.findall(res)
  116.         if getter==[]:
  117.             aut2=''
  118.         else:
  119.             temp=getter[0].replace("<rdf:li>","")
  120.             aut2=temp.replace("</rdf:li>","")
  121.             print aut2
  122.         ##PATH
  123.         rex=re.compile('Title\(.*\)[<|\/]')
  124.         getter=rex.findall(res)
  125.         if getter==[]:
  126.             pat=''
  127.         else:
  128.             pat=getter[0]
  129.             print pat.split("/")[0]
  130.         #SOFTware
  131.         arex=re.compile('Producer=(.*)>')  
  132.         getter=arex.findall(res)
  133.         if getter==[]:
  134.             producer=''
  135.         else:
  136.             producer=getter[0]
  137.             producer=producer.replace("></rdf:Description","")         
  138.        
  139.         arex=re.compile(' pdf:Producer=(.*) ') 
  140.         getter=arex.findall(res)
  141.         if getter==[]:
  142.             producer=''
  143.         else:
  144.             producer=getter[0]
  145.         aut=aut+aut2+aut3
  146.         return aut,pat
  147.  
  148.  
  149. def howmany(w):
  150.      h = httplib.HTTP('www.google.com')
  151.      h.putrequest('GET',"/search?hl=en&q=site%3A"+w+"+filetype%3A"+file)
  152.          h.putheader('Host', 'www.google.com')
  153.      h.putheader('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.107 Safari/534.13')
  154.      h.endheaders()
  155.      returncode, returnmsg, headers = h.getreply()
  156.      data=h.getfile().read()
  157.      r1 = re.compile('About ([0123456789,]*) results')
  158.      result = r1.findall(data)
  159.          
  160.      if result ==[]:
  161.         r1 = re.compile('([0123456789]*) results')
  162.         result = r1.findall(data)
  163.          
  164.      x = result[0]
  165.      clean = re.sub(' <b>','',x)
  166.      clean = re.sub('</b> ','',clean)
  167.      clean = re.sub('About','',clean)
  168.      clean = re.sub('results','',clean)
  169.      clean = re.sub(',','',clean)
  170.      clean = re.sub('of','',clean)
  171.      cleani = int(clean)
  172.      if len(result) == 0:
  173.         cleani = 0
  174.      return cleani
  175.  
  176.  
  177.  
  178. def run(w,i):
  179.     res = []
  180.     h = httplib.HTTP('www.google.com')
  181.     h.putrequest('GET',"/search?num=20&start="+str(i)+"&hl=en&q=site%3A"+w+"+filetype%3A"+file)
  182.     h.putheader('Host', 'www.google.com')
  183.     h.putheader('User-Agent','Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.107 Safari/534.13')
  184.     h.endheaders()
  185.     returncode, returnmsg, headers = h.getreply()
  186.     data=h.getfile().read()
  187.     #r1 = re.compile('\[[A-Z]*\]</b>(<)/font></span> <h2 class=[^>]+><a href="([^"]+)"')
  188.     r1 = re.compile('><a href="([^"]+.'+file+')"')
  189.     res = r1.findall(data)
  190.     return res
  191.  
  192.  
  193.  
  194. def test(argv):
  195.     global limit
  196.     global file
  197.     limit=20
  198.     down ='a'
  199.     if len(sys.argv) < 11:
  200.         usage()
  201.     try :
  202.         opts, args = getopt.getopt(argv,"l:d:f:o:t:")
  203.     except getopt.GetoptError:
  204.         usage()
  205.     for opt,arg in opts:
  206.         if opt == '-l':
  207.             limit = int(arg)
  208.             elif opt == '-d':
  209.                     word = str(arg)
  210.             elif opt == '-f':
  211.                     file = str(arg)
  212.             elif opt == '-o':
  213.                     ofile = str(arg)
  214.         elif opt =='-t':
  215.             dir = str(arg)
  216.     if dir == 'none':
  217.         dir = word
  218.     if file != 'all':
  219.         all=[file]
  220.     else:
  221.         all=['pdf','doc','xls','ppt','sdw','mdb','sdc','odp','ods','docx',"xlsx","pptx"]
  222.     try:
  223.         fil = open(ofile,'w')
  224.     except:
  225.         print "Failed"
  226.     test=extcommand.split(" ")[0]
  227.     if os.path.isfile(test):
  228.         print "[+] Command extract found, proceeding with leeching"
  229.     else:
  230.         print "Command extract not found, please check and change the location"
  231.         sys.exit()
  232.     date= time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())
  233.     fil.write("<style type=\"text\/css\"><!--BODY{font-family:sans-serif;}--></style>")
  234.     fil.write("<center><b>Meta<font color=\"#0000cc\">G</font><font color=\"#ff0000\">o</font><font color=\"#ffff00\">o</font>fil</b> results page for:</center>")
  235.     fil.write("<center><b>"+word+"</b></center>")
  236.     fil.write("<center>"+date+"</center>")
  237.     fil.write("<center><a href=\"http://www.edge-security.com\">By Edge-Security</a></center>")
  238.     fil.write("<hr>")
  239.     fil.write('<a href="#users">Results: Go directly to resuls.</a>')
  240.     authors=[]
  241.     pathos=[]
  242.     for fi in all:
  243.         file = fi
  244.         print "[+] Searching in " + word + " for: " + file
  245.         total = int(howmany(word))
  246.         print "[+] Total results in google: "+ str(total)
  247.         if total == 0:
  248.             pass
  249.         else:
  250.             cant = 0
  251.             fil.write("<hr>")
  252.             fil.write("<strong><u>Searching in " + word + " for: " + file+" files.</u></strong><br><br>")
  253.             if total < limit:
  254.                 limit=total
  255.             print "[+] Limit: ",int(limit)
  256.             result=[]
  257.             while cant < limit:
  258.                 print "[+] Searching results: " + str(cant) +"\r"
  259.                 res = run(word,cant)
  260.                 for x in res:
  261.                     if result.count(x) == 0:
  262.                         if x.count('http')!=0:
  263.                             result.append(x)
  264.                         else:
  265.                             pass
  266.                 cant+=20
  267.             fil.write("<strong>Total available files: "+str(total)+" </strong><br>")
  268.             t=0
  269.             if os.path.exists(dir):
  270.                 print "[+] Directory "+ dir + " already exist, reusing it"
  271.             else:
  272.                 os.mkdir(dir)
  273.             cantidad_todo=len(result)
  274.             contador=0
  275.             for x in result:
  276.                 contador+=1
  277.                 fil.write(x+"<br>")
  278.                 try:
  279.                     if down == "a"  :
  280.                         np = 0
  281.                         res=x.split('://')[1]
  282.                         res=res.split("/")
  283.                         leng=len(res)
  284.                         filename=res[leng-1]
  285.                         try:
  286.                             print "\t[ "+str(contador)+"/"+str(cantidad_todo)+" ] "+ x
  287.                             if os.path.exists(dir+'/'+filename):
  288.                                 pass
  289.                             else:
  290.                                 urllib.urlretrieve(x,str(dir)+"/"+str(filename))
  291.                         except IOError:
  292.                             print "Can't download"
  293.                             np = 1
  294.                         if np == 0:
  295.                             fil.write("<br>Local copy " + "<a href=\""+dir+"/"+filename+'\">Open</a>')
  296.                             fil.write("<br><br>Important metadata:")
  297.                             command = extcommand +' '+ dir +'/'+'"'+filename+'"'
  298.                             try:
  299.                                 stdin,stderr = os.popen4(command)
  300.                             except:
  301.                                 print "Error executing extract, maybe the binary path is wrong."
  302.                                 fil.write('<br>')
  303.                             mac=get_mac(filename,dir)
  304.                             author,path=get_info_pdf(filename,dir)
  305.                             if author!="":
  306.                                 if authors.count(author) == 0:
  307.                                     authors.append(author)
  308.                                 if pathos.count(path) == 0:
  309.                                     pathos.append(path)
  310.                             else:
  311.                                 pass
  312.  
  313.                             if file == 'pdf':
  314.                                 fil.write('<pre style=\"background:#C11B17;border:1px solid;\" >')
  315.                             elif file == 'doc':
  316.                                 fil.write('<pre style=\"background:#6698FF;border:1px solid;\">')
  317.                             elif file == 'xls':
  318.                                 fil.write('<pre style=\"background:#437C2C;border:1px solid;\">')
  319.                             elif file == 'ppt':
  320.                                 fil.write('<pre style=\"background:#E56717;border:1px solid;\">')
  321.                             else:
  322.                                 fil.write('<pre style=\"background:#827839;border:1px solid;\">')
  323.                             if mac !='':
  324.                                 fil.write('Mac address:' + mac +'\n' )
  325.                             else:
  326.                                 pass
  327.                             for line in stderr.readlines():
  328.                                 fil.write(line)
  329.                                 au = re.compile('Author -.*')
  330.                                 aut= au.findall(line)
  331.                                 if aut != []:
  332.                                     author=aut[0].split('- ')[1]
  333.                                     if authors.count(author) == 0:
  334.                                         authors.append(author)
  335.                                
  336.                                 au = re.compile('creator -.*')
  337.                                 aut= au.findall(line)
  338.                                 if aut != []:
  339.                                     author=aut[0].split('- ')[1]
  340.                                     if authors.count(author) == 0:
  341.                                         authors.append(author)
  342.  
  343.                                 au = re.compile('author -.*')
  344.                                 aut= au.findall(line)
  345.                                 if aut != []:
  346.                                     author=aut[0].split('- ')[1]
  347.                                     if authors.count(author) == 0:
  348.                                         authors.append(author)
  349.  
  350.  
  351.    
  352.                                 last = re.compile('last saved by -.*')
  353.                                 aut= last.findall(line)
  354.                                 if aut != []:
  355.                                     author=aut[0].split('- ')[1]
  356.                                     if authors.count(author) == 0:
  357.                                         authors.append(author)
  358.                                    
  359.                                 rev = re.compile(': Author \'.*\'')
  360.                                 aut=rev.findall(line)
  361.                                 if aut != []:
  362.                                     author=aut[0].split('\'')[1]
  363.                                     author=string.replace(author,'\'','')
  364.                                     if authors.count(author) == 0:
  365.                                         authors.append(author)
  366.  
  367.                                 pa= re.compile('worked on .*')
  368.                                 pat=pa.findall(line)
  369.                                 if pat !=[]:
  370.                                     if pathos.count(pat) == 0:
  371.                                         temp=pat[0].split('\'')[1]
  372.                                         pathos.append(temp)
  373.                                 pat=[] 
  374.                                 pa= re.compile('template -.*')
  375.                                 pat=pa.findall(line)
  376.                                 if pat !=[]:
  377.                                     if pathos.count(pat) == 0:
  378.                                         temp=pat[0].split('-')[1]
  379.                                         pathos.append(temp)
  380.                             fil.write('</pre>')
  381.                             fil.write('<hr>')
  382.                         else:
  383.                             print "Can't Download "+ x
  384.                             fil.write("<br>Local copy, failed download :(\n")
  385.                             fil.write('<hr>')
  386.                     else:
  387.                         print "====================="
  388.                 except KeyboardInterrupt:
  389.                         print "Process Interrupted by user\n"
  390.                         sys.exit()
  391.                 t+=1
  392.             fil.write("<strong>Total results for "+fi+": "+ str(t)+ "</strong><br>")
  393.     fil.write('<hr>')  
  394.     fil.write('<a name="users">')
  395.     fil.write('<br>')
  396.     fil.write('<b><h2>Total authors found (potential users):</h2></b>')
  397.     fil.write('<pre style=\"background:#737ca1;border:1px solid;\">')
  398.     print "\n"
  399.     print "Usernames found:"
  400.     print "================"       
  401.     if authors != []:
  402.         for x in authors:
  403.                 fil.write( str(x)+'<br>')
  404.                 print str(x)
  405.     else:
  406.         fil.write("0 users found.<br>")
  407.     fil.write('</pre>')
  408.     print "\n"
  409.     print "Paths found:"
  410.     print "============"   
  411.     fil.write('<b><h2>Path Disclosure:</h2></b>')
  412.     fil.write('<pre style=\"background:#c8bbbe;border:1px solid;\">')
  413.     paty=[]
  414.     if pathos != []:
  415.         for x in pathos:
  416.                 temp=""
  417.                 a=x.split('\\')
  418.                 for x in a:
  419.                     if x.count('.'):
  420.                         pass
  421.                     else:
  422.                         temp=temp+x+"\\"
  423.                 if paty.count(temp):
  424.                     pass
  425.                 else:
  426.                     fil.write(str(temp)+'<br>')
  427.                     paty.append(temp)
  428.                     print temp
  429.     else:
  430.              fil.write('0 path found.<br>')
  431.     fil.write('</pre>')
  432.     print "[+] Process finished"
  433.  
  434. if __name__ == "__main__":
  435.         try: test(sys.argv[1:])
  436.     except KeyboardInterrupt:
  437.         print "Process interrupted by user.."
  438.     except:
  439.         sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement