File size: 2,340 Bytes
dbc7dad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)