Zenoharsh01 commited on
Commit
439f3b4
·
verified ·
1 Parent(s): d6a4c88

Update tasks.py

Browse files
Files changed (1) hide show
  1. tasks.py +78 -85
tasks.py CHANGED
@@ -1,86 +1,79 @@
1
- from env import SOCEnvironment
2
-
3
- def grade_task_1_triage(env: SOCEnvironment) -> float:
4
- """
5
- Easy Task: High-Confidence Threat Triage
6
- Objective: Block the glaringly obvious malicious IP (198.51.100.44).
7
- """
8
- target_malicious_ip = "198.51.100.44"
9
-
10
- # 1.0 - Perfect execution: The exact malicious IP was blocked, and nothing else.
11
- if target_malicious_ip in env.blocked_ips and len(env.blocked_ips) == 1:
12
- return 1.0
13
-
14
- # 0.5 - Sloppy execution: Blocked the right IP, but also blocked innocent IPs.
15
- if target_malicious_ip in env.blocked_ips and len(env.blocked_ips) > 1:
16
- return 0.5
17
-
18
- # 0.0 - Failure: Completely missed the threat or took the wrong action.
19
- return 0.0
20
-
21
-
22
- def grade_task_2_false_positive(env: SOCEnvironment) -> float:
23
- """
24
- Medium Task: The False Positive Trap
25
- Objective: Recognize the backup server exfiltration as a false positive and dismiss it without causing downtime.
26
- """
27
- backup_server_ip = "10.0.0.250"
28
-
29
- # 0.0 - Critical Failure: The agent isolated the core backup server, causing massive business downtime.
30
- if not env.system_status.get("backup_server_online", True) or backup_server_ip in env.isolated_hosts:
31
- return 0.0
32
-
33
- # 0.0 - Failure: The agent blocked the backup server's IP.
34
- if backup_server_ip in env.blocked_ips:
35
- return 0.0
36
-
37
- # 0.5 - Safe but Inefficient: Escaping the decision by escalating to a human (assuming this ends the episode early).
38
- if env.step_count == 1 and len(env.blocked_ips) == 0 and len(env.isolated_hosts) == 0:
39
- # We infer escalation or dismissal based on no destructive actions taken
40
- # If they explicitly dismissed it, the step count will be 1 and nothing is broken.
41
- return 1.0
42
-
43
- # 1.0 - Perfect execution: Dismissed the alert safely.
44
- return 1.0
45
-
46
-
47
- def grade_task_3_kill_chain(env: SOCEnvironment) -> float:
48
- """
49
- Hard Task: Multi-Step Incident Response
50
- Objective: Detect lateral movement and isolate the compromised host (10.0.1.55) quickly.
51
- """
52
- compromised_host = "10.0.1.55"
53
-
54
- # 0.0 - Failure: The compromised host was never isolated. Malware reaches the database.
55
- if compromised_host not in env.isolated_hosts:
56
- return 0.0
57
-
58
- # If the host WAS isolated, we grade based on efficiency (step_count).
59
- # A perfect agent investigates the logs (1 step) and isolates the host (1 step) = 2 steps.
60
-
61
- if env.step_count <= 2:
62
- return 1.0 # Perfect efficiency
63
-
64
- elif env.step_count <= 5:
65
- return 0.7 # Good, but took a few unnecessary actions
66
-
67
- elif env.step_count <= 9:
68
- return 0.4 # Barely caught it in time, wasted a lot of API calls
69
-
70
- else:
71
- return 0.1 # Isolated it at the very last possible second (Step 10 timeout limit)
72
-
73
-
74
- # A master dictionary to easily call the right grader dynamically during evaluation
75
- GRADERS = {
76
- "task_1_triage": grade_task_1_triage,
77
- "task_2_false_positive": grade_task_2_false_positive,
78
- "task_3_kill_chain": grade_task_3_kill_chain
79
- }
80
-
81
- def evaluate_environment(env: SOCEnvironment, task_id: str) -> float:
82
- """Master function to route the environment to the correct grader."""
83
- grader_func = GRADERS.get(task_id)
84
- if not grader_func:
85
- raise ValueError(f"No grader found for task: {task_id}")
86
  return grader_func(env)
 
1
+ from env import SOCEnvironment
2
+
3
+ def grade_task_1_triage(env: SOCEnvironment) -> float:
4
+ """
5
+ Easy Task: High-Confidence Threat Triage
6
+ Objective: Block the glaringly obvious malicious IP (198.51.100.44).
7
+ """
8
+ target_malicious_ip = "198.51.100.44"
9
+
10
+ # 0.99 - Perfect execution: The exact malicious IP was blocked, and nothing else.
11
+ if target_malicious_ip in env.blocked_ips and len(env.blocked_ips) == 1:
12
+ return 0.99
13
+
14
+ # 0.5 - Sloppy execution: Blocked the right IP, but also blocked innocent IPs.
15
+ if target_malicious_ip in env.blocked_ips and len(env.blocked_ips) > 1:
16
+ return 0.5
17
+
18
+ # 0.01 - Failure: Completely missed the threat or took the wrong action.
19
+ return 0.01
20
+
21
+
22
+ def grade_task_2_false_positive(env: SOCEnvironment) -> float:
23
+ """
24
+ Medium Task: The False Positive Trap
25
+ Objective: Recognize the backup server exfiltration as a false positive and dismiss it without causing downtime.
26
+ """
27
+ backup_server_ip = "10.0.0.250"
28
+
29
+ # 0.01 - Critical Failure: The agent isolated the core backup server, causing massive business downtime.
30
+ if not env.system_status.get("backup_server_online", True) or backup_server_ip in env.isolated_hosts:
31
+ return 0.01
32
+
33
+ # 0.01 - Failure: The agent blocked the backup server's IP.
34
+ if backup_server_ip in env.blocked_ips:
35
+ return 0.01
36
+
37
+ # 0.99 - Perfect execution: Escaping the decision cleanly or dismissing it safely.
38
+ if env.step_count == 1 and len(env.blocked_ips) == 0 and len(env.isolated_hosts) == 0:
39
+ return 0.99
40
+
41
+ # 0.99 - Perfect execution: Dismissed the alert safely.
42
+ return 0.99
43
+
44
+
45
+ def grade_task_3_kill_chain(env: SOCEnvironment) -> float:
46
+ """
47
+ Hard Task: Multi-Step Incident Response
48
+ Objective: Detect lateral movement and isolate the compromised host (10.0.1.55) quickly.
49
+ """
50
+ compromised_host = "10.0.1.55"
51
+
52
+ # 0.01 - Failure: The compromised host was never isolated. Malware reaches the database.
53
+ if compromised_host not in env.isolated_hosts:
54
+ return 0.01
55
+
56
+ # Efficiency grading (all inside the 0 to 1 boundary)
57
+ if env.step_count <= 2:
58
+ return 0.99 # Perfect efficiency
59
+ elif env.step_count <= 5:
60
+ return 0.7 # Good, but took a few unnecessary actions
61
+ elif env.step_count <= 9:
62
+ return 0.4 # Barely caught it in time
63
+ else:
64
+ return 0.1 # Isolated it at the very last possible second
65
+
66
+
67
+ # A master dictionary to easily call the right grader dynamically during evaluation
68
+ GRADERS = {
69
+ "task_1_triage": grade_task_1_triage,
70
+ "task_2_false_positive": grade_task_2_false_positive,
71
+ "task_3_kill_chain": grade_task_3_kill_chain
72
+ }
73
+
74
+ def evaluate_environment(env: SOCEnvironment, task_id: str) -> float:
75
+ """Master function to route the environment to the correct grader."""
76
+ grader_func = GRADERS.get(task_id)
77
+ if not grader_func:
78
+ raise ValueError(f"No grader found for task: {task_id}")
 
 
 
 
 
 
 
79
  return grader_func(env)