Recon 2011 - Montreal



Similar documents
Putting it on the NIC: A Case Study on application offloading to a Network Interface Card (NIC)

Programming Interface. for. Bus Master IDE Controller. Revision 1.0

Embedded devices as an attack vector

TCP Offload Engines. As network interconnect speeds advance to Gigabit. Introduction to

Guardian: Hypervisor as Security Foothold for Personal Computers

Using the CoreSight ITM for debug and testing in RTX applications

Hello and welcome to this presentation of the STM32L4 Firewall. It covers the main features of this system IP used to secure sensitive code and data.

OSBRiDGE 5XLi. Configuration Manual. Firmware 3.10R

Intel Ethernet Switch Load Balancing System Design Using Advanced Features in Intel Ethernet Switch Family

Exploring the Remote Access Configuration Utility

Hello, and welcome to this presentation of the STM32 SDMMC controller module. It covers the main features of the controller which is used to connect

Wireshark in a Multi-Core Environment Using Hardware Acceleration Presenter: Pete Sanders, Napatech Inc. Sharkfest 2009 Stanford University

Security Overview of the Integrity Virtual Machines Architecture

Virtualization: TCP/IP Performance Management in a Virtualized Environment Orlando Share Session 9308

Introduction To Computer Networking

Internetworking and IP Address

The Lagopus SDN Software Switch. 3.1 SDN and OpenFlow. 3. Cloud Computing Technology

FRONT FLYLEAF PAGE. This page has been intentionally left blank

CCNA R&S: Introduction to Networks. Chapter 5: Ethernet

Virtual Private Systems for FreeBSD

Yukon FE+ 88E8040. PCI Express Fast Ethernet Controller with Embedded NV Memory for LOM Applications. Product Brief

Procedure: You can find the problem sheet on Drive D: of the lab PCs. Part 1: Router & Switch

CSC 2405: Computer Systems II

Configuring Your Computer and Network Adapters for Best Performance

Operating System Overview. Otto J. Anshus

Gigabit Ethernet Design

Guideline for setting up a functional VPN

Red Hat Linux Internals

ROM Monitor. Entering the ROM Monitor APPENDIX

CCNA 2 Chapter 5. Managing Cisco IOS Software

Technical Support Information Belkin internal use only

IP Network Layer. Datagram ID FLAG Fragment Offset. IP Datagrams. IP Addresses. IP Addresses. CSCE 515: Computer Network Programming TCP/IP

AT-2916SX AT-2931SX AT-2972SX AT-2972SX/2 AT-2972T/2

A very short history of networking

vsphere Networking vsphere 6.0 ESXi 6.0 vcenter Server 6.0 EN

Analysis of Open Source Drivers for IEEE WLANs

IP address format: Dotted decimal notation:

HP Compaq dc7800p Business PC with Intel vpro Processor Technology and Virtual Appliances

I/O Attacks in Intel-PC Architectures and Countermeasures

Network Traffic Analysis

ACHILLES CERTIFICATION. SIS Module SLS 1508

C-GEP 100 Monitoring application user manual

Operating Systems Design 16. Networking: Sockets

PIKA HMP 3.0 High Level API Programmer's Guide

Dell EqualLogic Red Hat Enterprise Linux 6.2 Boot from SAN

How to Setup Bare Metal Adaxa Suite Demonstration Box

Transport and Network Layer

FIPS Security Policy 3Com Embedded Firewall PCI Cards

Internet Working 5 th lecture. Chair of Communication Systems Department of Applied Sciences University of Freiburg 2004

Outline. CSc 466/566. Computer Security. 18 : Network Security Introduction. Network Topology. Network Topology. Christian Collberg

Storm Worm & Botnet Analysis

Debugging A MotoHawk Application using the Application Monitor

Operating Systems 4 th Class

CGL Architecture Specification

Code Injection From the Hypervisor: Removing the need for in-guest agents. Matt Conover & Tzi-cker Chiueh Core Research Group, Symantec Research Labs

Bridging the Gap between Software and Hardware Techniques for I/O Virtualization

Introduction to Analyzer and the ARP protocol

Optimizing Network Virtualization in Xen

POACHER TURNED GATEKEEPER: LESSONS LEARNED FROM EIGHT YEARS OF BREAKING HYPERVISORS. Rafal Wojtczuk

10/100/1000Mbps Ethernet MAC with Protocol Acceleration MAC-NET Core with Avalon Interface

Sockets vs. RDMA Interface over 10-Gigabit Networks: An In-depth Analysis of the Memory Traffic Bottleneck

Security Technology White Paper

INTRUDER DETECTION MONITORING APPLICATION USING SNMP PROTOCOL

Names & Addresses. Names & Addresses. Hop-by-Hop Packet Forwarding. Longest-Prefix-Match Forwarding. Longest-Prefix-Match Forwarding

Internet Control Protocols Reading: Chapter 3

H0/H2/H4 -ECOM100 DHCP & HTML Configuration. H0/H2/H4--ECOM100 DHCP Disabling DHCP and Assigning a Static IP Address Using HTML Configuration

EKT 332/4 COMPUTER NETWORK

Dynamic Host Configuration Protocol (DHCP) 02 NAT and DHCP Tópicos Avançados de Redes

User Guide. SUSIAccess. Remote Device Management

Cloud Networking Disruption with Software Defined Network Virtualization. Ali Khayam

Ethernet. Ethernet. Network Devices

Guide to TCP/IP, Third Edition. Chapter 3: Data Link and Network Layer TCP/IP Protocols

Application Protocols for TCP/IP Administration

Virtual KNX/EIB devices in IP networks

Subverting the Xen hypervisor

Tools for Attacking Layer 2 Network Infrastructure

We will give some overview of firewalls. Figure 1 explains the position of a firewall. Figure 1: A Firewall

PCI-SIG SR-IOV Primer. An Introduction to SR-IOV Technology Intel LAN Access Division

VLAN for DekTec Network Adapters

Efficient Addressing. Outline. Addressing Subnetting Supernetting CS 640 1

VXLAN: Scaling Data Center Capacity. White Paper

Network Terminology Review

The irnetbox Manager User Guide

Data Link Layer(1) Principal service: Transferring data from the network layer of the source machine to the one of the destination machine

Remote Supervisor Adapter II. User s Guide

Layered Architectures and Applications

Introduction to Embedded Systems. Software Update Problem

Network Discovery Protocol LLDP and LLDP- MED

Introduction to Routing and Packet Forwarding. Routing Protocols and Concepts Chapter 1

RMON, the New SNMP Remote Monitoring Standard Nathan J. Muller

I/O Virtualization Using Mellanox InfiniBand And Channel I/O Virtualization (CIOV) Technology

OneCommand NIC Teaming and VLAN Manager

HDHomeRun Troubleshooting Guide ( )

Design Issues in a Bare PC Web Server

Transcription:

How to develop a rootkit for Broadcom NetExtreme network cards Guillaume Delugré Sogeti / ESEC R&D guillaume(at)security-labs.org Recon 2011 - Montreal

. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 2/46 Plan 1 2

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 3/46 The targeted device

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 4/46 Previous work Targeted hardware Broadcom NetExtreme family of Ethernet cards Widely used on laptops, home computers, servers... MAC components MIPS CPU (executing firmware) Non-volatile EEPROM memory (firmware, config... ) Volatile SRAM memory (code, stack, packet buffers... ) Previous work Developed a set of tools to reverse engineer NetExtreme firmware Full access to ROM, EEPROM and SRAM in software Debugging of the firmware in real time from userland EEPROM write access, code execution at bootstrap

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 5/46 InVivo debugger interface (powered by Metasm)

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 6/46 Firmware development Firmware development Firmware developed in C, very few MIPS assembly required Replacing the proprietary Broadcom firmware? Also a nice place to hide a rootkit Remote access for an attacker Access to physical memory over PCI

. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 7/46 Plan 1 2

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 8/46 So what now? Thinking of a plan Now we can load and execute firmware code in the NIC Where do we go from here? Common beliefs The firmware is responsible for processing network frames The firmware controls everything in the NIC

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 8/46 So what now? Thinking of a plan Now we can load and execute firmware code in the NIC Where do we go from here? Common beliefs The firmware is responsible for processing network frames The firmware controls everything in the NIC WRONG!

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 9/46 In real life Here is the real story The firmware initializes the NIC (low-level stuff) It would possibly handle special features (WoL, PXE... ) if requested Once the NIC is ready to be used by driver, the firmware stalls its execution The End. In a nutshell Firmware almost does nothing Much of the work is directly inlined in hardware

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 9/46 In real life Here is the real story The firmware initializes the NIC (low-level stuff) It would possibly handle special features (WoL, PXE... ) if requested Once the NIC is ready to be used by driver, the firmware stalls its execution The End. In a nutshell Firmware almost does nothing Much of the work is directly inlined in hardware

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 10/46 So what now? The challenge So we got code execution on something which does nothing How can we turn this something to really do something? That is the real topic of this presentation Requested features We want to communicate remotely with the firmware We want to do arbitrary DMAs to physical memory Need to gain control over the Ethernet link and the DMA engines from firmware

. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 11/46 Plan 1 2

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 12/46 Two options 1 Let the firmware run and hook its execution flow afterwards 2 Rewrite the whole firmware initialization sequence

Hooking the firmware execution flow Hooking the firmware execution flow Much more easy and efficient It is possible without modifying the firmware code/data Original firmware can optionaly load other firmware Just burn the firmware and a special flag in the EEPROM The original firmware will automatically load yours after init Just a little thing to take care of You cannot directly rewrite the code which is loading the firmware (it will obviously crash) Load a trampoline code at a higher address Jump on it and rewrite the original firmware from there G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 13/46

Rewriting the whole firmware bootstrap routine Rewriting the firmware initialization sequence If you feel sport... Quick way: trace all the I/O accesses and replay them I started reversing the whole thing, but it uses a lot of undocumented registers Fun fact The EEPROM header is CRC32-checked by ROM code The ROM code for BCM5721 is bugged Firstly, CRC32 algorithm is wrongly implemented Performs CRC over the whole header, including the CRC field Compares with a static constant inlined in the assembly code Bruteforce the CRC32 field until it matches the constant... G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 14/46

. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 15/46 Plan 1 2

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 16/46 Objective We want to establish a communication channel with a remote attacker But the default firmware cannot do that... ASF Alert Standard Format A special firmware from Broadcom is dedicated to remote management System can be halted/rebooted remotely SNMP heartbeats are regularly sent over the network How does it do that?!

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 17/46 ASF firmware Reversing the ASF firmware This Broadcom firmware is actually a complete hack Makes use of an integrated QoS feature to catch special packets (ASF) Makes use of a poorly documented register to forge network frames (SNMP heartbeats)

. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 18/46 QoS in network card Quality of service A few models of cards supports integrated QoS Incoming packets are placed into different queues depending on their data Although most models supposedly don t support it, the registers are still here Mechanism 1 Up to 8 rules can be set up (logical conditions) 2 If a packet matches a rule, the RX flow is halted 3 An interrupt is sent to the MIPS CPU 4 Firmware can then inspect packet or even modify it 5 Packet can be dropped or passed to the OS

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 19/46 Hooking the RX flow

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 20/46 Forging packets How to send packets from the firmware? ASF firmware makes use of a poorly documented register Some undocumented structures are set up in NIC memory Those structures contain chunks of packet data A pointer to the structures list is put into the register The packet magically appears on the network! Reproducing the trick The thing was to understand those structures I found very similar ones defined in a very old driver C header They were never referenced in the code, no reason to be here Probably a wrong copy-paste from Broadcom developers...

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 21/46 Forging packets

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 22/46 Summary at this point Communication over the network So now I can catch any incoming packet...... and I can also forge new ones Consequently I can remotely communicate with the NIC Can we also intercept the TX flow? The answer is no, at least not easily No similar QoS thing exists for the outgoing packets The driver can request TCP segmentation off-loading by firmware But no driver actually does that... We will come back to this feature later however

Final step for network processing Networking setup Firmware only knows its own MAC address We need the gateway MAC, our own IP, maybe the DNS server IP... Detecting the network configuration Rootkit has its own IP/UDP stack Embeds a lightweight DHCP client If no DHCP server on LAN, catches DNS responses and extract MAC gateway, our own IP, DNS IP... A fake MAC address can also be used to simulate a ghost machine on the LAN G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 23/46

. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 24/46 Plan 1 2

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 25/46 Getting DMAs to work Next step! We can communicate with the firmware remotely. Cool. But it would be quite pointless if we couldn t attack the OS For this, we need to be able to do arbitrary DMAs to physical memory DMA Packets are exchanged between the driver and the NIC through DMA over PCI Everything is automatized, firmware does not interfere To hack the DMA engines, we need to delve into the NIC internals

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 26/46 NIC internals Exchanging packets between NIC and the driver A buffer is described by a Buffer Descriptor structure (BD) Pointer to data in physical memory Length of data Some optional flags for the NIC Buffer descriptors are organized into Ring Buffers NIC and driver use a consumer/producer design pattern Example: Packet send (TX) Here, driver = producer and NIC = consumer Driver produces a BD, increments producer index NIC fetches the pending BD, then packet data NIC increments its consumer index, and so on

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 27/46 TX process

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 28/46 NIC internals Example: Packet reception (RX) RX process is a little more complicated, uses two rings One with BDs pointing to preallocated memory One with BDs pointing to packet data Driver produces BDs with preallocated memory NIC consumes those BDs when a packet is received NIC copies packet in preallocated memory and produces a new BD Driver consumes the BD and finds the packet data in memory Producer and consumer indexes for each ring must be consistent on the driver and NIC sides

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 29/46 RX process

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 30/46 Status block Status block The NIC keeps track of its indexes into a Status Block structure The NIC regularly DMAs this structure to the driver Driver checks if some packets are pending for reception if sent packets have been properly processed (then it can free their memory)

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 31/46 Subverting the NIC DMA Buffer descriptors point to physical memory To achieve arbitrary DMAs, we need to corrupt Buffer Descriptors just in time For write access, corruption of BDs in the RX ring For read access, corruption of BDs in the TX ring Strong constraints BDs have to be corrupted just in time NIC and driver must keep working normally We will begin with the DMA writes which are much simpler to achieve

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 32/46 DMA write Principle for DMA write Impact We can interrupt the RX flow with the QoS trick Firmware corrupts the current BD in NIC memory Makes it point to an arbitrary address in physical memory Firmware modifies the packet contents in NIC memory Firmware then resumes the RX flow Arbitrary data is then DMAed to arbitrary address Driver sees an invalid packet, but keeps on working We can write between 4 and 1500 (MTU) bytes to physical memory in one shot

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 33/46 DMA write

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 34/46 DMA read DMA read DMA read is much more difficult to achieve, but still feasible The problem is we cannot interrupt the TX flow as for RX So we will simulates a TX event from firmware makes it trigger an interruption to the MIPS CPU Everything will be done using only DMA writes TCP segmentation feature TX process can be interrupted if a special flag is set in the BD Firmware can then offload TCP segmentation from the host CPU Driver never sets this flag by default, so we ll do it ourselves

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 35/46 DMA read Principle for DMA read Impact Corrupt the current BD in TX ring with DMA write Modify the address/length of data Set the TCP segmentation bit Trigger a TX event Register is not accessible from the MIPS CPU Emits a DMA write to the NIC itself to bypass that We can do this because we have access to the PCI BAR0 Arbitrary memory is DMAed to the NIC TCP segmentation interrupts the MIPS CPU Firmware appends network headers to data, resumes TX flow Arbitrary data is sent over the wire

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 36/46 DMA read

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 37/46 DMA read We are not done yet After experimentation, a packet with physical memory does appear on network HURRAY! Then the driver miserably crashes... What happened? The NIC has consumed a BD the driver has never produced We have Index NIC == Index driver + 1 Driver does see this, enters some recovery routine which crashes the whole thing We must resynchronize the driver with the NIC

Resynchronization technique #1 Resynchronization technique #1 Driver won t crash if we prevent the Status Block from being DMAed The ring buffer is usually made of 512 BD entries We use the same technique to trigger 512 DMA reads in a row At this time we have gone around the full ring to our initial point We can resume Status Block updating, driver and NIC are now resynchronized Drawback Triggers 512 DMA reads, quite a waste if we just want a few bytes G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 38/46

Resynchronization technique #2 Edge case behaviour We actually have Index NIC == Index driver + 1 If we block the Status Block update, driver will still see Index NIC == Index driver So if a new packet is sent, driver will do Index driver + 1, which equals to Index NIC Nothing happens on the NIC side, but the driver is resynchronized We can try to force the driver to send a packet (which will never be processed) Idea Fake the reception of an ARP request packet to the driver ARP reply will be automatically sent G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 39/46

Resynchronization technique #2 Faking a packet reception We have to fake the arrival of the ARP request, but we cannot let the Status Block being updated (or the driver will crash) Methodology: Block the Status Block updating process Replace a packet data with a fake ARP request packet Inject a fake Status Block in physical memory (RX index incremented) Send an interrupt to the driver to fake the packet arrival ARP reply is sent, discarded, and driver is resynchronized Restore the Status Block updating process G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 40/46

Resynchronization technique #2 Faking a packet reception We have to fake the arrival of the ARP request, but we cannot let the Status Block being updated (or the driver will crash) Methodology: Block the Status Block updating process Replace a packet data with a fake ARP request packet Inject a fake Status Block in physical memory (RX index incremented) Send an interrupt to the driver to fake the packet arrival ARP reply is sent, discarded, and driver is resynchronized Restore the Status Block updating process G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 41/46

Resynchronization technique #2 Triggering an interrupt from firmware If standard interrupts are used, then assert the PCI #INTA line If MSI are used (e.g. over PCI-Express) then Emits a DMA write to the APIC at 0xffe0xxxx This will trigger a Message Signaled Interrupt (MSI) We know the exact address and vector to use since it has been assigned to us by the chipset This information can be found in the PCI configuration space APIC will then send the right IRQ to the driver (no spurious interrupt) Advantage After all this, we have triggered only one DMA read This technique is much more hardcore, but it spares us from triggering 512 DMA reads in a row G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 42/46

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 43/46 Conclusion on DMA Bypassing inherent limitations Firmware was initially not meant to control the DMA engines DMA writes are yet achievable in a very stable way At first glance DMA reads looked unfeasible... The presented techniques make it possible using only DMA writes at predictable addresses No configured IOMMU was supposed to be present Remote DMA Rootkit offers read/write primitives to physical memory to the remote attacker Small and independent from the underlying operating system Intelligence has to reside on the client side

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 44/46 Conclusion In a nutshell... Getting code execution on the NIC is NOT the end of the game A lot of trickery is needed to turn the firmware into a malicious payload Rootkit can communicate with the attacker over the network R/W access primitives to physical memory are provided Security considerations Rootkit is active even if the machine is shutdown Rootkit can corrupt physical memory during the system boot Need for a trusted boot sequence coupled with a properly configured IOMMU

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 45/46 References References My talks about reverse engineering the Broadcom firmware (Hack.lu 2010, HITB 2011) Can you still trust your network card, Y-A. Perez, L. Duflot (CSW 2010) Runtime firmware integrity verification, Y-A. Perez, L. Duflot (CSW 2011)

G. Delugré How to develop a rootkit for Broadcom NetExtreme network cards 46/46 Thank you for your attention! Questions?