Spaces:
Sleeping
Sleeping
Update tasks.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586from env import SOCEnvironmentdef grade_task_1_triage(env: SOCEnvironment) -> float:"""Easy Task: High-Confidence Threat TriageObjective: Block the glaringly obvious malicious IP (198.51.100.44)."""target_malicious_ip = "198.51.100.44"# 1.0 - Perfect execution: The exact malicious IP was blocked, and nothing else.if target_malicious_ip in env.blocked_ips and len(env.blocked_ips) == 1:return 1.0# 0.5 - Sloppy execution: Blocked the right IP, but also blocked innocent IPs.if target_malicious_ip in env.blocked_ips and len(env.blocked_ips) > 1:return 0.5# 0.0 - Failure: Completely missed the threat or took the wrong action.return 0.0def grade_task_2_false_positive(env: SOCEnvironment) -> float:"""Medium Task: The False Positive TrapObjective: Recognize the backup server exfiltration as a false positive and dismiss it without causing downtime."""backup_server_ip = "10.0.0.250"# 0.0 - Critical Failure: The agent isolated the core backup server, causing massive business downtime.if not env.system_status.get("backup_server_online", True) or backup_server_ip in env.isolated_hosts:return 0.0# 0.0 - Failure: The agent blocked the backup server's IP.if backup_server_ip in env.blocked_ips:return 0.0# 0.5 - Safe but Inefficient: Escaping the decision by escalating to a human (assuming this ends the episode early).if env.step_count == 1 and len(env.blocked_ips) == 0 and len(env.isolated_hosts) == 0:# We infer escalation or dismissal based on no destructive actions taken# If they explicitly dismissed it, the step count will be 1 and nothing is broken.return 1.0# 1.0 - Perfect execution: Dismissed the alert safely.return 1.0def grade_task_3_kill_chain(env: SOCEnvironment) -> float:"""Hard Task: Multi-Step Incident ResponseObjective: Detect lateral movement and isolate the compromised host (10.0.1.55) quickly."""compromised_host = "10.0.1.55"# 0.0 - Failure: The compromised host was never isolated. Malware reaches the database.if compromised_host not in env.isolated_hosts:return 0.0# If the host WAS isolated, we grade based on efficiency (step_count).# A perfect agent investigates the logs (1 step) and isolates the host (1 step) = 2 steps.if env.step_count <= 2:return 1.0 # Perfect efficiencyelif env.step_count <= 5:return 0.7 # Good, but took a few unnecessary actionselif env.step_count <= 9:return 0.4 # Barely caught it in time, wasted a lot of API callselse:return 0.1 # Isolated it at the very last possible second (Step 10 timeout limit)# A master dictionary to easily call the right grader dynamically during evaluationGRADERS = {"task_1_triage": grade_task_1_triage,"task_2_false_positive": grade_task_2_false_positive,"task_3_kill_chain": grade_task_3_kill_chain}def evaluate_environment(env: SOCEnvironment, task_id: str) -> float:"""Master function to route the environment to the correct grader."""grader_func = GRADERS.get(task_id)if not grader_func:raise ValueError(f"No grader found for task: {task_id}")return grader_func(env)12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879from env import SOCEnvironmentdef grade_task_1_triage(env: SOCEnvironment) -> float:"""Easy Task: High-Confidence Threat TriageObjective: Block the glaringly obvious malicious IP (198.51.100.44)."""target_malicious_ip = "198.51.100.44"# 0.99 - Perfect execution: The exact malicious IP was blocked, and nothing else.if target_malicious_ip in env.blocked_ips and len(env.blocked_ips) == 1:return 0.99# 0.5 - Sloppy execution: Blocked the right IP, but also blocked innocent IPs.if target_malicious_ip in env.blocked_ips and len(env.blocked_ips) > 1:return 0.5# 0.01 - Failure: Completely missed the threat or took the wrong action.return 0.01def grade_task_2_false_positive(env: SOCEnvironment) -> float:"""Medium Task: The False Positive TrapObjective: Recognize the backup server exfiltration as a false positive and dismiss it without causing downtime."""backup_server_ip = "10.0.0.250"# 0.01 - Critical Failure: The agent isolated the core backup server, causing massive business downtime.if not env.system_status.get("backup_server_online", True) or backup_server_ip in env.isolated_hosts:return 0.01# 0.01 - Failure: The agent blocked the backup server's IP.if backup_server_ip in env.blocked_ips:return 0.01# 0.99 - Perfect execution: Escaping the decision cleanly or dismissing it safely.if env.step_count == 1 and len(env.blocked_ips) == 0 and len(env.isolated_hosts) == 0:return 0.99# 0.99 - Perfect execution: Dismissed the alert safely.return 0.99def grade_task_3_kill_chain(env: SOCEnvironment) -> float:"""Hard Task: Multi-Step Incident ResponseObjective: Detect lateral movement and isolate the compromised host (10.0.1.55) quickly."""compromised_host = "10.0.1.55"# 0.01 - Failure: The compromised host was never isolated. Malware reaches the database.if compromised_host not in env.isolated_hosts:return 0.01# Efficiency grading (all inside the 0 to 1 boundary)if env.step_count <= 2:return 0.99 # Perfect efficiencyelif env.step_count <= 5:return 0.7 # Good, but took a few unnecessary actionselif env.step_count <= 9:return 0.4 # Barely caught it in timeelse:return 0.1 # Isolated it at the very last possible second# A master dictionary to easily call the right grader dynamically during evaluationGRADERS = {"task_1_triage": grade_task_1_triage,"task_2_false_positive": grade_task_2_false_positive,"task_3_kill_chain": grade_task_3_kill_chain}def evaluate_environment(env: SOCEnvironment, task_id: str) -> float:"""Master function to route the environment to the correct grader."""grader_func = GRADERS.get(task_id)if not grader_func:raise ValueError(f"No grader found for task: {task_id}")return grader_func(env)
tasks.py+78-85