[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7EH5R6T5VBACATC6SC3928H":3,"skill-same:01M7EH5R6T5VBACATC6SC3928H":84},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":56,"commitSha":57,"skillDirectory":58,"forksCount":59,"repositoryHtmlUrl":60,"repositoryHomepageUrl":6,"ownerHtmlUrl":61,"ownerBlogUrl":6,"ownerDescription":62,"updatedAt":63,"install":64,"resources":77},"01M7EH5R6T5VBACATC6SC3928H","detecting-attacks-on-scada-systems",null,"This skill covers detecting cyber attacks targeting Supervisory Control and Data Acquisition (SCADA) systems including man-in-the-middle attacks on industrial protocols, unauthorized command injection into PLCs, HMI compromise, historian data manipulation, and denial-of-service against control system communications. It leverages OT-specific intrusion detection systems, industrial protocol anomaly detection, and process data analytics to identify attacks that traditional IT security tools miss.","lza6\u002FArmor-piercing-system-prompts","lza6","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F128880206?v=4","01M7EB3K7WPX5T28EJ2NVHE6EG","Chinese-tingfeng","01M7EB3K97E1KQ16QWKJMFNGX8",11,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F04-安全渗透\u002Fdetecting-attacks-on-scada-systems\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: detecting-attacks-on-scada-systems\ndescription: 'This skill covers detecting cyber attacks targeting Supervisory Control\n  and Data Acquisition (SCADA) systems including man-in-the-middle attacks on industrial\n  protocols, unauthorized command injection into PLCs, HMI compromise, historian data\n  manipulation, and denial-of-service against control system communications. It leverages\n  OT-specific intrusion detection systems, industrial protocol anomaly detection,\n  and process data analytics to identify attacks that traditional IT security tools\n  miss.\n\n  '\ndomain: cybersecurity\nsubdomain: ot-ics-security\ntags:\n- ot-security\n- ics\n- scada\n- industrial-control\n- iec62443\n- intrusion-detection\n- threat-detection\nversion: 1.0.0\nauthor: mahipal\nlicense: Apache-2.0\nnist_ai_rmf:\n- MEASURE-2.7\n- MAP-5.1\n- MANAGE-2.4\natlas_techniques:\n- AML.T0070\n- AML.T0066\n- AML.T0082\nnist_csf:\n- PR.IR-01\n- DE.CM-01\n- ID.AM-05\n- GV.OC-02\nmitre_attack:\n- T0846\n- T0836\n- T0831\n- T0814\n- T0832\n---\n\n# Detecting Attacks on SCADA Systems\n\n## When to Use\n\n- When deploying intrusion detection capabilities in a SCADA environment for the first time\n- When investigating suspected cyber attacks against industrial control systems\n- When building detection rules for OT-specific attack patterns (Stuxnet, TRITON, Industroyer)\n- When integrating OT network monitoring with an enterprise SOC for unified threat visibility\n- When responding to alerts from OT security monitoring tools (Dragos, Nozomi, Claroty)\n\n**Do not use** for detecting attacks on IT-only networks without SCADA\u002FICS components, for building generic network IDS rules (see building-detection-rules-with-sigma), or for incident response procedures after an attack is confirmed (see performing-ot-incident-response).\n\n## Prerequisites\n\n- Passive network monitoring sensors deployed on SPAN\u002FTAP ports at OT network boundaries\n- OT intrusion detection system (Dragos Platform, Nozomi Guardian, Claroty xDome, or Suricata with OT rulesets)\n- Understanding of industrial protocols in use (Modbus, DNP3, OPC UA, EtherNet\u002FIP, S7comm)\n- Baseline of normal SCADA communication patterns (polling intervals, function codes, register ranges)\n- Access to process historian data for physical process anomaly correlation\n\n## Workflow\n\n### Step 1: Establish SCADA Communication Baselines\n\nBefore detecting anomalies, establish what normal SCADA traffic looks like. Industrial protocols are highly deterministic - the same master polls the same slaves at the same intervals reading the same registers.\n\n```python\n#!\u002Fusr\u002Fbin\u002Fenv python3\n\"\"\"SCADA Communication Baseline Builder.\n\nAnalyzes OT network traffic to establish deterministic baselines for\nModbus\u002FTCP, DNP3, EtherNet\u002FIP, and S7comm communications.\n\"\"\"\n\nimport json\nimport sys\nfrom collections import defaultdict\nfrom datetime import datetime\nfrom statistics import mean, stdev\n\ntry:\n    from scapy.all import rdpcap, IP, TCP, UDP\nexcept ImportError:\n    print(\"Install scapy: pip install scapy\")\n    sys.exit(1)\n\nMODBUS_FUNC_NAMES = {\n    1: \"Read Coils\", 2: \"Read Discrete Inputs\",\n    3: \"Read Holding Registers\", 4: \"Read Input Registers\",\n    5: \"Write Single Coil\", 6: \"Write Single Register\",\n    8: \"Diagnostics\", 15: \"Write Multiple Coils\",\n    16: \"Write Multiple Registers\", 17: \"Report Slave ID\",\n    22: \"Mask Write Register\", 23: \"Read\u002FWrite Multiple Registers\",\n    43: \"Encapsulated Interface Transport\",\n}\n\n\nclass SCADABaselineBuilder:\n    \"\"\"Builds deterministic baselines from SCADA traffic captures.\"\"\"\n\n    def __init__(self):\n        self.modbus_sessions = defaultdict(lambda: {\n            \"func_codes\": defaultdict(int),\n            \"register_ranges\": set(),\n            \"intervals\": [],\n            \"last_seen\": None,\n            \"request_count\": 0,\n        })\n        self.communication_pairs = defaultdict(lambda: {\n            \"protocols\": set(),\n            \"packet_count\": 0,\n            \"first_seen\": None,\n            \"last_seen\": None,\n        })\n\n    def process_pcap(self, pcap_file):\n        \"\"\"Process pcap file to build SCADA baselines.\"\"\"\n        packets = rdpcap(pcap_file)\n        print(f\"[*] Processing {len(packets)} packets for baseline...\")\n\n        for pkt in packets:\n            if not pkt.haslayer(IP):\n                continue\n\n            src = pkt[IP].src\n            dst = pkt[IP].dst\n            ts = float(pkt.time)\n\n            # Track communication pairs\n            pair_key = f\"{src}->{dst}\"\n            pair = self.communication_pairs[pair_key]\n            pair[\"packet_count\"] += 1\n            if pair[\"first_seen\"] is None:\n                pair[\"first_seen\"] = ts\n            pair[\"last_seen\"] = ts\n\n            # Analyze Modbus\u002FTCP\n            if pkt.haslayer(TCP) and pkt[TCP].dport == 502:\n                self._analyze_modbus(pkt, src, dst, ts)\n\n    def _analyze_modbus(self, pkt, src, dst, timestamp):\n        \"\"\"Extract Modbus function codes and register ranges.\"\"\"\n        payload = bytes(pkt[TCP].payload)\n        if len(payload) \u003C 8:\n            return\n\n        # MBAP header: transaction_id(2) + protocol_id(2) + length(2) + unit_id(1) + func_code(1)\n        func_code = payload[7]\n        session_key = f\"{src}->{dst}\"\n        session = self.modbus_sessions[session_key]\n\n        session[\"func_codes\"][func_code] += 1\n        session[\"request_count\"] += 1\n        session[\"protocols\"] = {\"Modbus\u002FTCP\"}\n\n        # Track polling intervals\n        if session[\"last_seen\"] is not None:\n            interval = timestamp - session[\"last_seen\"]\n            if 0.01 \u003C interval \u003C 60:  # Reasonable polling interval\n                session[\"intervals\"].append(interval)\n        session[\"last_seen\"] = timestamp\n\n        # Extract register range for read\u002Fwrite operations\n        if len(payload) >= 12 and func_code in (1, 2, 3, 4, 5, 6, 15, 16):\n            start_register = (payload[8] \u003C\u003C 8) | payload[9]\n            if func_code in (1, 2, 3, 4, 15, 16) and len(payload) >= 12:\n                count = (payload[10] \u003C\u003C 8) | payload[11]\n                session[\"register_ranges\"].add((func_code, start_register, start_register + count))\n\n    def generate_baseline(self):\n        \"\"\"Generate the baseline profile from collected data.\"\"\"\n        baseline = {\n            \"generated\": datetime.now().isoformat(),\n            \"modbus_baselines\": {},\n            \"communication_pairs\": {},\n        }\n\n        for session_key, session in self.modbus_sessions.items():\n            avg_interval = mean(session[\"intervals\"]) if session[\"intervals\"] else 0\n            interval_std = stdev(session[\"intervals\"]) if len(session[\"intervals\"]) > 1 else 0\n\n            baseline[\"modbus_baselines\"][session_key] = {\n                \"allowed_function_codes\": list(session[\"func_codes\"].keys()),\n                \"function_code_distribution\": {\n                    MODBUS_FUNC_NAMES.get(k, f\"FC{k}\"): v\n                    for k, v in session[\"func_codes\"].items()\n                },\n                \"polling_interval_avg_sec\": round(avg_interval, 3),\n                \"polling_interval_stddev\": round(interval_std, 3),\n                \"register_ranges\": [\n                    {\"func_code\": r[0], \"start\": r[1], \"end\": r[2]}\n                    for r in session[\"register_ranges\"]\n                ],\n                \"total_requests\": session[\"request_count\"],\n            }\n\n        return baseline\n\n    def export_baseline(self, output_file):\n        \"\"\"Export baseline to JSON file.\"\"\"\n        baseline = self.generate_baseline()\n        with open(output_file, \"w\") as f:\n            json.dump(baseline, f, indent=2)\n        print(f\"[*] Baseline saved to: {output_file}\")\n\n        # Print summary\n        print(f\"\\n{'='*60}\")\n        print(\"SCADA COMMUNICATION BASELINE SUMMARY\")\n        print(f\"{'='*60}\")\n        for session, data in baseline[\"modbus_baselines\"].items():\n            print(f\"\\n  Session: {session}\")\n            print(f\"    Function Codes: {data['allowed_function_codes']}\")\n            print(f\"    Polling Interval: {data['polling_interval_avg_sec']}s (+\u002F- {data['polling_interval_stddev']}s)\")\n            print(f\"    Register Ranges: {len(data['register_ranges'])}\")\n            print(f\"    Total Requests: {data['total_requests']}\")\n\n\nif __name__ == \"__main__\":\n    if len(sys.argv) \u003C 2:\n        print(\"Usage: python scada_baseline.py \u003Cpcap_file> [output.json]\")\n        sys.exit(1)\n\n    builder = SCADABaselineBuilder()\n    builder.process_pcap(sys.argv[1])\n    output = sys.argv[2] if len(sys.argv) > 2 else \"scada_baseline.json\"\n    builder.export_baseline(output)\n```\n\n### Step 2: Deploy OT-Specific Detection Rules\n\nCreate detection rules for known SCADA attack patterns including those used by TRITON, Industroyer\u002FCrashOverride, and PIPEDREAM\u002FINCONTROLLER.\n\n```yaml\n# Suricata Rules for SCADA Attack Detection\n# Deploy on IDS sensor monitoring OT network SPAN port\n\n# --- Modbus Attack Detection ---\n\n# Unauthorized Modbus write to PLC from non-engineering workstation\nalert modbus any any -> $OT_PLC_SUBNET 502 (\n  msg:\"OT-DETECT Modbus write from unauthorized source\";\n  modbus_func:!read_coils; modbus_func:!read_discrete_inputs;\n  modbus_func:!read_holding_registers; modbus_func:!read_input_registers;\n  flow:to_server,established;\n  threshold:type both, track by_src, count 1, seconds 60;\n  classtype:attempted-admin;\n  sid:3000001; rev:1;\n)\n\n# Modbus diagnostic\u002Frestart command (FC 8) - potential PLC DoS\nalert modbus any any -> $OT_PLC_SUBNET 502 (\n  msg:\"OT-DETECT Modbus diagnostics command to PLC\";\n  modbus_func:diagnostics;\n  flow:to_server,established;\n  classtype:attempted-dos;\n  sid:3000002; rev:1;\n)\n\n# Modbus broadcast write (unit ID 0) - affects all slaves\nalert modbus any any -> $OT_PLC_SUBNET 502 (\n  msg:\"OT-CRITICAL Modbus broadcast write command\";\n  modbus_unit_id:0;\n  flow:to_server,established;\n  classtype:attempted-admin;\n  sid:3000003; rev:1;\n  priority:1;\n)\n\n# --- S7comm Attack Detection (Siemens) ---\n\n# S7comm CPU STOP command - shuts down PLC execution\nalert tcp any any -> $SIEMENS_PLC_SUBNET 102 (\n  msg:\"OT-CRITICAL S7comm CPU STOP command detected\";\n  content:\"|03 00|\"; offset:0; depth:2;\n  content:\"|29|\"; offset:17; depth:1;\n  flow:to_server,established;\n  classtype:attempted-dos;\n  sid:3000010; rev:1;\n  priority:1;\n)\n\n# S7comm PLC program upload (potential logic modification)\nalert tcp any any -> $SIEMENS_PLC_SUBNET 102 (\n  msg:\"OT-CRITICAL S7comm program download to PLC\";\n  content:\"|03 00|\"; offset:0; depth:2;\n  content:\"|1a|\"; offset:17; depth:1;\n  flow:to_server,established;\n  classtype:attempted-admin;\n  sid:3000011; rev:1;\n  priority:1;\n)\n\n# --- DNP3 Attack Detection ---\n\n# DNP3 cold restart command\nalert tcp any any -> $OT_RTU_SUBNET 20000 (\n  msg:\"OT-CRITICAL DNP3 cold restart command\";\n  content:\"|05 64|\"; offset:0; depth:2;\n  content:\"|0d|\"; offset:12; depth:1;\n  flow:to_server,established;\n  classtype:attempted-dos;\n  sid:3000020; rev:1;\n  priority:1;\n)\n\n# DNP3 firmware update command - potential PIPEDREAM indicator\nalert tcp any any -> $OT_RTU_SUBNET 20000 (\n  msg:\"OT-CRITICAL DNP3 file transfer \u002F firmware update\";\n  content:\"|05 64|\"; offset:0; depth:2;\n  content:\"|19|\"; offset:12; depth:1;\n  flow:to_server,established;\n  classtype:attempted-admin;\n  sid:3000021; rev:1;\n  priority:1;\n)\n\n# --- Network Anomaly Detection ---\n\n# New device communicating with PLCs (not in baseline)\nalert ip !$AUTHORIZED_OT_HOSTS any -> $OT_PLC_SUBNET any (\n  msg:\"OT-DETECT Unauthorized device communicating with PLC subnet\";\n  flow:to_server;\n  threshold:type limit, track by_src, count 1, seconds 3600;\n  classtype:network-scan;\n  sid:3000030; rev:1;\n)\n\n# Port scan targeting OT protocols\nalert tcp any any -> $OT_NETWORK any (\n  msg:\"OT-DETECT Port scan targeting industrial protocols\";\n  flags:S;\n  threshold:type threshold, track by_src, count 10, seconds 60;\n  classtype:network-scan;\n  sid:3000031; rev:1;\n)\n```\n\n### Step 3: Implement Process Data Anomaly Detection\n\nMonitor physical process data from the historian to detect attacks that manipulate the process while hiding their effects from operators (the Stuxnet attack pattern).\n\n```python\n#!\u002Fusr\u002Fbin\u002Fenv python3\n\"\"\"SCADA Process Data Anomaly Detector.\n\nMonitors historian data to detect physical process anomalies\nthat may indicate cyber attacks manipulating control logic\nwhile spoofing sensor readings (Stuxnet-style attacks).\n\"\"\"\n\nimport json\nimport sys\nimport time\nfrom collections import deque\nfrom dataclasses import dataclass\nfrom datetime import datetime\nfrom statistics import mean, stdev\nfrom typing import Optional\n\ntry:\n    import requests\nexcept ImportError:\n    print(\"Install requests: pip install requests\")\n    sys.exit(1)\n\n\n@dataclass\nclass ProcessVariable:\n    \"\"\"Represents a monitored process variable.\"\"\"\n    tag_name: str\n    description: str\n    unit: str\n    low_limit: float\n    high_limit: float\n    rate_of_change_limit: float  # Maximum change per second\n    engineering_low: float\n    engineering_high: float\n\n\n@dataclass\nclass Anomaly:\n    \"\"\"Represents a detected process anomaly.\"\"\"\n    timestamp: str\n    tag_name: str\n    anomaly_type: str\n    severity: str\n    current_value: float\n    expected_range: str\n    description: str\n    attack_pattern: str = \"\"\n\n\nclass ProcessAnomalyDetector:\n    \"\"\"Detects anomalies in SCADA process data from historian.\"\"\"\n\n    def __init__(self, historian_url, api_key=None):\n        self.historian_url = historian_url\n        self.api_key = api_key\n        self.variables = {}\n        self.history = defaultdict(lambda: deque(maxlen=1000))\n        self.anomalies = []\n\n    def add_variable(self, var: ProcessVariable):\n        \"\"\"Register a process variable to monitor.\"\"\"\n        self.variables[var.tag_name] = var\n\n    def fetch_current_values(self):\n        \"\"\"Fetch current values from historian API.\"\"\"\n        headers = {}\n        if self.api_key:\n            headers[\"Authorization\"] = f\"Bearer {self.api_key}\"\n\n        tag_list = list(self.variables.keys())\n        params = {\"tags\": \",\".join(tag_list), \"count\": 1}\n\n        try:\n            resp = requests.get(\n                f\"{self.historian_url}\u002Fapi\u002Fv1\u002Fstreams\u002Fvalues\u002Fcurrent\",\n                params=params,\n                headers=headers,\n                timeout=10,\n                verify=not os.environ.get(\"SKIP_TLS_VERIFY\", \"\").lower() == \"true\",  # Set SKIP_TLS_VERIFY=true for self-signed certs in lab environments\n            )\n            resp.raise_for_status()\n            return resp.json()\n        except requests.RequestException as e:\n            print(f\"[ERROR] Historian API error: {e}\")\n            return {}\n\n    def check_value(self, tag_name, value, timestamp):\n        \"\"\"Check a process variable value against all detection rules.\"\"\"\n        var = self.variables.get(tag_name)\n        if not var:\n            return\n\n        self.history[tag_name].append((timestamp, value))\n\n        # Rule 1: Value out of engineering limits\n        if value \u003C var.engineering_low or value > var.engineering_high:\n            self.anomalies.append(Anomaly(\n                timestamp=timestamp,\n                tag_name=tag_name,\n                anomaly_type=\"OUT_OF_RANGE\",\n                severity=\"critical\",\n                current_value=value,\n                expected_range=f\"{var.engineering_low}-{var.engineering_high} {var.unit}\",\n                description=f\"{tag_name} ({var.description}) at {value} {var.unit} - outside engineering limits\",\n                attack_pattern=\"Process manipulation - value driven outside safe operating range\",\n            ))\n\n        # Rule 2: Rate of change exceeds physical limits\n        history = list(self.history[tag_name])\n        if len(history) >= 2:\n            prev_ts, prev_val = history[-2]\n            try:\n                dt = (datetime.fromisoformat(timestamp) - datetime.fromisoformat(prev_ts)).total_seconds()\n                if dt > 0:\n                    rate = abs(value - prev_val) \u002F dt\n                    if rate > var.rate_of_change_limit:\n                        self.anomalies.append(Anomaly(\n                            timestamp=timestamp,\n                            tag_name=tag_name,\n                            anomaly_type=\"RATE_OF_CHANGE_VIOLATION\",\n                            severity=\"high\",\n                            current_value=value,\n                            expected_range=f\"Max rate: {var.rate_of_change_limit} {var.unit}\u002Fs\",\n                            description=(\n                                f\"{tag_name} changing at {rate:.2f} {var.unit}\u002Fs \"\n                                f\"(limit: {var.rate_of_change_limit} {var.unit}\u002Fs)\"\n                            ),\n                            attack_pattern=\"Possible sensor spoofing or actuator manipulation\",\n                        ))\n            except (ValueError, TypeError):\n                pass\n\n        # Rule 3: Flatline detection (sensor reading not changing when process is active)\n        if len(history) >= 20:\n            recent_values = [v for _, v in list(history)[-20:]]\n            if len(set(recent_values)) == 1:\n                self.anomalies.append(Anomaly(\n                    timestamp=timestamp,\n                    tag_name=tag_name,\n                    anomaly_type=\"FLATLINE_DETECTED\",\n                    severity=\"high\",\n                    current_value=value,\n                    expected_range=\"Expected variation during active process\",\n                    description=f\"{tag_name} flatlined at {value} for 20+ consecutive readings\",\n                    attack_pattern=\"Stuxnet-style replay attack - frozen sensor value while process is manipulated\",\n                ))\n\n        # Rule 4: Statistical anomaly (z-score based)\n        if len(history) >= 50:\n            values = [v for _, v in list(history)[-50:]]\n            avg = mean(values)\n            std = stdev(values) if len(values) > 1 else 0\n            if std > 0:\n                z_score = abs(value - avg) \u002F std\n                if z_score > 3.5:\n                    self.anomalies.append(Anomaly(\n                        timestamp=timestamp,\n                        tag_name=tag_name,\n                        anomaly_type=\"STATISTICAL_ANOMALY\",\n                        severity=\"medium\",\n                        current_value=value,\n                        expected_range=f\"Mean: {avg:.2f}, StdDev: {std:.2f} (z={z_score:.1f})\",\n                        description=f\"{tag_name} value {value} is {z_score:.1f} standard deviations from mean\",\n                        attack_pattern=\"Possible gradual process manipulation\",\n                    ))\n\n    def report_anomalies(self):\n        \"\"\"Print detected anomalies.\"\"\"\n        if not self.anomalies:\n            print(\"[*] No anomalies detected\")\n            return\n\n        print(f\"\\n{'='*70}\")\n        print(f\"PROCESS ANOMALY DETECTION REPORT - {len(self.anomalies)} anomalies\")\n        print(f\"{'='*70}\")\n\n        for a in self.anomalies:\n            print(f\"\\n  [{a.severity.upper()}] {a.anomaly_type}\")\n            print(f\"    Time: {a.timestamp}\")\n            print(f\"    Tag: {a.tag_name}\")\n            print(f\"    Value: {a.current_value}\")\n            print(f\"    Expected: {a.expected_range}\")\n            print(f\"    Detail: {a.description}\")\n            if a.attack_pattern:\n                print(f\"    Attack Pattern: {a.attack_pattern}\")\n\n\nif __name__ == \"__main__\":\n    from collections import defaultdict\n\n    detector = ProcessAnomalyDetector(\n        historian_url=\"https:\u002F\u002F10.30.1.50:5450\",\n    )\n\n    # Define monitored process variables for a chemical reactor\n    detector.add_variable(ProcessVariable(\n        tag_name=\"REACTOR_01.TEMP\",\n        description=\"Reactor 1 Temperature\",\n        unit=\"C\",\n        low_limit=150, high_limit=280,\n        rate_of_change_limit=5.0,\n        engineering_low=100, engineering_high=350,\n    ))\n    detector.add_variable(ProcessVariable(\n        tag_name=\"REACTOR_01.PRESSURE\",\n        description=\"Reactor 1 Pressure\",\n        unit=\"bar\",\n        low_limit=2.0, high_limit=8.0,\n        rate_of_change_limit=0.5,\n        engineering_low=0, engineering_high=12.0,\n    ))\n    detector.add_variable(ProcessVariable(\n        tag_name=\"PUMP_03.FLOW\",\n        description=\"Feed Pump 3 Flow Rate\",\n        unit=\"m3\u002Fh\",\n        low_limit=5.0, high_limit=25.0,\n        rate_of_change_limit=2.0,\n        engineering_low=0, engineering_high=30.0,\n    ))\n\n    print(\"[*] Starting process anomaly monitoring...\")\n    print(\"[*] Press Ctrl+C to stop and generate report\")\n\n    try:\n        while True:\n            data = detector.fetch_current_values()\n            for item in data.get(\"items\", []):\n                detector.check_value(\n                    item.get(\"tag\"),\n                    item.get(\"value\"),\n                    item.get(\"timestamp\", datetime.now().isoformat()),\n                )\n            time.sleep(5)\n    except KeyboardInterrupt:\n        detector.report_anomalies()\n```\n\n### Step 4: Detect Known ICS Malware Indicators\n\nMonitor for indicators of compromise (IOCs) associated with known ICS-targeting malware families.\n\n```yaml\n# Known ICS Malware Detection Signatures\n# Reference: MITRE ATT&CK for ICS, CISA ICS-CERT advisories\n\nmalware_families:\n  TRITON_TRISIS:\n    description: \"Targets Schneider Electric Triconex Safety Instrumented Systems\"\n    target: \"Safety controllers (SIS)\"\n    network_indicators:\n      - protocol: \"TriStation\"\n        port: 1502\n        pattern: \"Unusual TriStation commands from non-engineering workstation\"\n      - protocol: \"TCP\"\n        pattern: \"Connection to Triconex controller from unauthorized IP\"\n    host_indicators:\n      - \"trilog.exe present on engineering workstation\"\n      - \"inject.bin in System32 directory\"\n      - \"imain.bin payload targeting Triconex firmware\"\n    detection_rule: |\n      alert tcp !$SIS_ENGINEERING_WS any -> $SIS_CONTROLLERS 1502 (\n        msg:\"OT-CRITICAL Unauthorized TriStation connection to SIS\";\n        flow:to_server; sid:3000100; rev:1; priority:1;)\n\n  INDUSTROYER_CRASHOVERRIDE:\n    description: \"Targets power grid SCADA via IEC 60870-5-101\u002F104, IEC 61850, OPC DA\"\n    target: \"Power grid substations and SCADA\"\n    network_indicators:\n      - protocol: \"IEC 60870-5-104\"\n        port: 2404\n        pattern: \"Rapid sequence of control commands outside normal polling\"\n      - protocol: \"OPC DA\"\n        pattern: \"Enumeration of OPC servers followed by write commands\"\n    host_indicators:\n      - \"haslo.exe (backdoor launcher)\"\n      - \"61850.dll (IEC 61850 attack module)\"\n      - \"OPC.dll (OPC DA attack module)\"\n      - \"104.dll (IEC 104 attack module)\"\n    detection_rule: |\n      alert tcp any any -> $SUBSTATION_RTU 2404 (\n        msg:\"OT-CRITICAL Rapid IEC 104 control commands - Industroyer pattern\";\n        flow:to_server,established;\n        threshold:type threshold, track by_src, count 50, seconds 10;\n        sid:3000110; rev:1; priority:1;)\n\n  PIPEDREAM_INCONTROLLER:\n    description: \"Modular ICS attack framework targeting Schneider\u002FOMRON PLCs and OPC UA\"\n    target: \"Multiple PLC vendors (Schneider, OMRON) and OPC UA servers\"\n    network_indicators:\n      - protocol: \"CODESYS\"\n        port: 1217\n        pattern: \"CODESYS runtime exploitation attempts\"\n      - protocol: \"OPC UA\"\n        port: 4840\n        pattern: \"OPC UA server enumeration and unauthorized method calls\"\n      - protocol: \"Modbus\"\n        port: 502\n        pattern: \"Rapid Modbus write commands to multiple unit IDs\"\n    host_indicators:\n      - \"TAGRUN tool for OPC UA scanning\"\n      - \"CODECALL tool for CODESYS exploitation\"\n      - \"OMSHELL tool for OMRON PLC interaction\"\n    detection_rule: |\n      alert tcp any any -> $OT_NETWORK 1217 (\n        msg:\"OT-CRITICAL CODESYS runtime connection - PIPEDREAM indicator\";\n        flow:to_server,established;\n        sid:3000120; rev:1; priority:1;)\n```\n\n## Key Concepts\n\n| Term | Definition |\n|------|------------|\n| SCADA | Supervisory Control and Data Acquisition - architecture for remote monitoring and control of industrial processes via RTUs and communication infrastructure |\n| IDS\u002FIPS for OT | Intrusion Detection\u002FPrevention Systems designed for industrial protocols, using both signature-based and anomaly-based detection methods |\n| Process Anomaly | Deviation in physical process behavior (temperature, pressure, flow) that may indicate cyber manipulation of control systems |\n| Man-in-the-Middle (MITM) | Attack intercepting communication between SCADA master and field devices to modify commands or spoof sensor readings |\n| Replay Attack | Capturing legitimate SCADA traffic and replaying it to mask malicious changes to the process (used by Stuxnet) |\n| Protocol Anomaly | Deviation from expected industrial protocol behavior including unauthorized function codes, unusual polling patterns, or command sequences |\n\n## Tools & Systems\n\n- **Dragos Platform**: OT cybersecurity platform with threat detection powered by Dragos threat intelligence on ICS-targeting activity groups\n- **Nozomi Networks Guardian**: OT\u002FIoT visibility and threat detection using asset intelligence, anomaly detection, and vulnerability assessment\n- **Claroty xDome**: Cyber-physical systems protection with continuous threat monitoring and alert prioritization\n- **Suricata with ET Open ICS rules**: Open-source IDS\u002FIPS with community-maintained rules for industrial protocol detection\n- **Zeek (Bro) with OT scripts**: Network security monitor with protocol analyzers for Modbus, DNP3, and BACnet\n\n## Common Scenarios\n\n### Scenario: Detecting TRITON-Style Attack on Safety Systems\n\n**Context**: An OT security monitoring system alerts on unusual TriStation protocol traffic to a Triconex safety controller from an IP address that is not the authorized SIS engineering workstation.\n\n**Approach**:\n1. Immediately verify the source IP of the TriStation traffic - is it the authorized SIS engineering workstation or a compromised host?\n2. Check if there is an authorized maintenance activity scheduled for the SIS controllers\n3. Capture full packet payload of the TriStation communication for forensic analysis\n4. Alert the process safety team - SIS compromise is a safety-critical event\n5. If unauthorized, isolate the source host from the network immediately\n6. Verify SIS controller logic integrity by comparing running logic against known-good backup\n7. Check all engineering workstations in the facility for TRITON indicators (trilog.exe, inject.bin)\n\n**Pitfalls**: Never assume SIS traffic anomalies are false positives - TRITON demonstrated that sophisticated attackers specifically target safety systems. Do not restart the SIS controller without first verifying firmware and logic integrity. Avoid alerting only the IT SOC; the process safety team must be immediately engaged for any SIS-related incident.\n\n## Output Format\n\n```\nSCADA Attack Detection Report\n===============================\nDetection Time: YYYY-MM-DD HH:MM:SS UTC\nDetection Source: [IDS\u002FAnomaly Detector\u002FProcess Monitor]\n\nALERT DETAILS:\n  Alert ID: [unique identifier]\n  Severity: Critical\u002FHigh\u002FMedium\u002FLow\n  Attack Category: [Protocol Anomaly\u002FProcess Manipulation\u002FUnauthorized Access]\n  MITRE ATT&CK for ICS: [Technique ID and name]\n\n  Source: [IP\u002Fhostname]\n  Target: [IP\u002Fhostname - device type]\n  Protocol: [Modbus\u002FDNP3\u002FS7comm\u002Fetc]\n  Detail: [Specific finding description]\n\nBASELINE COMPARISON:\n  Normal: [Expected behavior]\n  Observed: [Actual behavior that triggered alert]\n  Deviation: [How the observed differs from baseline]\n\nRECOMMENDED RESPONSE:\n  1. [Immediate containment action]\n  2. [Verification step]\n  3. [Escalation path]\n```\n","# Detecting Attacks on SCADA Systems\n\n## When to Use\n\n- When deploying intrusion detection capabilities in a SCADA environment for the first time\n- When investigating suspected cyber attacks against industrial control systems\n- When building detection rules for OT-specific attack patterns (Stuxnet, TRITON, Industroyer)\n- When integrating OT network monitoring with an enterprise SOC for unified threat visibility\n- When responding to alerts from OT security monitoring tools (Dragos, Nozomi, Claroty)\n\n**Do not use** for detecting attacks on IT-only networks without SCADA\u002FICS components, for building generic network IDS rules (see building-detection-rules-with-sigma), or for incident response procedures after an attack is confirmed (see performing-ot-incident-response).\n\n## Prerequisites\n\n- Passive network monitoring sensors deployed on SPAN\u002FTAP ports at OT network boundaries\n- OT intrusion detection system (Dragos Platform, Nozomi Guardian, Claroty xDome, or Suricata with OT rulesets)\n- Understanding of industrial protocols in use (Modbus, DNP3, OPC UA, EtherNet\u002FIP, S7comm)\n- Baseline of normal SCADA communication patterns (polling intervals, function codes, register ranges)\n- Access to process historian data for physical process anomaly correlation\n\n## Workflow\n\n### Step 1: Establish SCADA Communication Baselines\n\nBefore detecting anomalies, establish what normal SCADA traffic looks like. Industrial protocols are highly deterministic - the same master polls the same slaves at the same intervals reading the same registers.\n\n```python\n#!\u002Fusr\u002Fbin\u002Fenv python3\n\"\"\"SCADA Communication Baseline Builder.\n\nAnalyzes OT network traffic to establish deterministic baselines for\nModbus\u002FTCP, DNP3, EtherNet\u002FIP, and S7comm communications.\n\"\"\"\n\nimport json\nimport sys\nfrom collections import defaultdict\nfrom datetime import datetime\nfrom statistics import mean, stdev\n\ntry:\n    from scapy.all import rdpcap, IP, TCP, UDP\nexcept ImportError:\n    print(\"Install scapy: pip install scapy\")\n    sys.exit(1)\n\nMODBUS_FUNC_NAMES = {\n    1: \"Read Coils\", 2: \"Read Discrete Inputs\",\n    3: \"Read Holding Registers\", 4: \"Read Input Registers\",\n    5: \"Write Single Coil\", 6: \"Write Single Register\",\n    8: \"Diagnostics\", 15: \"Write Multiple Coils\",\n    16: \"Write Multiple Registers\", 17: \"Report Slave ID\",\n    22: \"Mask Write Register\", 23: \"Read\u002FWrite Multiple Registers\",\n    43: \"Encapsulated Interface Transport\",\n}\n\n\nclass SCADABaselineBuilder:\n    \"\"\"Builds deterministic baselines from SCADA traffic captures.\"\"\"\n\n    def __init__(self):\n        self.modbus_sessions = defaultdict(lambda: {\n            \"func_codes\": defaultdict(int),\n            \"register_ranges\": set(),\n            \"intervals\": [],\n            \"last_seen\": None,\n            \"request_count\": 0,\n        })\n        self.communication_pairs = defaultdict(lambda: {\n            \"protocols\": set(),\n            \"packet_count\": 0,\n            \"first_seen\": None,\n            \"last_seen\": None,\n        })\n\n    def process_pcap(self, pcap_file):\n        \"\"\"Process pcap file to build SCADA baselines.\"\"\"\n        packets = rdpcap(pcap_file)\n        print(f\"[*] Processing {len(packets)} packets for baseline...\")\n\n        for pkt in packets:\n            if not pkt.haslayer(IP):\n                continue\n\n            src = pkt[IP].src\n            dst = pkt[IP].dst\n            ts = float(pkt.time)\n\n            # Track communication pairs\n            pair_key = f\"{src}->{dst}\"\n            pair = self.communication_pairs[pair_key]\n            pair[\"packet_count\"] += 1\n            if pair[\"first_seen\"] is None:\n                pair[\"first_seen\"] = ts\n            pair[\"last_seen\"] = ts\n\n            # Analyze Modbus\u002FTCP\n            if pkt.haslayer(TCP) and pkt[TCP].dport == 502:\n                self._analyze_modbus(pkt, src, dst, ts)\n\n    def _analyze_modbus(self, pkt, src, dst, timestamp):\n        \"\"\"Extract Modbus function codes and register ranges.\"\"\"\n        payload = bytes(pkt[TCP].payload)\n        if len(payload) \u003C 8:\n            return\n\n        # MBAP header: transaction_id(2) + protocol_id(2) + length(2) + unit_id(1) + func_code(1)\n        func_code = payload[7]\n        session_key = f\"{src}->{dst}\"\n        session = self.modbus_sessions[session_key]\n\n        session[\"func_codes\"][func_code] += 1\n        session[\"request_count\"] += 1\n        session[\"protocols\"] = {\"Modbus\u002FTCP\"}\n\n        # Track polling intervals\n        if session[\"last_seen\"] is not None:\n            interval = timestamp - session[\"last_seen\"]\n            if 0.01 \u003C interval \u003C 60:  # Reasonable polling interval\n                session[\"intervals\"].append(interval)\n        session[\"last_seen\"] = timestamp\n\n        # Extract register range for read\u002Fwrite operations\n        if len(payload) >= 12 and func_code in (1, 2, 3, 4, 5, 6, 15, 16):\n            start_register = (payload[8] \u003C\u003C 8) | payload[9]\n            if func_code in (1, 2, 3, 4, 15, 16) and len(payload) >= 12:\n                count = (payload[10] \u003C\u003C 8) | payload[11]\n                session[\"register_ranges\"].add((func_code, start_register, start_register + count))\n\n    def generate_baseline(self):\n        \"\"\"Generate the baseline profile from collected data.\"\"\"\n        baseline = {\n            \"generated\": datetime.now().isoformat(),\n            \"modbus_baselines\": {},\n            \"communication_pairs\": {},\n        }\n\n        for session_key, session in self.modbus_sessions.items():\n            avg_interval = mean(session[\"intervals\"]) if session[\"intervals\"] else 0\n            interval_std = stdev(session[\"intervals\"]) if len(session[\"intervals\"]) > 1 else 0\n\n            baseline[\"modbus_baselines\"][session_key] = {\n                \"allowed_function_codes\": list(session[\"func_codes\"].keys()),\n                \"function_code_distribution\": {\n                    MODBUS_FUNC_NAMES.get(k, f\"FC{k}\"): v\n                    for k, v in session[\"func_codes\"].items()\n                },\n                \"polling_interval_avg_sec\": round(avg_interval, 3),\n                \"polling_interval_stddev\": round(interval_std, 3),\n                \"register_ranges\": [\n                    {\"func_code\": r[0], \"start\": r[1], \"end\": r[2]}\n                    for r in session[\"register_ranges\"]\n                ],\n                \"total_requests\": session[\"request_count\"],\n            }\n\n        return baseline\n\n    def export_baseline(self, output_file):\n        \"\"\"Export baseline to JSON file.\"\"\"\n        baseline = self.generate_baseline()\n        with open(output_file, \"w\") as f:\n            json.dump(baseline, f, indent=2)\n        print(f\"[*] Baseline saved to: {output_file}\")\n\n        # Print summary\n        print(f\"\\n{'='*60}\")\n        print(\"SCADA COMMUNICATION BASELINE SUMMARY\")\n        print(f\"{'='*60}\")\n        for session, data in baseline[\"modbus_baselines\"].items():\n            print(f\"\\n  Session: {session}\")\n            print(f\"    Function Codes: {data['allowed_function_codes']}\")\n            print(f\"    Polling Interval: {data['polling_interval_avg_sec']}s (+\u002F- {data['polling_interval_stddev']}s)\")\n            print(f\"    Register Ranges: {len(data['register_ranges'])}\")\n            print(f\"    Total Requests: {data['total_requests']}\")\n\n\nif __name__ == \"__main__\":\n    if len(sys.argv) \u003C 2:\n        print(\"Usage: python scada_baseline.py \u003Cpcap_file> [output.json]\")\n        sys.exit(1)\n\n    builder = SCADABaselineBuilder()\n    builder.process_pcap(sys.argv[1])\n    output = sys.argv[2] if len(sys.argv) > 2 else \"scada_baseline.json\"\n    builder.export_baseline(output)\n```\n\n### Step 2: Deploy OT-Specific Detection Rules\n\nCreate detection rules for known SCADA attack patterns including those used by TRITON, Industroyer\u002FCrashOverride, and PIPEDREAM\u002FINCONTROLLER.\n\n```yaml\n# Suricata Rules for SCADA Attack Detection\n# Deploy on IDS sensor monitoring OT network SPAN port\n\n# --- Modbus Attack Detection ---\n\n# Unauthorized Modbus write to PLC from non-engineering workstation\nalert modbus any any -> $OT_PLC_SUBNET 502 (\n  msg:\"OT-DETECT Modbus write from unauthorized source\";\n  modbus_func:!read_coils; modbus_func:!read_discrete_inputs;\n  modbus_func:!read_holding_registers; modbus_func:!read_input_registers;\n  flow:to_server,established;\n  threshold:type both, track by_src, count 1, seconds 60;\n  classtype:attempted-admin;\n  sid:3000001; rev:1;\n)\n\n# Modbus diagnostic\u002Frestart command (FC 8) - potential PLC DoS\nalert modbus any any -> $OT_PLC_SUBNET 502 (\n  msg:\"OT-DETECT Modbus diagnostics command to PLC\";\n  modbus_func:diagnostics;\n  flow:to_server,established;\n  classtype:attempted-dos;\n  sid:3000002; rev:1;\n)\n\n# Modbus broadcast write (unit ID 0) - affects all slaves\nalert modbus any any -> $OT_PLC_SUBNET 502 (\n  msg:\"OT-CRITICAL Modbus broadcast write command\";\n  modbus_unit_id:0;\n  flow:to_server,established;\n  classtype:attempted-admin;\n  sid:3000003; rev:1;\n  priority:1;\n)\n\n# --- S7comm Attack Detection (Siemens) ---\n\n# S7comm CPU STOP command - shuts down PLC execution\nalert tcp any any -> $SIEMENS_PLC_SUBNET 102 (\n  msg:\"OT-CRITICAL S7comm CPU STOP command detected\";\n  content:\"|03 00|\"; offset:0; depth:2;\n  content:\"|29|\"; offset:17; depth:1;\n  flow:to_server,established;\n  classtype:attempted-dos;\n  sid:3000010; rev:1;\n  priority:1;\n)\n\n# S7comm PLC program upload (potential logic modification)\nalert tcp any any -> $SIEMENS_PLC_SUBNET 102 (\n  msg:\"OT-CRITICAL S7comm program download to PLC\";\n  content:\"|03 00|\"; offset:0; depth:2;\n  content:\"|1a|\"; offset:17; depth:1;\n  flow:to_server,established;\n  classtype:attempted-admin;\n  sid:3000011; rev:1;\n  priority:1;\n)\n\n# --- DNP3 Attack Detection ---\n\n# DNP3 cold restart command\nalert tcp any any -> $OT_RTU_SUBNET 20000 (\n  msg:\"OT-CRITICAL DNP3 cold restart command\";\n  content:\"|05 64|\"; offset:0; depth:2;\n  content:\"|0d|\"; offset:12; depth:1;\n  flow:to_server,established;\n  classtype:attempted-dos;\n  sid:3000020; rev:1;\n  priority:1;\n)\n\n# DNP3 firmware update command - potential PIPEDREAM indicator\nalert tcp any any -> $OT_RTU_SUBNET 20000 (\n  msg:\"OT-CRITICAL DNP3 file transfer \u002F firmware update\";\n  content:\"|05 64|\"; offset:0; depth:2;\n  content:\"|19|\"; offset:12; depth:1;\n  flow:to_server,established;\n  classtype:attempted-admin;\n  sid:3000021; rev:1;\n  priority:1;\n)\n\n# --- Network Anomaly Detection ---\n\n# New device communicating with PLCs (not in baseline)\nalert ip !$AUTHORIZED_OT_HOSTS any -> $OT_PLC_SUBNET any (\n  msg:\"OT-DETECT Unauthorized device communicating with PLC subnet\";\n  flow:to_server;\n  threshold:type limit, track by_src, count 1, seconds 3600;\n  classtype:network-scan;\n  sid:3000030; rev:1;\n)\n\n# Port scan targeting OT protocols\nalert tcp any any -> $OT_NETWORK any (\n  msg:\"OT-DETECT Port scan targeting industrial protocols\";\n  flags:S;\n  threshold:type threshold, track by_src, count 10, seconds 60;\n  classtype:network-scan;\n  sid:3000031; rev:1;\n)\n```\n\n### Step 3: Implement Process Data Anomaly Detection\n\nMonitor physical process data from the historian to detect attacks that manipulate the process while hiding their effects from operators (the Stuxnet attack pattern).\n\n```python\n#!\u002Fusr\u002Fbin\u002Fenv python3\n\"\"\"SCADA Process Data Anomaly Detector.\n\nMonitors historian data to detect physical process anomalies\nthat may indicate cyber attacks manipulating control logic\nwhile spoofing sensor readings (Stuxnet-style attacks).\n\"\"\"\n\nimport json\nimport sys\nimport time\nfrom collections import deque\nfrom dataclasses import dataclass\nfrom datetime import datetime\nfrom statistics import mean, stdev\nfrom typing import Optional\n\ntry:\n    import requests\nexcept ImportError:\n    print(\"Install requests: pip install requests\")\n    sys.exit(1)\n\n\n@dataclass\nclass ProcessVariable:\n    \"\"\"Represents a monitored process variable.\"\"\"\n    tag_name: str\n    description: str\n    unit: str\n    low_limit: float\n    high_limit: float\n    rate_of_change_limit: float  # Maximum change per second\n    engineering_low: float\n    engineering_high: float\n\n\n@dataclass\nclass Anomaly:\n    \"\"\"Represents a detected process anomaly.\"\"\"\n    timestamp: str\n    tag_name: str\n    anomaly_type: str\n    severity: str\n    current_value: float\n    expected_range: str\n    description: str\n    attack_pattern: str = \"\"\n\n\nclass ProcessAnomalyDetector:\n    \"\"\"Detects anomalies in SCADA process data from historian.\"\"\"\n\n    def __init__(self, historian_url, api_key=None):\n        self.historian_url = historian_url\n        self.api_key = api_key\n        self.variables = {}\n        self.history = defaultdict(lambda: deque(maxlen=1000))\n        self.anomalies = []\n\n    def add_variable(self, var: ProcessVariable):\n        \"\"\"Register a process variable to monitor.\"\"\"\n        self.variables[var.tag_name] = var\n\n    def fetch_current_values(self):\n        \"\"\"Fetch current values from historian API.\"\"\"\n        headers = {}\n        if self.api_key:\n            headers[\"Authorization\"] = f\"Bearer {self.api_key}\"\n\n        tag_list = list(self.variables.keys())\n        params = {\"tags\": \",\".join(tag_list), \"count\": 1}\n\n        try:\n            resp = requests.get(\n                f\"{self.historian_url}\u002Fapi\u002Fv1\u002Fstreams\u002Fvalues\u002Fcurrent\",\n                params=params,\n                headers=headers,\n                timeout=10,\n                verify=not os.environ.get(\"SKIP_TLS_VERIFY\", \"\").lower() == \"true\",  # Set SKIP_TLS_VERIFY=true for self-signed certs in lab environments\n            )\n            resp.raise_for_status()\n            return resp.json()\n        except requests.RequestException as e:\n            print(f\"[ERROR] Historian API error: {e}\")\n            return {}\n\n    def check_value(self, tag_name, value, timestamp):\n        \"\"\"Check a process variable value against all detection rules.\"\"\"\n        var = self.variables.get(tag_name)\n        if not var:\n            return\n\n        self.history[tag_name].append((timestamp, value))\n\n        # Rule 1: Value out of engineering limits\n        if value \u003C var.engineering_low or value > var.engineering_high:\n            self.anomalies.append(Anomaly(\n                timestamp=timestamp,\n                tag_name=tag_name,\n                anomaly_type=\"OUT_OF_RANGE\",\n                severity=\"critical\",\n                current_value=value,\n                expected_range=f\"{var.engineering_low}-{var.engineering_high} {var.unit}\",\n                description=f\"{tag_name} ({var.description}) at {value} {var.unit} - outside engineering limits\",\n                attack_pattern=\"Process manipulation - value driven outside safe operating range\",\n            ))\n\n        # Rule 2: Rate of change exceeds physical limits\n        history = list(self.history[tag_name])\n        if len(history) >= 2:\n            prev_ts, prev_val = history[-2]\n            try:\n                dt = (datetime.fromisoformat(timestamp) - datetime.fromisoformat(prev_ts)).total_seconds()\n                if dt > 0:\n                    rate = abs(value - prev_val) \u002F dt\n                    if rate > var.rate_of_change_limit:\n                        self.anomalies.append(Anomaly(\n                            timestamp=timestamp,\n                            tag_name=tag_name,\n                            anomaly_type=\"RATE_OF_CHANGE_VIOLATION\",\n                            severity=\"high\",\n                            current_value=value,\n                            expected_range=f\"Max rate: {var.rate_of_change_limit} {var.unit}\u002Fs\",\n                            description=(\n                                f\"{tag_name} changing at {rate:.2f} {var.unit}\u002Fs \"\n                                f\"(limit: {var.rate_of_change_limit} {var.unit}\u002Fs)\"\n                            ),\n                            attack_pattern=\"Possible sensor spoofing or actuator manipulation\",\n                        ))\n            except (ValueError, TypeError):\n                pass\n\n        # Rule 3: Flatline detection (sensor reading not changing when process is active)\n        if len(history) >= 20:\n            recent_values = [v for _, v in list(history)[-20:]]\n            if len(set(recent_values)) == 1:\n                self.anomalies.append(Anomaly(\n                    timestamp=timestamp,\n                    tag_name=tag_name,\n                    anomaly_type=\"FLATLINE_DETECTED\",\n                    severity=\"high\",\n                    current_value=value,\n                    expected_range=\"Expected variation during active process\",\n                    description=f\"{tag_name} flatlined at {value} for 20+ consecutive readings\",\n                    attack_pattern=\"Stuxnet-style replay attack - frozen sensor value while process is manipulated\",\n                ))\n\n        # Rule 4: Statistical anomaly (z-score based)\n        if len(history) >= 50:\n            values = [v for _, v in list(history)[-50:]]\n            avg = mean(values)\n            std = stdev(values) if len(values) > 1 else 0\n            if std > 0:\n                z_score = abs(value - avg) \u002F std\n                if z_score > 3.5:\n                    self.anomalies.append(Anomaly(\n                        timestamp=timestamp,\n                        tag_name=tag_name,\n                        anomaly_type=\"STATISTICAL_ANOMALY\",\n                        severity=\"medium\",\n                        current_value=value,\n                        expected_range=f\"Mean: {avg:.2f}, StdDev: {std:.2f} (z={z_score:.1f})\",\n                        description=f\"{tag_name} value {value} is {z_score:.1f} standard deviations from mean\",\n                        attack_pattern=\"Possible gradual process manipulation\",\n                    ))\n\n    def report_anomalies(self):\n        \"\"\"Print detected anomalies.\"\"\"\n        if not self.anomalies:\n            print(\"[*] No anomalies detected\")\n            return\n\n        print(f\"\\n{'='*70}\")\n        print(f\"PROCESS ANOMALY DETECTION REPORT - {len(self.anomalies)} anomalies\")\n        print(f\"{'='*70}\")\n\n        for a in self.anomalies:\n            print(f\"\\n  [{a.severity.upper()}] {a.anomaly_type}\")\n            print(f\"    Time: {a.timestamp}\")\n            print(f\"    Tag: {a.tag_name}\")\n            print(f\"    Value: {a.current_value}\")\n            print(f\"    Expected: {a.expected_range}\")\n            print(f\"    Detail: {a.description}\")\n            if a.attack_pattern:\n                print(f\"    Attack Pattern: {a.attack_pattern}\")\n\n\nif __name__ == \"__main__\":\n    from collections import defaultdict\n\n    detector = ProcessAnomalyDetector(\n        historian_url=\"https:\u002F\u002F10.30.1.50:5450\",\n    )\n\n    # Define monitored process variables for a chemical reactor\n    detector.add_variable(ProcessVariable(\n        tag_name=\"REACTOR_01.TEMP\",\n        description=\"Reactor 1 Temperature\",\n        unit=\"C\",\n        low_limit=150, high_limit=280,\n        rate_of_change_limit=5.0,\n        engineering_low=100, engineering_high=350,\n    ))\n    detector.add_variable(ProcessVariable(\n        tag_name=\"REACTOR_01.PRESSURE\",\n        description=\"Reactor 1 Pressure\",\n        unit=\"bar\",\n        low_limit=2.0, high_limit=8.0,\n        rate_of_change_limit=0.5,\n        engineering_low=0, engineering_high=12.0,\n    ))\n    detector.add_variable(ProcessVariable(\n        tag_name=\"PUMP_03.FLOW\",\n        description=\"Feed Pump 3 Flow Rate\",\n        unit=\"m3\u002Fh\",\n        low_limit=5.0, high_limit=25.0,\n        rate_of_change_limit=2.0,\n        engineering_low=0, engineering_high=30.0,\n    ))\n\n    print(\"[*] Starting process anomaly monitoring...\")\n    print(\"[*] Press Ctrl+C to stop and generate report\")\n\n    try:\n        while True:\n            data = detector.fetch_current_values()\n            for item in data.get(\"items\", []):\n                detector.check_value(\n                    item.get(\"tag\"),\n                    item.get(\"value\"),\n                    item.get(\"timestamp\", datetime.now().isoformat()),\n                )\n            time.sleep(5)\n    except KeyboardInterrupt:\n        detector.report_anomalies()\n```\n\n### Step 4: Detect Known ICS Malware Indicators\n\nMonitor for indicators of compromise (IOCs) associated with known ICS-targeting malware families.\n\n```yaml\n# Known ICS Malware Detection Signatures\n# Reference: MITRE ATT&CK for ICS, CISA ICS-CERT advisories\n\nmalware_families:\n  TRITON_TRISIS:\n    description: \"Targets Schneider Electric Triconex Safety Instrumented Systems\"\n    target: \"Safety controllers (SIS)\"\n    network_indicators:\n      - protocol: \"TriStation\"\n        port: 1502\n        pattern: \"Unusual TriStation commands from non-engineering workstation\"\n      - protocol: \"TCP\"\n        pattern: \"Connection to Triconex controller from unauthorized IP\"\n    host_indicators:\n      - \"trilog.exe present on engineering workstation\"\n      - \"inject.bin in System32 directory\"\n      - \"imain.bin payload targeting Triconex firmware\"\n    detection_rule: |\n      alert tcp !$SIS_ENGINEERING_WS any -> $SIS_CONTROLLERS 1502 (\n        msg:\"OT-CRITICAL Unauthorized TriStation connection to SIS\";\n        flow:to_server; sid:3000100; rev:1; priority:1;)\n\n  INDUSTROYER_CRASHOVERRIDE:\n    description: \"Targets power grid SCADA via IEC 60870-5-101\u002F104, IEC 61850, OPC DA\"\n    target: \"Power grid substations and SCADA\"\n    network_indicators:\n      - protocol: \"IEC 60870-5-104\"\n        port: 2404\n        pattern: \"Rapid sequence of control commands outside normal polling\"\n      - protocol: \"OPC DA\"\n        pattern: \"Enumeration of OPC servers followed by write commands\"\n    host_indicators:\n      - \"haslo.exe (backdoor launcher)\"\n      - \"61850.dll (IEC 61850 attack module)\"\n      - \"OPC.dll (OPC DA attack module)\"\n      - \"104.dll (IEC 104 attack module)\"\n    detection_rule: |\n      alert tcp any any -> $SUBSTATION_RTU 2404 (\n        msg:\"OT-CRITICAL Rapid IEC 104 control commands - Industroyer pattern\";\n        flow:to_server,established;\n        threshold:type threshold, track by_src, count 50, seconds 10;\n        sid:3000110; rev:1; priority:1;)\n\n  PIPEDREAM_INCONTROLLER:\n    description: \"Modular ICS attack framework targeting Schneider\u002FOMRON PLCs and OPC UA\"\n    target: \"Multiple PLC vendors (Schneider, OMRON) and OPC UA servers\"\n    network_indicators:\n      - protocol: \"CODESYS\"\n        port: 1217\n        pattern: \"CODESYS runtime exploitation attempts\"\n      - protocol: \"OPC UA\"\n        port: 4840\n        pattern: \"OPC UA server enumeration and unauthorized method calls\"\n      - protocol: \"Modbus\"\n        port: 502\n        pattern: \"Rapid Modbus write commands to multiple unit IDs\"\n    host_indicators:\n      - \"TAGRUN tool for OPC UA scanning\"\n      - \"CODECALL tool for CODESYS exploitation\"\n      - \"OMSHELL tool for OMRON PLC interaction\"\n    detection_rule: |\n      alert tcp any any -> $OT_NETWORK 1217 (\n        msg:\"OT-CRITICAL CODESYS runtime connection - PIPEDREAM indicator\";\n        flow:to_server,established;\n        sid:3000120; rev:1; priority:1;)\n```\n\n## Key Concepts\n\n| Term | Definition |\n|------|------------|\n| SCADA | Supervisory Control and Data Acquisition - architecture for remote monitoring and control of industrial processes via RTUs and communication infrastructure |\n| IDS\u002FIPS for OT | Intrusion Detection\u002FPrevention Systems designed for industrial protocols, using both signature-based and anomaly-based detection methods |\n| Process Anomaly | Deviation in physical process behavior (temperature, pressure, flow) that may indicate cyber manipulation of control systems |\n| Man-in-the-Middle (MITM) | Attack intercepting communication between SCADA master and field devices to modify commands or spoof sensor readings |\n| Replay Attack | Capturing legitimate SCADA traffic and replaying it to mask malicious changes to the process (used by Stuxnet) |\n| Protocol Anomaly | Deviation from expected industrial protocol behavior including unauthorized function codes, unusual polling patterns, or command sequences |\n\n## Tools & Systems\n\n- **Dragos Platform**: OT cybersecurity platform with threat detection powered by Dragos threat intelligence on ICS-targeting activity groups\n- **Nozomi Networks Guardian**: OT\u002FIoT visibility and threat detection using asset intelligence, anomaly detection, and vulnerability assessment\n- **Claroty xDome**: Cyber-physical systems protection with continuous threat monitoring and alert prioritization\n- **Suricata with ET Open ICS rules**: Open-source IDS\u002FIPS with community-maintained rules for industrial protocol detection\n- **Zeek (Bro) with OT scripts**: Network security monitor with protocol analyzers for Modbus, DNP3, and BACnet\n\n## Common Scenarios\n\n### Scenario: Detecting TRITON-Style Attack on Safety Systems\n\n**Context**: An OT security monitoring system alerts on unusual TriStation protocol traffic to a Triconex safety controller from an IP address that is not the authorized SIS engineering workstation.\n\n**Approach**:\n1. Immediately verify the source IP of the TriStation traffic - is it the authorized SIS engineering workstation or a compromised host?\n2. Check if there is an authorized maintenance activity scheduled for the SIS controllers\n3. Capture full packet payload of the TriStation communication for forensic analysis\n4. Alert the process safety team - SIS compromise is a safety-critical event\n5. If unauthorized, isolate the source host from the network immediately\n6. Verify SIS controller logic integrity by comparing running logic against known-good backup\n7. Check all engineering workstations in the facility for TRITON indicators (trilog.exe, inject.bin)\n\n**Pitfalls**: Never assume SIS traffic anomalies are false positives - TRITON demonstrated that sophisticated attackers specifically target safety systems. Do not restart the SIS controller without first verifying firmware and logic integrity. Avoid alerting only the IT SOC; the process safety team must be immediately engaged for any SIS-related incident.\n\n## Output Format\n\n```\nSCADA Attack Detection Report\n===============================\nDetection Time: YYYY-MM-DD HH:MM:SS UTC\nDetection Source: [IDS\u002FAnomaly Detector\u002FProcess Monitor]\n\nALERT DETAILS:\n  Alert ID: [unique identifier]\n  Severity: Critical\u002FHigh\u002FMedium\u002FLow\n  Attack Category: [Protocol Anomaly\u002FProcess Manipulation\u002FUnauthorized Access]\n  MITRE ATT&CK for ICS: [Technique ID and name]\n\n  Source: [IP\u002Fhostname]\n  Target: [IP\u002Fhostname - device type]\n  Protocol: [Modbus\u002FDNP3\u002FS7comm\u002Fetc]\n  Detail: [Specific finding description]\n\nBASELINE COMPARISON:\n  Normal: [Expected behavior]\n  Observed: [Actual behavior that triggered alert]\n  Deviation: [How the observed differs from baseline]\n\nRECOMMENDED RESPONSE:\n  1. [Immediate containment action]\n  2. [Verification step]\n  3. [Escalation path]\n```\n",{"name":5,"tags":24,"author":32,"domain":33,"license":15,"version":34,"nist_csf":35,"subdomain":40,"description":41,"nist_ai_rmf":42,"mitre_attack":46,"atlas_techniques":52},[25,26,27,28,29,30,31],"ot-security","ics","scada","industrial-control","iec62443","intrusion-detection","threat-detection","mahipal","cybersecurity","1.0.0",[36,37,38,39],"PR.IR-01","DE.CM-01","ID.AM-05","GV.OC-02","ot-ics-security","This skill covers detecting cyber attacks targeting Supervisory Control and Data Acquisition (SCADA) systems including man-in-the-middle attacks on industrial protocols, unauthorized command injection into PLCs, HMI compromise, historian data manipulation, and denial-of-service against control system communications. It leverages OT-specific intrusion detection systems, industrial protocol anomaly detection, and process data analytics to identify attacks that traditional IT security tools miss.\n",[43,44,45],"MEASURE-2.7","MAP-5.1","MANAGE-2.4",[47,48,49,50,51],"T0846","T0836","T0831","T0814","T0832",[53,54,55],"AML.T0070","AML.T0066","AML.T0082","main","d69096e239f2a89aabc2cd078c47664a9d3b1e11","04-安全渗透\u002Fdetecting-attacks-on-scada-systems",3,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts","https:\u002F\u002Fgithub.com\u002Flza6","个人vx：Tf00798\r\n个人✈：@TFGY999","2026-10-08 14:29:22",{"source":8,"skillName":5,"commands":65,"prompt":75,"zipAvailable":76},[66,69,72],{"tool":67,"command":68},"npx","npx skills add lza6\u002FArmor-piercing-system-prompts --skill detecting-attacks-on-scada-systems",{"tool":70,"command":71},"bunx","bunx skills add lza6\u002FArmor-piercing-system-prompts --skill detecting-attacks-on-scada-systems",{"tool":73,"command":74},"pnpm","pnpm dlx skills add lza6\u002FArmor-piercing-system-prompts --skill detecting-attacks-on-scada-systems","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F04-安全渗透\u002Fdetecting-attacks-on-scada-systems\u002FSKILL.md",true,[78],{"path":79,"resourceType":80,"resourceTypeDesc":81,"sizeBytes":82,"sourceHtmlUrl":83},"references\u002Fapi-reference.md","REFERENCE","参考文档",2078,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F04-安全渗透\u002Fdetecting-attacks-on-scada-systems\u002Freferences\u002Fapi-reference.md",[85,94,99,106,113,120],{"skillNo":86,"name":87,"nameZh":6,"description":88,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":89,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":92,"publishedAt":93},"01M7FFG485KY83TD6HSC4YPCMC","obsidian-clipper-template-creator","Guide for creating templates for the Obsidian Web Clipper. Use when you want to create a new clipping template, understand available variables, or format clipped content.","MIT","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobsidian-clipper-template-creator\u002FSKILL.md",[],[],"2026-11-16 10:05:34",{"skillNo":95,"name":87,"nameZh":6,"description":88,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":89,"licenseFileUrl":6,"sourceHtmlUrl":96,"categories":97,"keywords":98,"publishedAt":93},"01M7FFG0T6AZ0STEJPSB3CX84K","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobsidian-clipper-template-creator-antigravity-awesome-skills-main\u002FSKILL.md",[],[],{"skillNo":100,"name":101,"nameZh":6,"description":102,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":89,"licenseFileUrl":6,"sourceHtmlUrl":103,"categories":104,"keywords":105,"publishedAt":93},"01M7FFFY0QEM14SKWPDYGMXM2P","python-api","Programmatic Object-Detection-Metrics API guidance for BoundingBox, BoundingBoxes, Evaluator, enums, coordinate conversion, AP\u002FmAP semantics, and source-style import diagnostics.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002Fsub-skills\u002Fpython-api\u002FSKILL.md",[],[],{"skillNo":107,"name":108,"nameZh":6,"description":109,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":89,"licenseFileUrl":6,"sourceHtmlUrl":110,"categories":111,"keywords":112,"publishedAt":93},"01M7FFFVZQZ2GJ0C0TGP7JHD20","file-evaluation","Folder-based PASCAL VOC AP\u002FmAP evaluation from ground-truth and detection text files.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002Fsub-skills\u002Ffile-evaluation\u002FSKILL.md",[],[],{"skillNo":114,"name":115,"nameZh":6,"description":116,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":89,"licenseFileUrl":6,"sourceHtmlUrl":117,"categories":118,"keywords":119,"publishedAt":93},"01M7FFFSFNYSE77SJ6PE1CK2DA","object-detection-metrics","Guides legacy Object-Detection-Metrics PASCAL VOC AP\u002FmAP evaluation from detection text folders and direct Python API classes.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002FSKILL.md",[],[],{"skillNo":121,"name":122,"nameZh":6,"description":123,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":89,"licenseFileUrl":6,"sourceHtmlUrl":124,"categories":125,"keywords":126,"publishedAt":93},"01M7FFFP0GCK1RVXBCPQ8APBMT","nx-workspace-patterns","Configure and optimize Nx monorepo workspaces. Use when setting up Nx, configuring project boundaries, optimizing build caching, or implementing affected commands.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fnx-workspace-patterns\u002FSKILL.md",[],[]]