Spaces:
Sleeping
Sleeping
Update tasks.py
Browse files
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 |
-
#
|
| 11 |
-
if target_malicious_ip in env.blocked_ips and len(env.blocked_ips) == 1:
|
| 12 |
-
return
|
| 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.
|
| 19 |
-
return 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.
|
| 30 |
-
if not env.system_status.get("backup_server_online", True) or backup_server_ip in env.isolated_hosts:
|
| 31 |
-
return 0.
|
| 32 |
-
|
| 33 |
-
# 0.
|
| 34 |
-
if backup_server_ip in env.blocked_ips:
|
| 35 |
-
return 0.
|
| 36 |
-
|
| 37 |
-
# 0.
|
| 38 |
-
if env.step_count == 1 and len(env.blocked_ips) == 0 and len(env.isolated_hosts) == 0:
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
return
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 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)
|