-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_menu.py
More file actions
387 lines (293 loc) · 11.2 KB
/
cli_menu.py
File metadata and controls
387 lines (293 loc) · 11.2 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
"""
cli_menu.py
Phase 11 Enhancement — Interactive CLI Menu System
Provides a user-friendly menu-driven interface instead of
requiring command-line arguments.
Usage:
python cli_menu.py
"""
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from utils.terminal_ui import header, success, error, info, warning
def clear_screen():
"""Clear the terminal screen."""
os.system('cls' if os.name == 'nt' else 'clear')
def print_menu(title: str, options: list) -> None:
"""
Print a menu with numbered options.
Args:
title: menu title
options: list of option strings
"""
print(f"\n{title}")
print("=" * len(title))
for idx, opt in enumerate(options, 1):
print(f" {idx}. {opt}")
print(f" 0. Exit")
print()
def get_choice(max_option: int) -> int:
"""
Get a numeric choice from the user.
Args:
max_option: maximum valid option number
Returns:
Selected option number (0 = exit)
"""
while True:
try:
choice = input("Select an option: ").strip()
num = int(choice)
if 0 <= num <= max_option:
return num
else:
error(f"Invalid choice. Enter 0-{max_option}")
except ValueError:
error("Please enter a number")
except KeyboardInterrupt:
print()
return 0
def main_menu():
"""Main CLI menu."""
clear_screen()
header("SEC PLATFORM — Interactive Menu")
while True:
options = [
"Run single target scan (FULL ANALYSIS)",
"Run multi-target scan",
"View scan reports (dashboard)",
"Generate PDF report",
"Generate AI analysis report",
"Generate CVE-enhanced report",
"Compare two scans",
"Run SOC monitoring",
"Test CI/CD security gate",
"Update CVE database",
"Run async benchmark",
"Settings & Configuration",
]
print_menu("MAIN MENU", options)
choice = get_choice(len(options))
if choice == 0:
success("Goodbye!")
sys.exit(0)
elif choice == 1:
single_scan_menu()
elif choice == 2:
multi_scan_menu()
elif choice == 3:
view_dashboard()
elif choice == 4:
generate_pdf_menu()
elif choice == 5:
ai_analysis_menu()
elif choice == 6:
cve_report_menu()
elif choice == 7:
compare_scans_menu()
elif choice == 8:
soc_menu()
elif choice == 9:
cicd_gate_menu()
elif choice == 10:
update_cve_menu()
elif choice == 11:
benchmark_menu()
elif choice == 12:
settings_menu()
def single_scan_menu():
"""Single target scan submenu."""
clear_screen()
header("SINGLE TARGET SCAN (FULL ANALYSIS)")
target = input("\nEnter target URL (e.g., https://example.com): ").strip()
if not target:
error("No target provided")
input("\nPress Enter to continue...")
return
print("\nScan options:")
print(" 1. Full analysis (All features: injection + AI + CVE + reports)")
print(" 2. Quick scan (No AI/CVE, faster)")
print(" 3. Basic scan (Core scanners only)")
opt = input("\nSelect option (1-3, default=1): ").strip() or "1"
if opt == "1":
cmd = f'echo "{target}" | python run_scan.py --full-analysis'
elif opt == "2":
cmd = f'echo "{target}" | python run_scan.py --skip-ai --skip-cve'
else:
cmd = f'echo "{target}" | python run_scan.py --skip-ai --skip-cve --skip-injection --no-reports'
info(f"Scanning {target}...")
os.environ["SEC_AUTHORIZED"] = "yes"
os.system(cmd)
input("\nPress Enter to continue...")
def multi_scan_menu():
"""Multi-target scan submenu."""
clear_screen()
header("MULTI-TARGET SCAN")
info("This will scan all targets listed in targets.txt")
workers = input("\nNumber of parallel workers (default: 1): ").strip()
workers = workers if workers else "1"
info(f"Starting multi-target scan with {workers} workers...")
os.system(f"python orchestrator/multi_target_runner.py --workers {workers}")
input("\nPress Enter to continue...")
def view_dashboard():
"""Launch the web dashboard."""
clear_screen()
header("WEB DASHBOARD")
info("Starting dashboard server on http://localhost:5000")
info("Press Ctrl+C to stop the server")
input("\nPress Enter to start...")
os.system("python dashboard/app.py")
def generate_pdf_menu():
"""Generate PDF report menu."""
clear_screen()
header("GENERATE PDF REPORT")
# List available reports
reports_dir = "reports"
if os.path.exists(reports_dir):
files = [f for f in os.listdir(reports_dir) if f.endswith(".json") and not f.startswith("multi")]
if files:
print("\nAvailable reports:")
for idx, f in enumerate(files, 1):
print(f" {idx}. {f}")
choice = input(f"\nSelect report (1-{len(files)}) or Enter to cancel: ").strip()
if choice.isdigit() and 1 <= int(choice) <= len(files):
report_path = os.path.join(reports_dir, files[int(choice) - 1])
info(f"Generating PDF from {report_path}...")
os.system(f"python reports/pdf_generator.py {report_path}")
else:
warning("Cancelled")
else:
warning("No scan reports found. Run a scan first.")
else:
warning("Reports directory not found")
input("\nPress Enter to continue...")
def compare_scans_menu():
"""Compare scans menu."""
clear_screen()
header("COMPARE SCANS")
target = input("\nEnter target URL to compare (or leave blank for latest 2 scans): ").strip()
if target:
os.system(f"python reports/comparison_reporter.py {target}")
else:
warning("Comparing latest 2 scans overall...")
os.system("python -c \"from reports.comparison_reporter import compare_latest_two_scans; print(generate_comparison_report_text(compare_latest_two_scans()))\"")
input("\nPress Enter to continue...")
def soc_menu():
"""SOC monitoring menu."""
clear_screen()
header("SOC CONTINUOUS MONITORING")
target = input("\nEnter target URL (or leave blank to use targets.txt): ").strip()
info("Running full SOC pipeline...")
if target:
os.system(f"python soc/continuous_monitoring.py {target}")
else:
os.system("python soc/continuous_monitoring.py")
input("\nPress Enter to continue...")
def cicd_gate_menu():
"""CI/CD gate testing menu."""
clear_screen()
header("CI/CD SECURITY GATE")
info("This will test the latest scan report against the security gate policy")
max_risk = input("\nMax allowed risk score (default: 30): ").strip()
max_risk = max_risk if max_risk else "30"
fail_on = input("Fail on severities (default: critical high): ").strip()
fail_on = fail_on if fail_on else "critical high"
cmd = f"python cicd/security_gate.py --max-risk {max_risk} --fail-on {fail_on}"
os.system(cmd)
input("\nPress Enter to continue...")
def schedule_menu():
"""Scheduled scans menu."""
clear_screen()
header("SCHEDULED SCANS")
interval = input("\nScan interval in hours (default: 24): ").strip()
interval = interval if interval else "24"
mode = input("Scan mode (basic/soc, default: basic): ").strip().lower()
mode_flag = "--soc" if mode == "soc" else ""
info(f"Starting scheduled scanner (every {interval}h, mode={mode or 'basic'})")
info("Press Ctrl+C to stop")
input("\nPress Enter to start...")
os.system(f"python schedulers/scheduled_scan.py --interval {interval} {mode_flag}")
def benchmark_menu():
"""Async benchmark menu."""
clear_screen()
header("ASYNC PERFORMANCE BENCHMARK")
target = input("\nEnter target URL: ").strip()
if not target:
error("No target provided")
input("\nPress Enter to continue...")
return
info("Running sync vs async benchmark...")
os.system(f"python scanners/async_scanner.py --benchmark {target}")
input("\nPress Enter to continue...")
def settings_menu():
"""Settings and configuration menu."""
clear_screen()
header("SETTINGS & CONFIGURATION")
print("\nConfiguration files:")
print(" • targets.txt — Multi-target URL list")
print(" • requirements.txt — Python dependencies")
print(" • ai_feedback.json — AI trust model feedback")
print()
print("Environment variables:")
print(" • SEC_AUTHORIZED=yes — Skip authorization prompts")
print()
input("Press Enter to return to main menu...")
if __name__ == "__main__":
try:
main_menu()
except KeyboardInterrupt:
print("\n")
success("Goodbye!")
sys.exit(0)
def ai_analysis_menu():
"""AI analysis submenu."""
clear_screen()
header("AI DEEP ANALYSIS")
options = [
"Analyze latest scan with AI",
"Generate AI-enhanced report (JSON + Markdown)",
"Run false positive analysis",
"View AI model status",
]
print_menu("AI ANALYSIS OPTIONS", options)
choice = get_choice(len(options))
if choice == 0:
return
elif choice == 1:
info("Running AI deep analysis on latest scan...")
os.system("python reports/ai_report_generator.py")
elif choice == 2:
info("Generating AI-enhanced reports...")
os.system("python reports/ai_report_generator.py")
elif choice == 3:
info("Running false positive analysis...")
os.system("python ai_engine/false_positive_filter.py")
elif choice == 4:
info("AI Model Status:")
print("\n Models: DistilBERT (67MB) + MiniLM (23MB)")
print(" Location: .ai_models_cache/")
print(" First run: auto-downloads models")
print(" GPU: Not required (runs on CPU)")
print(" API keys: None needed (100% local)")
input("\nPress Enter to continue...")
# Update main_menu to add AI option
# Insert before line with "Settings & Configuration"
def cve_report_menu():
"""CVE-enhanced report generation menu."""
clear_screen()
header("CVE-ENHANCED REPORT")
info("Generating CVE-enhanced report with exploit/PoC tracking...")
os.system("python reports/cve_enhanced_report.py")
input("\nPress Enter to continue...")
def update_cve_menu():
"""CVE database update menu."""
clear_screen()
header("UPDATE CVE DATABASE")
days = input("\nFetch CVEs from last N days (default: 30): ").strip() or "30"
force = input("Force update even if recent? (y/N): ").strip().lower() == 'y'
cmd = f"python intelligence/cve_updater.py --days {days}"
if force:
cmd += " --force"
info(f"Updating CVE database (last {days} days)...")
os.system(cmd)
input("\nPress Enter to continue...")