Tier 1 SOC analysts are drowned in thousands of alerts. We ingest structured JSON security events (Sysmon Event ID 1: Process Creation, Event ID 3: Network Connection) and normalize them into a typed Pydantic event schema.
Terminal - Setup LangGraph & Security SDKs
pip install langgraph langchain-core pydantic httpx shodan
from pydantic import BaseModel, Field
from typing import Optional, List
class SecurityTelemetryEvent(BaseModel):
event_id: int = Field(description="Sysmon event ID (e.g. 1 for ProcessCreate, 3 for NetworkConnect)")
timestamp: str
hostname: str
process_name: str
command_line: str
parent_process: str
dest_ip: Optional[str] = None
dest_port: Optional[int] = None
sha256_hash: Optional[str] = None
user: str
class TriageVerdict(BaseModel):
is_malicious: bool
confidence: float
mitre_techniques: List[str]
threat_intel_score: float
containment_required: bool
recommended_action: str
Model the SOC triage workflow as a state machine: Event Ingest → MITRE TTP Correlation → Threat Intel Enrichment → Decision Gate (Benign vs. Dangerous) → Remediation.
from typing import TypedDict
from langgraph.graph import StateGraph, END
class AgentState(TypedDict):
event: dict
mitre_ttps: list
intel_reputation: dict
verdict: dict
containment_payload: str
approved: bool
workflow = StateGraph(AgentState)
workflow.add_node("mitre_correlator", correlate_mitre_ttps)
workflow.add_node("threat_intel_lookup", enrich_threat_intel)
workflow.add_node("incident_evaluator", evaluate_incident_severity)
workflow.add_node("remediation_builder", synthesize_containment_action)
workflow.set_entry_point("mitre_correlator")
workflow.add_edge("mitre_correlator", "threat_intel_lookup")
workflow.add_edge("threat_intel_lookup", "incident_evaluator")
workflow.add_conditional_edges(
"incident_evaluator",
lambda state: "remediation_builder" if state["verdict"]["containment_required"] else END
)
Inspect command-line parameters for obfuscation, base64 payloads, execution flags (-nop -w hidden -enc), and map them deterministically to MITRE techniques (e.g. T1059.001 Command and Scripting Interpreter: PowerShell, T1105 Ingress Tool Transfer).
import re
def correlate_mitre_ttps(state: AgentState) -> dict:
cmd = state["event"].get("command_line", "").lower()
proc = state["event"].get("process_name", "").lower()
matched = []
if "powershell" in proc and any(f in cmd for f in ["-enc", "-w hidden", "bypass"]):
matched.append({"id": "T1059.001", "tactic": "Execution", "confidence": 0.95})
if "certutil" in proc and "-urlcache" in cmd:
matched.append({"id": "T1105", "tactic": "Command and Control", "confidence": 0.98})
if "procdump" in proc or "comsvcs.dll" in cmd:
matched.append({"id": "T1003.001", "tactic": "Credential Access", "confidence": 0.99})
return {"mitre_ttps": matched}
Query live threat feeds asynchronously to cross-reference extracted process file hashes and destination C2 IP addresses against global malicious lists.
import httpx
async def enrich_threat_intel(state: AgentState) -> dict:
dest_ip = state["event"].get("dest_ip")
reputation = {"ip": dest_ip, "is_c2_known": False, "risk_score": 0.0}
if dest_ip:
async with httpx.AsyncClient(timeout=3.0) as client:
resp = await client.get(f"https://api.abuseipdb.com/api/v2/check?ipAddress={dest_ip}", headers={"Key": "DEMO_KEY"})
if resp.status_code == 200:
score = resp.json()["data"]["abuseConfidenceScore"]
reputation["risk_score"] = score / 100.0
reputation["is_c2_known"] = score > 60
return {"intel_reputation": reputation}
When high-severity malware or C2 connections are confirmed, the agent dynamically crafts targeted containment scripts: AWS Security Group ingress revokes, Linux iptables drop rules, and process termination commands.
def synthesize_containment_action(state: AgentState) -> dict:
bad_ip = state["event"].get("dest_ip")
bad_proc = state["event"].get("process_name")
host = state["event"].get("hostname")
containment_script = f"""
#!/usr/bin/env bash
# [AUTO-CONTAINMENT ACTION] Host: {host}
# Reason: MITRE TTPs {state['mitre_ttps']} | Threat Score: {state['intel_reputation']['risk_score']}
echo "Isolating compromised host connection..."
iptables -I OUTPUT -d {bad_ip} -j DROP
iptables -I INPUT -s {bad_ip} -j DROP
echo "Terminating rogue process tree: {bad_proc}..."
pkill -9 -f {bad_proc}
logger -t ECHO_SOC_AGENT "Incident Contained: Blocked {bad_ip} & killed {bad_proc} on {host}"
""".strip()
return {"containment_payload": containment_script}
Test the agent against a simulated Cobalt Strike C2 beacon event. LangGraph halts at an approval checkpoint, presenting the evidence dossier to the SOC Lead before applying firewall drops.
soc_app = workflow.compile(interrupt_before=["remediation_builder"])
simulated_event = {
"event_id": 1,
"timestamp": "2026-11-18T00:30:00Z",
"hostname": "DC-CORP-EAST",
"process_name": "powershell.exe",
"command_line": "powershell.exe -w hidden -enc JABjAGwAaQBlAG4AdAA...",
"parent_process": "wmiprvse.exe",
"dest_ip": "185.220.101.5",
"dest_port": 443,
"user": "CORP\\svc_backup"
}
initial_state = {"event": simulated_event, "approved": False}
for output in soc_app.stream(initial_state):
print(output)
SOC Console Triage Output
[TRIAGE ALERT] Severity: CRITICAL (Confidence: 0.98)
[MITRE] T1059.001 (PowerShell Obfuscation), T1047 (WMI Execution)
[INTEL] Destination IP 185.220.101.5 flagged on AbuseIPDB (Risk: 94%)
[CONTAINMENT PROPOSAL] Generated iptables drop rule for 185.220.101.5 and process kill.
>>> PAUSED: Awaiting SOC Commander approval to execute containment... [Y/n]