-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66a2661
commit cb1515b
Showing
5 changed files
with
174 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
#!/usr/bin/env python | ||
|
||
# Class will have the following properties: | ||
# 1) name / description | ||
# 2) main name called "ClassName" | ||
# 3) execute function (calls everthing it neeeds) | ||
# 4) places the findings into a queue | ||
import re | ||
import requests | ||
import urlparse | ||
import os | ||
import configparser | ||
import requests | ||
import time | ||
from Helpers import helpers | ||
from Helpers import Parser | ||
from BeautifulSoup import BeautifulSoup | ||
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter | ||
from pdfminer.converter import TextConverter | ||
from pdfminer.layout import LAParams | ||
from pdfminer.pdfpage import PDFPage | ||
from cStringIO import StringIO | ||
|
||
class ClassName: | ||
|
||
def __init__(self, Domain, verbose=False): | ||
self.name = "Google PDF Search for Emails" | ||
self.description = "Uses google Dorking to search for emails" | ||
config = configparser.ConfigParser() | ||
try: | ||
config.read('Common/SimplyEmail.ini') | ||
self.Domain = Domain | ||
self.Quanity = int(config['GooglePDFSearch']['StartQuantity']) | ||
self.UserAgent = { | ||
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'} | ||
self.Limit = int(config['GooglePDFSearch']['QueryLimit']) | ||
self.Counter = int(config['GooglePDFSearch']['QueryStart']) | ||
self.verbose = verbose | ||
self.urlList = [] | ||
self.Text = "" | ||
except: | ||
print helpers.color("[*] Major Settings for GooglePDFSearch are missing, EXITING!\n", warning=True) | ||
|
||
def execute(self): | ||
self.search() | ||
FinalOutput, HtmlResults = self.get_emails() | ||
return FinalOutput, HtmlResults | ||
|
||
|
||
def convert_pdf_to_txt(self, path): | ||
rsrcmgr = PDFResourceManager() | ||
retstr = StringIO() | ||
codec = 'utf-8' | ||
laparams = LAParams() | ||
device = TextConverter(rsrcmgr, retstr, codec=codec, laparams=laparams) | ||
fp = file(path, 'rb') | ||
interpreter = PDFPageInterpreter(rsrcmgr, device) | ||
password = "" | ||
maxpages = 0 | ||
caching = True | ||
pagenos=set() | ||
|
||
for page in PDFPage.get_pages(fp, pagenos, maxpages=maxpages, password=password,caching=caching, check_extractable=True): | ||
interpreter.process_page(page) | ||
|
||
text = retstr.getvalue() | ||
|
||
fp.close() | ||
device.close() | ||
retstr.close() | ||
return text | ||
|
||
|
||
def download_file(self, url): | ||
local_filename = url.split('/')[-1] | ||
# NOTE the stream=True parameter | ||
r = requests.get(url, stream=True) | ||
with open(local_filename, 'wb') as f: | ||
for chunk in r.iter_content(chunk_size=1024): | ||
if chunk: # filter out keep-alive new chunks | ||
f.write(chunk) | ||
#f.flush() commented by recommendation from J.F.Sebastian | ||
return local_filename | ||
|
||
|
||
def search(self): | ||
while self.Counter <= self.Limit and self.Counter <= 100: | ||
time.sleep(1) | ||
if self.verbose: | ||
p = '[*] Google PDF Search on page: ' + str(self.Counter) | ||
print helpers.color(p, firewall=True) | ||
try: | ||
urly = "https://www.google.com/search?q=site:" + self.Domain + "+filetype:pdf&start=" + str(self.Counter) | ||
except Exception as e: | ||
error = "[!] Major issue with Google Search:" + str(e) | ||
print helpers.color(error, warning=True) | ||
try: | ||
r = requests.get(urly) | ||
except Exception as e: | ||
error = "[!] Fail during Request to Google (Check Connection):" + \ | ||
str(e) | ||
print helpers.color(error, warning=True) | ||
RawHtml = r.content | ||
soup = BeautifulSoup(RawHtml) | ||
for a in soup.findAll('a'): | ||
try: | ||
# https://stackoverflow.com/questions/21934004/not-getting-proper-links- | ||
# from-google-search-results-using-mechanize-and-beautifu/22155412#22155412? | ||
# newreg=01f0ed80771f4dfaa269b15268b3f9a9 | ||
l = urlparse.parse_qs(urlparse.urlparse(a['href']).query)['q'][0] | ||
if l.startswith('http') or l.startswith('www'): | ||
if "webcache.googleusercontent.com" not in l: | ||
self.urlList.append(l) | ||
except: | ||
pass | ||
self.Counter += 10 | ||
# now download the required files | ||
try: | ||
for url in self.urlList: | ||
if self.verbose: | ||
p = '[*] Google PDF search downloading: ' + str(url) | ||
print helpers.color(p, firewall=True) | ||
try: | ||
FileName = self.download_file(url) | ||
self.Text += self.convert_pdf_to_txt(FileName) | ||
os.remove(FileName) | ||
except Exception as e: | ||
pass | ||
except: | ||
print helpers.color("[*] No PDF's to download from google!\n", firewall=true) | ||
|
||
|
||
def get_emails(self): | ||
Parse = Parser.Parser(self.Text) | ||
Parse.genericClean() | ||
Parse.urlClean() | ||
FinalOutput = Parse.GrepFindEmails() | ||
HtmlResults = Parse.BuildResults(FinalOutput,self.name) | ||
return FinalOutput, HtmlResults |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters