-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
583 lines (504 loc) · 22.2 KB
/
Copy pathmain.py
File metadata and controls
583 lines (504 loc) · 22.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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
#!/usr/bin/env python3
"""
ARES — Autonomous Reconnaissance & Exploitation System.
For authorized lab environments only (HackTheBox, TryHackMe, personal VMs).
"""
import argparse
import sys
import warnings
warnings.filterwarnings("ignore", message="Unverified HTTPS request")
from dotenv import load_dotenv
load_dotenv()
from rich.console import Console
from rich.panel import Panel
console = Console()
BANNER = r"""
[bold cyan]
█████╗ ██████╗ ███████╗███████╗
██╔══██╗██╔══██╗██╔════╝██╔════╝
███████║██████╔╝█████╗ ███████╗
██╔══██║██╔══██╗██╔══╝ ╚════██║
██║ ██║██║ ██║███████╗███████║
╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝
[/bold cyan][dim]
ARES v6.2 — Autonomous Reconnaissance & Exploitation System
[yellow]For authorized lab environments only[/yellow] (HTB / THM / personal VMs)
[/dim]"""
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="ARES — Autonomous Reconnaissance & Exploitation System",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=(
"Examples:\n"
" python main.py --target 192.168.1.10\n"
" python main.py --target 10.10.10.5 --agent --lang FR\n"
" python main.py --target 10.10.10.5 --exploit --lang EN\n"
" python main.py --network-scan --lang FR\n"
" python main.py --target 192.168.1.50 --mode android\n"
" python main.py --target 192.168.1.50 --mode android --android-shell\n"
" python main.py --target 192.168.1.51 --mode ios\n"
" python main.py --interface wlan0 --mode wireless\n"
" python main.py --phishing --template facebook --port 8080\n"
" python main.py --osint --name 'John Doe' --company example.com\n"
" python main.py --mobile-payload android_basic --lhost 192.168.1.5\n"
" python main.py --mobile-listen --lhost 192.168.1.5 --lport 4444\n"
" python main.py --stego hide --stego-file img.png --stego-secret 'hello'\n"
" python main.py --target 10.10.10.5 --agent --tui\n"
),
)
# ── Target (optional for wireless/phishing/osint modes) ──
parser.add_argument("--target", "-t", default=None,
help="Target: IP, CIDR range, or domain")
parser.add_argument("--mode", default="pentest",
choices=["pentest", "android", "ios", "wireless"],
help="Operation mode (default: pentest)")
# ── Recon ──
parser.add_argument("--recon-only", action="store_true",
help="Stop after Phase 1 recon — no exploitation, no agent loop")
parser.add_argument("--passive-only", "-p", action="store_true",
help="Passive recon only — no direct contact with the target")
parser.add_argument("--output", "-o", default=None,
help="Base output directory (default: ./output/<target>_<timestamp>)")
parser.add_argument("--verbose", "-v", action="store_true",
help="Show all logs in the terminal")
parser.add_argument("--delay", "-d", type=float, default=1.0,
help="Delay in seconds between requests (default: 1.0)")
# ── Reporting ──
parser.add_argument("--lang", default="EN", choices=["EN", "FR"],
help="Report language: EN or FR (default: EN)")
parser.add_argument("--no-pdf", action="store_true",
help="Skip PDF report generation")
parser.add_argument("--no-html", action="store_true",
help="Skip HTML report generation")
# ── Web dashboard (Flask) ──
parser.add_argument("--dashboard", action="store_true",
help="Launch web dashboard after scan completes")
parser.add_argument("--dashboard-port", type=int, default=5000,
help="Dashboard port (default: 5000)")
# ── TUI dashboard (Textual) ──
parser.add_argument("--tui", action="store_true",
help="Launch real-time Textual TUI dashboard during agent run")
# ── Exploitation ──
parser.add_argument("--exploit", action="store_true",
help="Run Phase 3 exploitation after recon")
parser.add_argument("--exploit-only", action="store_true",
help="Skip recon, run exploitation only (requires prior scan session)")
parser.add_argument("--no-msf", action="store_true",
help="Disable Metasploit, use direct tools only")
parser.add_argument("--no-brute", action="store_true",
help="Disable brute force (hydra)")
parser.add_argument("--msf-password", default="msfrpc",
help="Metasploit RPC password (default: msfrpc)")
parser.add_argument("--msf-port", type=int, default=55553,
help="Metasploit RPC port (default: 55553)")
parser.add_argument("--exploit-timeout", type=int, default=300,
help="Timeout per exploit in seconds (default: 300)")
# ── Post-exploitation ──
parser.add_argument("--post-exploit", action="store_true",
help="Run Phase 4 post-exploitation after Phase 3")
parser.add_argument("--post-exploit-only", action="store_true",
help="Run Phase 4 only (requires prior scan session)")
parser.add_argument("--no-persist", action="store_true",
help="Disable persistence installation")
parser.add_argument("--no-pivot", action="store_true",
help="Disable network pivot discovery")
parser.add_argument("--pivot-depth", type=int, default=2,
help="Maximum pivot recursion depth (default: 2)")
# ── Reactive agent (Phase 5) ──
parser.add_argument("--agent", action="store_true",
help="Run Phase 5 reactive AI agent (full autonomous mode)")
parser.add_argument("--agent-timeout", type=int, default=3600,
help="Agent timeout in seconds (default: 3600 = 1h)")
# ── Mobile (Android / iOS) ──
parser.add_argument("--android-port", type=int, default=5555,
help="ADB network port for Android mode (default: 5555)")
parser.add_argument("--ios-password", default="alpine",
help="SSH root password for iOS mode (default: alpine)")
parser.add_argument("--android-serial", default=None,
help="ADB device serial (USB) for Android mode")
parser.add_argument("--android-shell", action="store_true",
help="Drop into interactive ADB shell after connecting (android mode)")
# ── Wireless ──
parser.add_argument("--interface", default="wlan0",
help="Wireless interface for wireless mode (default: wlan0)")
parser.add_argument("--bssid", default=None,
help="Target BSSID for WPA2 capture")
parser.add_argument("--channel", default=None,
help="WiFi channel for WPA2 capture")
parser.add_argument("--wordlist",
default="/usr/share/wordlists/rockyou.txt",
help="Wordlist path for WPA2 cracking")
# ── Phishing ──
parser.add_argument("--phishing", action="store_true",
help="Run authorized phishing simulation")
parser.add_argument("--template", default=None,
choices=["facebook", "gmail", "linkedin", "office365"],
help="Phishing template to clone")
parser.add_argument("--port", type=int, default=8080,
help="Port for phishing capture server (default: 8080)")
parser.add_argument("--site-dir", default=None,
help="Path to already-cloned site directory")
# ── OSINT ──
parser.add_argument("--osint", action="store_true",
help="Run OSINT person search")
parser.add_argument("--name", default=None,
help="Full name for OSINT search")
parser.add_argument("--company", default=None,
help="Company domain for OSINT email pattern generation")
parser.add_argument("--hibp-key", default="",
help="HaveIBeenPwned API key for breach checking")
# ── Network scan ──
parser.add_argument("--network-scan", action="store_true",
help="Scan local network automatically (ping sweep + service detection)")
# ── Mobile payload (lab only) ──
parser.add_argument("--mobile-payload", default=None,
choices=["android_basic", "android_https", "android_shell"],
help="Generate a test Android APK with msfvenom (personal lab only)")
parser.add_argument("--mobile-listen", action="store_true",
help="Start Metasploit multi/handler listener for mobile payload")
parser.add_argument("--lhost", default=None,
help="LHOST for mobile payload / listener (auto-detected if omitted)")
parser.add_argument("--lport", type=int, default=4444,
help="LPORT for mobile payload / listener (default: 4444)")
parser.add_argument("--apk-out", default="lab_test.apk",
help="Output APK filename for --mobile-payload (default: lab_test.apk)")
# ── Steganography ──
parser.add_argument("--stego", default=None,
choices=["hide", "extract", "detect"],
help="Steganography action: hide / extract / detect")
parser.add_argument("--stego-file", default=None,
help="Input file for steganography (image or audio)")
parser.add_argument("--stego-secret", default=None,
help="Secret text to hide (--stego hide only)")
parser.add_argument("--stego-out", default=None,
help="Output file for --stego hide (default: <input>_stego.<ext>)")
return parser.parse_args()
def _require_target(args):
if not args.target:
console.print("[red]--target is required for this mode[/red]")
sys.exit(1)
def run_android_mode(args):
from modules.mobile.android_wifi_attack import AndroidWiFiAttack
attacker = AndroidWiFiAttack(
target_ip=args.target,
interface=args.interface,
lhost=args.lhost,
)
if args.android_shell:
# Skip multi-vector run; connect on 5555 then drop into shell directly
if attacker.attack_adb_open_port():
attacker.interactive_shell()
else:
console.print("[red]Could not connect to Android device via ADB[/red]")
else:
attacker.run_all()
def run_ios_mode(args):
from modules.mobile.ios_scanner import IOSScanner
scanner = IOSScanner(target_ip=args.target)
if scanner.connect_ssh(password=args.ios_password):
info = scanner.get_device_info()
console.print(Panel(
"\n".join(f"[cyan]{k}[/cyan]: {v}" for k, v in info.items()),
title="[bold green]iOS Device Info[/bold green]",
border_style="green",
))
sec = scanner.check_security_config()
console.print(Panel(
"\n".join(f"[yellow]{k}[/yellow]: {v}" for k, v in sec.items()),
title="[bold yellow]Security Config[/bold yellow]",
border_style="yellow",
))
scanner.disconnect()
else:
console.print("[red]Could not connect to iOS device via SSH[/red]")
def run_wireless_mode(args):
from modules.attacks.wireless import WirelessModule
wm = WirelessModule()
console.print(f"[cyan]Scanning networks on {args.interface}...[/cyan]")
networks = wm.scan_networks(interface=args.interface)
for net in networks:
console.print(f" [green]{net['ssid']:<30}[/green] {net['bssid']} ch={net['channel']} enc={net['encryption']}")
if args.bssid and args.channel:
console.print(f"[cyan]Capturing handshake from {args.bssid}...[/cyan]")
cap = wm.capture_handshake(
bssid=args.bssid,
channel=args.channel,
interface=f"{args.interface}mon",
)
if cap:
key = wm.crack_wpa2(cap, wordlist=args.wordlist)
if key:
console.print(f"[bold green]WPA2 passphrase: {key}[/bold green]")
def run_phishing_mode(args):
from modules.attacks.phishing import PhishingModule
ph = PhishingModule()
if args.site_dir:
site = args.site_dir
elif args.template:
console.print(f"[cyan]Cloning {args.template}...[/cyan]")
site = ph.clone_template(args.template)
elif args.target:
console.print(f"[cyan]Cloning {args.target}...[/cyan]")
site = ph.clone_website(args.target)
else:
console.print("[red]Provide --template, --site-dir, or --target for phishing mode[/red]")
sys.exit(1)
ph.inject_capture_hook(site)
ph.start_capture_server(site, port=args.port)
def run_network_scan(args):
from modules.network.network_scanner import NetworkScanner
scanner = NetworkScanner()
devices = scanner.scan_network()
scanner.generate_report(devices, lang=args.lang)
def run_mobile_payload(args):
from modules.mobile.payload_generator import generate_android_apk
generate_android_apk(
lhost=args.lhost,
lport=args.lport,
output=args.apk_out,
payload_type=args.mobile_payload,
)
def run_mobile_listen(args):
from modules.mobile.payload_generator import start_listener
proc = start_listener(lhost=args.lhost, lport=args.lport)
console.print(f"[green]Listener started (PID {proc.pid}) — waiting for session[/green]")
console.print("[dim]Press Ctrl+C to stop[/dim]")
try:
proc.wait()
except KeyboardInterrupt:
proc.terminate()
console.print("\n[yellow]Listener stopped[/yellow]")
def run_stego(args):
from modules.attacks.steganography import SteganographyModule
st = SteganographyModule()
if not args.stego_file:
console.print("[red]--stego-file required[/red]")
sys.exit(1)
if args.stego == "hide":
if not args.stego_secret:
console.print("[red]--stego-secret required for hide action[/red]")
sys.exit(1)
ext = args.stego_file.rsplit(".", 1)[-1].lower()
out = args.stego_out or args.stego_file.rsplit(".", 1)[0] + "_stego." + ext
if ext in ("wav", "mp3", "ogg"):
st.hide_in_audio(args.stego_file, args.stego_secret, output_file=out)
else:
st.hide_in_image(args.stego_file, args.stego_secret, out)
elif args.stego == "extract":
ext = args.stego_file.rsplit(".", 1)[-1].lower()
if ext in ("wav", "mp3", "ogg"):
result = st.extract_from_audio(args.stego_file,
output_file="/tmp/_stego_extracted.txt")
else:
result = st.extract_from_image(args.stego_file)
console.print(f"[green]Extracted:[/green] {result}")
elif args.stego == "detect":
results = st.detect_steganography(args.stego_file)
for tool, output in results.items():
console.print(Panel(str(output) or "[dim]no output[/dim]",
title=f"[cyan]{tool}[/cyan]", border_style="cyan"))
def run_osint_mode(args):
from modules.attacks.osint import OSINTModule
osint = OSINTModule(hibp_api_key=args.hibp_key)
if args.name:
results = osint.search_person(args.name, company=args.company)
if results.get("github"):
console.print(Panel(
"\n".join(f"[cyan]{k}[/cyan]: {v}"
for k, v in results["github"].items() if v),
title=f"[bold green]GitHub — {args.name}[/bold green]",
border_style="green",
))
if results.get("email_patterns"):
console.print("[yellow]Email patterns:[/yellow]")
for email in results["email_patterns"]:
console.print(f" {email}")
if args.target:
info = osint.domain_lookup(args.target)
console.print(Panel(
"\n".join(f"[cyan]{k}[/cyan]: {v}" for k, v in info.items() if v),
title=f"[bold cyan]Domain — {args.target}[/bold cyan]",
border_style="cyan",
))
def main():
args = parse_args()
from ui.intro import show_intro
if args.agent:
mode = "AGENT AUTONOME"
elif args.exploit:
mode = "EXPLOITATION"
elif args.mode == "android":
mode = "ANDROID AUDIT"
elif args.mode == "ios":
mode = "iOS AUDIT"
elif args.mode == "wireless":
mode = "WIRELESS AUDIT"
elif args.phishing:
mode = "PHISHING SIMULATION"
elif args.osint:
mode = "OSINT"
elif args.network_scan:
mode = "NETWORK SCAN"
elif args.mobile_payload:
mode = "MOBILE PAYLOAD"
elif args.mobile_listen:
mode = "MOBILE LISTENER"
elif args.stego:
mode = f"STEGO — {args.stego.upper()}"
else:
mode = "RECONNAISSANCE"
show_intro(target=args.target or "N/A", mode=mode)
# ── Standalone modes (no target required) ──
if args.network_scan:
run_network_scan(args)
return
if args.mobile_payload:
run_mobile_payload(args)
return
if args.mobile_listen:
run_mobile_listen(args)
return
if args.stego:
run_stego(args)
return
# ── Standalone modes (no pentest pipeline) ──
if args.mode == "android":
_require_target(args)
run_android_mode(args)
return
if args.mode == "ios":
_require_target(args)
run_ios_mode(args)
return
if args.mode == "wireless":
run_wireless_mode(args)
return
if args.phishing:
run_phishing_mode(args)
return
if args.osint:
run_osint_mode(args)
return
# ── Standard pentest pipeline (requires --target) ──
_require_target(args)
try:
from core.target import Target
target = Target(args.target)
except Exception as exc:
console.print(f"[red]Invalid target: {exc}[/red]")
sys.exit(1)
try:
from core.session import Session
session = Session(target=target, output_dir=args.output, verbose=args.verbose)
except Exception as exc:
console.print(f"[red]Failed to initialize session: {exc}[/red]")
sys.exit(1)
try:
from core.engine import Engine
engine = Engine(
session=session,
passive_only=args.passive_only,
delay=args.delay,
lang=args.lang,
no_pdf=args.no_pdf,
no_html=args.no_html,
)
engine.run()
except KeyboardInterrupt:
console.print("\n[yellow]Scan interrupted (Ctrl+C)[/yellow]")
session.save_partial_results()
console.print(f"[dim]Partial results: {session.output_dir}[/dim]")
sys.exit(130)
except Exception as exc:
console.print(f"[red]Unexpected error: {exc}[/red]")
if args.verbose:
console.print_exception()
session.save_partial_results()
sys.exit(1)
if args.recon_only:
console.print("[yellow]Mode recon-only — arrêt avant exploitation[/yellow]")
return
exploit_engine = None
if args.exploit or args.exploit_only:
try:
from exploitation.engine import ExploitationEngine
exploit_engine = ExploitationEngine(
session=session,
auto_confirm=False,
no_msf=args.no_msf,
no_brute=args.no_brute,
exploit_timeout=args.exploit_timeout,
msf_password=args.msf_password,
msf_port=args.msf_port,
lang=args.lang,
)
exploit_engine.run()
except KeyboardInterrupt:
console.print("\n[yellow]Exploitation interrupted (Ctrl+C)[/yellow]")
except Exception as exc:
console.print(f"[red]Exploitation error: {exc}[/red]")
if args.verbose:
console.print_exception()
if args.post_exploit or args.post_exploit_only:
try:
from post_exploitation.engine import PostExploitEngine
shared_msf_client = exploit_engine.msf_client if exploit_engine else None
shared_session_ids = exploit_engine.session_ids if exploit_engine else []
post_engine = PostExploitEngine(
session=session,
no_persist=args.no_persist,
no_pivot=args.no_pivot,
pivot_depth=args.pivot_depth,
lang=args.lang,
msf_client=shared_msf_client,
session_ids=shared_session_ids,
msf_password=args.msf_password,
msf_port=args.msf_port,
)
post_engine.run()
except KeyboardInterrupt:
console.print("\n[yellow]Post-exploitation interrupted (Ctrl+C)[/yellow]")
except Exception as exc:
console.print(f"[red]Post-exploitation error: {exc}[/red]")
if args.verbose:
console.print_exception()
if args.agent:
try:
from agent.reactive_agent import ReactiveAgent
from agent.mission_report import generate_mission_report
agent = ReactiveAgent(
target=args.target,
lang=args.lang,
max_depth=args.pivot_depth,
timeout=args.agent_timeout,
msf_password=args.msf_password,
msf_port=args.msf_port,
recon_only=args.recon_only,
)
if args.tui:
import threading
from ui.dashboard import run_tui_dashboard
t = threading.Thread(
target=run_tui_dashboard,
args=(agent.state,),
daemon=True,
)
t.start()
final_state = agent.run()
generate_mission_report(agent, final_state, args.output, args.lang)
except KeyboardInterrupt:
console.print("\n[yellow]Agent interrupted (Ctrl+C)[/yellow]")
except Exception as exc:
console.print(f"[red]Agent error: {exc}[/red]")
if args.verbose:
console.print_exception()
if args.dashboard:
console.print(f"\n[bold cyan]Launching dashboard on http://localhost:{args.dashboard_port}[/bold cyan]")
console.print("[dim]Press Ctrl+C to stop[/dim]")
try:
from dashboard.app import run
run(port=args.dashboard_port)
except KeyboardInterrupt:
console.print("\n[yellow]Dashboard stopped[/yellow]")
if __name__ == "__main__":
main()