Siemens S7Comm¶
S7Comm is the proprietary protocol used by Siemens S7-300, S7-400, S7-1200, and S7-1500 PLCs. It runs over TCP/102 and is layered:
- TPKT (RFC 1006): wraps ISO transport over TCP
- COTP (ISO 8073): ISO transport class 0
- S7: Siemens application layer
What IndustrialScanner does¶
The S7Comm analyzer:
- Reads PCAP/PCAPNG files
- Filters TCP traffic on port 102
- Unwraps TPKT/COTP framing
- Parses the S7 header (byte 0 = 0x32 magic, byte 1 = ROSCTR)
- Parses the parameter block (function code at offset 10)
- Classifies each packet by function code
- Flags suspect functions (WriteVar, Start, Stop, DownloadBlock, CopyRamToRom, FirmwareUpdate, Password)
- Enriches with MITRE ATT&CK for ICS techniques
Function codes detected¶
| Code | Name | Suspect | Description |
|---|---|---|---|
| 0x04 | ReadVar | No | Read variables |
| 0x05 | WriteVar | Yes | Write variables |
| 0x28 | Start | Yes | Start CPU |
| 0x29 | Stop | Yes | Stop CPU |
| 0xF0 | SetupComm | No | Setup communication handshake |
| 0x3A | DownloadBlock | Yes | Download block to PLC |
| 0x3B | UploadBlock | No | Upload block from PLC |
| 0x3C | DeleteBlock | Yes | Delete block |
| 0x44 | FirmwareUpdate | Yes | Update firmware |
| 0x45 | Password | Yes | Authentication |
| 0x46 | ReadDiag | No | Read diagnostic data |
| 0x4E | CopyRamToRom | Yes | Persist RAM to ROM |
Usage¶
# Analyze a single PCAP
industrial-scanner s7 --pcap capture.pcapng
# Batch process all PCAPs in pcaps/s7/
python -m s7_comm_analyzer.s7_analyze
Output¶
- JSON report in
reports/s7_batch/<basename>.json - HTML report in
reports/s7_batch/<basename>.html
Each packet entry includes:
- src, dst, function_code, length, hints (ASCII strings found in payload)
- rosctr (Job, Ack, AckData, Userdata)
- pdu_ref (PDU reference number)
- mitre_attack (list of MITRE techniques)
Limitations¶
- S7Comm-Plus (firmware ≥ V3.0 on S7-1200/1500) uses encrypted X3.1324
framing and is not supported. The analyzer will return
NonS7Payloadfor these frames. - The parser does not yet decode the item structure within the parameter block (variable addresses, data types). Only the function code is extracted.
Security considerations¶
- S7Comm has no authentication by default (the 0x45 Password function is optional and rarely used)
- Anyone with network access to TCP/102 can issue Start/Stop/DownloadBlock
- For production, use S7Comm-Plus (encrypted) or restrict TCP/102 access via firewall rules