Fuzzing and Debugging Cisco IOS - Black Hat Briefings · Cisco IOS architecture Architecture...

21
Cisco IOS architecture Architecture Analyzing Pros and Cons Use case: IOS malware Use case: ROMMON debugging Use cases: Fuzzer Wrapping up Fuzzing and Debugging Cisco IOS Blackhat Europe 2011 Sebastian Mu˜ niz, Alfredo Ortega Groundworks Technologies March 18, 2011 Groundworks Technologies Fuzzing and Debugging Cisco IOS

Transcript of Fuzzing and Debugging Cisco IOS - Black Hat Briefings · Cisco IOS architecture Architecture...

Cisco IOS architectureArchitecture

Analyzing Pros and ConsUse case: IOS malware

Use case: ROMMON debuggingUse cases: Fuzzer

Wrapping up

Fuzzing and Debugging Cisco IOSBlackhat Europe 2011

Sebastian Muniz, Alfredo Ortega

Groundworks Technologies

March 18, 2011

Groundworks Technologies Fuzzing and Debugging Cisco IOS

Cisco IOS architectureArchitecture

Analyzing Pros and ConsUse case: IOS malware

Use case: ROMMON debuggingUse cases: Fuzzer

Wrapping up

Agenda

Cisco IOS Architecture

Debugger internals

Dynamips modification

GDB supportIDA Pro support

Shortcomings of self-checkingroutines

Demos:

Malware analysisFuzzing example

Groundworks Technologies Fuzzing and Debugging Cisco IOS

Cisco IOS architectureArchitecture

Analyzing Pros and ConsUse case: IOS malware

Use case: ROMMON debuggingUse cases: Fuzzer

Wrapping up

Dynamips emulatorBuilt-in GDB server

cisco IOS architecture

Single binary image

Shared single address space

Cooperative priority-basedscheduler

Processes

Packet

Buffers

Kernel Device Drivers

Hardware

Fast

Softw.

Switch

Figure: Cisco IOS process memory

Groundworks Technologies Fuzzing and Debugging Cisco IOS

Cisco IOS architectureArchitecture

Analyzing Pros and ConsUse case: IOS malware

Use case: ROMMON debuggingUse cases: Fuzzer

Wrapping up

Dynamips emulatorBuilt-in GDB server

Dynamips emulator

Created by Christophe Fillot 1

Runs on Windows, Linux and Mac OS X.

Equivalent to QEMU/Bochs

Implements MIPS/PowerPC architecture and Cisco hardware

Supports the following models:

(a) 7200 (b) 36XX (c) 2691 (d) 3725 (e) 3745 (f) 26XX (g) 17XX

1http://www.ipflow.utc.fr/index.php/Cisco 7200 Simulator

Groundworks Technologies Fuzzing and Debugging Cisco IOS

Cisco IOS architectureArchitecture

Analyzing Pros and ConsUse case: IOS malware

Use case: ROMMON debuggingUse cases: Fuzzer

Wrapping up

Dynamips emulatorBuilt-in GDB server

Built-in GDB server

Used by Cisco developers and support engineers

Works over Telnet, SSH and Serial console

Slightly different GDB protocol

Examine Debug Kernel

Read Registers

Write Registers

Read Memory

Write Memory

Freeze OS

Remote

Figure: GDB debugging modes

Groundworks Technologies Fuzzing and Debugging Cisco IOS

Cisco IOS architectureArchitecture

Analyzing Pros and ConsUse case: IOS malware

Use case: ROMMON debuggingUse cases: Fuzzer

Wrapping up

Virtual Machine Debugger internals

Virtual Machine Debugger internals

Dynamips

GDBProtocol

PowerPC GDB

Server

Memory

Controller

MIPS

Special Hard

FPGA

PCI WIC

NM

Figure: GDB Server embedding

CPU/Memory instrumentation

No JIT support

Supported commands

Read/Write CPU RegistersRead/Write MemorySet/Unset Breakpoints

Any standard GDB client supported

Groundworks Technologies Fuzzing and Debugging Cisco IOS

Cisco IOS architectureArchitecture

Analyzing Pros and ConsUse case: IOS malware

Use case: ROMMON debuggingUse cases: Fuzzer

Wrapping up

Pros vs ConsWhy isolation is good?I don’t need this, I have the verify commandShortcomings of self-checking routines

Pros and Cons of Virtual Machine Debugger

Pros:

Complete isolation (almost!)

Cost-effective

Controlled debugging environment

Bug-hunter friendly

Cons:

Not 100% exact emulation

Not all models or hardware compatible

Findings need double-check with physical device

Check Cisco EULA before doing anything crazy. Just in case.

Groundworks Technologies Fuzzing and Debugging Cisco IOS

Cisco IOS architectureArchitecture

Analyzing Pros and ConsUse case: IOS malware

Use case: ROMMON debuggingUse cases: Fuzzer

Wrapping up

Pros vs ConsWhy isolation is good?I don’t need this, I have the verify commandShortcomings of self-checking routines

Why isolation is good?

Analyzing malware

Malware

Cisco IOS

Mirror

Built−In

GDB Stub

Read_Memory

Request

BytesExpected (fake)

GDB Client

Original memory

Figure: Using built-in GDB

Analyzing malware

GDB Stub

Malware

Cisco IOS

Read_Memory

Malware memory

GDB Client

DYNAMIPS

dump

Figure: Dynamips GDB server

Lesson learned: NEVER analyze malware inside an infected host.

Groundworks Technologies Fuzzing and Debugging Cisco IOS

Cisco IOS architectureArchitecture

Analyzing Pros and ConsUse case: IOS malware

Use case: ROMMON debuggingUse cases: Fuzzer

Wrapping up

Pros vs ConsWhy isolation is good?I don’t need this, I have the verify commandShortcomings of self-checking routines

I don’t need this, I have the verify command

Cisco Response on IOS rootkits 2:

Maintain chain of trust when verifying IOS images

Verify IOS image in external host, or before booting it

Use the MD5 File Validation command “verify” on Loadedimage:

Using the MD5 File Validation Feature

“The MD5 File Validation feature, added in Cisco IOS Software Releases12.2(4)T and 12.0(22)S, allows network administrators to calculate theMD5 hash of a Cisco IOS software image file that is loaded on a device.”

2http://www.cisco.com/warp/public/707/cisco-sr-20080516-rootkits.shtmlGroundworks Technologies Fuzzing and Debugging Cisco IOS

Cisco IOS architectureArchitecture

Analyzing Pros and ConsUse case: IOS malware

Use case: ROMMON debuggingUse cases: Fuzzer

Wrapping up

Pros vs ConsWhy isolation is good?I don’t need this, I have the verify commandShortcomings of self-checking routines

Shortcomings of self-checking routines

Malware-affected analysis

Verify CLI command

User expected

GDB server

MD5 CHK

Cisco IOS

Malware

Login routineMD5 chksum (fake)

Figure: Using built-in GDB

Clean analyis

Cisco

IOS

Calculate

Hash

Result

MD5 Tool

External Trusted environment

Figure: Using Dynamips GDBserver

Lesson learned (again): NEVER verify code inside an infected host.

Groundworks Technologies Fuzzing and Debugging Cisco IOS

Cisco IOS architectureArchitecture

Analyzing Pros and ConsUse case: IOS malware

Use case: ROMMON debuggingUse cases: Fuzzer

Wrapping up

Use cases: IOS malware

Demo: Backdoored IOS installation

Not trivial to analyze (Many IOS variations)

At least, possible:

Demo!

Groundworks Technologies Fuzzing and Debugging Cisco IOS

Cisco IOS architectureArchitecture

Analyzing Pros and ConsUse case: IOS malware

Use case: ROMMON debuggingUse cases: Fuzzer

Wrapping up

Use case: ROMMON debugging

ROMMON: Cisco bootloader 3

Very easy to verify and analyze (less variations)

Read-only in some models

Contains a basic but privileged debugger

ROMMON itself can be debugged by Dynamips

3 Felix ’FX’ Lindner , 25c3, Cisco IOS - Attack & DefenseGroundworks Technologies Fuzzing and Debugging Cisco IOS

Cisco IOS architectureArchitecture

Analyzing Pros and ConsUse case: IOS malware

Use case: ROMMON debuggingUse cases: Fuzzer

Wrapping up

Fuzzing requirementsTiming diagramExample fuzzerTriggered Vulnerability

Fuzzing requirements

Correct exception handling

Reproducible test-cases

Logging

Desirable: Debugging envirment (for post-analysis)

Groundworks Technologies Fuzzing and Debugging Cisco IOS

Cisco IOS architectureArchitecture

Analyzing Pros and ConsUse case: IOS malware

Use case: ROMMON debuggingUse cases: Fuzzer

Wrapping up

Fuzzing requirementsTiming diagramExample fuzzerTriggered Vulnerability

Fuzzing timing diagram

Fuzzer

Log

Dynamips

Exception

Restart

GDB

Fuzz case N+1

Registers

Get Regs

Start

Fuzz case N

Signal

Restart

Start

Groundworks Technologies Fuzzing and Debugging Cisco IOS

Cisco IOS architectureArchitecture

Analyzing Pros and ConsUse case: IOS malware

Use case: ROMMON debuggingUse cases: Fuzzer

Wrapping up

Fuzzing requirementsTiming diagramExample fuzzerTriggered Vulnerability

Example fuzzer

Attack surface viaProtocol fuzzer (ftp)

Trivial test-casegeneration (just anexample!)

DB

Yes

No

No Yes

Send:Command + "AAA..." (100 A’s)

Start

Connect to

FTP

Crash? Save state

Disconnect

More

CMDs?

End

Groundworks Technologies Fuzzing and Debugging Cisco IOS

Cisco IOS architectureArchitecture

Analyzing Pros and ConsUse case: IOS malware

Use case: ROMMON debuggingUse cases: Fuzzer

Wrapping up

Fuzzing requirementsTiming diagramExample fuzzerTriggered Vulnerability

Fuzzer Demo

Demo!

Groundworks Technologies Fuzzing and Debugging Cisco IOS

Cisco IOS architectureArchitecture

Analyzing Pros and ConsUse case: IOS malware

Use case: ROMMON debuggingUse cases: Fuzzer

Wrapping up

Fuzzing requirementsTiming diagramExample fuzzerTriggered Vulnerability

Triggered Vulnerability

Cisco Security Advisory: Multiple Vulnerabilitiesin the IOS FTP Server (cisco-sa-20070509-iosftp)

30 FTP commands, remote code execution on 16:(USER,CWD,DELE,RNFR,STOR,NLST,APPE,MKD,

RMD,STOU,RETR,LIST,STAT,MDTM,SIZE, and HELP)

Patched in 2007: Completely remove all FTP server code

Groundworks Technologies Fuzzing and Debugging Cisco IOS

Cisco IOS architectureArchitecture

Analyzing Pros and ConsUse case: IOS malware

Use case: ROMMON debuggingUse cases: Fuzzer

Wrapping up

How secure is this debugger?

Very.Can be used in a production environment to analyze maliciouscode?

No

Dynamips contains emulation bugs.

Demo!

Groundworks Technologies Fuzzing and Debugging Cisco IOS

Cisco IOS architectureArchitecture

Analyzing Pros and ConsUse case: IOS malware

Use case: ROMMON debuggingUse cases: Fuzzer

Wrapping up

Future Development

Honeypots

Malware analysis Lab

Exploit Dev

Duplicate exact memory behaviour (typical VMs problems)

Secure host isolation (squash Dynamips bugs)

Groundworks Technologies Fuzzing and Debugging Cisco IOS

Cisco IOS architectureArchitecture

Analyzing Pros and ConsUse case: IOS malware

Use case: ROMMON debuggingUse cases: Fuzzer

Wrapping up

Questions?

Via email:

[email protected]

[email protected]

Please download:http://www.groundworkstech.com/projects/dynamips-gdb-mod

Published under the GNU General Public Licence (GPL)

Groundworks Technologies Fuzzing and Debugging Cisco IOS

Cisco IOS architectureArchitecture

Analyzing Pros and ConsUse case: IOS malware

Use case: ROMMON debuggingUse cases: Fuzzer

Wrapping up

The End

Thanks for listening!

Groundworks Technologies Fuzzing and Debugging Cisco IOS