Vulnerability desing patterns

31

Click here to load reader

Transcript of Vulnerability desing patterns

Page 1: Vulnerability desing patterns

Vulnerability design

PATTERNS

case: Kernel mode

Page 2: Vulnerability desing patterns

PAST

Page 3: Vulnerability desing patterns

Environment for exploitation

Simple ioctl

W^X NX KASLRHardened

PoolSMEP SMAP

Page 4: Vulnerability desing patterns

Why kernel exploitation

Full control of system

Simple exploitation

Simple bugs

Page 5: Vulnerability desing patterns

KERNEL ESCAPE

few lines of code, simple, effective – for that time

Modified sample from : https://github.com/rapid7/metasploit-framework/blob/master/modules/exploits/linux/local/sock_sendpage.rb

Page 6: Vulnerability desing patterns

EVOLUTION

Page 7: Vulnerability desing patterns

Exploitation hierarchy

User

Elevated user

(admin / root)

supervisor

Page 8: Vulnerability desing patterns

Past exploitation shortcut

User

Elevated user

(admin / root)

supervisor

Page 9: Vulnerability desing patterns

Present (+-) & Future : Step by step

UserElevated user

(admin / root)Supervisor

• DEP, ASLR, SEHOP, ProtectedFree, Isolated Heap, CFG,

Virtual Table Guards, EMET...

• sandbox, SELinux and alikes

• KASLR, SMEP, SMAP, ..

Page 10: Vulnerability desing patterns

Why kernel escape

• Going to be more and more difficult, but ...

• still .. sometimes easier .. shortcut

• Natural bypass of SELinux

• Full control (cpl0 > cpl3)• for now do not considering cpl-1, ...

Page 11: Vulnerability desing patterns

exploitation ==> developing

• In past was very easy elevate privileges

• Now everything is fast moving

• You need to adapt to all changes & diversity

• Things are getting more complex

• Your exploitation code is expanding dramatically

• Every change can broke your black-box

• + Process of exploitation need more than ioctl

• Race conditions, complex mechanism break (ttf), sandbox escapes ...

Page 12: Vulnerability desing patterns

VULNERABILITY DESIGN PATTERNS

kernel case

Page 13: Vulnerability desing patterns

selected vulnerability classes

• Out Of Boundary

• Basic types Over/Under flows

• Stack overflows

• Buffer overflows

• nullptr writes

• Race conditions –not generic, but ...

• may create other bug from above group

Page 14: Vulnerability desing patterns

Out Of Boundary

Simple, mighty, generic

Page 15: Vulnerability desing patterns

OOB

• Read

• Write

• SMAP – limitation, but not

eliminate oob

• GENERIC approach

Page 16: Vulnerability desing patterns

Basic type Over/Under-flow

Generic, simple and useful when it comes to aligned rw

Page 17: Vulnerability desing patterns

Stack Overflow

sometimes protected, sometimes not .. local vars ?

.. depends on compilation ..

Page 18: Vulnerability desing patterns

Stack overview

• Local vars

• canaries

• Protect ret & args

• ... sometimes ... missing

• UNprotected inner calls ?

• Arg in main func preserved in register

• Inner call invoked, register may be putted onto stack

• Rewrite arg (or directly ret) on stack in inner call

• Return to main func with altered arg (in register)

• Can help more than it seems ;)

• Controlled copy, overwrite save your day

Page 19: Vulnerability desing patterns

Buffer Overflow

Common case, can be also byproduct, heap hardening can be

problem

Page 20: Vulnerability desing patterns

Buffer overview

• Windows kernel pool, SLUB

• not so predictable anymore

• but still far from not-predictable at some level

• kmalloc

• targeted kmalloc from user mode ?

• not so hard as can seems

• help with predictability

• Pool spray

• thread, process, pipe, socket ...

• caches (linux)

• can be problem for precise pool layout, but can be solved

Page 21: Vulnerability desing patterns

nullptr pwn

spray, write, pwn .. 64b bit more effort ...

Page 22: Vulnerability desing patterns

user part of cake

Pool spray

kmalloc

Pipes

ThreadsLocks

ret2dir

Kernel IO

Page 23: Vulnerability desing patterns

kernel pool

pipes, threads .. kmalloc .. spray

Page 24: Vulnerability desing patterns

Kernel IO

If doable, then almighty ...

Page 25: Vulnerability desing patterns

workers, locks, helpers

a lot of common issues per vuln task

Page 26: Vulnerability desing patterns

CODING STYLE MATTERS

Page 27: Vulnerability desing patterns

Elevation of Privilages

USER

• Find nt!_eprocess / thread_info

• Patch credentials

• Bypass ACL policy

• Reverse engineer per policy

• Implement

• Keep up to date

• Good if not change frequently .. Not that case

KERNEL

• Elevate process

• Grant access important operations (callbacks)

• File access

• Process access

• Registry access

• Network

• How effective without framework ?

Page 28: Vulnerability desing patterns

Kernel part of cake

• Boosting privs

• Why patching ?

• Recognize and grant access instead

• No LKM ? Are you sure ?

• Kernel exploitation may be equals to enable LKM

Page 29: Vulnerability desing patterns

CC-shellcoding framework

• developing instead of shellcoding ?

• C++, boost, std ?

• Loading your own kernel modules ?

https://github.com/k33nteam/cc-shellcoding

more info : http://www.k33nteam.org/blog.htm -

CC-SHELLCODING

@KEENTEAM

Page 30: Vulnerability desing patterns

2014 - $500,0002015 - $??????? Pick a device, name your own challenge!

Page 31: Vulnerability desing patterns

We are hiring! Kernel & app sec

A LOT of research

mobile, pc

M$, android, OSX ..

Thank You! Q & A

@K33nTeam