Dive Into VxWorkis Based IoT Device - Debug The Undebugable Device - Resize
Dive Into VxWorkis Based IoT Device - Debug The Undebugable Device - Resize
• Hunting vulnerabilities
• 2012 - Reversing Industrial firmware for fun and backdoors - Ruben Santamarta
• VxWorks firmware analyzing
• 2015 – Attacking VxWorks From stone age to interstellar - Yannick Formaggio & Eric Liu
• CVE-2015-7599 RPC Integer overflow
• Using WDB-RPC to detect and get crash information during fuzzing progress
XX-Link Router
Breaking HW
U-Boot Infomation
VxWorks CmdTask Commands
Memory Read/Write Command
Flash Command
Analyze VxWorks Firmware
Preparatory Works Before Analyze VxWorks Firmware
• Locate VxWorks image load address
• Locate symbols from firmware and rename functions in IDA
Method 1 - Read From Image Header
TPHEAD in Flash Dump
Method 2 - Locate Initial Stack
VxWorks Image in MIPS Memory Layout
Initial Stack Description
UsrInit Description
VxWorks Image Startup Codes
Jump to usrInit
Other Methods
• Read the boot Info from UART
• Read the developer document
• Use bss end address - image size to calculate the load address
•…
Load Image With Correct Address In IDA
Load image to 0x00 Load image to 0x80001000
Preparatory Works Before Analyze VxWorks Firmware
• Locate VxWorks image load address
• Locate symbols from firmware and rename functions in IDA
Compiled-in Symbol Table In VxWorks 5.5 Image
Stand Alone Symbol File From Firmware
Symbol file length Symbol count Symbol data Symbol Name table Addrss = 0x08 + 0x08 * 0x13ef = 0x9f80
load Symbols
• Operation
• data size cksum
• Data type
• byte short int …
• Endian
• big-endian(1) little-endian(0)
• Value
• Depends
• the area that the size or checksum operation depends on
Crash Detection
Fuzzing Targets
• Parser functions
• json xml url …
• Protocols
• http dns upnp …
DNS Example
DNS Example
• Possibility
• Target running in kernel mode
• We can read/write kernel memory
• We have firmware with symbols
VxSerial Debugger
• Python and instruction based debugger
• Depends
• Keystone - Generation machine code dynamically
• Capstone – Disassembly codes from memory
• Scapy - Parse various data structures in memory
• Support function
• Set breakpoint
• Read/Write memory
• Task status viewer(stacks, register)
• VxWorks structs viewer(netpool, mBlk, etc)
• ……
Overall Design
Debug Shellcode
Debug Loop Codes
Default Breakpoint Output
Condition Breakpoint(CallBack)
Break point parameters Custom condition function
Condition Breakpoint(CallBack)
Get packet address from MBlk header Print packet data
Analyze Vulnerabilities
CVE-2018-19528 DNS Request Buffer Overflow
Vulnerability Description
• Our target router will use domainFilter function to filter all dns request
packets and resolve tplogin.cn domain name to it’s own IP address by
directly modifying the original request packet in netBufLib Memory Pool.
Packet In netBufLib Memory Pool
What Does domainFilter Do?
Direct modify request dns packet in Mblk Call ip_output to send modified packet
It’s Time To Debugging The POC
Packet(Cluster) Data Modified By domainFilter
Packet data before modify Packet data after modify
MBLK Header Modified By domainFilter
Mblk header before modify Mblk header after modify
ip_output -> ip_deliver_packet -> connection_pullup(Root Cause Found)
netTupleGet
netTupleGet parameters Mblk returned by netTupleGet
Copy Modified Mblk Chain Data Using netMblkToBufCopy
netMblkToBufCopy
Copy Chain Data To Target Buffer netMblkToBufCopy Parameters
Buffer Data(Cluster) Before Copy
Buffer Data(Cluster) After Copy
Crash Logs