Skip to content

Commit

Permalink
Update cpe_search with further speedup
Browse files Browse the repository at this point in the history
Also removes memory-based CPE search and increases number of
retrieved related queries to 5.
  • Loading branch information
ra1nb0rn committed Oct 11, 2023
1 parent 061893d commit 904a3ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cpe_search
Submodule cpe_search updated 1 files
+25 −173 cpe_search.py
19 changes: 9 additions & 10 deletions search_vulns.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,16 +345,18 @@ def search_vulns(query, db_cursor=None, software_match_threshold=CPE_SEARCH_THRE
close_cursor_after = False
if not db_cursor:
db_conn_file = sqlite3.connect(DATABASE_FILE)
db_conn_mem = sqlite3.connect(':memory:')
db_conn_file.backup(db_conn_mem)
db_cursor = db_conn_mem.cursor()
# db_cursor = db_conn_file.cursor()
if keep_data_in_memory:
db_conn_mem = sqlite3.connect(':memory:')
db_conn_file.backup(db_conn_mem)
db_cursor = db_conn_mem.cursor()
else:
db_cursor = db_conn_file.cursor()
close_cursor_after = True

# if given query is not already a CPE, retrieve a CPE that matches the query
cpe = query
if not MATCH_CPE_23_RE.match(query):
cpe = search_cpes(query, count=1, threshold=software_match_threshold, keep_data_in_memory=keep_data_in_memory)
cpe = search_cpes(query, count=1, threshold=software_match_threshold)

if not cpe or not cpe[query]:
return None
Expand All @@ -365,7 +367,7 @@ def search_vulns(query, db_cursor=None, software_match_threshold=CPE_SEARCH_THRE

cpe = cpe[query][0][0]
elif not is_good_cpe:
pot_matching_cpe = match_cpe23_to_cpe23_from_dict(cpe, keep_data_in_memory=keep_data_in_memory)
pot_matching_cpe = match_cpe23_to_cpe23_from_dict(cpe)
if pot_matching_cpe:
cpe = pot_matching_cpe

Expand Down Expand Up @@ -394,7 +396,7 @@ def search_vulns_return_cpe(query, db_cursor=None, software_match_threshold=CPE_
cpe, pot_cpes = query, []
if not MATCH_CPE_23_RE.match(query):
is_good_cpe = False
cpes = search_cpes(query, count=4, threshold=0.25, zero_extend_versions=zero_extend_versions, keep_data_in_memory=keep_data_in_memory)
cpes = search_cpes(query, count=5, threshold=0.25, zero_extend_versions=zero_extend_versions)

if not cpes or not cpes[query]:
return {query: {'cpe': None, 'vulns': None, 'pot_cpes': []}}
Expand Down Expand Up @@ -512,9 +514,6 @@ def main():

# get handle for vulnerability database
db_conn_file = sqlite3.connect(DATABASE_FILE)
# db_conn_mem = sqlite3.connect(':memory:')
# db_conn_file.backup(db_conn_mem)
# db_cursor = db_conn_mem.cursor()
db_cursor = db_conn_file.cursor()

# retrieve known vulnerabilities for every query and print them
Expand Down

0 comments on commit 904a3ec

Please sign in to comment.