Skip to content

Commit d9d1269

Browse files
authored
Update threattracer.py
1 parent cc5dfb4 commit d9d1269

File tree

1 file changed

+67
-61
lines changed

1 file changed

+67
-61
lines changed

threattracer.py

Lines changed: 67 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
import re
33
from termcolor import colored
44
from datetime import datetime
5+
import json
6+
from pyExploitDb import PyExploitDb
57

68
art = """
79
_______ _ _ _______
810
|__ __| | | |__ __|
911
| | | |__ _ __ ___ __ _| |_ | |_ __ __ _ ___ ___ _ __
1012
| | | '_ \| '__/ _ \/ _` | __|| | '__/ _` |/ __/ _ \ '__|
1113
| | | | | | | | __/ (_| | |_ | | | | (_| | (_| __/ |
12-
|_| |_| |_|_| \___|\__,_|\__||_|_| \__,_|\___\___|_|
14+
|_| |_| |_|_| \___|\__,_|\__||_|_| \__,_|\___\___|_| Version 2.0
1315
A Script to identify CVE using CPE by name & version
1416
Credit: @FR13ND0x7F @0xCaretaker @meppohak5
1517
"""
@@ -39,46 +41,61 @@ def synk_db(cve_id):
3941
snyk_short_name = a_tag_matches[0].lstrip().rstrip()
4042
return snyk_short_name
4143

42-
def fetch_cve_details(cpe_strings):
44+
def fetch_cve_details(cpe_string):
4345
base_url = "https://services.nvd.nist.gov/rest/json/cves/1.0"
4446
results = []
4547

46-
for cpe_string in cpe_strings:
47-
cve_query_string = ":".join(cpe_string.split(":")[1:5]) # Extract relevant CPE part (vendor, product, version, update)
48-
url = f"{base_url}?cpeMatchString=cpe:/{cve_query_string}"
48+
cve_query_string = ":".join(cpe_string.split(":")[1:5]) # Extract relevant CPE part (vendor, product, version, update)
49+
url = f"{base_url}?cpeMatchString=cpe:/{cve_query_string}"
4950

50-
response = requests.get(url)
51+
response = requests.get(url)
52+
53+
try:
5154
data = response.json()
52-
53-
if "result" in data:
54-
cves = data["result"]["CVE_Items"]
55-
for cve_item in cves:
56-
cve_id = cve_item["cve"]["CVE_data_meta"]["ID"]
57-
snyk_short_name = synk_db(cve_id)
58-
59-
description = cve_item["cve"]["description"]["description_data"][0]["value"]
60-
link = f"https://nvd.nist.gov/vuln/detail/{cve_id}"
61-
62-
weaknesses = []
63-
if "problemtype" in cve_item["cve"]:
64-
for problem_type in cve_item["cve"]["problemtype"]["problemtype_data"]:
65-
for description in problem_type["description"]:
66-
weaknesses.append(description["value"])
67-
68-
if "description_data" in cve_item["cve"]["description"]:
69-
description_text = cve_item["cve"]["description"]["description_data"][0]["value"]
70-
else:
71-
description_text = "Description not available."
72-
73-
cve_details = {
74-
"CVE ID": cve_id,
75-
"Short Name": snyk_short_name,
76-
"Description": description_text,
77-
"Weaknesses": ", ".join(weaknesses),
78-
"Link": link
79-
}
80-
81-
results.append(cve_details)
55+
except json.JSONDecodeError:
56+
print(colored(f"Error decoding JSON for CPE: {cpe_string}. Skipping.", "red"))
57+
return []
58+
59+
if "result" in data:
60+
cves = data["result"]["CVE_Items"]
61+
for cve_item in cves:
62+
cve_id = cve_item["cve"]["CVE_data_meta"]["ID"]
63+
snyk_short_name = synk_db(cve_id)
64+
65+
description = cve_item["cve"]["description"]["description_data"][0]["value"]
66+
link = f"https://nvd.nist.gov/vuln/detail/{cve_id}"
67+
68+
weaknesses = []
69+
if "problemtype" in cve_item["cve"]:
70+
for problem_type in cve_item["cve"]["problemtype"]["problemtype_data"]:
71+
for description in problem_type["description"]:
72+
weaknesses.append(description["value"])
73+
74+
if "description_data" in cve_item["cve"]["description"]:
75+
description_text = cve_item["cve"]["description"]["description_data"][0]["value"]
76+
else:
77+
description_text = "Description not available."
78+
79+
# Check for public exploit using pyExploitDb
80+
pEdb = PyExploitDb()
81+
pEdb.debug = False
82+
pEdb.openFile()
83+
exploit_status = pEdb.searchCve(cve_id)
84+
if exploit_status:
85+
exploit_status = "Public Exploit Found"
86+
else:
87+
exploit_status = "No Public Exploit Found"
88+
89+
cve_details = {
90+
"CVE ID": cve_id,
91+
"Short Name": snyk_short_name,
92+
"Description": description_text,
93+
"Weaknesses": ", ".join(weaknesses),
94+
"Link": link,
95+
"Exploit Status": exploit_status
96+
}
97+
98+
results.append(cve_details)
8299

83100
return results
84101

@@ -95,32 +112,21 @@ def fetch_cve_details(cpe_strings):
95112
for cpe_string in cpe_strings:
96113
print(colored(f" {cpe_string}", "green"))
97114

98-
export_option = input(colored("\nDo you want to export results to a text document? (yes/no): ", "yellow"))
99-
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
100-
filename = f"{component}_{version}_{timestamp}.txt"
101-
102-
if export_option.lower() == "yes":
103-
results = fetch_cve_details(cpe_strings)
104-
with open(filename, "w") as f:
115+
for cpe_string in cpe_strings:
116+
results = fetch_cve_details(cpe_string)
117+
if results:
118+
print(colored("\nCVE Details", "cyan", attrs=["underline"]))
105119
for result in results:
106-
f.write(f"CVE ID: {result['CVE ID']}\n")
120+
print(colored(f"CVE ID: {result['CVE ID']}", "white"))
107121
if result["Short Name"]:
108-
f.write(f"Short Name: {result['Short Name']}\n")
109-
f.write(f"Description: {result['Description']}\n")
122+
print(colored(f"Short Name: {result['Short Name']}", "light_blue"))
123+
print(colored(f"Description: {result['Description']}", "yellow"))
110124
if result["Weaknesses"]:
111-
f.write(f"Weaknesses: {result['Weaknesses']}\n")
112-
f.write(f"Link: {result['Link']}\n\n")
113-
print(colored(f"Results exported to '{filename}'", "green"))
114-
115-
results = fetch_cve_details(cpe_strings)
116-
for result in results:
117-
print(colored("\nCVE Details", "cyan", attrs=["underline"]))
118-
print(colored(f"CVE ID: {result['CVE ID']}", "red"))
119-
if result["Short Name"]:
120-
print(colored(f"Short Name: {result['Short Name']}", "green"))
121-
print(colored(f"Description: {result['Description']}", "yellow"))
122-
if result["Weaknesses"]:
123-
print(colored(f"Weaknesses: {result['Weaknesses']}", "magenta"))
124-
print(colored(f"Link: {result['Link']}\n", "blue"))
125-
else:
125+
print(colored(f"Weaknesses: {result['Weaknesses']}", "magenta"))
126+
print(colored(f"Link: {result['Link']}", "blue"))
127+
if result["Exploit Status"] == "Public Exploit Found":
128+
print(colored(f"Exploit Status: {result['Exploit Status']}\n", "red"))
129+
else:
130+
print(colored(f"Exploit Status: {result['Exploit Status']}\n", "green"))
131+
else:
126132
print(colored("CPEs not found for the provided component and version.", "red"))

0 commit comments

Comments
 (0)