[CCC-28c3] Post Memory Corruption Memory Analysis

Moabi.com
Moabi.comHacker at Moabi.com
Post Memory Corruption Memory Analysis Jonathan Brossard CEO – Toucan System jonathan@ toucan-system.com
Who am I ? - Security Research Engineer at Toucan System - Speaker at Blackhat, Defcon, HITB, H2HC, Kiwicon, Ruxcon. - Organiser of the Hackito Ergo Sum conference (Paris). - I'm the guy who comes to CCC with 90+ slides...
I don't reverse plain text
Agenda ,[object Object],Extending Pmcma PMCMA Design Being environment aware A few basics
Tool available at http://www.pmcma.org
We got 10k downloads+ in 2 less than months... …  and every email we get is questioning exploitation of remote stack overflows instead of invalid memory writes... ;(
What's pmcma ? It's a debugger, for Linux (maybe one day *NIX) ptrace() based. Pmcma allows to find and test  exploitation scenarios . Pmcma's output is a roadmap to exploitation, not exploit code. Tells you if a given bug triggering an  invalid memory access  is a vulnerability, if it is exploitable with the state of the art, and how to exploit it.
What's pmcma ? DEMO
Coz you asked for it...
Remote stack overflow automated exploitation NX/SSP (stack cookies)/ASLR/PIE/STATIC GOT/Ascii Armoring... => No problem, easy cheesy : can be done with static analysis (of the libc/binary) only.
Remote stack overflow automated exploitation SSP :  cookies can be bruteforced remotely  (cf Ben Hawks @ Ruxcon 2006).
Remote stack overflow automated exploitation FORTIFY :  - Doesn't apply all the time. - Fails silently (this is bad !!) - Is consistent under Linux (but not Apple...)
Remote stack overflow automated exploitation PIE : - The bug new thing (every deamon compiled with PIE under ubuntu 10.10) - No public exploits (untill today ;) - We can bruteforce the saved EIP, then get back to ret2plt or ROP.
DEMO
Now, let's move to the real thing...
A FEW BASICS
Seriously, can we skip this section ?
How do applications crash ? * Stack corruptions -> stack overflows, usually now detected because of SSP | studied a LOT * Signal 6 -> assert(),abort(): unexpected execution paths (assert() in particular), heap corruptions  * Segfault (Signal 11) -> Invalid memory access
How do applications crash ? * Stack corruptions -> stack overflows, usually now detected because of SSP | studied a LOT * Signal 6 -> assert(),abort(): unexpected execution paths (assert() in particular), heap corruptions  * Segfault (Signal 11) -> Invalid memory access
Invalid memory access - trying to  read  a page not readable. often not mapped at all. - trying to  write  to a page not writable. often not mapped at all. - trying to  execute  a page not executable. often not mapped at all.
Why do they happen ? Because of any kind of miscomputation, really : - integer overflows in loop counters or destination registers when copying/initializing data, casting errors when extending registers or  - uninitialised memory, dangling pointers - variable misuse - heap overflows (when inadvertently overwriting a function ptr) - missing format strings - overflows in heap, .data, .bss, or any other writable section (including shared libraries). - stack overflows when no stack cookies are present...
Exploiting invalid exec Trivial, really. Eg : call eax with eax fully user controled
Invalid memory reads (1/2) Eg : CVE-2011-0761 (Perl) cmp   BYTE PTR  [ ebx+0x8 ] ,0x9
Invalid memory reads (2/2) Eg : CVE-2011-0764 (t1lib) fld  QWORD PTR [eax+0x8]
Exploiting invalid memory reads ? - usually plain not exploitable - won't allow us to modify the memory of the mapping directly - in theory : we could perform a user controled read, to trigger a second (better) bug.
Invalid memory writes Eg : CVE-2011-1824 (Opera) mov  DWORD PTR  [ ebx+edx*1 ] ,eax
How to... To exploit invalid writes, we need to find ways to transform an arbitray write into an arbitrary exec. The most obvious targets are function pointers.
Exploiting invalid memory writes : scenario - Target a known function pointer (typically : .dtors, GOT entry...). Can be prevented at compile time : no .dtors, static GOT... - Target function pointers in the whole binary ? - Overwrite a given location to trigger an other bug (eg : stack overflow)
Being environment aware
Problems to take into account - Kernel : ASLR ? NX ? - Compilation/linking : RELRO (partial/full) ? no .dtors section ? SSP ? FORTIFY_SOURCE ? => Pmcma needs to mesure/detect those features
ASLR Major problem when chosing an exploitation strategy.
ASLR : not perfect - Prelinking (default on Fedora) breaks ASLR - All kernels don't have the same randomization strength. - Non PIE binaries => Truth is : we need better tools to test it !
Testing ASLR -Run a binary X times (say X=100) -Stop execution after loading -Record mappings. => Compare mappings, deduce randomization
DEMO : being environment aware
PMCMA DESIGN
GOALS - We want to test overwriting different memory locations inside a process and see if they have an influence over the flow of execution - We want to scale to big applications (web browsers, network deamons...) - We want a decent execution time
mk_fork() The idea : -We start analysing after a SEGFAULT -We make the process fork() (many many times) -Inside each offspring, we overwrite a different memory location
mk_fork() : benefits Mapping looks « just like » it will when actually exploiting a binary No ASLR/mapping replication problem Exhaustive and hopefully fast
How to force a process to fork ? 1) Find a +X location mapped in memory. 2) Save registers 3) Use ptrace() to inject fork() shellcode. 4) Modify registers so eip points to shellcode. 5) Execute shellcode. 6) Wait() for both original process and offspring. 7) Restore bytes in both processes. 8) Restore registers in both processes.
Forking shellcode ;forking shellcode: 00000000  6631C0  xor eax,eax 00000003  B002  mov al,0x2 00000005  CD80  int 0x80
Original process Executable Writable Executable … Offspring 2 Executable Writable Executable … Offspring 1 Executable Writable Executable … mk_fork()
Offspring 1 Executable Writable Executable … mk_fork()
Offspring 2 Executable Writable Executable … mk_fork()
Offspring  n Executable Writable Executable … mk_fork()
mk_fork() : PROS - allows for multiple tests out of a single process - fast, efficient (no recording of memory snapshots) - no need to use breakpoints - no single stepping
mk_fork() : CONS - Dealing with offsprings termination ? (Zombie  processes) - I/O, IPC, network sockets will be in unpredictable state - Hence syscalls will get wrong too (!!)
Zombie reaping - Avoid the wait() for a SIGCHILD in the parent process. - Kill processes after a given timeout, including all of their children.
Zombie reaping : the SIGCHILD  problem If we can have the parent process ignore SIGCHILD signals, we won't create Zombies. => We inject a small shellcode to perform this via sigaction()
Zombie reaping : the SIGCHILD  problem 1) Find a +X location mapped in memory. 2) Save registers 3) Use ptrace() to inject sigaction() shellcode. 4) Modify registers so eip points to shellcode. 5) Execute shellcode. 6) Wait() for the process while executing shellcode. 7) Restore bytes in +X location. 8) Restore registers in the process.
Force process grouping : shellcode ; Sigaction shellcode: // Zombie reaper ; struct sigaction sa = {.sa_handler = SIG_IGN};  ; sigaction(SIGCHLD, &sa, NULL); _start: nop nop nop nop call fake fake: pop ecx add ecx,0x18  ; delta to sigaction structure xor eax,eax mov al,0x43  ; sigaction mov ebx,0x11  ; SIGCHLD xor edx,edx  ; 0x00 int 0x80 db 0xcc, 0xcc,0xcc,0xcc ; struct sigaction sa = {.sa_handler = SIG_IGN}; db 01, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
Zombie reaping : killing the offsprings and their children Fortunatly, this is possible using « process grouping »...
Process grouping setpgid()  sets  the  PGID of the process specified by pid to pgid.  If pid is zero, then the process ID of the calling process  is  used.  If pgid is zero, then the PGID of the process specified by pid is made the same as its process ID.  If setpgid() is used to move  a  process  from one  process  group to another (as is done by some shells when creating pipelines), both process groups must be part of the same  session  (see setsid(2)  and  credentials(7)).  In  this case, the pgid specifies an existing process group to be joined and the session ID  of  that  group must match the session ID of the joining process.
Zombie reaping : forcing process grouping 1) Find a +X location mapped in memory. 2) Save registers 3) Use ptrace() to inject setpgid() shellcode. 4) Modify registers so eip points to shellcode. 5) Execute shellcode. 6) Wait() for the process while executing shellcode. 7) Restore bytes in +X location. 8) Restore registers in the process.
Force process grouping... ; ; setpgid(0,0); shellcode ; _start: nop nop nop nop mov eax,0x39 ; setpgid xor ebx,ebx xor ecx,ecx int 0x80 db 0xcc, 0xcc
Zombie reaping : final details From now on, to kill a process and all of its children : kill (-pid, SIGTERM) ;
IPC, I/O, invalid syscalls One possibility is to recode correct execution on the original process (after clearing signals and ignoring the SEGFAULT). Then replay/fake the syscalls on the offsprings. => Minimal userland « virtualization ».
PMCMA : FEATURES
Exploiting invalid memory writes via function pointers We now want to find all the function pointers called by the application from the instruction which triggered the SEGFAULT until it actually halts. (including pointers in shared libraries!!)
Finding all the function pointers actually called 1) Parse all the +W memory, look for possible pointers to any section 1  bis) optionally disassemble the destination and see if it is a proper prologue. 2) use mk_fork() to create many children 3) in each children, overwrite a different possible function pointer with a canari value (0xf1f2f3f4). 4) Monitor execution of the offsprings
Finding all the function pointers actually called Overwritten pointer leads to execution of canari address 0xf1f2f3f4 <=> We found a called function pointer.
Finding all the function pointers actually called DEMO
So what can we test now ? Invalid write anything anywhere  : attacker has full control over data written and destination where written => GAME OVER
So what can we test now ? Overflows  (in any writtable section but the stack) : Simply limit the results of pmcma to this section.
So what can we test now ? What if the attacker has little or  no control over the data being written  (arbitrary write non controled data, anywhere) ?
Partial overwrites and pointers truncation If we can't properly overwrite a function pointer, maybe we can still  truncate  one (with the data we don't control) so that it transfers execution to a controled memory zone ?
Exemple : --[ Function pointers exploitable by truncation with 0x41424344: At 0xb70ce070 : 0xb70c63c2 will become 0xb70c4142 (lower truncated by 16 bits, dest perms:RW) At 0xb70e40a4 : 0xb70ca8f2 will become 0xb70c4142 (lower truncated by 16 bits, dest perms:RW) At 0xb70ec080 : 0xb70e5e02 will become 0xb70e4142 (lower truncated by 16 bits, dest perms:RW) At 0xb731a030 : 0xb7315da2 will become 0xb7314142 (lower truncated by 16 bits, dest perms:RW) At 0xb73230a4 : 0xb732003a will become 0xb7324142 (lower truncated by 16 bits, dest perms:RW) At 0xb732803c : 0xb7325a36 will become 0xb7324142 (lower truncated by 16 bits, dest perms:RW) At 0xb76a80d8 : 0xb7325bf0 will become 0xb7324142 (lower truncated by 16 bits, dest perms:RW)
One more situation... Sometimes, an attacker has limited control over the destination of the write (wether he controls the data being written or not). Eg : 4b aligned memory writes.
Exploiting 4b aligned memory writes We can't attack a function pointer directly, unless it is unaligned (rare because of compiler internals). Pmcma will still let you know if this happens ;)
Exploiting 4b aligned memory writes : plan B Find all « normal » variables we can overwrite/truncate, and attempt to trigger a second bug because of this overwrite.
Finding all unaligned memory accesses Setting the  unaligned flag  in the EFLAGS register will trigger a signal 7 uppon next access of unaligned memory (read/write).
Finding all unaligned memory accesses DEMO
Finding all unaligned memory accesses DEMO x86_64
Defeating ASLR : Automated memory mapping leakage How does WTFuzz did it at CansecWest 2010 to win the pwn2own contest against IE8/Windows 7 ? Overwrite the null terminator of a JS string to perform a mem leak uppon usage (trailing bytes).
Defeating ASLR with an arbitrary write ? In the original process : - use ptrace() PTRACE_SYSCALL - record the calls to sys_write() and sys_socketall() (wrapper to sys_send() or sys_sendto()...), including : where is the data sent ? How many bytes ?
Defeating ASLR with an arbitrary write ? Create many offsprings using mk_fork(). -In each of them : overwrite a different location with dummy data. -Follow execution using PTRACE_SYSCALL -Monitor differences : a different address or a bigger size means a memory leak :)
Extending Pmcma
Means of modifying the flow of execution without function pointers Call tables. Calling [Offset+register] => This is also already performed automatically using pmcma.
Pointers and ASLR If overwritting a given function pointer isn't practical because of ASLR : is it possible to overwrite a pointer (in an other section) to a structure containing this function pointer ? Would this « other section » be less randomised ?
Finding pointers to structures containing function pointers Executable Writable (high ASLR) Executable … Writable (no ASLR) Executable Complex structure … void* f(a,b,c)
Finding pointers to structures containing function pointers We'd like to have the debugged process create a new section, with a given mapping (to ease identify). Modify a possible pointer per offspring (use mk_fork()). Monitor execution : is the offspring calling a function pointer from our custom mapping ?
Forcing a process to create a new mapping : 1) Find a +X location mapped in memory. 2) Save registers 3) Use ptrace() to inject mmap() shellcode. 4) Modify registers so eip points to shellcode. 5) Execute shellcode. 6) Wait() for the process while executing shellcode. 7) Restore bytes in +X location. 8) Restore registers in the process.
; ; old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, 0, 0) shellcode: ; _start: nop nop nop nop xor eax, eax xor ebx, ebx xor ecx, ecx xor edx, edx xor esi, esi xor edi, edi mov bx, 0x1000 ; 1 page mov cl, 0x3 ; PROT_READ|PROT_WRITE mov dl, 0x21 ; MAP_SHARED|MAP_ANON push eax push eax push edx push ecx push ebx push eax mov ebx, esp mov al, 0x5a ; sys_mmap int 0x80 ; eax contains address of new mapping db 0xcc, 0xcc, 0xcc, 0xcc
In case all of the above failed... Can we trigger secondary bugs by overwritting specific memory locations ? Testing exhaustively arbitrary writes
Testing exhaustively arbitrary writes Complexity is huge ! Still doable with Pmcma, with no guaranty over the time of execution.
Testing exhaustively arbitrary reads In the same veine, attacker controled invalid reads can trigger secondary bugs, which will be exploitable. => We can test the whole 4+ billions search space (under x86 Intel architecture), or just a few evenly chosen ones.
Stack desynchronization W^X is a problem. Even if we can overwrite fully a function pointer and modify the flow of execution... what do we want to execute in 2011 ?
Stack desynchronization Instead of returning directly to shellcode in +W section (hence probably not +X) : -Return to a function epilogue chosen so that esp will be set to user controled data in the stack. - Fake stack frames in the stack itself. - Use your favorite ROP/ret2plt shellcode
Stack desynchronization : Exemple : sudo - stack is ~1000 big (at analysis time) -  we find a function pointer to overwrite (at 0x0806700c) - we overwrite it with a carefully chosen prologue (inc esp by more than 1000)
Stack desynchronization : Exemple : sudo jonathan@blackbox:~$ objdump -Mintel -d  /usr/bin/sudo ...  805277a:  81 c4 20 20 00 00  add esp,0x2020 8052780:  5b  pop  ebx 8052781:  5e  pop  esi 8052782:  5d  pop  ebp 8052783:  c3  ret
Stack desynchronization : Exemple : sudo We can control the destination where esp is going to point : simply use an environment variable  TOTO=mydata sudo
Stack desynchronization : Exemple : sudo We then forge fake stack frames in the stack itself - « Nop sled » : any pointer to 'ret' Eg :804997b:  c3  ret - Then copy shellcode to .bss byte per byte using memcpy via ret2plt - Use GOT overwrite to get pointer to mprotect() in the GOT (ROP) - call mprotect to make .bss +X via ret2plt - return to shellcode in .bss
DEMOS
Future Work - port to more architectures (Linux x86_64 on the way, arm...) - port to more OS (Mac OSX, *BSD) - port to Windows (hard) - add tests for other bug classes
Questions ? Thank you for coming
1 of 94

Recommended

[Defcon24] Introduction to the Witchcraft Compiler Collection by
[Defcon24] Introduction to the Witchcraft Compiler Collection[Defcon24] Introduction to the Witchcraft Compiler Collection
[Defcon24] Introduction to the Witchcraft Compiler CollectionMoabi.com
3K views67 slides
[Defcon] Hardware backdooring is practical by
[Defcon] Hardware backdooring is practical[Defcon] Hardware backdooring is practical
[Defcon] Hardware backdooring is practicalMoabi.com
130.2K views70 slides
Hardware backdooring is practical : slides by
Hardware backdooring is practical : slidesHardware backdooring is practical : slides
Hardware backdooring is practical : slidesMoabi.com
1.3K views49 slides
Essentials of Multithreaded System Programming in C++ by
Essentials of Multithreaded System Programming in C++Essentials of Multithreaded System Programming in C++
Essentials of Multithreaded System Programming in C++Shuo Chen
6.5K views31 slides
I/O, You Own: Regaining Control of Your Disk in the Presence of Bootkits by
I/O, You Own: Regaining Control of Your Disk in the Presence of BootkitsI/O, You Own: Regaining Control of Your Disk in the Presence of Bootkits
I/O, You Own: Regaining Control of Your Disk in the Presence of BootkitsCrowdStrike
5.3K views78 slides
Make container without_docker_7 by
Make container without_docker_7Make container without_docker_7
Make container without_docker_7Sam Kim
184 views52 slides

More Related Content

What's hot

syzbot and the tale of million kernel bugs by
syzbot and the tale of million kernel bugssyzbot and the tale of million kernel bugs
syzbot and the tale of million kernel bugsDmitry Vyukov
397 views55 slides
Talk 160920 @ Cat System Workshop by
Talk 160920 @ Cat System WorkshopTalk 160920 @ Cat System Workshop
Talk 160920 @ Cat System WorkshopQuey-Liang Kao
297 views52 slides
Lightweight Virtualization with Linux Containers and Docker | YaC 2013 by
Lightweight Virtualization with Linux Containers and Docker | YaC 2013Lightweight Virtualization with Linux Containers and Docker | YaC 2013
Lightweight Virtualization with Linux Containers and Docker | YaC 2013dotCloud
14.2K views76 slides
Introduction to Docker and deployment and Azure by
Introduction to Docker and deployment and AzureIntroduction to Docker and deployment and Azure
Introduction to Docker and deployment and AzureJérôme Petazzoni
2.1K views72 slides
Docker Introduction + what is new in 0.9 by
Docker Introduction + what is new in 0.9 Docker Introduction + what is new in 0.9
Docker Introduction + what is new in 0.9 Jérôme Petazzoni
3.7K views91 slides
Racing with Droids by
Racing with DroidsRacing with Droids
Racing with DroidsPeter Hlavaty
3.5K views46 slides

What's hot(20)

syzbot and the tale of million kernel bugs by Dmitry Vyukov
syzbot and the tale of million kernel bugssyzbot and the tale of million kernel bugs
syzbot and the tale of million kernel bugs
Dmitry Vyukov397 views
Talk 160920 @ Cat System Workshop by Quey-Liang Kao
Talk 160920 @ Cat System WorkshopTalk 160920 @ Cat System Workshop
Talk 160920 @ Cat System Workshop
Quey-Liang Kao297 views
Lightweight Virtualization with Linux Containers and Docker | YaC 2013 by dotCloud
Lightweight Virtualization with Linux Containers and Docker | YaC 2013Lightweight Virtualization with Linux Containers and Docker | YaC 2013
Lightweight Virtualization with Linux Containers and Docker | YaC 2013
dotCloud14.2K views
Introduction to Docker and deployment and Azure by Jérôme Petazzoni
Introduction to Docker and deployment and AzureIntroduction to Docker and deployment and Azure
Introduction to Docker and deployment and Azure
Jérôme Petazzoni2.1K views
Docker Introduction + what is new in 0.9 by Jérôme Petazzoni
Docker Introduction + what is new in 0.9 Docker Introduction + what is new in 0.9
Docker Introduction + what is new in 0.9
Jérôme Petazzoni3.7K views
You didnt see it’s coming? "Dawn of hardened Windows Kernel" by Peter Hlavaty
You didnt see it’s coming? "Dawn of hardened Windows Kernel" You didnt see it’s coming? "Dawn of hardened Windows Kernel"
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
Peter Hlavaty9.4K views
Introduction to Docker (and a bit more) at LSPE meetup Sunnyvale by Jérôme Petazzoni
Introduction to Docker (and a bit more) at LSPE meetup SunnyvaleIntroduction to Docker (and a bit more) at LSPE meetup Sunnyvale
Introduction to Docker (and a bit more) at LSPE meetup Sunnyvale
Jérôme Petazzoni4.4K views
Ищем уязвимости нулевого дня в ядре Linux by Positive Hack Days
Ищем уязвимости нулевого дня в ядре LinuxИщем уязвимости нулевого дня в ядре Linux
Ищем уязвимости нулевого дня в ядре Linux
Positive Hack Days768 views
Introduction to Docker at Glidewell Laboratories in Orange County by Jérôme Petazzoni
Introduction to Docker at Glidewell Laboratories in Orange CountyIntroduction to Docker at Glidewell Laboratories in Orange County
Introduction to Docker at Glidewell Laboratories in Orange County
Jérôme Petazzoni2.1K views
도커 없이 컨테이너 만들기 4편 네트워크네임스페이스 (2) by Sam Kim
도커 없이 컨테이너 만들기 4편 네트워크네임스페이스 (2)도커 없이 컨테이너 만들기 4편 네트워크네임스페이스 (2)
도커 없이 컨테이너 만들기 4편 네트워크네임스페이스 (2)
Sam Kim265 views
Efficient logging in multithreaded C++ server by Shuo Chen
Efficient logging in multithreaded C++ serverEfficient logging in multithreaded C++ server
Efficient logging in multithreaded C++ server
Shuo Chen14.3K views
Intel Nervana Graph とは? by Mr. Vengineer
Intel Nervana Graph とは?Intel Nervana Graph とは?
Intel Nervana Graph とは?
Mr. Vengineer2.5K views
DeathNote of Microsoft Windows Kernel by Peter Hlavaty
DeathNote of Microsoft Windows KernelDeathNote of Microsoft Windows Kernel
DeathNote of Microsoft Windows Kernel
Peter Hlavaty9.4K views
도커 없이 컨테이너 만들기 5편 마운트 네임스페이스와 오버레이 파일시스템 by Sam Kim
도커 없이 컨테이너 만들기 5편 마운트 네임스페이스와 오버레이 파일시스템도커 없이 컨테이너 만들기 5편 마운트 네임스페이스와 오버레이 파일시스템
도커 없이 컨테이너 만들기 5편 마운트 네임스페이스와 오버레이 파일시스템
Sam Kim229 views
syzkaller: the next gen kernel fuzzer by Dmitry Vyukov
syzkaller: the next gen kernel fuzzersyzkaller: the next gen kernel fuzzer
syzkaller: the next gen kernel fuzzer
Dmitry Vyukov82.6K views
NovaProva, a new generation unit test framework for C programs by Greg Banks
NovaProva, a new generation unit test framework for C programsNovaProva, a new generation unit test framework for C programs
NovaProva, a new generation unit test framework for C programs
Greg Banks1.1K views
Muduo network library by Shuo Chen
Muduo network libraryMuduo network library
Muduo network library
Shuo Chen12.3K views
Java Hates Linux. Deal With It. by Greg Banks
Java Hates Linux.  Deal With It.Java Hates Linux.  Deal With It.
Java Hates Linux. Deal With It.
Greg Banks1.7K views

Similar to [CCC-28c3] Post Memory Corruption Memory Analysis

[HITB Malaysia 2011] Exploit Automation by
[HITB Malaysia 2011] Exploit Automation[HITB Malaysia 2011] Exploit Automation
[HITB Malaysia 2011] Exploit AutomationMoabi.com
1.2K views84 slides
[Kiwicon 2011] Post Memory Corruption Memory Analysis by
[Kiwicon 2011] Post Memory Corruption Memory Analysis[Kiwicon 2011] Post Memory Corruption Memory Analysis
[Kiwicon 2011] Post Memory Corruption Memory AnalysisMoabi.com
807 views84 slides
[Ruxcon 2011] Post Memory Corruption Memory Analysis by
[Ruxcon 2011] Post Memory Corruption Memory Analysis[Ruxcon 2011] Post Memory Corruption Memory Analysis
[Ruxcon 2011] Post Memory Corruption Memory AnalysisMoabi.com
793 views92 slides
HES2011 - Aaron Portnoy and Logan Brown - Black Box Auditing Adobe Shockwave by
HES2011 - Aaron Portnoy and Logan Brown - Black Box Auditing Adobe ShockwaveHES2011 - Aaron Portnoy and Logan Brown - Black Box Auditing Adobe Shockwave
HES2011 - Aaron Portnoy and Logan Brown - Black Box Auditing Adobe ShockwaveHackito Ergo Sum
1.2K views119 slides
NSC #2 - Challenge Solution by
NSC #2 - Challenge SolutionNSC #2 - Challenge Solution
NSC #2 - Challenge SolutionNoSuchCon
1.6K views47 slides
Library Operating System for Linux #netdev01 by
Library Operating System for Linux #netdev01Library Operating System for Linux #netdev01
Library Operating System for Linux #netdev01Hajime Tazaki
45.3K views40 slides

Similar to [CCC-28c3] Post Memory Corruption Memory Analysis(20)

[HITB Malaysia 2011] Exploit Automation by Moabi.com
[HITB Malaysia 2011] Exploit Automation[HITB Malaysia 2011] Exploit Automation
[HITB Malaysia 2011] Exploit Automation
Moabi.com1.2K views
[Kiwicon 2011] Post Memory Corruption Memory Analysis by Moabi.com
[Kiwicon 2011] Post Memory Corruption Memory Analysis[Kiwicon 2011] Post Memory Corruption Memory Analysis
[Kiwicon 2011] Post Memory Corruption Memory Analysis
Moabi.com807 views
[Ruxcon 2011] Post Memory Corruption Memory Analysis by Moabi.com
[Ruxcon 2011] Post Memory Corruption Memory Analysis[Ruxcon 2011] Post Memory Corruption Memory Analysis
[Ruxcon 2011] Post Memory Corruption Memory Analysis
Moabi.com793 views
HES2011 - Aaron Portnoy and Logan Brown - Black Box Auditing Adobe Shockwave by Hackito Ergo Sum
HES2011 - Aaron Portnoy and Logan Brown - Black Box Auditing Adobe ShockwaveHES2011 - Aaron Portnoy and Logan Brown - Black Box Auditing Adobe Shockwave
HES2011 - Aaron Portnoy and Logan Brown - Black Box Auditing Adobe Shockwave
Hackito Ergo Sum1.2K views
NSC #2 - Challenge Solution by NoSuchCon
NSC #2 - Challenge SolutionNSC #2 - Challenge Solution
NSC #2 - Challenge Solution
NoSuchCon1.6K views
Library Operating System for Linux #netdev01 by Hajime Tazaki
Library Operating System for Linux #netdev01Library Operating System for Linux #netdev01
Library Operating System for Linux #netdev01
Hajime Tazaki45.3K views
Docker Introduction, and what's new in 0.9 — Docker Palo Alto at RelateIQ by Jérôme Petazzoni
Docker Introduction, and what's new in 0.9 — Docker Palo Alto at RelateIQDocker Introduction, and what's new in 0.9 — Docker Palo Alto at RelateIQ
Docker Introduction, and what's new in 0.9 — Docker Palo Alto at RelateIQ
Jérôme Petazzoni9.2K views
Writing Metasploit Plugins by amiable_indian
Writing Metasploit PluginsWriting Metasploit Plugins
Writing Metasploit Plugins
amiable_indian15.5K views
[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese... by Moabi.com
[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese...[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese...
[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese...
Moabi.com1.2K views
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas... by tutorialsruby
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
tutorialsruby1.5K views
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas... by tutorialsruby
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
tutorialsruby352 views
Bugs from Outer Space | while42 SF #6 by While42
Bugs from Outer Space | while42 SF #6Bugs from Outer Space | while42 SF #6
Bugs from Outer Space | while42 SF #6
While421.1K views
Exploitation of counter overflows in the Linux kernel by Vitaly Nikolenko
Exploitation of counter overflows in the Linux kernelExploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernel
Vitaly Nikolenko330 views
OS scheduling and The anatomy of a context switch by Daniel Ben-Zvi
OS scheduling and The anatomy of a context switchOS scheduling and The anatomy of a context switch
OS scheduling and The anatomy of a context switch
Daniel Ben-Zvi2.8K views
What Have Syscalls Done for you Lately? by Docker, Inc.
What Have Syscalls Done for you Lately?What Have Syscalls Done for you Lately?
What Have Syscalls Done for you Lately?
Docker, Inc.379 views
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytes by Peter Hlavaty
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytesWindows Kernel Exploitation : This Time Font hunt you down in 4 bytes
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytes
Peter Hlavaty31.1K views
Open Source Systems Performance by Brendan Gregg
Open Source Systems PerformanceOpen Source Systems Performance
Open Source Systems Performance
Brendan Gregg33.4K views
Docker and-containers-for-development-and-deployment-scale12x by rkr10
Docker and-containers-for-development-and-deployment-scale12xDocker and-containers-for-development-and-deployment-scale12x
Docker and-containers-for-development-and-deployment-scale12x
rkr10112 views

More from Moabi.com

[Blackhat2015] FileCry attack against Internet Explorer by
[Blackhat2015] FileCry attack against Internet Explorer[Blackhat2015] FileCry attack against Internet Explorer
[Blackhat2015] FileCry attack against Internet ExplorerMoabi.com
1.4K views7 slides
[Blackhat2015] FileCry attack against Java by
[Blackhat2015] FileCry attack against Java[Blackhat2015] FileCry attack against Java
[Blackhat2015] FileCry attack against JavaMoabi.com
1.8K views7 slides
[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES... #Whitepaper by
[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES... #Whitepaper[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES... #Whitepaper
[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES... #WhitepaperMoabi.com
3.1K views10 slides
[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES... by
[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES...[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES...
[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES...Moabi.com
2K views52 slides
[2013 syscan360] Jonathan Brossard_katsuni理论介绍以及在沙盒和软件仿真方面的应用 by
[2013 syscan360] Jonathan Brossard_katsuni理论介绍以及在沙盒和软件仿真方面的应用[2013 syscan360] Jonathan Brossard_katsuni理论介绍以及在沙盒和软件仿真方面的应用
[2013 syscan360] Jonathan Brossard_katsuni理论介绍以及在沙盒和软件仿真方面的应用Moabi.com
1.7K views45 slides
Hardware backdooring is practical by
Hardware backdooring is practicalHardware backdooring is practical
Hardware backdooring is practicalMoabi.com
1.2K views13 slides

More from Moabi.com(12)

[Blackhat2015] FileCry attack against Internet Explorer by Moabi.com
[Blackhat2015] FileCry attack against Internet Explorer[Blackhat2015] FileCry attack against Internet Explorer
[Blackhat2015] FileCry attack against Internet Explorer
Moabi.com1.4K views
[Blackhat2015] FileCry attack against Java by Moabi.com
[Blackhat2015] FileCry attack against Java[Blackhat2015] FileCry attack against Java
[Blackhat2015] FileCry attack against Java
Moabi.com1.8K views
[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES... #Whitepaper by Moabi.com
[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES... #Whitepaper[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES... #Whitepaper
[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES... #Whitepaper
Moabi.com3.1K views
[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES... by Moabi.com
[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES...[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES...
[Blackhat2015] SMB : SHARING MORE THAN JUST YOUR FILES...
Moabi.com2K views
[2013 syscan360] Jonathan Brossard_katsuni理论介绍以及在沙盒和软件仿真方面的应用 by Moabi.com
[2013 syscan360] Jonathan Brossard_katsuni理论介绍以及在沙盒和软件仿真方面的应用[2013 syscan360] Jonathan Brossard_katsuni理论介绍以及在沙盒和软件仿真方面的应用
[2013 syscan360] Jonathan Brossard_katsuni理论介绍以及在沙盒和软件仿真方面的应用
Moabi.com1.7K views
Hardware backdooring is practical by Moabi.com
Hardware backdooring is practicalHardware backdooring is practical
Hardware backdooring is practical
Moabi.com1.2K views
[Hackito2012] Hardware backdooring is practical by Moabi.com
[Hackito2012] Hardware backdooring is practical[Hackito2012] Hardware backdooring is practical
[Hackito2012] Hardware backdooring is practical
Moabi.com1.4K views
[h2hc] Generic exploitation of invalid memory writes by Moabi.com
[h2hc] Generic exploitation of invalid memory writes[h2hc] Generic exploitation of invalid memory writes
[h2hc] Generic exploitation of invalid memory writes
Moabi.com1K views
[Ruxcon] Breaking virtualization by switching the cpu to virtual 8086 mode by Moabi.com
[Ruxcon] Breaking virtualization by switching the cpu to virtual 8086 mode[Ruxcon] Breaking virtualization by switching the cpu to virtual 8086 mode
[Ruxcon] Breaking virtualization by switching the cpu to virtual 8086 mode
Moabi.com3K views
[HackInTheBox] Breaking virtualization by any means by Moabi.com
[HackInTheBox] Breaking virtualization by any means[HackInTheBox] Breaking virtualization by any means
[HackInTheBox] Breaking virtualization by any means
Moabi.com2.1K views
[DEFCON] Bypassing preboot authentication passwords by instrumenting the BIOS... by Moabi.com
[DEFCON] Bypassing preboot authentication passwords by instrumenting the BIOS...[DEFCON] Bypassing preboot authentication passwords by instrumenting the BIOS...
[DEFCON] Bypassing preboot authentication passwords by instrumenting the BIOS...
Moabi.com2.2K views
[DEFCON 16] Bypassing pre-boot authentication passwords by instrumenting the... by Moabi.com
[DEFCON 16] Bypassing pre-boot authentication passwords  by instrumenting the...[DEFCON 16] Bypassing pre-boot authentication passwords  by instrumenting the...
[DEFCON 16] Bypassing pre-boot authentication passwords by instrumenting the...
Moabi.com10.5K views

Recently uploaded

Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ... by
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...ShapeBlue
146 views15 slides
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... by
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...ShapeBlue
154 views62 slides
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...James Anderson
156 views32 slides
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R... by
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...ShapeBlue
132 views15 slides
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha... by
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...ShapeBlue
138 views18 slides
Confidence in CloudStack - Aron Wagner, Nathan Gleason - Americ by
Confidence in CloudStack - Aron Wagner, Nathan Gleason - AmericConfidence in CloudStack - Aron Wagner, Nathan Gleason - Americ
Confidence in CloudStack - Aron Wagner, Nathan Gleason - AmericShapeBlue
88 views9 slides

Recently uploaded(20)

Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ... by ShapeBlue
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
ShapeBlue146 views
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... by ShapeBlue
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
ShapeBlue154 views
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson156 views
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R... by ShapeBlue
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
ShapeBlue132 views
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha... by ShapeBlue
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
ShapeBlue138 views
Confidence in CloudStack - Aron Wagner, Nathan Gleason - Americ by ShapeBlue
Confidence in CloudStack - Aron Wagner, Nathan Gleason - AmericConfidence in CloudStack - Aron Wagner, Nathan Gleason - Americ
Confidence in CloudStack - Aron Wagner, Nathan Gleason - Americ
ShapeBlue88 views
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue by ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlueMigrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
ShapeBlue176 views
Digital Personal Data Protection (DPDP) Practical Approach For CISOs by Priyanka Aash
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOs
Priyanka Aash153 views
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue by ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
ShapeBlue179 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker50 views
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT by ShapeBlue
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBITUpdates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
ShapeBlue166 views
NTGapps NTG LowCode Platform by Mustafa Kuğu
NTGapps NTG LowCode Platform NTGapps NTG LowCode Platform
NTGapps NTG LowCode Platform
Mustafa Kuğu365 views
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
ShapeBlue103 views
Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates by ShapeBlue
Keynote Talk: Open Source is Not Dead - Charles Schulz - VatesKeynote Talk: Open Source is Not Dead - Charles Schulz - Vates
Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates
ShapeBlue210 views
Initiating and Advancing Your Strategic GIS Governance Strategy by Safe Software
Initiating and Advancing Your Strategic GIS Governance StrategyInitiating and Advancing Your Strategic GIS Governance Strategy
Initiating and Advancing Your Strategic GIS Governance Strategy
Safe Software140 views
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPool by ShapeBlue
Extending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPoolExtending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPool
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPool
ShapeBlue84 views
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And... by ShapeBlue
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
ShapeBlue63 views
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading... by The Digital Insurer
Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading...
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue by ShapeBlue
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlueVNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue
ShapeBlue163 views

[CCC-28c3] Post Memory Corruption Memory Analysis

  • 1. Post Memory Corruption Memory Analysis Jonathan Brossard CEO – Toucan System jonathan@ toucan-system.com
  • 2. Who am I ? - Security Research Engineer at Toucan System - Speaker at Blackhat, Defcon, HITB, H2HC, Kiwicon, Ruxcon. - Organiser of the Hackito Ergo Sum conference (Paris). - I'm the guy who comes to CCC with 90+ slides...
  • 3. I don't reverse plain text
  • 4.
  • 5. Tool available at http://www.pmcma.org
  • 6. We got 10k downloads+ in 2 less than months... … and every email we get is questioning exploitation of remote stack overflows instead of invalid memory writes... ;(
  • 7. What's pmcma ? It's a debugger, for Linux (maybe one day *NIX) ptrace() based. Pmcma allows to find and test exploitation scenarios . Pmcma's output is a roadmap to exploitation, not exploit code. Tells you if a given bug triggering an invalid memory access is a vulnerability, if it is exploitable with the state of the art, and how to exploit it.
  • 9. Coz you asked for it...
  • 10. Remote stack overflow automated exploitation NX/SSP (stack cookies)/ASLR/PIE/STATIC GOT/Ascii Armoring... => No problem, easy cheesy : can be done with static analysis (of the libc/binary) only.
  • 11. Remote stack overflow automated exploitation SSP : cookies can be bruteforced remotely (cf Ben Hawks @ Ruxcon 2006).
  • 12. Remote stack overflow automated exploitation FORTIFY : - Doesn't apply all the time. - Fails silently (this is bad !!) - Is consistent under Linux (but not Apple...)
  • 13. Remote stack overflow automated exploitation PIE : - The bug new thing (every deamon compiled with PIE under ubuntu 10.10) - No public exploits (untill today ;) - We can bruteforce the saved EIP, then get back to ret2plt or ROP.
  • 14. DEMO
  • 15. Now, let's move to the real thing...
  • 17. Seriously, can we skip this section ?
  • 18. How do applications crash ? * Stack corruptions -> stack overflows, usually now detected because of SSP | studied a LOT * Signal 6 -> assert(),abort(): unexpected execution paths (assert() in particular), heap corruptions * Segfault (Signal 11) -> Invalid memory access
  • 19. How do applications crash ? * Stack corruptions -> stack overflows, usually now detected because of SSP | studied a LOT * Signal 6 -> assert(),abort(): unexpected execution paths (assert() in particular), heap corruptions * Segfault (Signal 11) -> Invalid memory access
  • 20. Invalid memory access - trying to read a page not readable. often not mapped at all. - trying to write to a page not writable. often not mapped at all. - trying to execute a page not executable. often not mapped at all.
  • 21. Why do they happen ? Because of any kind of miscomputation, really : - integer overflows in loop counters or destination registers when copying/initializing data, casting errors when extending registers or - uninitialised memory, dangling pointers - variable misuse - heap overflows (when inadvertently overwriting a function ptr) - missing format strings - overflows in heap, .data, .bss, or any other writable section (including shared libraries). - stack overflows when no stack cookies are present...
  • 22. Exploiting invalid exec Trivial, really. Eg : call eax with eax fully user controled
  • 23. Invalid memory reads (1/2) Eg : CVE-2011-0761 (Perl) cmp BYTE PTR [ ebx+0x8 ] ,0x9
  • 24. Invalid memory reads (2/2) Eg : CVE-2011-0764 (t1lib) fld QWORD PTR [eax+0x8]
  • 25. Exploiting invalid memory reads ? - usually plain not exploitable - won't allow us to modify the memory of the mapping directly - in theory : we could perform a user controled read, to trigger a second (better) bug.
  • 26. Invalid memory writes Eg : CVE-2011-1824 (Opera) mov DWORD PTR [ ebx+edx*1 ] ,eax
  • 27. How to... To exploit invalid writes, we need to find ways to transform an arbitray write into an arbitrary exec. The most obvious targets are function pointers.
  • 28. Exploiting invalid memory writes : scenario - Target a known function pointer (typically : .dtors, GOT entry...). Can be prevented at compile time : no .dtors, static GOT... - Target function pointers in the whole binary ? - Overwrite a given location to trigger an other bug (eg : stack overflow)
  • 30. Problems to take into account - Kernel : ASLR ? NX ? - Compilation/linking : RELRO (partial/full) ? no .dtors section ? SSP ? FORTIFY_SOURCE ? => Pmcma needs to mesure/detect those features
  • 31. ASLR Major problem when chosing an exploitation strategy.
  • 32. ASLR : not perfect - Prelinking (default on Fedora) breaks ASLR - All kernels don't have the same randomization strength. - Non PIE binaries => Truth is : we need better tools to test it !
  • 33. Testing ASLR -Run a binary X times (say X=100) -Stop execution after loading -Record mappings. => Compare mappings, deduce randomization
  • 36. GOALS - We want to test overwriting different memory locations inside a process and see if they have an influence over the flow of execution - We want to scale to big applications (web browsers, network deamons...) - We want a decent execution time
  • 37. mk_fork() The idea : -We start analysing after a SEGFAULT -We make the process fork() (many many times) -Inside each offspring, we overwrite a different memory location
  • 38. mk_fork() : benefits Mapping looks « just like » it will when actually exploiting a binary No ASLR/mapping replication problem Exhaustive and hopefully fast
  • 39. How to force a process to fork ? 1) Find a +X location mapped in memory. 2) Save registers 3) Use ptrace() to inject fork() shellcode. 4) Modify registers so eip points to shellcode. 5) Execute shellcode. 6) Wait() for both original process and offspring. 7) Restore bytes in both processes. 8) Restore registers in both processes.
  • 40. Forking shellcode ;forking shellcode: 00000000 6631C0 xor eax,eax 00000003 B002 mov al,0x2 00000005 CD80 int 0x80
  • 41. Original process Executable Writable Executable … Offspring 2 Executable Writable Executable … Offspring 1 Executable Writable Executable … mk_fork()
  • 42. Offspring 1 Executable Writable Executable … mk_fork()
  • 43. Offspring 2 Executable Writable Executable … mk_fork()
  • 44. Offspring n Executable Writable Executable … mk_fork()
  • 45. mk_fork() : PROS - allows for multiple tests out of a single process - fast, efficient (no recording of memory snapshots) - no need to use breakpoints - no single stepping
  • 46. mk_fork() : CONS - Dealing with offsprings termination ? (Zombie processes) - I/O, IPC, network sockets will be in unpredictable state - Hence syscalls will get wrong too (!!)
  • 47. Zombie reaping - Avoid the wait() for a SIGCHILD in the parent process. - Kill processes after a given timeout, including all of their children.
  • 48. Zombie reaping : the SIGCHILD problem If we can have the parent process ignore SIGCHILD signals, we won't create Zombies. => We inject a small shellcode to perform this via sigaction()
  • 49. Zombie reaping : the SIGCHILD problem 1) Find a +X location mapped in memory. 2) Save registers 3) Use ptrace() to inject sigaction() shellcode. 4) Modify registers so eip points to shellcode. 5) Execute shellcode. 6) Wait() for the process while executing shellcode. 7) Restore bytes in +X location. 8) Restore registers in the process.
  • 50. Force process grouping : shellcode ; Sigaction shellcode: // Zombie reaper ; struct sigaction sa = {.sa_handler = SIG_IGN}; ; sigaction(SIGCHLD, &sa, NULL); _start: nop nop nop nop call fake fake: pop ecx add ecx,0x18 ; delta to sigaction structure xor eax,eax mov al,0x43 ; sigaction mov ebx,0x11 ; SIGCHLD xor edx,edx ; 0x00 int 0x80 db 0xcc, 0xcc,0xcc,0xcc ; struct sigaction sa = {.sa_handler = SIG_IGN}; db 01, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
  • 51. Zombie reaping : killing the offsprings and their children Fortunatly, this is possible using « process grouping »...
  • 52. Process grouping setpgid() sets the PGID of the process specified by pid to pgid. If pid is zero, then the process ID of the calling process is used. If pgid is zero, then the PGID of the process specified by pid is made the same as its process ID. If setpgid() is used to move a process from one process group to another (as is done by some shells when creating pipelines), both process groups must be part of the same session (see setsid(2) and credentials(7)). In this case, the pgid specifies an existing process group to be joined and the session ID of that group must match the session ID of the joining process.
  • 53. Zombie reaping : forcing process grouping 1) Find a +X location mapped in memory. 2) Save registers 3) Use ptrace() to inject setpgid() shellcode. 4) Modify registers so eip points to shellcode. 5) Execute shellcode. 6) Wait() for the process while executing shellcode. 7) Restore bytes in +X location. 8) Restore registers in the process.
  • 54. Force process grouping... ; ; setpgid(0,0); shellcode ; _start: nop nop nop nop mov eax,0x39 ; setpgid xor ebx,ebx xor ecx,ecx int 0x80 db 0xcc, 0xcc
  • 55. Zombie reaping : final details From now on, to kill a process and all of its children : kill (-pid, SIGTERM) ;
  • 56. IPC, I/O, invalid syscalls One possibility is to recode correct execution on the original process (after clearing signals and ignoring the SEGFAULT). Then replay/fake the syscalls on the offsprings. => Minimal userland « virtualization ».
  • 58. Exploiting invalid memory writes via function pointers We now want to find all the function pointers called by the application from the instruction which triggered the SEGFAULT until it actually halts. (including pointers in shared libraries!!)
  • 59. Finding all the function pointers actually called 1) Parse all the +W memory, look for possible pointers to any section 1 bis) optionally disassemble the destination and see if it is a proper prologue. 2) use mk_fork() to create many children 3) in each children, overwrite a different possible function pointer with a canari value (0xf1f2f3f4). 4) Monitor execution of the offsprings
  • 60. Finding all the function pointers actually called Overwritten pointer leads to execution of canari address 0xf1f2f3f4 <=> We found a called function pointer.
  • 61. Finding all the function pointers actually called DEMO
  • 62. So what can we test now ? Invalid write anything anywhere  : attacker has full control over data written and destination where written => GAME OVER
  • 63. So what can we test now ? Overflows (in any writtable section but the stack) : Simply limit the results of pmcma to this section.
  • 64. So what can we test now ? What if the attacker has little or no control over the data being written  (arbitrary write non controled data, anywhere) ?
  • 65. Partial overwrites and pointers truncation If we can't properly overwrite a function pointer, maybe we can still truncate one (with the data we don't control) so that it transfers execution to a controled memory zone ?
  • 66. Exemple : --[ Function pointers exploitable by truncation with 0x41424344: At 0xb70ce070 : 0xb70c63c2 will become 0xb70c4142 (lower truncated by 16 bits, dest perms:RW) At 0xb70e40a4 : 0xb70ca8f2 will become 0xb70c4142 (lower truncated by 16 bits, dest perms:RW) At 0xb70ec080 : 0xb70e5e02 will become 0xb70e4142 (lower truncated by 16 bits, dest perms:RW) At 0xb731a030 : 0xb7315da2 will become 0xb7314142 (lower truncated by 16 bits, dest perms:RW) At 0xb73230a4 : 0xb732003a will become 0xb7324142 (lower truncated by 16 bits, dest perms:RW) At 0xb732803c : 0xb7325a36 will become 0xb7324142 (lower truncated by 16 bits, dest perms:RW) At 0xb76a80d8 : 0xb7325bf0 will become 0xb7324142 (lower truncated by 16 bits, dest perms:RW)
  • 67. One more situation... Sometimes, an attacker has limited control over the destination of the write (wether he controls the data being written or not). Eg : 4b aligned memory writes.
  • 68. Exploiting 4b aligned memory writes We can't attack a function pointer directly, unless it is unaligned (rare because of compiler internals). Pmcma will still let you know if this happens ;)
  • 69. Exploiting 4b aligned memory writes : plan B Find all « normal » variables we can overwrite/truncate, and attempt to trigger a second bug because of this overwrite.
  • 70. Finding all unaligned memory accesses Setting the unaligned flag in the EFLAGS register will trigger a signal 7 uppon next access of unaligned memory (read/write).
  • 71. Finding all unaligned memory accesses DEMO
  • 72. Finding all unaligned memory accesses DEMO x86_64
  • 73. Defeating ASLR : Automated memory mapping leakage How does WTFuzz did it at CansecWest 2010 to win the pwn2own contest against IE8/Windows 7 ? Overwrite the null terminator of a JS string to perform a mem leak uppon usage (trailing bytes).
  • 74. Defeating ASLR with an arbitrary write ? In the original process : - use ptrace() PTRACE_SYSCALL - record the calls to sys_write() and sys_socketall() (wrapper to sys_send() or sys_sendto()...), including : where is the data sent ? How many bytes ?
  • 75. Defeating ASLR with an arbitrary write ? Create many offsprings using mk_fork(). -In each of them : overwrite a different location with dummy data. -Follow execution using PTRACE_SYSCALL -Monitor differences : a different address or a bigger size means a memory leak :)
  • 77. Means of modifying the flow of execution without function pointers Call tables. Calling [Offset+register] => This is also already performed automatically using pmcma.
  • 78. Pointers and ASLR If overwritting a given function pointer isn't practical because of ASLR : is it possible to overwrite a pointer (in an other section) to a structure containing this function pointer ? Would this « other section » be less randomised ?
  • 79. Finding pointers to structures containing function pointers Executable Writable (high ASLR) Executable … Writable (no ASLR) Executable Complex structure … void* f(a,b,c)
  • 80. Finding pointers to structures containing function pointers We'd like to have the debugged process create a new section, with a given mapping (to ease identify). Modify a possible pointer per offspring (use mk_fork()). Monitor execution : is the offspring calling a function pointer from our custom mapping ?
  • 81. Forcing a process to create a new mapping : 1) Find a +X location mapped in memory. 2) Save registers 3) Use ptrace() to inject mmap() shellcode. 4) Modify registers so eip points to shellcode. 5) Execute shellcode. 6) Wait() for the process while executing shellcode. 7) Restore bytes in +X location. 8) Restore registers in the process.
  • 82. ; ; old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, 0, 0) shellcode: ; _start: nop nop nop nop xor eax, eax xor ebx, ebx xor ecx, ecx xor edx, edx xor esi, esi xor edi, edi mov bx, 0x1000 ; 1 page mov cl, 0x3 ; PROT_READ|PROT_WRITE mov dl, 0x21 ; MAP_SHARED|MAP_ANON push eax push eax push edx push ecx push ebx push eax mov ebx, esp mov al, 0x5a ; sys_mmap int 0x80 ; eax contains address of new mapping db 0xcc, 0xcc, 0xcc, 0xcc
  • 83. In case all of the above failed... Can we trigger secondary bugs by overwritting specific memory locations ? Testing exhaustively arbitrary writes
  • 84. Testing exhaustively arbitrary writes Complexity is huge ! Still doable with Pmcma, with no guaranty over the time of execution.
  • 85. Testing exhaustively arbitrary reads In the same veine, attacker controled invalid reads can trigger secondary bugs, which will be exploitable. => We can test the whole 4+ billions search space (under x86 Intel architecture), or just a few evenly chosen ones.
  • 86. Stack desynchronization W^X is a problem. Even if we can overwrite fully a function pointer and modify the flow of execution... what do we want to execute in 2011 ?
  • 87. Stack desynchronization Instead of returning directly to shellcode in +W section (hence probably not +X) : -Return to a function epilogue chosen so that esp will be set to user controled data in the stack. - Fake stack frames in the stack itself. - Use your favorite ROP/ret2plt shellcode
  • 88. Stack desynchronization : Exemple : sudo - stack is ~1000 big (at analysis time) - we find a function pointer to overwrite (at 0x0806700c) - we overwrite it with a carefully chosen prologue (inc esp by more than 1000)
  • 89. Stack desynchronization : Exemple : sudo jonathan@blackbox:~$ objdump -Mintel -d /usr/bin/sudo ... 805277a: 81 c4 20 20 00 00 add esp,0x2020 8052780: 5b pop ebx 8052781: 5e pop esi 8052782: 5d pop ebp 8052783: c3 ret
  • 90. Stack desynchronization : Exemple : sudo We can control the destination where esp is going to point : simply use an environment variable TOTO=mydata sudo
  • 91. Stack desynchronization : Exemple : sudo We then forge fake stack frames in the stack itself - « Nop sled » : any pointer to 'ret' Eg :804997b: c3 ret - Then copy shellcode to .bss byte per byte using memcpy via ret2plt - Use GOT overwrite to get pointer to mprotect() in the GOT (ROP) - call mprotect to make .bss +X via ret2plt - return to shellcode in .bss
  • 92. DEMOS
  • 93. Future Work - port to more architectures (Linux x86_64 on the way, arm...) - port to more OS (Mac OSX, *BSD) - port to Windows (hard) - add tests for other bug classes
  • 94. Questions ? Thank you for coming