IncidentResponse-Env / simulate_attack.py
Abhinav21110's picture
architecture verification
dbc7dad
Raw History Blame Contribute Delete
2.34 kB
import time
from ir_env.engine import IncidentResponseEnv
from ir_env.models import IRAction
import json
def run_live_attack_simulation(task_id="task_3_apt", steps=15):
print(f"=== Starting Live Attack Simulation for {task_id} ===")
print("The agent is passively monitoring to observe the attacker's progression.\n")
env = IncidentResponseEnv(task_id=task_id)
obs = env.reset()
# We will just monitor the CEO laptop to let time pass without taking containment actions
passive_action = IRAction(
action_type="monitor_only",
target="LAPTOP-CEO",
reason="Passive observation to see attack spread"
)
for step in range(1, steps + 1):
print(f"\n--- STEP {step} ---")
result = env.step(passive_action)
# Get internal state to see the ground truth (hidden from standard observation)
state = env.state()
attack_stage = state.get("attack_stage", "unknown")
print(f"Attack Stage: {attack_stage.upper()}")
# Print active alerts generated in this step
obs = result.observation
new_alerts = [a for a in obs.active_alerts if a.timestamp == f"step_{step}" or step == 1]
if step == 1:
print(f"Triggered {len(obs.active_alerts)} initial alerts. Example:")
for a in obs.active_alerts[:2]:
print(f" [{a.severity.upper()}] {a.event_type} on {a.source_host} -> {a.raw_log[:80]}...")
else:
if new_alerts:
print(f"NEW ALERTS GENERATED:")
for a in new_alerts:
print(f" [!] {a.event_type} on {a.source_host}: {a.raw_log}")
else:
print(" (No new auto-alerts this step)")
# Determine compromised hosts that are still "normal" (attacker moving laterally)
compromised_hosts = [
hostname for hostname, info in state["host_states"].items()
if info["is_compromised"]
]
print(f"Compromised Hosts: {', '.join(compromised_hosts)}")
if result.done:
print("\nIncident closed or attacker completed objective!")
break
time.sleep(0.5)
if __name__ == "__main__":
run_live_attack_simulation("task_3_apt", 12)