usr bin env python import time import string import httplib sys from s

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env python
import time
import string
import httplib,sys
from socket import *
import re
import getopt
from optparse import OptionParser
from sets import Set
class SearchEngine(object):
"""Base class for engines"""
query = ""
counter = 0
netloc = ""
path = ""
limit = 100
label = "base"
data = ""
step = 1
user_agent = ""
def search(self):
"""Sends request"""
path = self._prepare_path()
h = httplib.HTTP(self.netloc)
h.putrequest('GET', path)
h.putheader('Host', self.netloc)
h.putheader('User-agent', self.user_agent)
h.endheaders()
returncode, returnmsg, headers = h.getreply()
self.data = h.getfile().read()
def find_emails(self, data=None, domain_name=None):
"""Finds emails in HTML"""
data = data if data else self.data
domain_name = domain_name if domain_name else self.query
for e in ('<b>','</b>','<em>','</em>'):
data = string.replace(data, e, '')
for e in ('>',':','=','<','/','\\',';'):
data = string.replace(data,e,' ')
r1 = re.compile('[a-zA-Z0-9.-_]*' + '@' + domain_name)
res = r1.findall(data)
return res
def next_page(self):
if self.counter < self.limit:
self.counter = self.counter + self.step
return True
else:
return False
def prev_page(self):
if self.counter > self.step:
self.counter = self.counter - self.step
return True
else:
return False
def page_count(self):
raise Exception, "Implement method!"
def _prepare_path(self):
pass
class Google(SearchEngine):
"""Google Engine"""
label = "google"
counter = 0
step = 10
limit = 50
netloc = "www.google.com"
def _prepare_path(self):
"""Prepare path"""
path = '/search?num=100&start=' + str(self.counter) \
+ '&hl=es&btnG=B%C3%BAsqueda+en+Google&meta=&q=' + self.query
return path
class Yandex(SearchEngine):
"""Yandex Engine"""
label = "yandex"
counter = 0
step = 1
limit = 10
netloc = "yandex.ru"
def _prepare_path(self):
path = '/yandsearch?p=' + str(self.counter) \
+ '&text=' + self.query
return path
class App(object):
version = "0.1"
verbose = False
user_agent = "Internet Explorer 6.0 "
banner = """
Mail harvester by Pento <naplanetu@gmail.com>
==============
"""
engines = []
domain_name = ""
allowed_engines = []
def __init__(self):
"""Contructor"""
self.engines.append(Google())
self.engines.append(Yandex())
self.emails = Set()
def process_arguments(self):
"""Process command line arguments"""
usage = "Usage: %prog [options] domain"
parser = OptionParser(usage, version="%prog " + self.version)
parser.add_option("-s", "--searh-engines", dest="engines", \
help="Search engines", default="google")
parser.add_option("-v", "--verbose", action="store_true", dest="verbose", \
help="Increase verbosity level", default=False)
(options, args) = parser.parse_args()
self.allowed_engines = options.engines.split(",")
if not len(args) or not self.allowed_engines:
parser.error("Incorrect number of arguments. Specify domain.")
self.verbose = options.verbose
self.domain_name = args[0]
def run(self):
"""Process command line arguments and run"""
print self.banner
self.process_arguments()
for engine in self.engines:
if engine.label in self.allowed_engines:
if self.verbose:
print "[+] Engine in action " + engine.label
engine.user_agent = self.user_agent
engine.query = "mail+" + self.domain_name
page = True
while page:
engine.search()
emails = engine.find_emails(None, self.domain_name)
for email in emails:
email = email.strip()
if email:
self.emails.add(email)
page = engine.next_page()
self.print_results()
def print_results(self):
"""Print results"""
print "[!] Findings %d:\n" % len(self.emails)
for email in self.emails:
print email
if __name__ == "__main__":
try:
app = App()
app.run()
except KeyboardInterrupt:
print "Search interrupted by user.."