dive into vxworkis based iot device - debug the undebugable … · • 2010 -shiny old vxworks...

72
Dive into VxWorks Based IoT Device Debug the Undebugable Device

Upload: others

Post on 11-Mar-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Dive into VxWorks Based IoT DeviceDebug the Undebugable Device

Page 2: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Who Are We?• Yu Zhou(@504137480)

• Ant-Financial Light-Year Security Lab

• Fuzzing/IoT/AI

• Wenzhe Zhu (@dark_lbp)

• Pingan Galaxy Lab

• ICS/IoT

Page 3: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Outline• Introduction to VxWorks

• VxWorks firmware analyze

• Hunting vulnerabilities

• Build customized debugger – VxSerial Debugger

• Analyze and exploit vulnerabilities

Page 4: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Introduction VxWorks• Embedded RTOS

• First released in 1987 by Wind River• Closed-source

• [1996~2002] - VxWorks 5.x• [2004~2009] - VxWorks 6.x• [2014] - VxWorks 7

Page 5: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

VxWorks Customers

Page 6: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Previous Research Papers• 2010 - Shiny Old VxWorks Vulnerabilities - HD Moore

• 4 Metasploit modules targeting WDB RPC• Weak password hash entropy

• 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

Page 7: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

XX-Link Router

Page 8: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Breaking HW

Page 9: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

U-Boot Infomation

Page 10: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

VxWorks CmdTask Commands

Page 11: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Memory Read/Write Command

Page 12: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Flash Command

Page 13: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Analyze VxWorks Firmware

Page 14: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Preparatory Works Before Analyze VxWorks Firmware• Locate VxWorks image load address• Locate symbols from firmware and rename functions in IDA

Page 15: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Method 1 - Read From Image Header

Page 16: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

TPHEAD in Flash Dump

Page 17: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Method 2 - Locate Initial Stack

Page 18: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

VxWorks Image in MIPS Memory Layout

Page 19: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Initial Stack Description

Page 20: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

UsrInit Description

Page 21: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

VxWorks Image Startup Codes

Set Initial Stack to 0x80000ff0

Correct load address is 0x80001000

Jump to usrInit

Page 22: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Other Methods• Read the boot Info from UART• Read the developer document• Use bss end address - image size to calculate the load address• …

Page 23: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Load Image With Correct Address In IDA

Load image to 0x00 Load image to 0x80001000

Page 24: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Preparatory Works Before Analyze VxWorks Firmware• Locate VxWorks image load address• Locate symbols from firmware and rename functions in IDA

Page 25: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Compiled-in Symbol Table In VxWorks 5.5 Image

Page 26: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Stand Alone Symbol File From Firmware

Symbol file length Symbol count Symbol data Symbol Name table Addrss = 0x08 + 0x08 * 0x13ef = 0x9f80

Page 27: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

load Symbols

6694 functions Now

Page 28: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Hidden Shell Command Parameter

Page 29: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

CmdTask Command Register Codes

Page 30: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

system Command Help

Page 31: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

system Command Parser Code

Page 32: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Hidden Parameter - moduletree

Page 33: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Hidden Parameter - symble

Page 34: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Hunting Vulnerabilities

Page 35: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Memory Fuzzing Design

• Written in C and converted to MIPS assembly• Write assembly code to the router through the serial port

Page 36: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Fuzzing Approaches

• Generation Based• Data Fields

• byte ubyte• short ushort• int uint• string

• Calculated Fields• checksum• size

• Mutation Based• Random byte filp

Page 37: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Grammar Design

• 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

Page 38: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Crash Detection

Page 39: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Fuzzing Targets• Parser functions• json xml url …

• Protocols• http dns upnp …

Page 40: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

DNS Example

Page 41: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

DNS Example

More fuzzing results: https://github.com/PAGalaxyLab/VulInfo/tree/master/TP-Link/WR886N

Page 42: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Debug The Target

Page 43: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

How Can We Debug IT?• Undebuggable• No WDB, no command line debugger, no JTAG• No known solution

• Possibility• Target running in kernel mode• We can read/write kernel memory• We have firmware with symbols

Page 44: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

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)• ……

Page 45: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Overall Design

Page 46: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Debug Shellcode

Page 47: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Debug Loop Codes

Page 48: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Default Breakpoint Output

Page 49: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Condition Breakpoint(CallBack)

Break point parameters Custom condition function

Page 50: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Condition Breakpoint(CallBack)

Get packet address from MBlk header Print packet data

Page 51: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Analyze Vulnerabilities

Page 52: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

CVE-2018-19528 DNS Request Buffer Overflow

Page 53: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

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 bydirectly modifying the original request packet in netBufLib Memory Pool.

Page 54: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Packet In netBufLib Memory Pool

Page 55: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

What Does domainFilter Do?Direct modify request dns packet in Mblk Call ip_output to send modified packet

Page 56: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

It’s Time To Debugging The POC

Page 57: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Packet(Cluster) Data Modified By domainFilter

Packet data before modify Packet data after modify

Page 58: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

MBLK Header Modified By domainFilter

Mblk header before modify Mblk header after modify

Page 59: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

ip_output -> ip_deliver_packet -> connection_pullup(Root Cause Found)

Page 60: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

netTupleGet

netTupleGet parameters Mblk returned by netTupleGet

Page 61: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Copy Modified Mblk Chain Data Using netMblkToBufCopy

Page 62: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

netMblkToBufCopyCopy Chain Data To Target Buffer netMblkToBufCopy Parameters

Page 63: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Buffer Data(Cluster) Before Copy

Page 64: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Buffer Data(Cluster) After Copy

Page 65: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Crash Logs

Crash in _clBlkFree function Crash in excExcHandle function

Page 66: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Exploitability

Page 67: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Exploit - Overwrite Arbitrary Bit Value To 1 In _clBlkFree Function

Page 68: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Example Exploit Data

Page 69: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Fake clpool and cluster Example

Page 70: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Exploit – Bit Overwrite To RCE Using Exception HookexcExcHandle Function Codes

Page 71: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Demo

Page 72: Dive into VxWorkis Based IoT Device - Debug the Undebugable … · • 2010 -Shiny Old VxWorks Vulnerabilities -HD Moore • 4 Metasploit modules targeting WDB RPC • Weak password

Thanks!