Chuyển đến nội dung
Skillpedia
Agent35k · #7851

detecting-modbus-protocol-anomalies

Skill này làm gì

Công cụ này giúp tìm hoạt động bất thường trong lưu lượng giao tiếp Modbus công nghiệp. Nó kiểm tra xem các lệnh được dùng có đúng dự kiến không và dữ liệu truy cập có nằm trong phạm vi bình thường không.

Khi nào nên dùng

  • ✓Khi thiết lập hệ thống bảo mật cho mạng công nghiệp.
  • ✓Khi điều tra một sự cố hoặc hoạt động đáng ngờ trên dây chuyền sản xuất.
  • ✓Khi lập bản ghi về hành vi mạng bình thường để so sánh sau này.

Liên kết skill

https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/detecting-modbus-protocol-anomalies/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/detecting-modbus-protocol-anomalies/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Hãy kiểm tra lưu lượng Modbus xem có lệnh trái phép hoặc truy cập dữ liệu bất thường không.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Công cụ theo dõi các lệnh (mã chức năng) và dữ liệu (thanh ghi) được trao đổi trên mạng. Nó so sánh lưu lượng hiện tại với bản ghi về mức bình thường để phát hiện sai lệch.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Detecting Modbus Protocol Anomalies

When to Use

  • When deploying Modbus-specific intrusion detection in an OT environment
  • When building baseline models for deterministic Modbus polling patterns
  • When investigating suspicious Modbus traffic flagged by OT monitoring tools
  • When implementing function code allowlisting on industrial firewalls
  • When detecting unauthorized Modbus write commands that could manipulate process setpoints

Do not use for securing Modbus communications end-to-end (Modbus has no native security; see implementing-network-segmentation-for-ot for firewall-based controls), for non-Modbus protocol monitoring (see detecting-anomalies-in-industrial-control-systems for multi-protocol), or for active fuzzing of Modbus implementations (see performing-plc-firmware-security-analysis).

Prerequisites

  • Network SPAN/TAP access to monitor Modbus/TCP traffic (port 502)
  • Zeek (formerly Bro) with Modbus protocol analyzer or Suricata with OT rulesets
  • Python 3.9+ with scapy and pymodbus for custom analysis
  • Baseline capture of normal Modbus traffic (minimum 1-2 weeks)
  • Documentation of authorized Modbus clients, function codes, and register maps

Workflow

Step 1: Capture and Parse Modbus Traffic

Deploy passive monitoring to capture all Modbus/TCP traffic and parse it into structured records for analysis.

#!/usr/bin/env python3
"""Modbus Protocol Anomaly Detection System.

Monitors Modbus/TCP traffic for anomalies including unauthorized
function codes, unusual register access, timing deviations,
and rogue client devices.
"""

import json
import struct
import sys
import time
from collections import defaultdict, deque
from dataclasses import dataclass, field
from datetime import datetime
from statistics import mean, stdev

try:
    from scapy.all import sniff, rdpcap, IP, TCP
except ImportError:
    print("Install scapy: pip install scapy")
    sys.exit(1)


MODBUS_FUNCTION_CODES = {
    1: ("Read Coils", "read"),
    2: ("Read Discrete Inputs", "read"),
    3: ("Read Holding Registers", "read"),
    4: ("Read Input Registers", "read"),
    5: ("Write Single Coil", "write"),
    6: ("Write Single Register", "write"),
    7: ("Read Exception Status", "diagnostic"),
    8: ("Diagnostics", "diagnostic"),
    11: ("Get Comm Event Counter", "diagnostic"),
    12: ("Get Comm Event Log", "diagnostic"),
    15: ("Write Multiple Coils", "write"),
    16: ("Write Multiple Registers", "write"),
    17: ("Report Slave ID", "diagnostic"),
    22: ("Mask Write Register", "write"),
    23: ("Read/Write Multiple Registers", "read_write"),
    43: ("Encapsulated Interface Transport", "diagnostic"),
}


@dataclass
class ModbusAnomaly:
    timestamp: str
    anomaly_type: str
    severity: str
    src_ip: str
    dst_ip: str
    unit_id: int
    func_code: int
    detail: str
    mitre_technique: str = ""


@dataclass
class ModbusSession:
    """Tracks state for a Modbus master-slave session."""
    src_ip: str
    dst_ip: str
    func_codes_seen: dict = field(default_factory=lambda: defaultdict(int))
    register_ranges: set = field(default_factory=set)
    intervals: list = field(default_factory=lambda: deque(maxlen=500))
    last_timestamp: float = 0
    request_count: int = 0
    write_count: int = 0


class ModbusAnomalyDetector:
    """Detects anomalies in Modbus/TCP traffic."""

    def __init__(self):
        self.sessions = {}
        self.baseline_sessions = {}
        self.anomalies = []
        self.authorized_clients = set()
        self.authorized_func_codes = {}  # per-session allowed FCs
        self.packet_count = 0

    def set_authorized_clients(self, clients):
        """Set list of authorized Modbus client IPs."""
        self.authorized_clients = set(clients)

    def set_authorized_func_codes(self, session_key, func_codes):
        """Set allowed function codes for a specific session."""
        self.authorized_func_codes[session_key] = set(func_codes)

    def load_baseline(self, baseline_file):
        """Load baseline profiles from previous capture analysis."""
        with open(baseline_file) as f:
            baseline = json.load(f)
        for key, data in baseline.get("modbus_baselines", {}).items():
            self.baseline_sessions[key] = data
            self.authorized_func_codes[key] = set(data.get("allowed_function_codes", []))
        print(f"[*] Loaded {len(self.baseline_sessions)} Modbus baselines")

    def process_packet(self, pkt):

…
Câu hỏi thường gặp

Modbus là gì?

Modbus là giao thức truyền thông trong hệ thống công nghiệp, cho phép các thiết bị như cảm biến và bộ điều khiển giao tiếp với nhau.

“Bất thường” trong ngữ cảnh này nghĩa là gì?

Bất thường là hoạt động lệch khỏi mẫu bình thường, chẳng hạn dùng lệnh không được phép hoặc truy cập vùng dữ liệu không mong đợi, có thể là dấu hiệu của sự cố hoặc tấn công.

Tôi có cần kiến thức kỹ thuật để dùng không?

Nên có hiểu biết về mạng công nghiệp và giao thức Modbus để đọc kết quả, nhưng công cụ được thiết kế để kết quả rõ ràng nhất có thể.

Chi tiết

Mô tả gốc của tác giả

Detect anomalies in Modbus/TCP and Modbus RTU industrial traffic via function code monitoring, register range validation, timing analysis, and deep packet inspection, using Zeek's Modbus analyzer, Suricata IDS with OT rules, and Python Markov chain models of normal transaction sequences. Use for deploying Modbus IDS in OT environments, baselining polling patterns, investigating suspicious Modbus t

repo: mukul975/Anthropic-Cybersecurity-Skills

Độ phổ biến

Sao GitHub
35k
Vị trí xếp hạng
#7851
Giấy phép
Apache-2.0
Cập nhật
31/8/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự