-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
1020 lines (917 loc) · 32.3 KB
/
Copy pathmain.py
File metadata and controls
1020 lines (917 loc) · 32.3 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
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""Command-line interface for MUDOS."""
from __future__ import annotations
from datetime import datetime
import click
from click.shell_completion import CompletionItem
from config import (
APP_EDITION,
APP_LICENSE,
APP_LICENSE_NAME,
APP_NAME,
APP_VERSION,
DEVELOPER_EMAIL,
DEVELOPER_GITHUB,
DEVELOPER_LINKEDIN,
DEVELOPER_NAME,
ETHICS_WARNING,
)
from controller import AttackController
from utils.cli_helpers import (
apply_tls_vector_defaults,
build_campaign_phase_overrides,
build_run_attack_options,
format_unknown_attack_error,
require_confirm_or_abort,
resolve_spoof_for_run,
resolve_ssl_for_attack,
validate_campaign_numeric_overrides,
validate_mutually_exclusive_flags,
)
from utils.cli_options import campaign_attack_overrides, run_attack_options
from utils.cli_paths import ProjectProfilePath
from utils.console import (
banner as render_banner,
)
from utils.console import (
key_values,
note,
section,
table,
warning_panel,
)
from utils.console import (
report_paths as render_report_paths,
)
from utils.logger import setup_logger
from utils.platform import is_root_user
from utils.probe import probe_target
from utils.scope import ScopeError
logger = setup_logger()
def _complete_attack_names(ctx, param, incomplete: str):
"""Shell completion callback for attack names."""
from attacks import ATTACK_REGISTRY
prefix = incomplete.lower()
return [
CompletionItem(name, help=cls.description)
for name, cls in sorted(ATTACK_REGISTRY.items())
if name.lower().startswith(prefix)
]
def _complete_profile_names(ctx, param, incomplete: str):
"""Shell completion callback for campaign profile names."""
from profiles.loader import list_profile_names
prefix = incomplete.lower()
return [
CompletionItem(name, help="campaign profile")
for name in list_profile_names()
if name.lower().startswith(prefix)
]
@click.group()
@click.version_option(version=APP_VERSION, prog_name=APP_NAME)
def cli():
"""MUDOS - professional multi-vector DDoS testing tool."""
@cli.command("completion")
@click.argument("shell", type=click.Choice(["bash", "zsh", "fish"]))
@click.option(
"--prog-name",
default="mudos",
show_default=True,
help="Executable name to generate completion for",
)
def completion_cmd(shell: str, prog_name: str):
"""Generate shell completion script."""
from click.shell_completion import get_completion_class
completion_cls = get_completion_class(shell)
if completion_cls is None:
raise click.ClickException(f"Unsupported shell: {shell}")
complete_var = f"_{prog_name.replace('-', '_').replace('.', '_').upper()}_COMPLETE"
click.echo(completion_cls(cli, {}, prog_name, complete_var).source())
@cli.command("list")
def list_attacks():
"""List all available attack vectors."""
controller = AttackController()
attacks = controller.list_attacks()
rows = [
(
attack["name"],
"yes" if attack["requires_root"] else "no",
attack["category"],
attack["description"],
)
for attack in attacks
]
table(
("Attack", "Root", "Category", "Description"),
rows,
title="Attack Catalog",
footer=f"Total: {len(attacks)} attack vectors",
max_col_widths=(24, 6, 14, 70),
)
@cli.command("profiles")
def list_profiles_cmd():
"""List available campaign profiles."""
from profiles.loader import list_profiles
profiles = list_profiles()
if not profiles:
note("No profiles found in profiles/ directory.", fg="yellow")
return
table(
("Profile", "Phases", "Description"),
[(p["name"], p["phases"], p["description"]) for p in profiles],
title="Campaign Profiles",
max_col_widths=(24, 8, 78),
)
@cli.command("about")
def about_cmd():
"""Show edition, developer, and project contact information."""
key_values(
"About MUDOS",
[
("Edition", APP_EDITION, "ok"),
("Version", APP_VERSION, None),
("Developer", DEVELOPER_NAME, None),
("Email", DEVELOPER_EMAIL, None),
("LinkedIn", DEVELOPER_LINKEDIN, None),
("GitHub", DEVELOPER_GITHUB, None),
("License", f"{APP_LICENSE} ({APP_LICENSE_NAME})", "warn"),
],
)
@cli.command("coverage")
@click.option(
"--show",
"show_filter",
default="all",
type=click.Choice(["all", "covered", "missing", "out-of-scope"]),
show_default=True,
help="Filter vector families by coverage status",
)
def coverage_cmd(show_filter: str):
"""Show DDoS vector-family coverage against the implemented catalog."""
from attacks import ATTACK_REGISTRY
from attacks.taxonomy import coverage_rows, coverage_summary
summary = coverage_summary(ATTACK_REGISTRY.keys())
key_values(
"DDoS Coverage Summary",
[
("Registered Vectors", len(ATTACK_REGISTRY), "ok"),
("In-Scope Families", summary["in_scope_families"], "ok"),
("Covered Families", summary["covered_families"], "ok"),
(
"Missing Families",
summary["missing_families"],
"fail" if summary["missing_families"] else "ok",
),
("Out of Scope", summary["out_of_scope_families"], "warn"),
("Coverage", f"{summary['coverage_percent']}%", "ok"),
],
)
if summary["problems"]:
table(
("Problem",),
[(problem,) for problem in summary["problems"]],
title="Catalog Integrity Problems",
max_col_widths=(110,),
)
rows = coverage_rows(ATTACK_REGISTRY.keys())
normalized_filter = show_filter.replace("-", "_")
if normalized_filter != "all":
rows = [row for row in rows if row["status"] == normalized_filter]
table(
("Domain", "MITRE", "Status", "Family", "Vectors"),
[
(
row["domain"],
row["mitre"],
str(row["status"]).replace("_", "-"),
row["family"],
", ".join(row["covered_by"]) if row["covered_by"] else row["notes"],
)
for row in rows
],
title="Vector Family Coverage",
max_col_widths=(22, 24, 12, 42, 80),
)
@cli.command("check")
@click.option(
"--strict",
is_flag=True,
default=False,
help="Exit with code 1 when libpcap, scapy, h2, or aioquic is missing.",
)
@click.option(
"--quick",
is_flag=True,
default=False,
help="Check core dependencies only (skip vector registry and coverage scan).",
)
def check_cmd(strict: bool, quick: bool):
"""Verify dependencies and environment readiness."""
raise SystemExit(check_environment(strict=strict, quick=quick))
@cli.command("probe")
@click.option("--target", "-t", required=True, help="Target IP or hostname")
@click.option("--port", "-p", default=80, show_default=True, help="Target port")
@click.option("--protocol", default="tcp", type=click.Choice(["tcp", "udp"]), help="Probe protocol")
@click.option("--ipv6", is_flag=True, default=False, help="Resolve target over IPv6")
@click.option("--allowlist", multiple=True, help="Authorized target CIDR/IP (repeatable)")
@click.option("--allowlist-file", default=None, help="File with authorized targets")
@click.option("--confirm", is_flag=True, default=False, help="Confirm authorized use")
def probe_cmd(
target: str,
port: int,
protocol: str,
ipv6: bool,
allowlist: tuple,
allowlist_file: str | None,
confirm: bool,
):
"""Probe target reachability and latency."""
from utils.network import merge_target_port, parse_port, port_override_notice, resolve_target
from utils.scope import ScopeError, combine_allowlist, validate_engagement
warning_panel(ETHICS_WARNING, err=True)
try:
require_confirm_or_abort(dry_run=False, confirm=confirm)
except SystemExit:
note("Aborted. Re-run with --confirm.", fg="red", bold=True, err=True)
raise
info = resolve_target(target, ipv6=ipv6)
port = parse_port(merge_target_port(port, info))
notice_text = port_override_notice(info, port)
if notice_text:
note(notice_text, fg="yellow", err=True)
combined_allowlist = combine_allowlist(list(allowlist) or None, allowlist_file)
scope_target = info.address
if combined_allowlist and info.resolved_addresses:
from utils.network import pick_scoped_address
scope_target = pick_scoped_address(info, combined_allowlist)
try:
validate_engagement(
scope_target,
precombined_allowlist=combined_allowlist,
require_allowlist=True,
dry_run=False,
)
except ScopeError as exc:
note(str(exc), fg="red", err=True)
raise SystemExit(1) from exc
result = probe_target(scope_target, port, protocol)
from utils.audit import log_event
from utils.reporter import sanitize_scope_metadata
log_event(
"probe",
details={
"target": scope_target,
"port": port,
"protocol": protocol,
"reachable": result["reachable"],
"scope": sanitize_scope_metadata(
{
"target": scope_target,
"allowlist": combined_allowlist,
"allowlist_enforced": bool(combined_allowlist),
}
),
},
)
rows = [
("Target", f"{scope_target}:{port}", None),
("Protocol", protocol.upper(), None),
("IPv6", "yes" if info.is_ipv6 else "no", "ok" if info.is_ipv6 else None),
(
"Reachable",
"yes" if result["reachable"] else "no",
"ok" if result["reachable"] else "fail",
),
]
if result.get("reachability_confidence"):
confidence = result["reachability_confidence"]
rows.append(
(
"Confidence",
confidence,
"warn" if confidence == "inconclusive" else "ok",
)
)
if result.get("udp_status"):
rows.append(("UDP Status", result["udp_status"], None))
if result.get("latency_ms") is not None:
rows.append(("Latency", f"{result['latency_ms']} ms", None))
if result.get("error"):
rows.append(("Error", result["error"], "fail"))
key_values("Probe Result", rows)
if not result["reachable"]:
raise SystemExit(1)
@cli.command("campaign")
@click.option(
"--profile",
"-f",
required=True,
type=ProjectProfilePath(),
help="Campaign YAML profile",
shell_complete=_complete_profile_names,
)
@click.option("--operator", default=None, help="Operator name for audit log")
@click.option("--engagement-id", default=None, help="Override profile engagement ID")
@click.option("--allowlist", multiple=True, help="Override/add authorized target CIDR/IP")
@click.option("--allowlist-file", default=None, help="Override profile allowlist file")
@click.option(
"--require-allowlist",
is_flag=True,
default=False,
help="Require allowlist during dry-run too (live runs always require it)",
)
@click.option("--require-engagement-id", is_flag=True, default=False, help="Require engagement ID")
@click.option("--ipv6", is_flag=True, default=False, help="Resolve target over IPv6")
@click.option("--no-ipv6", is_flag=True, default=False, help="Disable IPv6 even if set in profile")
@click.option("--probe", is_flag=True, default=False, help="Probe target before/after campaign")
@click.option(
"--no-probe", is_flag=True, default=False, help="Disable probe even if set in profile"
)
@click.option(
"--dashboard",
is_flag=True,
default=False,
help="Show a live terminal stats dashboard during each phase",
)
@click.option("--dry-run", is_flag=True, default=False, help="Validate profile without executing")
@click.option(
"--no-report",
"skip_report",
is_flag=True,
default=False,
help="Disable automatic reports",
)
@click.option("--confirm", is_flag=True, default=False, help="Confirm authorized use")
@campaign_attack_overrides
def campaign_cmd(
profile: str,
operator: str | None,
engagement_id: str | None,
allowlist: tuple,
allowlist_file: str | None,
require_allowlist: bool,
require_engagement_id: bool,
ipv6: bool,
no_ipv6: bool,
probe: bool,
no_probe: bool,
dry_run: bool,
skip_report: bool,
confirm: bool,
port: int | None,
rate: int | None,
broadcast: str | None,
max_held_connections: int | None,
payload_size: int | None,
packet_size: int | None,
spoof: bool,
connection_limit: int | None,
slow_delay: float | None,
ramp_up: int | None,
duration: int | None,
threads: int | None,
max_sockets: int | None,
query_domain: str | None,
concurrent_streams: int | None,
streams_per_conn: int | None,
community: str | None,
bypass_preset: str | None,
iface: str | None,
bind_source: str | None,
spoof_source_file: str | None,
grpc_method: str | None,
ws_channel: str | None,
ws_path: str | None,
arp_target: str | None,
connect_port: int | None,
sse_path: str | None,
doh_path: str | None,
ssl: bool,
no_ssl: bool,
no_spoof: bool,
insecure: bool,
dashboard: bool = False,
):
"""Run a multi-phase attack campaign from a YAML profile."""
from profiles.loader import load_profile, validate_campaign_ready
from utils.platform import is_root_user
render_banner()
if probe and no_probe:
raise click.UsageError("--probe and --no-probe are mutually exclusive.")
validate_mutually_exclusive_flags(
(("--ipv6", ipv6), ("--no-ipv6", no_ipv6)),
(("--ssl", ssl), ("--no-ssl", no_ssl)),
(("--spoof", spoof), ("--no-spoof", no_spoof)),
)
try:
validate_campaign_numeric_overrides(port=port, duration=duration, threads=threads)
except click.UsageError as exc:
note(str(exc), fg="red", err=True)
raise SystemExit(1) from exc
ipv6_override = False if no_ipv6 else (True if ipv6 else None)
try:
profile_data = load_profile(profile)
from profiles.loader import build_campaign_allowlist
campaign_allowlist = build_campaign_allowlist(
profile_data,
cli_allowlist=list(allowlist) or None,
cli_allowlist_file=allowlist_file,
)
if (require_allowlist or not dry_run) and not campaign_allowlist:
raise ValueError(
"Campaign allowlist is required for live execution or when "
"--require-allowlist is set. "
"Use --allowlist CIDR or --allowlist-file path."
)
from utils.network import (
merge_target_port,
parse_port,
port_override_notice,
resolve_target,
)
profile_target_info = resolve_target(
profile_data["target"],
ipv6=ipv6_override if ipv6_override is not None else profile_data.get("ipv6", False),
)
if port is not None:
profile_port = parse_port(port)
else:
profile_port = parse_port(
merge_target_port(profile_data.get("port", 80), profile_target_info)
)
port_notice = port_override_notice(profile_target_info, profile_port)
if port_notice:
note(port_notice, fg="yellow", err=True)
except (ValueError, FileNotFoundError) as exc:
note(str(exc), fg="red", err=True)
raise SystemExit(1) from exc
except ScopeError as exc:
note(str(exc), fg="red", err=True)
raise SystemExit(1) from exc
phase_overrides = build_campaign_phase_overrides(
rate=rate,
broadcast=broadcast,
max_held_connections=max_held_connections,
payload_size=payload_size,
packet_size=packet_size,
connection_limit=connection_limit,
slow_delay=slow_delay,
ramp_up=ramp_up,
duration=duration,
threads=threads,
max_sockets=max_sockets,
query_domain=query_domain,
concurrent_streams=concurrent_streams,
streams_per_conn=streams_per_conn,
community=community,
bypass_preset=bypass_preset,
iface=iface,
bind_source=bind_source,
spoof_source_file=spoof_source_file,
grpc_method=grpc_method,
ws_channel=ws_channel,
ws_path=ws_path,
arp_target=arp_target,
connect_port=connect_port,
sse_path=sse_path,
doh_path=doh_path,
spoof=spoof,
ssl=ssl,
insecure=insecure,
no_ssl=no_ssl,
no_spoof=no_spoof,
)
phase_overrides = apply_tls_vector_defaults(
profile_data, phase_overrides, no_ssl=no_ssl
)
try:
from profiles.loader import validate_campaign_ready
validate_campaign_ready(
profile_data,
phase_overrides,
cli_allowlist=list(allowlist) or None,
cli_allowlist_file=allowlist_file,
ipv6_override=ipv6_override,
default_port_override=port,
)
except ValueError as exc:
note(str(exc), fg="red", err=True)
raise SystemExit(1) from exc
if profile_data.get("require_root") and not is_root_user():
note(
"Campaign profile requires root privileges (sudo) for live execution.",
fg="yellow",
bold=True,
err=True,
)
if not dry_run:
raise SystemExit(1)
warning_panel(ETHICS_WARNING, err=True)
try:
require_confirm_or_abort(dry_run=dry_run, confirm=confirm)
except SystemExit:
note("Aborted. Re-run with --confirm.", fg="red", bold=True, err=True)
raise
controller = AttackController()
try:
result = controller.run_campaign(
profile_data,
dry_run=dry_run,
operator=operator,
skip_report=skip_report if skip_report else None,
engagement_id=engagement_id,
allowlist=list(allowlist) or None,
allowlist_file=allowlist_file,
require_allowlist=require_allowlist or not dry_run,
require_engagement_id=require_engagement_id,
ipv6=ipv6 if ipv6 else None,
probe=probe if probe else None,
disable_ipv6=no_ipv6,
disable_probe=no_probe,
phase_overrides=phase_overrides,
dashboard=dashboard,
port_override=port,
profile_validated=True,
phase_overrides_validated=True,
phase_compat_validated=True,
)
render_report_paths(result.get("reports"))
except KeyboardInterrupt:
controller.stop()
paths = controller.export_report(status="interrupted")
render_report_paths(paths)
raise SystemExit(0) from None
except (ValueError, FileNotFoundError, ScopeError, PermissionError) as exc:
logger.error(str(exc))
raise SystemExit(1) from exc
except Exception as exc:
logger.error(f"Campaign failed: {exc}")
controller.stop()
paths = controller.export_report(status="failed")
render_report_paths(paths)
raise SystemExit(1) from exc
@cli.command("run")
@click.option("--attack", "-a", required=True, help="Attack type", shell_complete=_complete_attack_names)
@click.option("--target", "-t", required=True, help="Target IP, hostname, or URL")
@run_attack_options
def run_attack(
attack: str,
target: str,
port: int,
duration: int,
threads: int,
ssl: bool,
insecure: bool,
ipv6: bool,
packet_size: int,
payload_size: int,
slow_delay: float,
rate: int,
ramp_up: int,
spoof: bool,
no_ssl: bool,
no_spoof: bool,
connection_limit: int,
broadcast: str | None,
max_held_connections: int | None,
engagement_id: str | None,
operator: str | None,
allowlist: tuple,
allowlist_file: str | None,
probe: bool,
dashboard: bool,
skip_report: bool,
dry_run: bool,
confirm: bool,
require_allowlist: bool,
require_engagement_id: bool,
max_sockets: int | None,
query_domain: str | None,
concurrent_streams: int | None,
streams_per_conn: int | None,
community: str | None,
bypass_preset: str | None,
iface: str | None,
bind_source: str | None,
spoof_source_file: str | None,
grpc_method: str | None,
ws_channel: str | None,
ws_path: str | None,
arp_target: str | None,
connect_port: int | None,
sse_path: str | None,
doh_path: str | None,
):
"""Execute a DDoS test attack against the specified target."""
from attacks import ATTACK_REGISTRY
from utils.network import port_override_notice
from utils.platform import is_root_user
from utils.preflight import preflight_single_run
render_banner()
validate_mutually_exclusive_flags(
(("--ssl", ssl), ("--no-ssl", no_ssl)),
(("--spoof", spoof), ("--no-spoof", no_spoof)),
)
ssl = resolve_ssl_for_attack(attack, ssl, no_ssl)
spoof = resolve_spoof_for_run(spoof, no_spoof)
attack_options = build_run_attack_options(
ssl=ssl,
insecure=insecure,
ipv6=ipv6,
packet_size=packet_size,
payload_size=payload_size,
slow_delay=slow_delay,
rate=rate,
ramp_up=ramp_up,
spoof=spoof,
connection_limit=connection_limit,
broadcast=broadcast,
max_held_connections=max_held_connections,
max_sockets=max_sockets,
query_domain=query_domain,
concurrent_streams=concurrent_streams,
streams_per_conn=streams_per_conn,
community=community,
bypass_preset=bypass_preset,
iface=iface,
bind_source=bind_source,
spoof_source_file=spoof_source_file,
grpc_method=grpc_method,
ws_channel=ws_channel,
ws_path=ws_path,
arp_target=arp_target,
connect_port=connect_port,
sse_path=sse_path,
doh_path=doh_path,
)
try:
target_info, effective_port = preflight_single_run(
attack,
target,
port,
duration,
threads,
attack_options,
ipv6=ipv6,
)
attack_cls = ATTACK_REGISTRY[attack]
from utils.network import pick_scoped_address
from utils.scope import combine_allowlist, validate_engagement
combined_allowlist = combine_allowlist(list(allowlist) or None, allowlist_file)
scope_target = target_info.address
if combined_allowlist and target_info.resolved_addresses:
scope_target = pick_scoped_address(target_info, combined_allowlist)
if scope_target != target_info.address:
from utils.network import target_info_with_address
target_info = target_info_with_address(target_info, scope_target)
prevalidated_scope = validate_engagement(
scope_target,
engagement_id=engagement_id,
precombined_allowlist=combined_allowlist,
require_engagement_id=require_engagement_id,
require_allowlist=require_allowlist or not dry_run,
dry_run=dry_run,
)
port_notice = port_override_notice(target_info, effective_port)
if port_notice:
note(port_notice, fg="yellow", err=True)
except ValueError as exc:
note(str(exc), fg="red", err=True)
raise SystemExit(1) from exc
if attack_cls.requires_root and not is_root_user():
note(
f"{attack} requires root privileges (sudo). "
"Dry-run also validates this requirement.",
fg="yellow",
bold=True,
err=True,
)
if not dry_run:
raise SystemExit(1)
warning_panel(ETHICS_WARNING, err=True)
try:
require_confirm_or_abort(dry_run=dry_run, confirm=confirm)
except SystemExit:
note("Aborted. Re-run with --confirm.", fg="red", bold=True, err=True)
raise
controller = AttackController()
try:
result = controller.run(
attack_type=attack,
target=target,
port=effective_port,
duration=duration,
threads=threads,
engagement_id=engagement_id,
operator=operator,
allowlist=list(allowlist) or None,
allowlist_file=allowlist_file,
require_allowlist=require_allowlist or not dry_run,
require_engagement_id=require_engagement_id,
probe=probe,
dashboard=dashboard,
skip_report=skip_report,
dry_run=dry_run,
cached_target_info=target_info,
prevalidated_scope=prevalidated_scope,
skip_scope_check=True,
skip_param_validation=True,
skip_compat_validation=True,
**attack_options,
)
render_report_paths(result.get("reports"))
except KeyboardInterrupt:
controller.stop()
paths = controller.export_report(status="interrupted")
render_report_paths(paths)
raise SystemExit(0) from None
except (ValueError, FileNotFoundError, ScopeError, PermissionError) as exc:
logger.error(str(exc))
raise SystemExit(1) from exc
except Exception as exc:
logger.error(f"Attack failed: {exc}")
controller.stop()
paths = controller.export_report(status="failed")
render_report_paths(paths)
raise SystemExit(1) from exc
@cli.command("info")
@click.argument("attack_name", shell_complete=_complete_attack_names)
def attack_info(attack_name: str):
"""Show details about a specific attack type."""
from attacks import ATTACK_REGISTRY
from utils.cli_helpers import (
attack_ssl_example_flag,
attack_supports_rate,
attack_transport_hint,
)
if attack_name not in ATTACK_REGISTRY:
click.echo(format_unknown_attack_error(attack_name, list(ATTACK_REGISTRY.keys())))
raise SystemExit(1)
cls = ATTACK_REGISTRY[attack_name]
supports_rate = attack_supports_rate(cls.name, cls.category)
transport = attack_transport_hint(cls.name, cls.category)
rows = [
("Name", cls.name, None),
("Category", cls.category, None),
("Description", cls.description, None),
(
"Root",
"required" if cls.requires_root else "not required",
"warn" if cls.requires_root else "ok",
),
("Rate Limit", "supported (--rate)" if supports_rate else "not applicable", None),
]
if transport:
rows.append(("Transport", transport, None))
key_values("Attack Details", rows)
section("Example")
ssl_flag = attack_ssl_example_flag(cls.name, cls.category)
note(
f" mudos run -a {cls.name} -t TARGET --confirm "
f"--allowlist TARGET/32 -d 30 -n 10{ssl_flag}"
)
@cli.command("reports")
@click.option("--limit", "-n", default=10, type=click.IntRange(min=1), help="Number of recent reports to show")
def list_reports(limit: int):
"""List recently generated HTML reports."""
from utils.reporter import HTML_DIR
html_dir = HTML_DIR
if not html_dir.exists():
note("No reports found. Run an attack to generate reports.", fg="yellow")
return
files = sorted(html_dir.glob("*.html"), key=lambda p: p.stat().st_mtime, reverse=True)
if not files:
note("No HTML reports found.", fg="yellow")
return
rows = []
for path in files[:limit]:
mtime = datetime.fromtimestamp(path.stat().st_mtime).strftime("%Y-%m-%d %H:%M:%S")
try:
display_path = path.relative_to(html_dir)
except ValueError:
display_path = path.name
rows.append((mtime, str(display_path)))
table(
("Generated", "Report File"),
rows,
title="Recent HTML Reports",
footer=f"Total: {len(files)} reports in {html_dir.name}/",
max_col_widths=(22, 90),
)
def check_environment(*, strict: bool = False, quick: bool = False) -> int:
"""Verify dependencies and environment readiness. Returns process exit code."""
import sys
from importlib.metadata import version as pkg_version
import aiohttp
import colorama
import psutil
import yaml
try:
import click as click_lib
click_version = pkg_version("click")
except Exception:
import click as click_lib
click_version = getattr(click_lib, "__version__", "unknown")
try:
jsonschema_version = pkg_version("jsonschema")
except Exception:
jsonschema_version = "installed"
try:
rich_version = pkg_version("rich")
except Exception:
rich_version = "installed"
try:
import scapy
scapy_version = scapy.__version__
except ImportError:
scapy_version = "not installed (FAIL for root-required attacks)"
libpcap_status = "n/a"
libpcap_level = None
if not scapy_version.startswith("not installed"):
from utils.scapy_runtime import activate_scapy_libpcap
if activate_scapy_libpcap():
libpcap_status = "active (Scapy pcap)"
libpcap_level = "ok"
else:
libpcap_status = "not available — install libpcap for raw/L2 captures"
libpcap_level = "warn"
try:
import httpx
httpx_version = httpx.__version__
except ImportError:
httpx_version = "not installed"
try:
import h2
h2_version = getattr(h2, "__version__", "installed")
except ImportError:
h2_version = "not installed"
try:
import aioquic
aioquic_version = getattr(aioquic, "__version__", "installed")
except ImportError:
aioquic_version = "not installed"
is_root = is_root_user()
rows = [
("Edition", APP_EDITION, "ok"),
("Python", sys.version.split()[0], "ok" if sys.version_info >= (3, 10) else "fail"),
("aiohttp", aiohttp.__version__, "ok"),
("httpx", httpx_version, "fail" if httpx_version == "not installed" else "ok"),
("h2", h2_version, "fail" if h2_version == "not installed" else "ok"),
("aioquic", aioquic_version, "fail" if aioquic_version == "not installed" else "ok"),
("scapy", scapy_version, "warn" if scapy_version.startswith("not installed") else "ok"),
("libpcap", libpcap_status, libpcap_level),
("psutil", psutil.__version__, "ok"),
("colorama", colorama.__version__, "ok"),
("click", click_version, "ok"),
("pyyaml", yaml.__version__, "ok"),
("jsonschema", jsonschema_version, "ok"),
("rich", rich_version, "ok"),
(
"Root Access",
"yes" if is_root else "no (required for raw socket attacks)",
"ok" if is_root else "warn",
),
]
from attacks.plugins import plugin_check_status
plugin_text, plugin_level = plugin_check_status()
rows.append(("Attack Plugins", plugin_text, plugin_level))
if not quick:
from attacks import ATTACK_REGISTRY
from attacks.taxonomy import coverage_summary
from profiles.loader import list_profile_names
profile_count = len(list_profile_names())
coverage = coverage_summary(ATTACK_REGISTRY.keys())
rows.extend(
[
("Attacks", f"{len(ATTACK_REGISTRY)} vectors registered", "ok"),
(
"DDoS Coverage",
f"{coverage['covered_families']}/{coverage['in_scope_families']} families",
"fail" if coverage["missing_families"] else "ok",
),
("Profiles", f"{profile_count} campaign profiles", "ok"),
]
)
else:
coverage = {"missing_families": []}
rows.extend(
[
("Developer", DEVELOPER_NAME, None),
("Contact", DEVELOPER_EMAIL, None),
]
)