ModScan - Defcon 2008
ModScan - Defcon 2008
ModScan
Agenda
Brief introduction to SCADA Systems ModScan Primer The MODBUS Protocol MODBUS/TCP ModScan Demonstration ModScan Project Information Q&A
Disclaimer
The material in this presentation is to be
used for authorized security scanning/ auditing
What is SCADA?
Supervisory Control And Data Acquisition
is a system that centrally gathers data in real time from local and remote locations in order to control equipment and conditions. Control Systems (ICS), which is not accurate but close
Where is SCADA?
Power Generation/Transmission Water Treatment/Distribution Pipelines Trafc Control Systems Manufacturing Facilities National Infrastructure
SCADA Architecture
What is ModScan?
ModScan is a tool to detect open
MODBUS/TCP ports and identify device Slave IDs associated with IP addresses
Valid Function codes are 1-127 256 byte maximum packet size Big-Endian encoding Error Check is CRC/LRC
Function Codes
Function Code 01 02 03 04 05 06 07 08 0B 0C 0F 10 11 14 15 16 17 18 Description Read Coils Read Discretes Read Holding Registers Read Input Registers Write Coil Write Register Read Exception Status Diagnostics Get Comm Event Counter Get Comm Event Log Write Multiple Coils Write Multiple Registers Report Slave ID Read File Record Write File Record Mask Write Register Read/Write Multiple Registers Read FIFO Que
Diagnostic Codes
Function Code 00 01 02 03 04 05-09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 16+ Description Return Query Data Restart Communication Return Diagnostic Register Change ASCII Input Delimiter Force Listen Only Mode Reserved Clear Counters and Diagnostic Reg. Return Bus Message Count Return Bus Communication Error Count Return Bus Exception Error Count Return Slave Message Count Return Slave No Response Count Return Slave NAK Count Return Slave Busy Count Return Bus Character Overrun Count Reserved Clear Overrun Counter and Flag Reserved
Typical Communication
Master Slave Initiate Request
SID Fn Data Ec
Receive Response
Error Communication
Master Slave Initiate Request
SID Fn Data Ec
Receive Error
Addressing Valid Slave IDs 1-247 Slave ID must be unique per bus Masters do not have to have an address Slaves will error when improperly addressed Communication One request on the line at a time Masters must wait for responses
Modbus Notes
ModBus/TCP
ModBus protocol wrapped in TCP
Goodness
Checksum dropped Introduction of Gateways Port 502 is reserved for Modbus/TCP Basic protocol is unchanged
ModBus/TCP Architecture
ModBus/TCP Packet
MBAP Tran ID Proto ID Length SID Fn 2 2 2 1 1 PDU Data 252
Bytes
MBAP: MODBUS Application Protocol Header PDU remains the same from the MODBUS spec Protocol ID is always 0x0000 Big-Endian encoding
Example Request
Request sent by Master Request is to Slave 01 Fn 8 Diagnostics Diagnostic code 00 for Return Query Data
Example Response
Response sent by slave Request is to Slave 01 Fn 8 Diagnostics Diagnostic code 00 for Return Query Data Identical to Request
Error Request
Error Response
Function code is 0x88 or 0x08 + 0x80 Specic Error codes are returned in data eld Error 0x03 is Illegal data value
ModScan
Modscan Scans the IP range provided for
open TCP 502
Options
-p PORT (502) -t TIMEOUT socket timeout (100 mills) -a --aggressive Aggressive Mode -f FUNCTION MODBUS Function Code (17) --data Data for use with -f -v, -d Verbose, Debug
ModScan Demonstration
Scanning our sample network A look at a pcap Demo of additional Options
ModScan Project
http://modscan.googlecode.com Uses Network Enumeration IDS/Network Monitoring Test Asset Management Bulk Commands
Known Issues
Really, Really Noisy Port Scanning bits are not efcient Brute forcing SIDs is noisy Does not interpret Error Codes or
responses
Planned Enhancements
Interpret Error Codes Implement with SCAPY Additional Protocol Support Device Fingerprinting Anything cool someone suggests....
Contact Information
Mark Bristow mark.bristow@gmail.com modscan.googlecode.com onelittlewindow.org
Questions?