forked from qingsh4n/whaweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
whatweb.py
110 lines (83 loc) · 2.5 KB
/
whatweb.py
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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import sys
import threading
import urllib2
import random
is_identification = False
g_index = 0
lock = threading.Lock()
def usage():
print '''
python whatweb.py 线程数 目标网站
example:
python whatweb.py 20 http://www.baidu.com
python whatweb.py 15 wwww.baidu.com
'''
def list_file(dir):
files = os.listdir(dir)
return files
def request_url(url='', data=None, header={}):
page_content = ''
request = urllib2.Request(url, data, header)
try:
response = urllib2.urlopen(request)
page_content = response.read()
#print page_content
except Exception, e:
pass
return page_content
def whatweb(target):
global is_identification
global g_index
global cms
while True:
if is_identification:
break
if g_index > len(cms)-1:
break
lock.acquire()
eachline = cms[g_index]
g_index = g_index + 1
lock.release()
if len(eachline.strip())==0 or eachline.startswith('#'):
pass
else:
#eachline添加strip()防止空行,后面赋值出错
url, pattern, cmsname = eachline.split('------')
html = request_url(target+url)
rate = float(g_index)/float(len(cms))
ratenum = int(100*rate)
sys.stdout.write(random.choice('x+') + ' ' + str(ratenum) + '% ' + target+url + "\r")
sys.stdout.flush()
if pattern.upper() in html.upper():
is_identification = True
print "[*] 成功识别CMS:%s,匹配的URL:%s,匹配的规则:%s" % (cmsname.strip('\n').strip('\r'), url, pattern)
break
#print threading.currentThread().getName(),'exit'
return
if __name__ == '__main__':
if len(sys.argv) != 3:
usage()
sys.exit()
threadnum = int(sys.argv[1])
target_url = sys.argv[2]
f = open('./cms.txt')
cms = f.readlines()
threads = []
if target_url.endswith('/'):
target_url = target_url[:-1]
if target_url.startswith('http://') or target_url.startswith('https://'):
pass
else:
target_url = 'http://' + target_url
for i in range(threadnum):
t = threading.Thread(target=whatweb, args=(target_url,))
threads.append(t)
print '[*] 开启%d线程' % threadnum
for t in threads:
t.start()
for t in threads:
t.join()
print "\n[*] All threads exit"