-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcve_search_cli.py
More file actions
executable file
·129 lines (121 loc) · 5.25 KB
/
cve_search_cli.py
File metadata and controls
executable file
·129 lines (121 loc) · 5.25 KB
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
#!/usr/bin/env python3
import requests
import argparse
import sys
from datetime import datetime
try:
from rich import print
from rich.console import Console
from rich.panel import Panel
from rich.text import Text
except ImportError:
print("[bold red]Rich library not found. Please install with 'pip install rich'.")
sys.exit(1)
console = Console()
BASE_URL = "https://cve.circl.lu/api"
NVD_BASE_URL = "https://services.nvd.nist.gov/rest/json/cves/2.0"
def format_date(date_str):
if not date_str:
return "N/A"
try:
return datetime.fromisoformat(date_str.replace('Z', '+00:00')).strftime('%Y-%m-%d %H:%M')
except Exception:
return date_str
def search_cve_by_id(cve_id):
url = f"{BASE_URL}/cve/{cve_id}"
resp = requests.get(url)
if resp.status_code == 200:
data = resp.json()
cve_id = data.get('cveMetadata', {}).get('cveId', data.get('id'))
published = format_date(data.get('cveMetadata', {}).get('datePublished', data.get('Published')))
modified = format_date(data.get('cveMetadata', {}).get('dateUpdated', data.get('Modified')))
cvss = None
severity = None
metrics = data.get('containers', {}).get('cna', {}).get('metrics', [])
if metrics:
cvss = metrics[0].get('cvssV3_1', {}).get('baseScore')
severity = metrics[0].get('cvssV3_1', {}).get('baseSeverity')
if not cvss:
cvss = data.get('cvss')
summary = data.get('summary')
if not summary:
cna = data.get('containers', {}).get('cna', {})
descriptions = cna.get('descriptions', [])
if descriptions:
summary = descriptions[0].get('value')
references = []
for ref in data.get('containers', {}).get('cna', {}).get('references', []):
references.append(ref.get('url'))
# Proper rich formatting
panel_text = Text()
panel_text.append(f"CVE ID: ", style="bold yellow")
panel_text.append(f"{cve_id}\n", style="white")
panel_text.append(f"Published: ", style="bold green")
panel_text.append(f"{published}\n", style="white")
panel_text.append(f"Modified: ", style="bold green")
panel_text.append(f"{modified}\n", style="white")
panel_text.append(f"CVSS Score: ", style="bold magenta")
panel_text.append(f"{cvss if cvss else 'N/A'}\n", style="white")
panel_text.append(f"Severity: ", style="bold magenta")
panel_text.append(f"{severity if severity else 'N/A'}\n\n", style="white")
panel_text.append(f"Description:\n", style="bold cyan")
panel_text.append(f"{summary if summary else 'No description available.'}\n\n", style="white")
if references:
panel_text.append("References:\n", style="bold blue")
for ref in references:
panel_text.append(f" {ref}\n", style="blue underline")
console.print(Panel(panel_text, title=f"{cve_id}", expand=False, border_style="red"))
else:
console.print(f"[bold red]Error: CVE {cve_id} not found.")
def search_cve_by_keyword(keyword):
params = {"keywordSearch": keyword, "resultsPerPage": 5}
resp = requests.get(NVD_BASE_URL, params=params)
if resp.status_code == 200:
data = resp.json()
results = data.get('vulnerabilities', [])
if not results:
console.print(f"[bold red]No CVEs found for keyword: {keyword}")
return
for item in results:
cve = item.get('cve', {})
cve_id = cve.get('id')
if cve_id:
search_cve_by_id(cve_id)
else:
console.print(f"[bold red]Error: Could not fetch CVEs for keyword: {keyword}")
def interactive_menu():
console.print("[bold green]\n==============================\n[bold yellow]Made by DEBASIS - CVE Checker CLI\n==============================\n", style="bold green")
while True:
console.print("[bold cyan]\nChoose an option:")
console.print("[bold magenta]1.[/] Search by CVE ID")
console.print("[bold magenta]2.[/] Search by keyword in description")
console.print("[bold magenta]3.[/] Exit")
choice = input("Enter choice (1/2/3): ").strip()
if choice == '1':
cve_id = input("Enter CVE ID (e.g., CVE-2025-55184): ").strip()
search_cve_by_id(cve_id)
elif choice == '2':
keyword = input("Enter keyword (e.g., wordpress, plugin, vuln): ").strip()
search_cve_by_keyword(keyword)
elif choice == '3':
console.print("[bold green]Goodbye!")
break
else:
console.print("[bold red]Invalid choice. Please try again.")
def main():
parser = argparse.ArgumentParser(description="CVE Search CLI Tool")
parser.add_argument("--id", help="Search CVE by ID, e.g., CVE-2024-12345")
parser.add_argument("--keyword", help="Search CVEs by keyword in description")
args = parser.parse_args()
if args.id:
search_cve_by_id(args.id)
elif args.keyword:
search_cve_by_keyword(args.keyword)
else:
interactive_menu()
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
console.print("\n[bold yellow]Interrupted by user. Exiting.[/]")
sys.exit(130)