forked from brock7/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprobe.py
More file actions
executable file
·295 lines (257 loc) · 7.8 KB
/
probe.py
File metadata and controls
executable file
·295 lines (257 loc) · 7.8 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/usr/bin/python
# -*- encoding: utf-8 -*-
#
# filename: probe.py
# written by brock
# email: [email protected]
# date: 2014-06-06
#
###############################################################################
import urllib, urllib2
import re
import sys, getopt
import os
from lxml import etree
import socket
import time
import signal
import cookielib
#from httpshandler import HTTPSHandler
import random
###############################################################################
outfile = 'output'
os.environ['PATH'] += ';nikto-2.1.5;sqlmap' # FIXME
socket.setdefaulttimeout(20)
addresses = set()
hosts = set()
invIPs = set(["180.168.41.175"])
disableNikto = False
disableSqlmap = False
disableNmap = False
disableGoogleHack = False
level = 2
fixLevel = False
waitTime = 0
dbType = ''
probeType = ''
###############################################################################
def usage():
print "probe [-hnms] <host/domain>"
pass
def createlog(fname):
global outfile
outfile = fname
os.system('echo GENERATED BY PROBE.PY > %s' % (outfile))
def log(text):
os.system('echo [%s] "%s" | tee -a %s' % (time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), text, outfile));
def execute(cmdline):
os.system("%s | tee -a %s" % (cmdline, outfile))
###############################################################################
def doNmap(host):
execute("nmap -O -sV %s" % (host))
def doNikto(host):
if waitTime > 0:
execute("nikto.pl -Pause %d -h %s" % (waitTime, host))
else:
execute("nikto.pl -h %s" % (host))
def doSqlmap(host):
opts = ''
if dbType != '':
opts = '--dbms ' + dbType
if waitTime > 0:
execute('sqlmap.py --random-agent --threads=2 %s --delay %d --batch -g "site:%s"' % (opts, waitTime, host))
else:
execute('sqlmap.py --random-agent --threads=2 %s --batch -g "site:%s"' % (opts, host))
user_agents = ['Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20130406 Firefox/23.0', \
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0', \
'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533+ \
(KHTML, like Gecko) Element Browser 5.0', \
'IBM WebExplorer /v0.94', 'Galaxy/1.0 [en] (Mac OS X 10.5.6; U; en)', \
'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)', \
'Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14', \
'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) \
Version/6.0 Mobile/10A5355d Safari/8536.25', \
'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) \
Chrome/28.0.1468.0 Safari/537.36', \
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0; TheWorld)']
def google(host, what):
log('* google site:%s %s' % (host, what))
what = urllib2.quote("site:%s %s" % (host, what))
#print what
url = 'https://www.google.com.hk/search?hl=en&q=%s' % what
request = urllib2.Request(url)
index = random.randint(0, 9)
user_agent = user_agents[index]
request.add_header('User-agent', user_agent)
#print 'before'
response = urllib2.urlopen(request, data = None, timeout = 17)
#print 'after'
html = response.read()
#results = self.extractSearchResults(html)
tree = etree.HTML(html)
nodes = tree.xpath(r"//a/@href")
for node in nodes:
if node.find(host) == -1 or node.find('google') != -1 or node.find('http') == -1 or node.find('youtube') != -1:
continue
log('\tLink: '+ node)
#print html
return
#results = self.extractSearchResults(html)
# cj = cookielib.CookieJar()
#
# try:
# #response = urllib2.urlopen('http://www.google.com/search?q=python', timeout=10)
# #req = urllib2.Request('http://www.google.com.hk/search?q=ext:xls+site:www.vancl.com')
#
# opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj), HTTPSHandler())
# opener.addheaders.append(("User-Agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0"))
# req = urllib2.Request('http://www.google.com/ncr')
# print 1
# response = opener.open(req)
# print response.read()
# req = urllib2.Request('http://www.google.com/search?q=python')
# print 2
# response = opener.open(req)
# #response = urllib2.urlopen('http://www.google.com.hk/search?q=ext:xls+site:www.vancl.com')
# except urllib2.HTTPError, e:
# log("google error: " + e.msg + ' - ' + host)
# return
# html = response.read()
# print html
#tree = etree.HTML(html)
#nodes = tree.xpath(r"//a/@href")
#for node in nodes:
# print node
hacks = ('ext:xls', 'ext:xlsx', 'ext:doc', 'ext:docx', 'ext:txt', 'ext:zip',
'ext:conf', 'ext:rar', 'ext:sh', 'ext:gz', 'ext:bz2', 'ext:tar', 'ext:tgz',
'ext:mdb', 'ext:ini', "#",
'inurl:filename', 'inurl:upload', 'inurl:profile 管理员',
'inurl:file', 'inurl:down', "#",
'intitle:"index.of"', 'intitle:管理 ', "#",
'intext:*@*.com', 'intext:*@*.net', 'intext:*@*.cn', 'intext:ftp://*:* ',
'intext:powered by',
)
def googleHack(host):
log('******* google hack: ' + host)
count = 1
for hack in hacks:
if hack == '#':
#time.sleep(5)
continue
google(host, hack)
time.sleep(3 if random.random() > 0.5 else 2)
if count % 5 == 0:
time.sleep(5)
count = count + 1
###############################################################################
def scanHost(host):
try:
result = socket.getaddrinfo(host, None) # FIXME: handle exception
except:
log('cannot resolve the ip: ' + host)
return
ip = result[0][4][0]
log('******* host: %s(ip: %s) *******' % (host, ip));
if ip in invIPs:
log('invalid host: ' + host + '. skiped')
return
if probeType != 'domain' and not disableGoogleHack:
googleHack(host)
if ip in addresses:
log('duplication. host: ' + host + '. skip nmap')
else:
addresses.add(ip)
if not disableNmap:
doNmap(host)
if not disableNikto:
doNikto(host)
if not disableSqlmap:
doSqlmap(host)
def scanDomain(domain):
global level
if not fixLevel:
level = domain.count('.') + 1
if not disableGoogleHack:
googleHack(domain)
req = urllib2.Request('http://i.links.cn/subdomain/')
data = 'domain=%s&b2=1&b3=1&b4=1' % domain
#enable cookie
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
response = opener.open(req, data)
#response = urllib2.urlopen('http://www.baidu.com/')
html = response.read()
#print html
tree = etree.HTML(html)
nodes = tree.xpath(r"//a/@href")
for node in nodes:
if node.find(domain) == -1:
continue
#host, rest = urllib.splithost(node)
pos = node.find('//')
if pos >= 0:
node = node[pos + 2:]
if node.count('.') > level:
print node + ' skiped'
continue
if node in hosts:
continue
hosts.add(node)
try:
scanHost(node)
except:
log('occurred a exception with ' + node)
def scanHostsfile(filename):
for line in open(filename, "r").readlines():
line = line.strip()
#print line
#if line.count('.') > level:
# print line + ' skiped'
# continue
try:
scanHost(line)
except:
log('occurred a exception with ' + node)
###############################################################################
opts, args = getopt.getopt(sys.argv[1:], "h:f:nmsgl:w:t:")
method = ''
host = ""
filename = ""
for op, value in opts:
if op == "-h":
host = value
elif op == "-f":
filename = value
elif op == '-m':
disableNmap = True
elif op == '-n':
disableNikto = True
elif op == '-s':
disableSqlmap = True
elif op == '-g':
disableGoogleHack = True
elif op == '-l':
level = int(value)
fixLevel = True
elif op == '-w':
waitTime = int(value)
elif op == '-t':
dbType = value
else:
usage()
sys.exit()
if host =='' and filename == '' and len(args) < 1:
usage()
sys.exit()
if filename != '':
createlog(filename + '.log')
log('* Hosts file: %s' % (filename));
scanHostsfile(filename)
elif host != '':
createlog(host + '.log')
log('* Host: %s' % (host));
scanHost(host)
else:
probeType = 'domain'
createlog(args[0] + '.log')
log('* Domain: %s' % (args[0]));
scanDomain(args[0])