executing-plans
executing-plans
Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available
re-ics工控协议逆向:Modbus/DNP3/OPC UA。 触发词:工控、ICS、Modbus、DNP3、OPC UA、SCADA、PLC
Independent GitHub snapshot · Automated classification · Original documentation governs
所有工具先验证再使用。ICS 分析红线:只测授权系统、默认隔离网络([[re-analyze/platform-tips]] 最高原则)——测试环境严禁接生产 OT 网络(见步骤 5)。
apt install wireshark tshark / dnf install wireshark-cli wireshark / pacman -S wireshark-cli wireshark-qt(Arch 已拆分为 wireshark-cli + wireshark-qt;Debian 安装时选"允许非 root 抓包",或 sudo dpkg-reconfigure wireshark-common 后把用户加入 wireshark 组)brew install --cask wireshark(含 tshark CLI;或 brew install wireshark 仅 CLI)choco install wireshark(或官方安装包);WSL 内用 Linux 版tshark --version;tshark -G fields | grep -iE 'modbus|dnp3|opcua' 列出 ICS 字段名(各版本字段名可能有微调,以该输出为准)pip install scapy(Python 3,推荐)apt install python3-scapy(Debian 系;含 contrib 层)python3 -c "from scapy.contrib.modbus import ModbusADURequest, ModbusADUResponse; print('ok')"scapy.contrib.modbus(非默认层,需显式 import,ModbusADURequest/ModbusADUResponse + ModbusPDU0X*Request/Response 各功能码类);scapy 各版本均无 DNP3 / OPC UA 层 → DNP3/OPC UA 用 Wireshark 解析或写自定义解析器(见步骤 4)rdpcap(纯 Python 解析,无需 libpcap)按顺序执行,每步记下结果。前提:流量已捕获([[re-netcap]])且为明文(密文先走 [[re-crypto-decrypt]])。
协议识别(端口 + 特征):
tshark -r cap.pcap -T fields -e tcp.dstport | sort | uniq -c | sort -rn # 端口统计
tshark -r cap.pcap -q -z io,phs # 协议分层统计(dissector 命中情况)
05 64;OPC UA 二进制头 3 字节消息类型(HEL/ACK/OPN/CLO/MSG)Wireshark 解析(dissector 优先):
tshark -d tcp.port==5020,modbus)tshark -r cap.pcap -Y 'modbus' -T fields -e modbus.func_code -e mbtcp.unit_id # unit id 官方字段在 mbtcp 层(modbus.unit_id 非官方)
tshark -r cap.pcap -Y 'dnp3' -T fields -e dnp3.ctl -e dnp3.dst -e dnp3.src # 控制字 dnp3.ctl(子字段 dnp3.ctl.dir/prm/fcb/fcv/prifunc/secfunc);站地址在顶层 dnp3.dst/dnp3.src
tshark -r cap.pcap -Y 'opcua' -T fields -e opcua.nodeid.numeric -e opcua.nodeid.string -e opcua.nodeid.guid # nodeid 无顶层字段,按类型用子字段
tshark -G fields | grep -iE 'modbus|dnp3|opcua' 输出为准功能码与对象点表:
scapy 解析器(modbus)+ 自定义 DNP3 解析:
from scapy.all import rdpcap
from scapy.contrib.modbus import ModbusADURequest, ModbusADUResponse
for p in rdpcap('cap.pcap'):
if 'TCP' in p and p['TCP'].dport == 502 and len(p['TCP'].payload) >= 6:
mb = ModbusADURequest(bytes(p['TCP'].payload)) # MBAP+PDU 一起解
mb.show() # transId/protoId/len/unitId + PDU(功能码与寄存器字段)
05 64 | len | ctrl | dst(2) | src(2) | CRC(2),源地址后为强制头 CRC),用 struct 解析即可;后续数据每 16 字节带 2 字节 CRC 分块;传输层/应用层按 IEEE 1815 的组-变体格式递进from scapy.contrib.modbus import ModbusPDU03ReadHoldingRegistersRequest
req = ModbusADURequest() / ModbusPDU03ReadHoldingRegistersRequest(startAddr=0, quantity=10) # 字段名是 camelCase startAddr(scapy 定义),不是 start_addr
授权范围与安全测试边界:
tshark -Y modbus.func_code),点表按功能码分空间(01/02 线圈空间、03/04 寄存器空间)-d 强制指定 dissector