CypherCon 2024 Reverse Engineering Protocols
CypherCon 2024 Reverse Engineering Protocols
FUN!
Vulnerability icon by Dewi Sari – Flaticon
Interoperability icon by phatplus - Flaticon
5
What is a Protocol?
A set of rules governing the exchange or
transmission of data.
In the real world:
Semaphore flag positions
6
What is a Protocol?
Our protocols are bits on a wire
Data commonly either text based or mixed binary types
Protocols can be updated to run over newer transports
7
Why people make custom protocols?
“We didn’t know about the standard protocol”
“The standard doesn’t exactly cover our use case”
Credit: XKCD
https://xkcd.com/927/
8
Why people make custom protocols?
Efficiency: Say only what we need to say to accomplish goal
Data is specific to a device
• Configuration
• Program Downloads
• Addresses • Checksum/CRCs
• Lengths • Data
10
Typical Data Configuration Data
Model Usernames/Passwords
Contain:
Data of interest: Device Info, Settings, Status
Metadata: Lengths, Checksums, Sequence Numbers
12
Reverse Engineering Basic Process
Protocol capture
14
Matching Data
15
Matching Data - Integers
Field size: 8, 16 or 32 bits?
Size Hex Range Unsigned Range Signed Range
8 Bits 0x00 - 0xFF 0 to 255 -128 to 127
16 Bits 0x0000 - 0xFFFF 0 to ~65k -32k to 32k
32 Bits 0x00000000 – 0xFFFFFFFF 0 to 4.2bn -2.1bn to 2.1bn
Big Endian or Little Endian?
Integer Hexadecimal Endianness Wire Bytes
Big AB CD
43,981 0xABCD
Little CD AB
16
Matching Data - Strings
Null Terminated ASCII (C-String)
43 79 70 68 65 72 43 6F 6E 32 30 32 34 00 ➔ “CypherCon2024/0”
Fixed Allotment
43 79 70 68 65 72 43 6F 6E 32 30 32 34 00 00 00 ➔ “CypherCon2024/0/0/0”
Look-up Table
0x2D ➔ “CypherCon2024”
17
IP & MAC Addresses
IP Addresses
• Usually just 4 bytes: 10.1.128.34 ➔ 0A 01 80 22
• Rarely a string representation: “10.1.128.34”
MAC Addresses
• Almost always a series of 6 bytes
18
Matching Data - Timestamps
As string: “1.2.4r23”
1.2.4r23
20
Change and Recapture
In the packet: What changes? What stays the same?
• Look for matching data changes
• For strings, is there a length field that changes?
• Are there packet length changes?
• Watch for Checksums/CRCs
23
Putting it together – Modbus TCP
24
Putting it together – Modbus TCP
25
Putting it together – Modbus TCP
26
Putting it together – Modbus TCP
27
Putting it together – Modbus TCP
0x28 * 2 = 0x50
28
Putting it together – Custom Protocol
The following slides are examples from a real custom protocol
• Left: data in the vendor software
• Upper Right: software transmitted packet
• Lower Right: device
29
Putting it together
Sent Data:
Response Data:
30
Putting it together
Sent Data:
Response Data:
31
Putting it together
Sent Data:
Response Data:
32
Putting it together
Sent Data:
Response Data:
33
Putting it together
Sent Data:
Response Data:
34
Putting it together
Sent Data:
Response Data:
35
Putting it together Sent Data:
Response Data:
36
Putting it together
37
Putting it together
Sent Data:
Response Data:
=0A 01 80 1B
=/24 =0x18
38
Encryption
Makes life much harder
Becoming more common
Two basic types:
• Signing: Hashing for integrity
• Full Packet Encryption: All data obfuscated
Many algorithms & levels of sophistication
• Wireshark Dissectors
42
Reverse Engineering Summary
• Search for documentation
• Get the device & software
• Identify what data could be on the wire
• Search the captures
• Make changes and watch the packets change
• Use simulation, debuggers & decompilers as needed
43
Common Protocol Issues: Authentication
No Authentication
Bad Password handling
• XOR/simple hash
• No rate limiting
• Password and check on opposite end of the wire
• Password available with unauthenticated protocols
44
Common Protocol Issues: Data Protection
Clear text sensitive data in Protocol
• Passwords, Usernames, Wireless Network Keys
Ability to read/change anything without authentication:
• Read or set passwords and keys
• Download configurations/User Programs
• “Update” firmware
45
Common Protocol Issues: Implementation
Overflow/Underflow issues
Injection attacks
46
Summary I am fluent in
over six million
protocols
Protocols are how devices talk to each other
47
Thank You
Luciano Moretti
[email protected]
www.verveindustrial.com