-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchcve.py
133 lines (113 loc) · 5.11 KB
/
searchcve.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
from vulners import VulnersApi
import os
from prettytable import PrettyTable
from termcolor import colored
import sys
import time
def print_banner():
banner = """
███████╗██████╗ ██╗ ██╗██████╗ ██████╗██╗ ██╗ ██████╗██╗ ██╗███████╗
██╔════╝╚════██╗██║ ██║██╔══██╗██╔════╝██║ ██║██╔════╝██║ ██║██╔════╝
███████╗ █████╔╝███████║██████╔╝██║ ███████║██║ ██║ ██║█████╗
╚════██║ ╚═══██╗╚════██║██╔══██╗██║ ██╔══██║██║ ╚██╗ ██╔╝██╔══╝
███████║██████╔╝ ██║██║ ██║╚██████╗██║ ██║╚██████╗ ╚████╔╝ ███████╗
╚══════╝╚═════╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═════╝ ╚═══╝ ╚══════╝
"""
print(colored(banner, 'cyan'))
print(colored("Developed by: ", 'white') + colored("D4X3D", 'green'))
print(colored("GitHub: ", 'white') + colored("https://github.com/Davidson0071", 'blue'))
print("\n" + "="*80 + "\n")
def load_api_key():
try:
if not os.path.exists('api.txt'):
key = input(colored("Please enter your Vulners API key: ", 'yellow'))
with open('api.txt', 'w') as f:
f.write(key)
print(colored("\n[+] API key saved successfully!", 'green'))
else:
with open('api.txt', 'r') as f:
key = f.read().strip()
return key
except Exception as e:
print(colored(f"\n[-] Error loading API key: {str(e)}", 'red'))
sys.exit(1)
def get_search_parameters():
query = input(colored("\nEnter search query (e.g., 'php 8.1'): ", 'yellow'))
while True:
try:
limit = int(input(colored("Enter result limit (3-5 recommended): ", 'yellow')))
if limit < 1:
print(colored("[-] Limit must be at least 1", 'red'))
continue
break
except ValueError:
print(colored("[-] Please enter a valid number", 'red'))
return query, limit
def search_vulnerabilities(api_key, query, limit):
try:
vulners_api = VulnersApi(api_key=api_key)
results = vulners_api.find_all(query=query, limit=limit)
return results
except Exception as e:
print(colored(f"\n[-] Error during search: {str(e)}", 'red'))
return None
def get_cvss_score(result):
cvss = result.get('cvss')
if isinstance(cvss, dict):
for key in ['score', 'baseScore', 'cvss', 'CVSS']:
if key in cvss:
return str(cvss[key])
return 'N/A'
elif cvss is not None:
return str(cvss)
return 'N/A'
def display_results(results):
if not results:
print(colored("\n[-] No results found", 'red'))
return
table = PrettyTable()
table.field_names = [
colored("Title", 'cyan'),
colored("CVSS", 'yellow'),
colored("CVE List", 'green'),
colored("Type", 'magenta'),
colored("URL", 'blue')
]
table.align = "l"
table.max_width = 40
for result in results:
cvss_str = get_cvss_score(result)
if cvss_str == 'N/A':
cvss_colored = colored(cvss_str, 'white')
else:
try:
cvss_float = float(cvss_str)
cvss_colored = colored(cvss_str,
'red' if cvss_float >= 7.0 else
'yellow' if cvss_float >= 4.0 else
'green')
except ValueError:
cvss_colored = colored(cvss_str, 'white')
table.add_row([
result.get('title', 'N/A')[:40] + ('...' if len(result.get('title', '')) > 40 else ''),
cvss_colored,
'\n'.join(result.get('cvelist', ['N/A']))[:30],
result.get('bulletinFamily', 'N/A'),
result.get('href', 'N/A')[:40]
])
print("\n" + str(table))
def main():
print_banner()
api_key = load_api_key()
while True:
query, limit = get_search_parameters()
print(colored("\n[+] Searching...", 'cyan'))
time.sleep(1) # Add a small delay for better UX
results = search_vulnerabilities(api_key, query, limit)
if results:
display_results(results)
if input(colored("\nWould you like to perform another search? (y/n): ", 'yellow')).lower() != 'y':
break
print(colored("\nThanks 534rchCVE! Goodbye!\n", 'green'))
if __name__ == "__main__":
main()