-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
77 lines (57 loc) · 2.56 KB
/
Copy pathmain.py
File metadata and controls
77 lines (57 loc) · 2.56 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
import sys
from core.scanner import run_nmap_scan, run_nmap_scan_no_ping, run_nmap_network_scan
from core.parser import parse_nmap_xml, has_open_ports
from core.analyzer import analyze_with_ollama
from core.reporter import build_report, build_network_report, save_report
from core.utils import ensure_directories, timestamp
def is_network_target(target: str) -> bool:
return "/" in target
def main() -> None:
if len(sys.argv) < 2:
print("Usage: python3 main.py <target> [mode]")
print("Examples:")
print(" python3 main.py 192.168.20.103")
print(" python3 main.py 192.168.20.103 dual")
print(" python3 main.py 192.168.20.103 offensive")
print(" python3 main.py 192.168.20.103 defensive")
print(" python3 main.py 192.168.20.0/24")
sys.exit(1)
target = sys.argv[1]
mode = sys.argv[2] if len(sys.argv) > 2 else "dual"
ensure_directories()
ts = timestamp()
safe_target = target.replace("/", "_")
report_path = f"reports/{safe_target}_{ts}.md"
if is_network_target(target):
scan_base = f"scans/{safe_target}_{ts}"
print(f"[+] Network overview mode: {target}")
xml_path, scan_mode = run_nmap_network_scan(target, scan_base)
print(f"[+] Scan saved: {xml_path}")
print("[+] Parsing XML")
parsed = parse_nmap_xml(str(xml_path))
print("[+] Generating network overview report")
report_text = build_network_report(target, parsed, scan_mode)
final_report = save_report(report_text, report_path)
print(f"[+] Done. Report saved to: {final_report}")
return
print(f"[+] Mode: {mode}")
scan_base = f"scans/{safe_target}_{ts}"
print(f"[+] Starting scan on {target}")
xml_path, scan_mode = run_nmap_scan(target, scan_base)
print(f"[+] Scan saved: {xml_path}")
print("[+] Parsing XML")
parsed = parse_nmap_xml(str(xml_path))
if not has_open_ports(parsed):
print("[!] No open ports found. Retrying with -Pn...")
scan_base_retry = f"scans/{safe_target}_{ts}_pn"
xml_path, scan_mode = run_nmap_scan_no_ping(target, scan_base_retry)
print(f"[+] Retry scan saved: {xml_path}")
parsed = parse_nmap_xml(str(xml_path))
print("[+] Analyzing with local LLM")
analysis = analyze_with_ollama(parsed, mode=mode)
print("[+] Generating report")
report_text = build_report(target, parsed, analysis, scan_mode)
final_report = save_report(report_text, report_path)
print(f"[+] Done. Report saved to: {final_report}")
if __name__ == "__main__":
main()