2
2
import re
3
3
from termcolor import colored
4
4
from datetime import datetime
5
+ import json
6
+ from pyExploitDb import PyExploitDb
5
7
6
8
art = """
7
9
_______ _ _ _______
8
10
|__ __| | | |__ __|
9
11
| | | |__ _ __ ___ __ _| |_ | |_ __ __ _ ___ ___ _ __
10
12
| | | '_ \| '__/ _ \/ _` | __|| | '__/ _` |/ __/ _ \ '__|
11
13
| | | | | | | | __/ (_| | |_ | | | | (_| | (_| __/ |
12
- |_| |_| |_|_| \___|\__,_|\__||_|_| \__,_|\___\___|_|
14
+ |_| |_| |_|_| \___|\__,_|\__||_|_| \__,_|\___\___|_| Version 2.0
13
15
A Script to identify CVE using CPE by name & version
14
16
Credit: @FR13ND0x7F @0xCaretaker @meppohak5
15
17
"""
@@ -39,46 +41,61 @@ def synk_db(cve_id):
39
41
snyk_short_name = a_tag_matches [0 ].lstrip ().rstrip ()
40
42
return snyk_short_name
41
43
42
- def fetch_cve_details (cpe_strings ):
44
+ def fetch_cve_details (cpe_string ):
43
45
base_url = "https://services.nvd.nist.gov/rest/json/cves/1.0"
44
46
results = []
45
47
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 } "
49
50
50
- response = requests .get (url )
51
+ response = requests .get (url )
52
+
53
+ try :
51
54
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 )
82
99
83
100
return results
84
101
@@ -95,32 +112,21 @@ def fetch_cve_details(cpe_strings):
95
112
for cpe_string in cpe_strings :
96
113
print (colored (f" { cpe_string } " , "green" ))
97
114
98
- export_option = input (colored ("\n Do 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 ("\n CVE Details" , "cyan" , attrs = ["underline" ]))
105
119
for result in results :
106
- f . write ( f"CVE ID: { result ['CVE ID' ]} \n " )
120
+ print ( colored ( f"CVE ID: { result ['CVE ID' ]} " , "white" ) )
107
121
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" ) )
110
124
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 ("\n CVE 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 :
126
132
print (colored ("CPEs not found for the provided component and version." , "red" ))
0 commit comments