Attack Simulation API¶
Pure core - attack_core¶
attack_core.pick_target ¶
pick_target(attack_type: str, idx: dict) -> str
Pick a plausible target node for the attack type.
Pure function: relies on a pre-built index dict produced by telecom_attack._build_target_index(). No DB access here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attack_type
|
str
|
key from ATTACK_CATALOG. |
required |
idx
|
dict
|
dict with keys {"cores", "all_cores", "cells_5g", "cells_6g"}. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A node_id or cell_id, or "UNKNOWN" if the pool is empty. |
Source code in attack_core.py
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 | |
attack_core.generate_scenarios ¶
generate_scenarios(n: int, target_idx: dict, now: datetime | None = None) -> list[dict]
Generate n random attack scenarios with plausible timings.
Pure: does not touch the DB. Caller supplies a pre-built target index (see telecom_attack._build_target_index()).
Guarantees a share of 6G scenarios (RIS_PHASE_POISON, AI_RAN_POISON, THZ_JAMMING, QUIC_FLOOD_6G).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
number of scenarios to generate. |
required |
target_idx
|
dict
|
dict with keys {"cores", "all_cores", "cells_5g", "cells_6g"}. |
required |
now
|
datetime | None
|
reference time; defaults to datetime.now(). |
None
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of dicts matching the attack_scenarios table schema. |
Source code in attack_core.py
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 | |
attack_core.expand_events ¶
expand_events(scenarios: list[dict], samples_per_scenario: int = 20) -> list[dict]
Expand each scenario into a time-series of event samples.
Pure: no DB, no I/O.
For each scenario, generate samples_per_scenario equally-spaced
samples between start_ts and end_ts. Each sample carries MTTD,
MTTR, and KPI impact (latency, drop) derived from pps.
Source code in attack_core.py
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 | |
attack_core.attacks_to_alerts ¶
attacks_to_alerts(scenarios: list[dict], events: list[dict]) -> list[dict]
Convert attack scenarios into alert rows for the alerts table.
Pure: no DB, no I/O. Only DETECTED/SUCCESS/ONGOING or CRITICAL scenarios become alerts. Each alert routes to one SOC recipient.
Source code in attack_core.py
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 | |
DB layer - telecom_attack¶
telecom_attack.init_attack_tables ¶
init_attack_tables()
Source code in telecom_attack.py
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 | |
telecom_attack.generate_attack_scenarios ¶
generate_attack_scenarios(n: int = 25) -> list[dict]
Generate n random attack scenarios with plausible timings.
Picks attack types from ATTACK_CATALOG, resolves a target node from the DB (via _build_target_index), and assigns: - realistic start/end timestamps within the last 24h, - a rate (pps) drawn from the attack family's typical range, - a status in {BLOCKED, DETECTED, SUCCESS, ONGOING}.
Guarantees a share of 6G scenarios (RIS_PHASE_POISON, AI_RAN_POISON, THZ_JAMMING, QUIC_FLOOD_6G) so 6G is always represented.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of scenarios to generate. Default 25. |
25
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of dicts, each with the schema of the |
list[dict]
|
table (see init_attack_tables()). |
Source code in telecom_attack.py
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 | |
telecom_attack.persist_attacks ¶
persist_attacks(scenarios: list[dict], events: list[dict]) -> None
Source code in telecom_attack.py
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 | |
telecom_attack.inject_attack_alerts ¶
inject_attack_alerts(alerts: list[dict]) -> None
Merge attack-derived alerts into the alerts table.
Source code in telecom_attack.py
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 | |
telecom_attack.run_attack_simulation ¶
run_attack_simulation(n_scenarios: int = 25, samples_per_scenario: int = 20, inject_alerts: bool = True) -> dict
End-to-end attack simulation: generate → persist → alert.
Pipeline
- generate_attack_scenarios(n_scenarios)
- expand_events(...) → time-series
- persist_attacks(...) → attack_scenarios + attack_events tables
- attacks_to_alerts(...) → alert rows
- inject_attack_alerts(...) → merge into alerts + sms_alerts
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_scenarios
|
int
|
Number of attack scenarios to generate. |
25
|
samples_per_scenario
|
int
|
Event samples per scenario. |
20
|
inject_alerts
|
bool
|
If True, merge into alerts/sms_alerts tables. |
True
|
Returns:
| Type | Description |
|---|---|
dict
|
Summary dict: { "scenarios": int, "events": int, "alerts": int, "by_status": {status: count, ...}, "by_severity": {severity: count, ...}, } |
Source code in telecom_attack.py
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 | |