Vitaly Chipounov and George Candea
School of Computer & Communica3on Sciences
RevNIC
Reverse Engineering of Binary Device Drivers
jeudi, 15 avril 2010
RevNIC ReverseEngineeringofBinaryDeviceDrivers - - PowerPoint PPT Presentation
RevNIC ReverseEngineeringofBinaryDeviceDrivers VitalyChipounovandGeorgeCandea SchoolofComputer&Communica3onSciences jeudi, 15 avril 2010 Drivers:HardtoWriteandHardtoPort
Vitaly Chipounov and George Candea
School of Computer & Communica3on Sciences
Reverse Engineering of Binary Device Drivers
jeudi, 15 avril 2010
jeudi, 15 avril 2010
jeudi, 15 avril 2010
http://bplteensofwa.files.wordpress.com/2009/07/computer.jpg
jeudi, 15 avril 2010
SyntheDc Driver NIC Driver Template Virtual Machine Guest OS
Original Binary Driver
Driver Exerciser RevNIC Code Synthesizer
Hardware interac3on traces
jeudi, 15 avril 2010
SyntheDc Driver NIC Driver Template Virtual Machine Guest OS
Original Binary Driver
Driver Exerciser RevNIC Code Synthesizer
Hardware interac3on traces
jeudi, 15 avril 2010
SyntheDc Driver NIC Driver Template Virtual Machine Guest OS
Original Binary Driver
Driver Exerciser RevNIC Code Synthesizer
Hardware interac3on traces
jeudi, 15 avril 2010
SyntheDc Driver NIC Driver Template Virtual Machine Guest OS
Original Binary Driver
Driver Exerciser RevNIC Code Synthesizer
Hardware interac3on traces
jeudi, 15 avril 2010
jeudi, 15 avril 2010
int irq_handler(device_t *dev) { status = hw_read(STATUS_REG); if (status == RX){ pkt_size = hw_read(RX_SIZE_REG); if (pkt_size < 1514) { recv_packet(dev); }else { drop_packet(dev); } }else if (status == TX) { ... } }
jeudi, 15 avril 2010
int irq_handler(device_t *dev) { status = hw_read(STATUS_REG); if (status == RX){ pkt_size = hw_read(RX_SIZE_REG); if (pkt_size < 1514) { recv_packet(dev); }else { drop_packet(dev); } }else if (status == TX) { ... } }
jeudi, 15 avril 2010
int irq_handler(device_t *dev) { status = hw_read(STATUS_REG); if (status == RX){ pkt_size = hw_read(RX_SIZE_REG); if (pkt_size < 1514) { recv_packet(dev); }else { drop_packet(dev); } }else if (status == TX) { ... } }
jeudi, 15 avril 2010
int irq_handler(device_t *dev) { status = hw_read(STATUS_REG); if (status == RX){ pkt_size = hw_read(RX_SIZE_REG); if (pkt_size < 1514) { recv_packet(dev); }else { drop_packet(dev); } }else if (status == TX) { ... } }
jeudi, 15 avril 2010
status == RX pkt_size < 1514 status == TX ... ... drop packet receive packet
F T
int irq_handler(device_t *dev) { status = hw_read(STATUS_REG); if (status == RX){ pkt_size = hw_read(RX_SIZE_REG); if (pkt_size < 1514) { recv_packet(dev); }else { drop_packet(dev); } }else if (status == TX) { ... } }
jeudi, 15 avril 2010
status == RX pkt_size < 1514 status == TX ... ... drop packet receive packet
F T
int irq_handler(device_t *dev) { status = hw_read(STATUS_REG); if (status == RX){ pkt_size = hw_read(RX_SIZE_REG); if (pkt_size < 1514) { recv_packet(dev); }else { drop_packet(dev); } }else if (status == TX) { ... } }
jeudi, 15 avril 2010
Device Drivers ndis.sys
e x p l
e r . e x e m s v c r t . d l l a d v a p i 3 2 . d l l n t d l l . d l l . . . . . . . . .
Applications and libraries Windows Kernel
. . . rtl8139.sys u s e r 3 2 . d l l
jeudi, 15 avril 2010
NICDRIVER.SYS IniDalize(...) QueryInformaDon(...) SendPacket(...) HandleInterrupt(...) Unload(...)
jeudi, 15 avril 2010
NICDRIVER.SYS IniDalize(...) QueryInformaDon(...) SendPacket(...) HandleInterrupt(...) Unload(...)
jeudi, 15 avril 2010
IniDalize(...)
jeudi, 15 avril 2010
IniDalize(...)
☹ ☺ ☹ ☹ ☹ ☺ ☹
jeudi, 15 avril 2010
IniDalize(...)
☹ ☺ ☹ ☹ ☹ ☺ ☹ ☺
jeudi, 15 avril 2010
IniDalize(...)
☹ ☺ ☹ ☹ ☹ ☺ ☹ ☺
jeudi, 15 avril 2010
IniDalize(...)
☹ ☺ ☹ ☹ ☹ ☺ ☹
Send(..., Packet, ...)
☺
jeudi, 15 avril 2010
IniDalize(...)
☹ ☺ ☹ ☹ ☹ ☺ ☹
Send(..., Packet, ...)
☺
001a706650e3...
jeudi, 15 avril 2010
IniDalize(...)
☹ ☺ ☹ ☹ ☹ ☺ ☹ ☹ ☺ ☹ ☹ ☹ ☺ ☹
Send(..., Packet, ...)
☺
α β γ δ ε ϛ...
jeudi, 15 avril 2010
☹ ☺ ☹ ☹ ☹ ☺ ☹ ☹ ☹ ☺ ☹
Send(..., Packet, ...)
☺
α β γ δ ε ϛ...
jeudi, 15 avril 2010
☹ ☺ ☹ ☹ ☹ ☺ ☹ ☹ ☹ ☺ ☹
Send(..., Packet, ...)
☺
α β γ δ ε ϛ...
jeudi, 15 avril 2010
☹ ☺ ☹ ☹ ☹ ☺ ☹ ☹ ☹ ☺ ☹
Send(..., Packet, ...)
HandleInterrupt(...)
☺
α β γ δ ε ϛ...
jeudi, 15 avril 2010
☹ ☺ ☹
Send(..., Packet, ...) HandleInterrupt(...)
jeudi, 15 avril 2010
☹ ☺ ☹
Send(..., Packet, ...) HandleInterrupt(...) Unload(...)
jeudi, 15 avril 2010
SyntheDc Driver NIC Driver Template Virtual Machine Guest OS
Original Binary Driver
Driver Exerciser RevNIC Code Synthesizer
Hardware interac3on traces
jeudi, 15 avril 2010
SyntheDc Driver NIC Driver Template Virtual Machine Guest OS
Original Binary Driver
Driver Exerciser RevNIC Code Synthesizer
Hardware interac,on traces
jeudi, 15 avril 2010
Trace Files
Virtual Machine Guest OS
Original Binary Driver
Driver Exerciser
jeudi, 15 avril 2010
SyntheDc Driver NIC Driver Template Virtual Machine Guest OS
Original Binary Driver
Driver Exerciser RevNIC Code Synthesizer
Hardware interac,on traces
jeudi, 15 avril 2010
SyntheDc Driver NIC Driver Template Virtual Machine Guest OS
Original Binary Driver
Driver Exerciser RevNIC Code Synthesizer
Hardware interac3on traces
jeudi, 15 avril 2010
jeudi, 15 avril 2010
BB 4 BB 1 BB 2 BB 3 BB 5 BB 6 BB 7
Trace #1
jeudi, 15 avril 2010
BB 4 BB 1 BB 2 BB 3 BB 5 BB 6 BB 7 BB 8 BB 9 BB 1 BB 2 BB 3 BB 4 BB 7
Trace #1 Trace #2
jeudi, 15 avril 2010
BB 4 BB 1 BB 2 BB 3 BB 5 BB 6 BB 7 BB 8 BB 9 BB 1 BB 2 BB 3 BB 4 BB 7
Trace #1 Trace #2
jeudi, 15 avril 2010
BB 4 BB 1 BB 2 BB 3 BB 5 BB 6 BB 7 BB 8 BB 9 BB 1 BB 2 BB 3 BB 4 BB 7 BB 4 BB 1 BB 2 BB 3 BB 5 BB 6 BB 7 BB 8 BB 9 BB 1 BB 2 BB 3 BB 4 BB 7
Trace #1 Trace #2
jeudi, 15 avril 2010
BB 4 BB 1 BB 2 BB 3 BB 5 BB 6 BB 7 BB 8 BB 9 BB 1 BB 2 BB 3 BB 4 BB 7 BB 4 BB 1 BB 2 BB 3 BB 5 BB 6 BB 7 BB 8 BB 9 BB 1 BB 2 BB 3 BB 4 BB 7
Trace #1 Trace #2
jeudi, 15 avril 2010
BB 1 BB 2 BB 3 BB 4 BB 5 BB 6 BB 7 BB 8 BB 9 BB 1 BB 2 BB 3 BB 4 BB 7
Trace #1 Trace #2
BB 1 BB 2 BB 3 BB 4 BB 5 BB 6 BB 7 BB 8 BB 9 BB 1 BB 2 BB 3 BB 4 BB 7
jeudi, 15 avril 2010
BB 1 BB 2 BB 3 BB 4 BB 5 BB 6 BB 7 BB 8 BB 9 BB 1 BB 2 BB 3 BB 4 BB 7
jeudi, 15 avril 2010
uint32_t function_0001(...) { BB1: BB2: BB3: BB4: BB5: BB6: BB8: BB9: BB7: }
BB 1 BB 2 BB 3 BB 4 BB 5 BB 6 BB 7 BB 8 BB 9 BB 1 BB 2 BB 3 BB 4 BB 7
jeudi, 15 avril 2010
uint32_t function_0001(uint32_t param1, uint32_t param2) { /* ... */ BB1: goto BB2; BB2: v1 = read_port(param1); BB3: v2 = read_port(param2); BB4: if (v1 & 0x21) goto BB8; BB5: write_port(param2, 0x1234); BB6: goto BB7; BB8: write_port(param1, 0x4567); BB9: goto BB7; BB7: }
BB 1 BB 2 BB 3 BB 4 BB 5 BB 6 BB 7 BB 8 BB 9 BB 1 BB 2 BB 3 BB 4 BB 7
jeudi, 15 avril 2010
SyntheDc Driver NIC Driver Template Virtual Machine Guest OS
Original Binary Driver
Driver Exerciser RevNIC Code Synthesizer
Hardware interac3on traces
jeudi, 15 avril 2010
SyntheDc Driver NIC Driver Template Virtual Machine Guest OS
Original Binary Driver
Driver Exerciser RevNIC Code Synthesizer
Hardware interac3on traces
jeudi, 15 avril 2010
jeudi, 15 avril 2010
Driver Template Hardware InteracDon Code
jeudi, 15 avril 2010
Linux Network Driver Template
int pci_nic_init(...) {
/* Allocate device resources */
i = pci_enable_device (pdev); if (i) { ... } ioaddr = pci_resource_start (pdev, 0); irq = pdev->irq; if (request_region (ioaddr, ADDR_RANGE, DRV_NAME) == NULL) { ... }
/* --------------------------------- * Insert device detection code here * --------------------------------- */ /* Allocate private memory */
dev = alloc_netdev(...); if (!dev) { ... }
/* Register entry points */
... }
jeudi, 15 avril 2010
Linux Network Driver Template
int pci_nic_init(...) {
/* Allocate device resources */
i = pci_enable_device (pdev); if (i) { ... } ioaddr = pci_resource_start (pdev, 0); irq = pdev->irq; if (request_region (ioaddr, ADDR_RANGE, DRV_NAME) == NULL) { ... }
/* --------------------------------- * Insert device detection code here * --------------------------------- */ /* Allocate private memory */
dev = alloc_netdev(...); if (!dev) { ... }
/* Register entry points */
... }
jeudi, 15 avril 2010
/* Allocate private memory */
dev = alloc_netdev(...); if (!dev) { ... }
/* Register entry points */
... } int pci_nic_init(...) {
/* Allocate device resources */
i = pci_enable_device (pdev); if (i) { ... } ioaddr = pci_resource_start (pdev, 0); irq = pdev->irq; if (request_region (ioaddr, ADDR_RANGE, DRV_NAME) == NULL) { ... }
/* --------------------------------- * Insert device detection code here * --------------------------------- */
jeudi, 15 avril 2010
/* Allocate private memory */
dev = alloc_netdev(...); if (!dev) { ... }
/* Register entry points */
... } int pci_nic_init(...) {
/* Allocate device resources */
i = pci_enable_device (pdev); if (i) { ... } ioaddr = pci_resource_start (pdev, 0); irq = pdev->irq; if (request_region (ioaddr, ADDR_RANGE, DRV_NAME) == NULL) { ... }
/* --------------------------------- * Insert device detection code here * --------------------------------- */
jeudi, 15 avril 2010
/* Allocate private memory */
dev = alloc_netdev(...); if (!dev) { ... }
/* Register entry points */
... } int pci_nic_init(...) {
/* Allocate device resources */
i = pci_enable_device (pdev); if (i) { ... } ioaddr = pci_resource_start (pdev, 0); irq = pdev->irq; if (request_region (ioaddr, ADDR_RANGE, DRV_NAME) == NULL) { ... }
/* --------------------------------- * Insert device detection code here * --------------------------------- */
if (hw_checkdevice(ioaddr) < 0) { v1 = read_port(ioaddr); if (!(v1 & 1)) { goto lbl0; } write_port(ioaddr, 0); lbl0: write_port(ioaddr, 1); }
jeudi, 15 avril 2010
SyntheDc Driver NIC Driver Template Virtual Machine Guest OS
Original Binary Driver
Driver Exerciser RevNIC Code Synthesizer
Hardware interac3on traces
jeudi, 15 avril 2010
SyntheDc Driver NIC Driver Template Virtual Machine Guest OS
Original Binary Driver
Driver Exerciser RevNIC Code Synthesizer
Hardware interac3on traces
insmod revnic_driver.ko
jeudi, 15 avril 2010
1 F. Bellard. QEMU, a Fast and Portable Dynamic Translator. In USENIX 2005. 2 C. Cadar et al. KLEE: Unassisted and automa3c genera3on of high‐coverage tests for
complex systems programs. In OSDI 2008.
jeudi, 15 avril 2010
jeudi, 15 avril 2010
Driver Size1 AMD PCNet 35 KB Realtek RTL8139 20 KB SMSC 91C111 19 KB Realtek RTL8029 (NE2000) 18 KB
1 80% of Linux 2.6.26 NIC drivers are smaller than 35KB
jeudi, 15 avril 2010
http://bplteensofwa.files.wordpress.com/2009/07/computer.jpg
jeudi, 15 avril 2010
http://bplteensofwa.files.wordpress.com/2009/07/computer.jpg
jeudi, 15 avril 2010
http://bplteensofwa.files.wordpress.com/2009/07/computer.jpg
jeudi, 15 avril 2010
http://bplteensofwa.files.wordpress.com/2009/07/computer.jpg
jeudi, 15 avril 2010
DMA, etc.
jeudi, 15 avril 2010
20 40 60 80 100 200 400 600 800 1000 1200 1400 Throughput (Mbps) UDP Packet Size (Bytes) Windows→KitOS Windows→Windows Linux Original Windows→Linux Windows Original
jeudi, 15 avril 2010
20 40 60 80 100 200 400 600 800 1000 1200 1400 Throughput (Mbps) UDP Packet Size (Bytes) Windows→KitOS Windows→Windows Linux Original Windows→Linux Windows Original
jeudi, 15 avril 2010
20 40 60 80 100 200 400 600 800 1000 1200 1400 Throughput (Mbps) UDP Packet Size (Bytes) Windows→KitOS Windows→Windows Linux Original Windows→Linux Windows Original
jeudi, 15 avril 2010
20 40 60 80 100 200 400 600 800 1000 1200 1400 Throughput (Mbps) UDP Packet Size (Bytes) Windows→KitOS Windows→Windows Linux Original Windows→Linux Windows Original
jeudi, 15 avril 2010
jeudi, 15 avril 2010
Virtual Machine Guest OS
Original Binary Driver
Driver Exerciser
jeudi, 15 avril 2010
RevNIC Code Synthesizer
Virtual Machine Guest OS
Original Binary Driver
Driver Exerciser
jeudi, 15 avril 2010
NIC Driver Template RevNIC Code Synthesizer
Virtual Machine Guest OS
Original Binary Driver
Driver Exerciser
jeudi, 15 avril 2010
SyntheDc Driver (e.g., Linux) NIC Driver Template RevNIC Code Synthesizer
Virtual Machine Guest OS
Original Binary Driver
Driver Exerciser
jeudi, 15 avril 2010
Device Manual (Linux) Manual (Linux) RevNIC vNIC Device Persons Span Persons Span RTL8139 18 4 years 1 1 week 91C111 8 4 years 1 4 days NE2000 5 2 years 1 5 days PCNet 3 4 years 1 1 week
jeudi, 15 avril 2010
Device Manual (Linux) Manual (Linux) RevNIC vNIC Device Persons Span Persons Span RTL8139 18 4 years 1 1 week 91C111 8 4 years 1 4 days NE2000 5 2 years 1 5 days PCNet 3 4 years 1 1 week
jeudi, 15 avril 2010
Device Manual (Linux) Manual (Linux) RevNIC vNIC Device Persons Span Persons Span RTL8139 18 4 years 1 1 week 91C111 8 4 years 1 4 days NE2000 5 2 years 1 5 days PCNet 3 4 years 1 1 week
Mostly fixing undocumented quirks
jeudi, 15 avril 2010
Device Manual (Linux) Manual (Linux) RevNIC vNIC Device Persons Span Persons Span RTL8139 18 4 years 1 1 week 91C111 8 4 years 1 4 days NE2000 5 2 years 1 5 days PCNet 3 4 years 1 1 week
jeudi, 15 avril 2010
jeudi, 15 avril 2010
jeudi, 15 avril 2010