forked from CaiJiJi/VulScritp
-
Notifications
You must be signed in to change notification settings - Fork 71
/
Rescan.py
90 lines (84 loc) · 1.93 KB
/
Rescan.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
#coding=utf-8
#author=Cond0r@CodeScan
import socket
import threading
from concurrent import futures
from Queue import Queue
from sys import argv
import ipaddr
import sys
socket.setdefaulttimeout(3)
data='''
Lib:
https://github.com/google/ipaddr-py
https://pypi.python.org/pypi/futures
pip install futures
Usage:
python rescan.py -f inputfile.txt
inputfile.txt:
10.14.40.194:6379
python rescan.py -i 192.168.1.1/24 -p 6379
'''
target_list=[]
def stdout( name):
scanow ='[*] Scan %s.. '%(name)
sys.stdout.write(str(scanow)+" "*20+"\b\b\r")
sys.stdout.flush()
def extract_target(inputfile):
global target_list
inputdata=open(inputfile).read().replace("\r",'').split("\n")
for host in inputdata:
host=host.split(":")
if len(host)==2:
target_list.append("%s:%s"%(host[0],host[1]))
elif len(host)==1:
target_list.append("%s:6379"%(host[0]))
return target_list
def send_dbsize(conn):
try:
conn.send("dbsize\n")
recv=conn.recv(5)
conn.close()
recv=recv.replace("\n",''),
return recv
except:
return False
def conn_redis(args):
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
args=args.split(":")
host=args[0]
port=int(args[1])
try:
client.connect((host, port))
return client
except:
return False
def run_task(target):
stdout(target)
conn=conn_redis(target)
if conn:
size=send_dbsize(conn)
size=str(size)
if 'NOAUTH' not in size and ':' in size:
return "[!] Find %s Unauthorized "% target
def main():
targetlist=[]
if len(argv)>2:
if argv[1]=='-f':
return extract_target(argv[2])
if argv[1]=='-i':
port=6379
if len(argv)==5:
port=int(argv[4])
targets = ipaddr.IPv4Network(argv[2])
for tar in targets:
targetlist.append("%s:%d"%(tar,port))
return targetlist
if len(argv)<3:
print data
exit()
target_list=main()
thread_pool = futures.ThreadPoolExecutor(max_workers=10)
for i in thread_pool.map(run_task, target_list):
if i!=None:
print i