-
Notifications
You must be signed in to change notification settings - Fork 2
/
rdp0708scanner.py
101 lines (85 loc) · 2.81 KB
/
rdp0708scanner.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
import threading
import subprocess
import sys
import re
import getopt
vulnerable = []
def check_target(target, port, verbose=False):
global vulnerable, threadLimiter
threadLimiter.acquire()
print("Checking {}".format(target))
try:
process = subprocess.Popen("0708Detector_v2.exe -t {} -p {}".format(target, port), shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = process.communicate()
if verbose:
print(out.decode())
print(err.decode())
if "IS VULNERABLE" in out.decode():
vulnerable.append(target)
finally:
threadLimiter.release()
def start(targets, port, verbose=False):
threads = [threading.Thread(target=check_target, args=(target, port, verbose)) for target in targets]
for thread in threads:
thread.start()
for thread in threads:
thread.join()
global vulnerable
return vulnerable
def main(argv):
port = 3389
targets_list = []
target = None
listfile = None
verbose = False
max_threads = 5
global threadLimiter
try:
opts, args = getopt.getopt(argv[1:], 't:f:p:x:v', ['target=', 'listfile=', 'port=', 'maxthreads=', 'verbose'])
except getopt.GetoptError:
print("args error")
sys.exit(1)
for opt, arg in opts:
if opt in ('-t', '--target'):
target = arg
elif opt in ('-f', '--listfile'):
listfile = arg
elif opt in ('-p', '--port'):
port = arg
elif opt in ('-x', '--maxthreads'):
max_threads = int(arg)
elif opt in ('-v', '--verbose'):
verbose = True
else:
print("unknown args")
sys.exit(2)
if target:
targets_list.append(target)
if listfile:
with open(listfile, "r") as ins:
for line in ins:
addr = line.strip()
if re.match(r'^#', addr):
continue
if len(addr) == 0:
continue
if re.match(r'^(\d{1,3}\.){3}\d{1,3}$', addr):
targets_list.append(addr)
if targets_list:
threadLimiter = threading.BoundedSemaphore(max_threads)
print("======== CVE-2019-0708 check start =======")
results = start(targets_list, port, verbose)
print("======== CVE-2019-0708 check complete =======")
for ip in results:
print("{} IS VULNERABLE!".format(ip))
print("{} targets in total".format(len(targets_list)))
if len(results):
print("{} vulnerable host(s)".format(len(results)))
else:
print("No vulnerable host found")
else:
print("No targets")
if __name__ == "__main__":
main(sys.argv)