Skip to content

Commit b256c7e

Browse files
authored
Update web_utils.py
support multihash search support, requires to specify seaerch term as md5: sha1: sha256: hash1, hash2 etc
1 parent 41f738b commit b256c7e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/cuckoo/common/web_utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,11 +1399,17 @@ def perform_search(
13991399

14001400
if repconf.mongodb.enabled and query_val:
14011401
if term in hash_searches:
1402+
# The file details are uniq, and we store 1 to many. So where hash type is uniq, IDs are list
1403+
split_by = "," if "," in query_val else " "
1404+
query_val = {"$in": [val.strip() for val in query_val.split(split_by)]}
14021405
# The file details are uniq, and we store 1 to many. So where hash type is uniq, IDs are list
14031406
file_docs = list(mongo_find(FILES_COLL, {hash_searches[term]: query_val}, {"_task_ids": 1}))
14041407
if not file_docs:
14051408
return []
1406-
ids = sorted(list(set(file_docs[0]["_task_ids"])), reverse=True)[:search_limit]
1409+
all_ids = []
1410+
for file_doc in file_docs:
1411+
all_ids.extend(file_doc["_task_ids"])
1412+
ids = sorted(list(set(all_ids)), reverse=True)[:search_limit]
14071413
term = "ids"
14081414
mongo_search_query = {"info.id": {"$in": ids}}
14091415
elif isinstance(search_term_map[term], str):

0 commit comments

Comments
 (0)