fuzzing & exploiting wireless device drivers Vienna, 23 - - PowerPoint PPT Presentation

fuzzing exploiting wireless device drivers
SMART_READER_LITE
LIVE PREVIEW

fuzzing & exploiting wireless device drivers Vienna, 23 - - PowerPoint PPT Presentation

fuzzing & exploiting wireless device drivers Vienna, 23 November 2007 Sylvester Keil Clemens Kolbitsch sk (at) seclab (dot) tuwien (dot) ac (dot) at ck (at) seclab (dot) tuwien (dot) ac (dot) at Agenda 802.11 fundamentals 802.11


slide-1
SLIDE 1

fuzzing & exploiting wireless device drivers

Clemens Kolbitsch

ck (at) seclab (dot) tuwien (dot) ac (dot) at

Sylvester Keil

sk (at) seclab (dot) tuwien (dot) ac (dot) at

Vienna, 23 November 2007

slide-2
SLIDE 2

Agenda

  • 802.11 fundamentals
  • 802.11 fuzzing
  • Virtual 802.11 fuzzing & live demonstration
  • Kernel-mode exploits primer
slide-3
SLIDE 3

introduction

slide-4
SLIDE 4

About us

  • We are two students from the Technical University Vienna
  • Right now we ought to be working on our master theses at the

Secure Systems Lab @ TU Vienna

  • The work presented here is based on the results of a seminar

paper we wrote during a collaboration between the Secure Systems Lab and SEC Consult

  • SEC Consult also has a “Vulnerability Bonus Program” – for

details see http://www.sec-consult.com or mail to vulnerabilities@sec-consult.com

slide-5
SLIDE 5

The playground

  • Wireless networks have become a widely used

means of communication. Compatible devices are included in most portable computers, mobile phones, etc.

  • That means, there is an increasing number of

mobile targets out there…

  • What’s more, the device drivers typically operate

in supervisor-mode (i.e. in kernel-space), thus rendering vulnerabilities extremely dangerous.

slide-6
SLIDE 6

802.11 primer

slide-7
SLIDE 7

The IEEE 802 Family

802 Overview and architecture 802.1 Management 802.2 Logical link control (LLC) 802.3 MAC 802.3 PHY 802.11 Media access control (MAC) 802.11 PHY 802.11 PHY 802.11 PHY Data Link Layer Physical Layer

slide-8
SLIDE 8

802.11 MAC frames

header (30 byte) body (up to 2312 byte) FCS (4 byte)

Information Element Information Elements … FC … Addresses Addresses

  • Three types of frames: management, control and

data frames

  • Management frames used to advertise and connect

to networks

slide-9
SLIDE 9

802.11 states

DeAuthentication

State I Class 1 State 2 Classes 1, 2 State 3 Classes 1, 2, 3

Authentication Association

  • r

Reassociation Disassociation

slide-10
SLIDE 10

802.11 association

station access point

slide-11
SLIDE 11

802.11 association

station access point

Beacons

1

slide-12
SLIDE 12

802.11 association

station access point

Beacons

1 2

Probe Request

slide-13
SLIDE 13

802.11 association

station access point

Beacons

1 2

Probe Request

3

Probe Response

slide-14
SLIDE 14

802.11 association

station access point

Beacons

1 2

Probe Request

3

Probe Response

4

Authentication

slide-15
SLIDE 15

802.11 association

station access point

Beacons

1

Authentication

5 2

Probe Request

3

Probe Response

4

Authentication

slide-16
SLIDE 16

802.11 association

station access point

Beacons

1

Authentication

5 2

Probe Request

3

Probe Response

4

Authentication

State 2

slide-17
SLIDE 17

802.11 association

station access point

Beacons

1

Authentication

5 2

Probe Request

3

Probe Response

4

Authentication

6

Association Request

slide-18
SLIDE 18

802.11 association

station access point

Beacons

1

Association Response

7

Authentication

5 2

Probe Request

3

Probe Response

4

Authentication

6

Association Request

slide-19
SLIDE 19

802.11 association

station access point

Beacons

1

Association Response

7

Authentication

5 2

Probe Request

3

Probe Response

4

Authentication

6

Association Request

State 3

slide-20
SLIDE 20

802.11 fuzzing

slide-21
SLIDE 21

802.11 fuzzing issues

  • Fuzzers must be aware of frequency channels,

BSSIDs, states, modes, and data link encryption (filtering may take place at hardware level!)

  • Response time and timing of replies is critical (e.g.,

because of reply windows or channel hopping)

  • Overload, interference, packet corruption may
  • ccur
  • Attacker and target must be co-ordinated and

target must be continuously monitored

slide-22
SLIDE 22

What to fuzz?

  • Some Information Elements (IE) follow type-

length-value pattern

  • Type and length fields have fixed size, the value

field’s size is variable (potential overflow)

type value length

slide-23
SLIDE 23

Example: a beacon frame

FCS

Time-stamp FC Source Destination BSSID ID 0x00 Beacon Interval Capability Information

0x0 (ID) 0x9 (LEN) ‘MyNetwork’ (SSID) 0x1 (ID) 0x8 (LEN) 11.0 (B) . . . 54.0 (B) (Supported Rates) 0x1 (ID) 0x1 (LEN) 0x9 (Freq)

slide-24
SLIDE 24

virtual 802.11 fuzzing

slide-25
SLIDE 25

A novel approach

  • Requirements
  • Eliminate timing contraints
  • Replace unstable wireless medium
  • Allow guaranteed delivery
  • Support advanced target monitoring
  • Solution
  • Move target into a virtual environment!
slide-26
SLIDE 26

Advantages

  • Virtual wireless device (software) replaces network

hardware

  • High-level IPC instead of live frame-injection
  • CPU of virtual machine can be interrupted and

stopped if necessary

  • Guest OS monitoring at low-level (system restart,

console output, etc.)

  • Drastically simplifies complexity of fuzzing process
slide-27
SLIDE 27

Our solution

  • Develop a fuzzing “framework” on the basis of

Fabrice Bellard’s QEMU (optional ethernet card can be added via command-line option)

  • Modular design
  • packets read from outgoing queue are copied to shared memory
  • connected modules are notified via semaphores
  • packets are read from shared memory and copied to incoming

queue

slide-28
SLIDE 28

System overview

Dumper (RM): store outgoing packets Listener (RM): display outgoing packets Injector (IM): inject arbitrary packets Stateless fuzzer (IM): reply directly Access point (RM & IM) Stateful fuzzer (RM & IM): AP and fuzzer CPU MMU Ethernet

QEMU

Reply (RM) Inject (IM) Shared memory 802.11 Fuzzer PCI ID: 168c0013 (rev01) Atheros Communications, Inc. AR5212 802.11abg NIC (rev 01)

slide-29
SLIDE 29

Access Point module

  • Broadcasts beacon frames
  • Responds to incoming probe requests
  • Supports complete Open System Authentication
  • Responds to incoming association requests
  • Features minimum implementation of ICMP
  • Full logging of 802.11 traffic
  • But words can only say so much…
slide-30
SLIDE 30

Stateful fuzzer module

  • Initially, the fuzzer behaves like an access point

module, broadcasting valid beacons and responding to probe requests

  • Once authentication is complete, it is possible to

fuzz the target in state 2, e.g. transmit fuzzed association response frames

  • See it yourself…
slide-31
SLIDE 31

fuzzing results

slide-32
SLIDE 32

Results

  • We have developed a “framework” for 802.11

fuzzing using QEMU

  • So far the framework supports fuzzing in all three

states of a target in managed mode

  • A simple fuzzer using the framework and old

versions of the MadWifi driver detected known vulnerabilities

  • A previously undocumented vulnerability was also

found!

slide-33
SLIDE 33

The vulnerability

  • Our fuzzer detected a flaw in the MadWifi

implementation

  • A beacon frame with a specially crafted Extended

Supported Rates information element crashes Linux when scanning for available networks

  • Sadly (uh, is deepsec blackhat?), no remote code

execution possible (but DoS)

  • Recently published by SEC Consult & TU

Vienna and fixed since 0.9.3.3

slide-34
SLIDE 34

kernel-mode exploits

slide-35
SLIDE 35

Vulnerabilities in kernel space

slide-36
SLIDE 36

Vulnerabilities in kernel space

  • What types of kernel space vulnerabilities are there?
slide-37
SLIDE 37

Vulnerabilities in kernel space

  • What types of kernel space vulnerabilities are there?
  • How can they be exploited (remotely)?
slide-38
SLIDE 38

Vulnerabilities in kernel space

  • What types of kernel space vulnerabilities are there?
  • How can they be exploited (remotely)?
  • How generic are these exploits?
slide-39
SLIDE 39

NULL / user-space dereference

ring0 ring3

slide-40
SLIDE 40

NULL / user-space dereference

ring0 ring3

slide-41
SLIDE 41

NULL / user-space dereference

ring0 ring3

… foo = kmalloc(size, GFP_KERNEL); /* if kmalloc fails, foo will be NULL */ … /* later on... */ foo->data->value = some_value;

slide-42
SLIDE 42

NULL / user-space dereference

ring0 ring3

… foo = kmalloc(size, GFP_KERNEL); /* if kmalloc fails, foo will be NULL */ … /* later on... */ foo->data->value = some_value;

slide-43
SLIDE 43

NULL / user-space dereference

ring0 ring3

… foo = kmalloc(size, GFP_KERNEL); /* if kmalloc fails, foo will be NULL */ … /* later on... */ foo->data->value = some_value;

slide-44
SLIDE 44

Heap (slab) overflows

slide-45
SLIDE 45

Heap (slab) overflows

  • The slab allocator can create so called lookaside caches for you:

pools of memory objects (slabs) that all have the same size.

slide-46
SLIDE 46

Heap (slab) overflows

  • The slab allocator can create so called lookaside caches for you:

pools of memory objects (slabs) that all have the same size.

  • kmalloc uses just a number of such pools!
slide-47
SLIDE 47

Heap (slab) overflows

  • The slab allocator can create so called lookaside caches for you:

pools of memory objects (slabs) that all have the same size.

  • kmalloc uses just a number of such pools!
  • A slab overflow is, if we write beyond the boundary of a slab and

into the adjacent slab.

slide-48
SLIDE 48

Heap (slab) overflows

  • The slab allocator can create so called lookaside caches for you:

pools of memory objects (slabs) that all have the same size.

  • kmalloc uses just a number of such pools!
  • A slab overflow is, if we write beyond the boundary of a slab and

into the adjacent slab.

slab slab slab buffer

slide-49
SLIDE 49

Heap (slab) overflows

  • The slab allocator can create so called lookaside caches for you:

pools of memory objects (slabs) that all have the same size.

  • kmalloc uses just a number of such pools!
  • A slab overflow is, if we write beyond the boundary of a slab and

into the adjacent slab.

  • If we know the contents of the adjacent slab, we might be able to
  • verwrite a pointer and thus create a pointer dereference exploit,
  • r similar scenario.

slab slab slab buffer

slide-50
SLIDE 50

Stack overflows

  • Typically, kernel stack is 4k or 8k.
  • Otherwise similar to user stack exploits:
  • verwrite saved return address with

buffer address.

  • How do we know where to jump to? And

how do we know the location of the saved return address?

thread_info ...

slide-51
SLIDE 51

Stack overflows

  • Typically, kernel stack is 4k or 8k.
  • Otherwise similar to user stack exploits:
  • verwrite saved return address with

buffer address.

  • How do we know where to jump to? And

how do we know the location of the saved return address?

thread_info ... nop nop ... ... shellcode

slide-52
SLIDE 52

Stack overflows

  • Typically, kernel stack is 4k or 8k.
  • Otherwise similar to user stack exploits:
  • verwrite saved return address with

buffer address.

  • How do we know where to jump to? And

how do we know the location of the saved return address?

thread_info ... nop nop ... ... shellcode

ret

slide-53
SLIDE 53

Stack overflows

  • Typically, kernel stack is 4k or 8k.
  • Otherwise similar to user stack exploits:
  • verwrite saved return address with

buffer address.

  • How do we know where to jump to? And

how do we know the location of the saved return address?

thread_info ... &(jmp *%esp) nop nop ... ... shellcode

ret

slide-54
SLIDE 54

Stack overflows

  • Typically, kernel stack is 4k or 8k.
  • Otherwise similar to user stack exploits:
  • verwrite saved return address with

buffer address.

  • How do we know where to jump to? And

how do we know the location of the saved return address?

thread_info

esp

... &(jmp *%esp) nop nop ... ... shellcode

ret

slide-55
SLIDE 55

Stack overflows

  • Typically, kernel stack is 4k or 8k.
  • Otherwise similar to user stack exploits:
  • verwrite saved return address with

buffer address.

  • How do we know where to jump to? And

how do we know the location of the saved return address?

thread_info

esp

... jmp -N &(jmp *%esp) nop nop ... ... shellcode

ret

slide-56
SLIDE 56

Stack overflows

  • Typically, kernel stack is 4k or 8k.
  • Otherwise similar to user stack exploits:
  • verwrite saved return address with

buffer address.

  • How do we know where to jump to? And

how do we know the location of the saved return address?

thread_info

ret

... jmp -N &(jmp *%esp) nop nop ... ... shellcode

slide-57
SLIDE 57

Stack overflows

  • Typically, kernel stack is 4k or 8k.
  • Otherwise similar to user stack exploits:
  • verwrite saved return address with

buffer address.

  • How do we know where to jump to? And

how do we know the location of the saved return address?

thread_info

ret

... jmp -N &(jmp *%esp) ... &(ret) &(ret) nop nop ... ... shellcode

slide-58
SLIDE 58

Stack overflows

  • Typically, kernel stack is 4k or 8k.
  • Otherwise similar to user stack exploits:
  • verwrite saved return address with

buffer address.

  • How do we know where to jump to? And

how do we know the location of the saved return address?

thread_info

ret esp

... jmp -N &(jmp *%esp) ... &(ret) &(ret) nop nop ... ... shellcode

slide-59
SLIDE 59

Stack overflows

  • Typically, kernel stack is 4k or 8k.
  • Otherwise similar to user stack exploits:
  • verwrite saved return address with

buffer address.

  • How do we know where to jump to? And

how do we know the location of the saved return address?

thread_info

ret esp

... jmp -N &(jmp *%esp) ... &(ret) &(ret) nop nop ... ... shellcode

slide-60
SLIDE 60

Stack overflows

  • Typically, kernel stack is 4k or 8k.
  • Otherwise similar to user stack exploits:
  • verwrite saved return address with

buffer address.

  • How do we know where to jump to? And

how do we know the location of the saved return address?

thread_info

ret

... jmp -N &(jmp *%esp) ... &(ret) &(ret) nop nop ... ... shellcode

esp

slide-61
SLIDE 61

Inside ring0, now what?

ring0 ring3

slide-62
SLIDE 62

Inside ring0, now what?

ring0 ring3

slide-63
SLIDE 63

Inside ring0, now what?

ring0 ring3

slide-64
SLIDE 64

Inside ring0, now what?

ring0 ring3

slide-65
SLIDE 65

Inside ring0, now what?

ring0 ring3

slide-66
SLIDE 66

Inside ring0, now what?

ring0 ring3

slide-67
SLIDE 67

Inside ring0, now what?

ring0 ring3

slide-68
SLIDE 68

Inside ring0, now what?

ring0 ring3

slide-69
SLIDE 69

Return to ring3!

target attacker

r0 exploit r3 shellcode

slide-70
SLIDE 70

Metasploit’s approach

  • Migration (not implemented yet)
  • Stager
  • Recovery
  • Stage (regular ring3 payloads)
slide-71
SLIDE 71

Migration

  • The goal of this step, is to transition to a state

where the ring0 payload can be executed in a safe manner.

  • On Windows it may be necessary to adjust the

current IRQL. On Linux, it may be necessary to cleanly get out from an interrupt or softirq.

  • May coincide with the stager component.
slide-72
SLIDE 72

Stager

  • Copy the ring0 or ring3 to a suitable location
  • We may only be able to access currently loaded pages
  • Space between kernel stack and thread_info
  • Unused entries in the IDT
  • Install hook that will execute the payload in the

desired context

  • Interrupt handlers
  • System call handlers (how do we find the system call table?)
slide-73
SLIDE 73

Recovery

  • If the system crashes after the stager has finished,

we haven’t accomplished anything

  • We need to recover from the exploit and leave the

system in a safe state

  • Recovery depends on the situation:
  • Restore registers (but we smashed the stack…)
  • Enable interrupts or preemption
  • Release spinlocks
slide-74
SLIDE 74

Stage

  • Ideally, the stage is simply a ring3 shellcode
  • Depending on the migration / stager we may have

a two-level stage

  • Copy ring3 payload to user-space (in context of a user-mode process)
  • Adjust process privileges ;-)
  • Set process saved instruction pointer or some function pointer to payload
  • We hooked the sys_execve system call and replaced the command to be

executed

slide-75
SLIDE 75

conclusion

slide-76
SLIDE 76

Conclusion

  • Fuzzing 802.11 live on the air is a cumbersome and

time-consuming process due to the limitations and requirements of the wireless medium

  • Moving the fuzzer and the target into an emulated

environment dramatically speeds up and simplifies the process!

  • Every kernel vulnerabilities is a story of its own,

but some generalizations are still possible

slide-77
SLIDE 77

references & tools

Fabrice Bellard. “QEMU, a Fast and Portable Dynamic Translator” USENIX 2005 Annual Technical Conference QEMU

http://www.qemu.org

sgrakkyu & twiz. “Attacking the Core: Kernel Attacking Notes” Phrack 0x0c, 0x40, #0x06

slide-78
SLIDE 78

kudos & respect

Christopher Kruegel Engin Kirda

http://www.seclab.tuwien.ac.at

Bernhard Müller

http://www.sec-consult.com

slide-79
SLIDE 79

vielen dank