Reverse Engineering USB Device Drivers



Similar documents
Ellisys USB Analysis Software

USB Overview. This course serves as an introduction to USB.

USB Simply Buffered (USB) Mass Storage Class Bulk-Only Transport

Application Note. 8-bit Microcontrollers. AVR280: USB Host CDC Demonstration. 1. Introduction

UM1734 User manual. STM32Cube USB device library. Introduction

Introducing the Adafruit Bluefruit LE Sniffer

AN PSoC 3 / PSoC 5: USB Vendor-Specific Device. Application Note Abstract. Introduction

USB Debugging and Profiling Techniques. Kishon Vijay Abraham I and Basak Partha

USB Card Reader Configuration Utility. User Manual. Draft!

AXI Performance Monitor v5.0

Revealing Embedded Fingerprints: Deriving intelligence from USB stack interactions

Design Considerations for USB Mass Storage

1500 bytes Universal Serial Bus Bandwidth Analysis

An Introduction to VoIP Protocols

M6310 USB Flash Drive Tester/Duplicator

Learning USB by Doing.

Network Security: Workshop

ACR122 NFC Contactless Smart Card Reader

Universal Serial Bus Device Class Definition for Printing Devices

This text refers to the 32bit version of Windows, unfortunately I don't have access to a 64bit development environment.

Exam 1 Review Questions

Brunata Optuna W (171)

Robe Universal Interface API

EMV (Chip-and-PIN) Protocol

Data recovery from a drive with physical defects within the firmware Service Area, unrecoverable using

3M Multi-Touch PX4nn ASIC Controller Reference Guide

Dolphin In-Circuit programming Updating Firmware in the field

Useful USB Gadgets on Linux

Frequently Asked Questions

Do More With Less. On Driver-less Interfacing with Embedded Devices. Peter Korsgaard

Technical Support Bulletin Nr.18 Modbus Tips

CX-Supervisor CX-MODBUS TCP

Hacking cars in the style of Stuxnet

The Bus (PCI and PCI-Express)

3. USB FLASH DRIVE PREPARATION. Almost all current PC firmware permits booting from a USB drive, allowing the launch

Project 4: Pseudo USB Simulation Introduction to UNIVERSAL SERIAL BUS (USB) STANDARD

Supporting ZDOs with the XBee API

Windows Server 2008 R2 Hyper V. Public FAQ

How To Monitor And Test An Ethernet Network On A Computer Or Network Card

AN295 USB AUDIO CLASS TUTORIAL. 1. Introduction. 2. USB, Isochronous Transfers, and the Audio Class Overview USB Operational Overview

i.mx USB loader A white paper by Tristan Lelong

Local Interconnect Network Training. Local Interconnect Network Training. Overview

Exploiting USB Devices with Arduino. Greg Ose Black Hat USA 2011

Atmel AVR4920: ASF - USB Device Stack - Compliance and Performance Figures. Atmel Microcontrollers. Application Note. Features.

US Equities/Options Multicast PITCH Specification. Version

Question: 3 When using Application Intelligence, Server Time may be defined as.

Application Note. Introduction AN2471/D 3/2003. PC Master Software Communication Protocol Specification

Software User Guide UG-461

Volume Serial Numbers and Format Date/Time Verification

CITRIX 1Y0-A14 EXAM QUESTIONS & ANSWERS

An introduction to nxpusblib. March 2012

INTERNATIONAL JOURNAL OF PURE AND APPLIED RESEARCH IN ENGINEERING AND TECHNOLOGY

The easy way! Mark Maszak. Jane Lawrence Program Manager Microsoft. Microsoft

USB Peripheral Communications Device Class Driver (PCDC) using USB Basic Mini Firmware

Quick Start Guide v1.0. This Quick Start Guide is relevant to Laird s BT800, BT810 and BT820 Bluetooth modules.

MBP_MSTR: Modbus Plus Master 12

Atmel AVR4950: ASF - USB Host Stack. 8-bit Atmel Microcontrollers. Application Note. Features. 1 Introduction

EtherNet/IP Modbus XPort, NET232, and NET485

Real-time Operating Systems Lecture 27.1

Data Acquisition Module with I2C interface «I2C-FLEXEL» User s Guide

BRMO 80 / ETH-IP. User Manual. Réf : MU-BRMO 80-ETH-IP-1.4-EN

AKD EtherNet/IP Communication

APPLICATION NOTE. AVR2130: Lightweight Mesh Developer Guide. Atmel MCU Wireless. Features. Description

Interface Protocol v1.2

Implementation of Web Application Firewall

Linux Kernel Architecture

Packet Sniffers Submitted in partial fulfillment of the requirement for the award of degree Of MCA

David Cowen Matthew Seyer G-C Partners, LLC

D1.2 Network Load Balancing

Lecture N -1- PHYS Microcontrollers

There are various types of NAND Flash available. Bare NAND chips, SmartMediaCards, DiskOnChip.

Evaluation Report: Emulex OCe GbE and OCe GbE Adapter Comparison with Intel X710 10GbE and XL710 40GbE Adapters

CAM-VGA100 User Manual

Bluetooth HID Profile

C-Bus Application Messages & Behaviour Chapter 25 Air Conditioning

The Quest for Speed - Memory. Cache Memory. A Solution: Memory Hierarchy. Memory Hierarchy

Universal Serial Bus Class Definitions for Communication Devices

IBM Tivoli Composite Application Manager for Microsoft Applications: Microsoft Hyper-V Server Agent Version Fix Pack 2.

Overview of Desktop Virtualization

STM32F102xx and STM32F103xx series Microcontrollers

What is LOG Storm and what is it useful for?

USB Peripheral Communications Device Class Driver for USB Mini Firmware Using Firmware Integration Technology

NVMe TM and PCIe SSDs NVMe TM Management Interface

Accelerating Development and Troubleshooting of Data Center Bridging (DCB) Protocols Using Xgig

One solution to protect all Physical, Virtual and Cloud

Revealing Embedded Fingerprints: Deriving intelligence from USB stack interactions

CTNET Field Protocol Specification November 19, 1997 DRAFT

How to Install Applications (APK Files) on Your Android Phone

VoIP Recorder V2 Setup Guide

USB Flash Drive User s Manual

TitanMist: Your First Step to Reversing Nirvana TitanMist. mist.reversinglabs.com

WinDriver 5.22 User s Guide. Jungo Ltd

ALTIRIS Deployment Solution 6.8 Preboot Automation Environment

Intrusion Detection, Packet Sniffing

What s Really Happening on Your Wireless Network Multi-Channel Analysis for WLAN Mobility

Red Hat Linux Internals

UG129: ZigBee USB Virtual Gateway Reference Design (RD ) User's Guide

Caml Virtual Machine File & data formats Document version: 1.4

Performance of VMware vcenter (VC) Operations in a ROBO Environment TECHNICAL WHITE PAPER

Evo Laser Firmware Developer s Manual

Transcription:

Reverse Engineering USB Device Drivers Jan Hauffa (jhauffa@gmail.com)

Outline 1. What's this all about? 2. USB fundamentals 3. Sniffing and analyzing USB traffic 4. Case study

Why reverse engineering? hardware manufacturers that... only provide Windows drivers only provide Linux binary drivers for x86 don't provide any documentation http://linuxdriverproject.org/foswiki/bin/view/main/driversneeded repurposing of hardware

> What exactly are you trying to protect? > The communication protocol, some image processing > functions, the firmware? Mainly, we're protecting the clever things we do in software to reduce hardware costs. It's not impossible to figure out our methods but we aren't willing to just hand it over to our competitors. There is some other stuff in there to protect but that's the main one. http://permalink.gmane.org/gmane.comp.graphics.scanning.sane.devel/19722

Why USB devices? basic USB protocol is well documented and easy to understand USB devices... can be programmed from user space can be reliably passed through to an OS running inside a VM sniffing USB traffic is easy: can be done in software FOSS tools available

Why not disassemble the driver? legal gray area http://en.wikipedia.org/wiki/reverse_engineering#legality some open source projects do not accept code based on disassembling proprietary software http://kerneltrap.org/node/6692 code obfuscation, anti-debugging techniques http://www.ossir.org/windows/supports/2005/2005-11-07/eads- CCR_Fabrice_Skype.pdf traffic analysis may actually be less work

USB fundamentals, part 1 device provides 1-32 endpoints for communication also called pipes transfer modes: isochronous: guaranteed bandwidth, bounded latency, possible data loss interrupt: bounded latency bulk: no guarantees on bandwidth or latency control: specific request/response message format

USB fundamentals, part 2 endpoints for control transfers are bi-directional, all others uni-directional every device supports control transfers on endpoint 0 host can request a configuration descriptor that contains information on the other endpoints

USB fundamentals, part 3 structure of a USB control transfer: Offset Field Size Value Description 0 bmrequesttype 1 Bit-Map D7 Data Phase Transfer Direction 0 = Host to Device 1 = Device to Host D6..5 Type 0 = Standard 1 = Class 2 = Vendor 3 = Reserved D4..0 Recipient 0 = Device 1 = Interface 2 = Endpoint 3 = Other 4..31 = Reserved 1 brequest 1 Value Request 2 wvalue 2 Value Value 4 windex 2 Index or Offset Index 6 wlength 2 Count Number of bytes to transfer if there is a data phase http://www.beyondlogic.org/usbnutshell/usb1.shtml

Sending USB requests Windows: UsbBuildVendorRequest(urb, Function, // bits 0..5 of bmrequesttype sizeof(struct URB_CONTROL_TRANSFER), TransferFlags, // bit 7 of bmrequesttype 0, brequest, wvalue, windex, buffer, NULL, wlength, NULL); status = CallUSBDI(dev, urb); prepare URB submit URB libusb: libusb_control_transfer (dev, bmrequesttype, brequest, wvalue, windex, buffer, wlength, timeout);

SniffUSB 2.0 Sniffing USB traffic http://www.pcausa.com/utilities/usbsnoop/ installs a filter between the device driver and the USB stack, writes all USB requests to disk

[1570 ms] UsbSnoop - FilterDispatchAny(8c37bfd2) : IRP_MJ_INTERNAL_DEVICE_CONTROL [1570 ms] UsbSnoop - FdoHookDispatchInternalIoctl(8c37c1ea) : fdo=84432030, Irp=8458b4b8, IRQL=0 [1570 ms] >>> URB 36 going down >>> -- URB_FUNCTION_VENDOR_DEVICE: TransferFlags = 00000000 (USBD_TRANSFER_DIRECTION_OUT, ~USBD_SHORT_TRANSFER_OK) TransferBufferLength = 00000001 TransferBuffer = 85c70df8 TransferBufferMDL = 00000000 00000000: c0 UrbLink = 00000000 RequestTypeReservedBits = 00000000 Request = 00000002 Value = 00000000 Index = 00000041 [1581 ms] UsbSnoop - MyInternalIOCTLCompletion(8c37c126) : fido=00000000, Irp=8458b4b8, Context=8462bd60, IRQL=2 [1581 ms] <<< URB 36 coming back <<< -- URB_FUNCTION_CONTROL_TRANSFER: PipeHandle = 846451bc TransferFlags = 0000000a (USBD_TRANSFER_DIRECTION_OUT, USBD_SHORT_TRANSFER_OK) TransferBufferLength = 00000001 TransferBuffer = 85c70df8 TransferBufferMDL = 84649ab8 UrbLink Imagine = 00000000 400 A4 pages of this stuff... SetupPacket = 00000000: 40 02 00 00 41 00 01 00 [1590 ms] UsbSnoop - FilterDispatchAny(8c37bfd2) : IRP_MJ_INTERNAL_DEVICE_CONTROL [1590 ms] UsbSnoop - FdoHookDispatchInternalIoctl(8c37c1ea) : fdo=84432030, Irp=8458b4b8, IRQL=0 [1590 ms] >>> URB 37 going down >>> -- URB_FUNCTION_VENDOR_DEVICE: TransferFlags = 00000000 (USBD_TRANSFER_DIRECTION_OUT, ~USBD_SHORT_TRANSFER_OK) TransferBufferLength = 00000001 TransferBuffer = 85c70df8 TransferBufferMDL = 00000000 00000000: c1

Analyzing USB traffic start with simple operations over short periods of time write scripts to extract the interesting parts perform operations with different settings, compare traffic logs find patterns look at datasheets of similar chips / devices replay traffic logs http://lindi.iki.fi/lindi/darcs/usbsnoop2libusb/

Case Study Aiptek Hyper VCam Mobile Product ID: 0xa511 Vendor ID: 0x05a9 (OmniVision Technologies, Inc.) Version: 1.00 Speed: Up to 12 Mb/sec Location ID: 0x1a200000 Current Available (ma): 500 Current Required (ma): 500 OmniVision OV511+

Event 6: level = 0x01 req_type = URB_FUNCTION_VENDOR_DEVICE req_transferflags = 0 req_transferbufferlength = 0x01 req_data = 3d req_request = 0x02 req_value = 0 req_index = 0x50 res_type = URB_FUNCTION_CONTROL_TRANSFER res_transferflags = 0x0a res_transferbufferlength = 0x01 Event 7: level = 0x01 req_type = URB_FUNCTION_VENDOR_DEVICE req_transferflags = 0x01 req_transferbufferlength = 0x01 req_request = 0x03 req_value = 0 req_index = 0x5f res_type = URB_FUNCTION_CONTROL_TRANSFER res_transferflags = 0x0b res_transferbufferlength = 0x01 res_data = 00 what you can't see: This is a log of plugging in the device and capturing a single frame. constant stream of control transfers as soon as the device is plugged in all of them single byte read/write requests as shown here

Event 6: level = 0x02 OV511_command = write_register regidx = 0x50 value = 0x3d Event 7: level = 0x02 OV511_command = read_register regidx = 0x5f value = 0 Event 8: level = 0x02 OV511_command = write_register regidx = 0x41 value = 0xc0 Event 9: level = 0x02 OV511_command = write_register regidx = 0x44 value = 0xc1 Event 10: level = 0x02 OV511_command = write_register regidx = 0x42 value = 0x12

Event 348: level = 0x01 req_type = URB_FUNCTION_ISOCH_TRANSFER req_endpoint = 0x51 req_transferflags = 0x01 req_transferbufferlength = 0x00006020 req_startframe = 0x00011b96 req_numberofpackets = 0x20 req_isopacket[0].offset = 0 req_isopacket[0].length = 0 req_isopacket[1].offset = 769 req_isopacket[1].length = 0... res_type = URB_FUNCTION_ISOCH_TRANSFER res_endpoint = 0x51 res_transferflags = 0x01 res_transferbufferlength = 0x00006020 res_startframe = 0x00011b76 res_numberofpackets = 0x20 res_errorcount = 0 res_isopacket[0].offset = 0 res_isopacket[0].length = 769 res_isopacket[0].status = 0 res_isopacket[0].status_data = 00 00 00 00 00 00 00 00 59 c8 f4 80 3e 80 01 02 01 01 02 42 1e c0 ff fe c7 f9 51 0d 01 fc 02 fe

memcpy(buf, "\x3d", 0x0000001); ret = libusb_control_transfer(devh, LIBUSB_REQUEST_TYPE_VENDOR LIBUSB_RECIPIENT_DEVICE, 0x0000002, 0x0000000, 0x0000050, buf, 0x0000001, 1000); usleep(111*1000); ret = libusb_control_transfer(devh, LIBUSB_REQUEST_TYPE_VENDOR LIBUSB_RECIPIENT_DEVICE LIBUSB_ENDPOINT_IN, 0x0000003, 0x0000000, 0x000005f, buf, 0x0000001, 1000); printf("control msg returned %d, bytes: ", ret); print_bytes(buf, ret); printf("\n"); usleep(39*1000);

stream = fopen ("frame.ppm", "wb"); snprintf (header, sizeof (header), "P5\n%d %d\n255\n", 768, 128); fwrite (header, 1, strlen (header), stream); for (i = 0; i < 4; i++) { iso_trans = libusb_alloc_transfer(32); libusb_fill_iso_transfer(iso_trans, devh, 0x00000081, isobuf, 32 * 769, 32, iso_callback, NULL, 1000); libusb_set_iso_packet_lengths(iso_trans, 769); ret = libusb_submit_transfer(iso_trans); while (!iso_transfer_finished) libusb_handle_events(ctx); iso_transfer_finished = 0; for (j = 0; j < iso_trans->num_iso_packets; j++) { offset = libusb_get_iso_packet_buffer_simple(iso_trans, j); fwrite(offset, 1, 768, stream); printf("0x%x\n", offset[768]); } } libusb_free_transfer(iso_trans); fclose (stream);

result: Ubuntu 10.10:

In this case, we can cheat by reading the manual (prepare for the worst): http://mxhaard.free.fr/spca50x/doc/omnivision/ds_511p.pdf