Skip to content

Commit 048b1cd

Browse files
committed
UPDATED: NVD_NIST
1 parent 43baebd commit 048b1cd

File tree

3 files changed

+58
-46
lines changed

3 files changed

+58
-46
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ git clone https://github.com/ruskonert/cve-mysql-python.git
2626
cd cve-mysql-python
2727
pip install -r requirements.txt
2828
```
29-
pip 2 버전이 이미 설치되어 있다면, 다음 명렁어로 대신 입력하십시오:
29+
pip 2 버전이 이미 설치되어 있다면, 다음 명렁어를 입력하십시오:
3030
```
31-
pip3 install -r requirements.txt
31+
pip3 install --upgrade pip
32+
pip install -r requirements.txt
3233
```
3334

3435
만약 파이썬 인터프리터가 없다면, 아래의 링크를 통해 Released된 실행 가능한 최신 파일을 다운로드하여 사용하십시오.<br>

cvemysql.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ def __init__(self, error):
2525
super().__init__(error)
2626

2727

28-
def initialize(user, password, host, port, char="utf8"):
28+
def initialize(user, password, host, port, char="utf8", not_used_password=False):
2929
""" 사용할 데이터베이스에 연결하고 작업이 이루어질 수 있는 환경을 객체화하여 반환합니다. """
30-
if password is None:
30+
if password is None and not not_used_password:
3131
password = getpass.getpass('Please input your password {u}@{h} > '.format(u=user, h=host))
3232
database = MySqlBase(user, password, host, port)
3333
database.connect()

nvdnist.py

+53-42
Original file line numberDiff line numberDiff line change
@@ -146,40 +146,40 @@ def workstation(sql_user, sql_password, sql_host, sql_port, sql_database, tablen
146146
lastModifiedDate = str(jsonElement.get('lastModifiedDate', ''))
147147

148148
# Unused variable for column fields
149-
sql_user = None
150-
sql_database = None
151-
sql_port = None
152-
sql_host = None
153-
sql_password = None
154-
149+
c = None
155150
d = None
156-
defined = None
151+
152+
sql_data = {'sql_user' : False, 'sql_database' : False, 'sql_port' : False, 'sql_host' : False, 'sql_password' : False, 'tablename': False}
153+
filter_vars = lambda l: isinstance(l[1], str) and sql_data.get(l[0], True) and l[1] is not None
157154

158155
if safe_insert:
159156
subWorker = SQLWorker(_cpeList).initialize(2)
157+
158+
# Check the cpe elements has at least 1
160159
while len(data) != 0:
161-
defined = dict(vars())
160+
defined = None
162161
r = jsonElement[data.pop()].split(' || ')
163-
subWorker._submit.append(subWorker._executor.submit(subWorker._function, sql_user, sql_password, sql_host, sql_port, sql_database, tablename, c, r, defined))
162+
defined = dict((i, j) for i, j in filter(filter_vars, list(dict(vars()).items())))
163+
subWorker._submit.append(subWorker._executor.submit(subWorker._function, sql_user, sql_password, sql_host, sql_port, sql_database, tablename, r, cpe_list, defined))
164164

165165
for ps in subWorker.as_complete():
166166
result = result + ps.result()
167+
167168
subWorker.terminate()
168169

169170
else:
170171
while len(data) != 0:
171-
c = data.pop()
172-
r = jsonElement[c].split(' || ')
172+
r = jsonElement[data.pop()].split(' || ')
173173
cpe_list_clone = list(cpe_list)
174174
cpe_list_clone.reverse()
175175

176176
# It will use the value of table columns.
177177
affects_vendor_name = r[0]
178178
affects_product_name = r[1]
179179
affects_version_value = r[2]
180-
c = None
181180

182181
while len(cpe_list_clone) != 0:
182+
defined = None
183183
cp = cpe_list_clone.pop()
184184
r = cp.split('||')
185185

@@ -194,23 +194,23 @@ def workstation(sql_user, sql_password, sql_host, sql_port, sql_database, tablen
194194
cp = None
195195

196196
# Get deined variables
197-
v = dict(vars())
197+
defined = dict((i, j) for i, j in filter(filter_vars, list(dict(vars()).items())))
198198

199-
if execute(base, tablename, v):
199+
if execute(base, tablename, defined):
200200
result = result + 1
201201
else:
202202
print('err\n')
203203
base.disconnect()
204204
return result
205205
except (KeyboardInterrupt, SystemExit):
206206
print("Interrupt")
207-
return 0
207+
sys.exit(0)
208208

209-
def _cpeList(sql_user, sql_password, sql_host, sql_port, sql_database, tablename, ID, c, r, variable):
209+
def _cpeList(sql_user, sql_password, sql_host, sql_port, sql_database, tablename, r, cpe_list, variable):
210210
base = initialize(sql_user, sql_password, sql_host, sql_port)
211211
base.use_database(sql_database)
212212
result = 0
213-
cpe_list_clone = list(c)
213+
cpe_list_clone = list(cpe_list)
214214
cpe_list_clone.reverse()
215215

216216
affects_vendor_name = r[0]
@@ -229,32 +229,39 @@ def _cpeList(sql_user, sql_password, sql_host, sql_port, sql_database, tablename
229229
sql_host = None
230230
sql_password = None
231231

232+
sql_data = {'sql_user' : False, 'sql_database' : False, 'sql_port' : False, 'sql_host' : False, 'sql_password' : False, 'tablename': False}
233+
filter_vars = lambda l: isinstance(l[1], str) and sql_data.get(l[0], True) and l[1] is not None
234+
232235
while len(cpe_list_clone) != 0:
233236
cp = cpe_list_clone.pop().split('||')
234237
nodes_cpe_vulnerable = cp[0]
235238
nodes_cpe_cpe22uri = cp[1]
236239
nodes_cpe_cpe23uri = cp[2]
237240
nodes_cpe = cp[3]
241+
238242
cp = None
239-
v = dict(vars()).update(variable)
240-
if execute(base, tablename, v):
243+
current_variable = dict(vars())
244+
245+
defined = dict((i, j) for i, j in filter(filter_vars, list(current_variable.items())))
246+
defined.update(variable)
247+
248+
if execute(base, tablename, defined):
241249
result = result + 1
242250
else:
243251
print('sub-process err\n')
244252
base.disconnect()
245253
return result
246254

247-
def execute(base, tablename, v):
255+
def execute(base, tablename, variable):
248256
query_header = "("
249257
query_format = "("
250258
query_argument = []
251259

252260
# automatic insert value
253-
for variable_name in v.keys():
254-
if isinstance(v[variable_name], str) and not variable_name == "tablename":
255-
query_header += variable_name + ','
256-
query_format += "%s,"
257-
query_argument.append(v[variable_name])
261+
for variable_name in variable.keys():
262+
query_header += variable_name + ','
263+
query_format += "%s,"
264+
query_argument.append(variable[variable_name])
258265

259266
query_header = query_header[:-1]
260267
query_header += ")"
@@ -466,25 +473,29 @@ def find_key(self, element, pattern):
466473
return key
467474

468475
def table_insert(self, tablename, jsonCollection):
469-
result = 0
470-
finish = 0
471-
print("USE_MAX_THREAD_COUNT=%d" % self._usuge_thread)
472-
worker = SQLWorker(workstation).initialize(self._usuge_thread)
473-
self._worker = worker
474-
475-
print("Inserting value ...")
476-
for jsonElement in jsonCollection:
477-
worker.reserve(self.user, self.password, self.host, self.port, self.database, tablename, jsonElement)
478-
479-
for ps in worker.as_complete():
480-
result = result + ps.result()
481-
finish = finish + 1
482-
sys.stdout.write("\rFinish CVE(s): %d :: Processed amount: %d" % (finish, result))
483-
sys.stdout.flush()
476+
try:
477+
result = 0
478+
finish = 0
479+
print("USE_MAX_THREAD_COUNT=%d" % self._usuge_thread)
480+
worker = SQLWorker(workstation).initialize(self._usuge_thread)
481+
self._worker = worker
482+
483+
print("Inserting value ...")
484+
for jsonElement in jsonCollection:
485+
worker.reserve(self.user, self.password, self.host, self.port, self.database, tablename, jsonElement)
486+
487+
for ps in worker.as_complete():
488+
result = result + ps.result()
489+
finish = finish + 1
490+
sys.stdout.write("\rFinish CVE(s): %d :: Processed amount: %d" % (finish, result))
491+
sys.stdout.flush()
484492

485-
print("\nAll data insert completed.")
493+
print("\nAll data insert completed.")
486494

487-
self._worker.terminate()
495+
self._worker.terminate()
496+
except (KeyboardInterrupt, SystemExit):
497+
self._worker.terminate()
498+
sys.exit(0)
488499

489500
def auto_serialize(self, obj, jsonDefault, o=None):
490501
default_type = {str: True,bool: True,float: True,str: True,int: True}

0 commit comments

Comments
 (0)