SlideShare a Scribd company logo
Riding the Overflow – 
Then and Now 
Miroslav Štampar 
(mstampar@zsis.hr)
tl;dr 
FSec 2014, Varaždin (Croatia) September 17th, 2014 2
Buffer overflow 
(a.k.a.) Buffer overrun 
An anomaly where a program, while writing 
data to the buffer, overruns its boundary, thus 
overwriting adjacent memory location(s) 
Commonly associated with programming 
languages C and C++ (no boundary checking) 
Stack-based (e.g. statically allocated built-in 
array at compile time) – overwriting stack 
elements 
Heap-based (e.g. dynamically allocated 
malloc() array at run time) – overwriting heap 
internal structures (e.g. linked list pointers) 
FSec 2014, Varaždin (Croatia) September 17th, 2014 3
Stack-based overflow 
FSec 2014, Varaždin (Croatia) September 17th, 2014 4
Heap-based overflow 
FSec 2014, Varaždin (Croatia) September 17th, 2014 5
Vulnerable code (stack-based) 
FSec 2014, Varaždin (Croatia) September 17th, 2014 6
Vulnerable code (heap-based) 
FSec 2014, Varaždin (Croatia) September 17th, 2014 7
History 
 1961 - Burroughs 5000 (executable space protection) 
 1972 - Computer Security Technology Planning Study (buffer 
overflow as an idea) 
 1988 - Morris worm (earliest exploitation – gets() in fingerd) 
 1995 - Buffer overflow rediscovered (Bugtraq) 
 1996 - “Smashing the Stack for Fun and Profit” (Aleph One) 
 1997 - “Return-into-lib(c) exploits” (Solar Designer) 
 2000 - The Linux PaX project 
 2001 - Code Red (IIS 5.0); Heap spraying (MS01-033) 
 2003 - SQL Slammer (MsSQL 2000); Microsoft VS 2003 flag /GS 
 2004 - NX on Linux (kernel 2.6.8); DEP on Windows (XP SP2); Egg 
hunting (skape) 
 2005 - ASLR on Linux (kernel 2.6.12); GCC flag -fstack-protector 
 2007 - ASLR on Windows (Vista); ROP (Sebastian Krahmer) 
FSec 2014, Varaždin (Croatia) September 17th, 2014 8
Stack canaries 
(a.k.a.) Stack cookies, Stack-Smashing 
Protector (SSP) 
Named for analogy to a canary in a coal mine 
Implemented by the compiler 
Placing a small (e.g. random) integer value to 
stack just before the return pointer 
In order to overwrite the return pointer (and 
thus take control of the process) the canary 
value would also be overwritten 
This value is checked to make sure it has not 
changed before a routine uses the return 
pointer from the stack 
FSec 2014, Varaždin (Croatia) September 17th, 2014 9
ASCII armor 
Generally maps important library addresses 
(e.g. libc) to a memory range containing a 
NULL byte (e.g. 0x00****** - 0x0100******) 
Makes it hard to construct address or pass 
arguments by exploiting string functions (e.g. 
strcpy()) 
Not effective when NULL (i.e. 0x00) byte is not 
an issue (rarely) 
Easily bypassable by using PLT (Procedure 
Language Table) entries in case of position 
independent binary 
FSec 2014, Varaždin (Croatia) September 17th, 2014 10
SEH 
Structured Exception Handler 
Implemented by the compiler 
Pointer to the exception handler is added to 
the stack in the form of the “Exception 
Registration Record” (SEH) and “Next 
Exception Registration Record” (nSEH) 
If the buffer is overflown and (junk) data is 
written to the SEH (located eight bytes after 
ESP), invalid handler is called due to the 
inherently raised exception (i.e. 
STATUS_ACCESS_VIOLATION), thus preventing 
successful execution of used payload 
FSec 2014, Varaždin (Croatia) September 17th, 2014 11
SEH (chain) 
FSec 2014, Varaždin (Croatia) September 17th, 2014 12
SEHOP 
Structured Exception Handler Overwrite 
Protection 
Blocks exploits that use (highly popular) SEH 
overwrite method 
Enabled by default on Windows Server 2008, 
disabled on Windows Vista SP1 and Windows 7 
Symbolic exception registration record 
appended to the end of exception handler list 
Integrity of exception handler chain is broken if 
symbolic record can't be reached and/or if it's 
found to be invalid 
FSec 2014, Varaždin (Croatia) September 17th, 2014 13
SafeSEH 
Safe Structured Exception Handling 
(a.k.a.) Software-enforced DEP 
All exception handlers' entry points collected to 
a designated read-only table collected at the 
compilation time 
Safe Exception Handler Table 
Attempt to execute any unregistered exception 
handler will result in the immediate program 
termination 
FSec 2014, Varaždin (Croatia) September 17th, 2014 14
DEP/NX 
Data Execution Prevention/No eXecute 
(a.k.a.) Non-executable stack, Execute Disable, 
Exec Shield (Linux), W^X (FreeBSD) 
Set of hardware and software technologies that 
perform additional checks on memory 
Provides protection for all memory pages that 
are not specifically marked as executable 
Processor must support hardware-enforced 
mechanism (NX/EVP/XD) 
Executables and libraries have to be 
specifically linked (problems with older 
software) 
FSec 2014, Varaždin (Croatia) September 17th, 2014 15
ASLR 
Address Space Layout Randomization 
Introduces the randomness into the address 
space of process 
Positions of key data areas are randomly 
scattered (i.e. dynamic/shared libraries, heap 
and stack) 
Its strength is based upon the low chance of an 
attacker guessing the locations of randomly 
placed areas 
Executables and dynamic/shared libraries have 
to be specifically linked (problems with older 
software) 
FSec 2014, Varaždin (Croatia) September 17th, 2014 16
Safe functions 
Well-written functions that automatically 
perform buffer management (including 
boundary checking), reducing the occurrence 
and impact of buffer overflows 
Usually by introducing explicit parameter size 
FSec 2014, Varaždin (Croatia) September 17th, 2014 17
NOP sled 
(a.k.a.) NOP slide, NOP ramp 
Oldest and most widely known method for 
stack buffer overflow exploitation 
Large sequence of NOP (no-operation) 
instructions meant to “slide” the CPU's 
execution flow 
Used when jump location has to be given 
(payload), while it's impossible to be exactly 
predicted 
Today widely used in high profile exploits 
utilizing “Heap spraying” method (e.g. 
browsers) 
FSec 2014, Varaždin (Croatia) September 17th, 2014 18
NOP sled (visual) 
FSec 2014, Varaždin (Croatia) September 17th, 2014 19
ret2libc 
(a.k.a.) ret2system, arc injection 
Overwriting the return address with location of 
a function that is already loaded in the binary 
or via shared library 
Required arguments are also provided through 
stack overwrite 
Shared library libc(.so) is always linked to 
executables on UNIX style systems and 
provides useful calls (e.g. system()) 
Dynamic library kernel32(.dll) is always loaded 
by executables on Win32 style systems and 
provides useful calls (e.g. WinExec()) 
FSec 2014, Varaždin (Croatia) September 17th, 2014 20
ret2libc (visual) 
FSec 2014, Varaždin (Croatia) September 17th, 2014 21
ret2reg 
Return-to-register (e.g. ESP, EAX, etc.) 
(a.k.a.) Trampolining 
Also, variants like ret2pop, ret2ret, etc. 
We overwrite the EIP with the address of an 
existing instruction that would jump to the 
location of a register 
Preferred choice is the register pointing to the 
location inside our buffer (usually ESP) 
Much more reliable method than NOP sled 
Without the need for extra room for NOP sled 
and without having to guess stack offset 
FSec 2014, Varaždin (Croatia) September 17th, 2014 22
ret2reg (visual) 
FSec 2014, Varaždin (Croatia) September 17th, 2014 23
Egg hunting 
Used in reduced buffer space situations 
Allows usage of a small payload (“egg hunter”) 
to find the actual (bigger) payload 
The final payload must be somewhere in 
memory (i.e. stack, heap or secondary buffer) 
prepended with the unique marking string (2x4 
bytes) called “egg” (e.g. “w00tw00t”) 
Searching memory byte at a time 
Memory “peeking” with syscall mechanism(s) 
to bypass access violation issues 
Egg hunter types: SEH, IsBadReadPtr, 
NtDisplayString, NtAccessCheckAndAuditAlarm 
FSec 2014, Varaždin (Croatia) September 17th, 2014 24
Egg hunter (NtDisplayString) 
loop_inc_page: 
or dx, 0x0fff // Add PAGE_SIZE-1 to edx 
loop_inc_one: 
inc edx // Increment our pointer by one 
loop_check: 
push edx // Save edx 
push 0x43 // Push NtDisplayString 
pop eax // Pop into eax 
int 0x2e // Perform the syscall 
cmp al, 0x05 // Did we get 0xc0000005 (ACCESS_VIOLATION) ? 
pop edx // Restore edx 
loop_check_8_valid: 
je loop_inc_page // Yes, invalid ptr, go to the next page 
is_egg: 
mov eax, 0x50905090 // Throw our egg in eax 
mov edi, edx // Set edi to the pointer we validated 
scasd // Compare the dword in edi to eax 
jnz loop_inc_one // No match? Increment the pointer by one 
scasd // Compare the dword in edi to eax again (which is now 
edx + 4) 
jnz loop_inc // No match? Increment the pointer by one 
matched: 
jmp edi // Found the egg. Jump 8 bytes past it into our code. 
FSec 2014, Varaždin (Croatia) September 17th, 2014 25
Egg hunting (visual) 
FSec 2014, Varaždin (Croatia) September 17th, 2014 26
SEH bypass 
SEH is highly flawed against buffer overflows 
Overwrite (last in chain) SEH with address of 
"POP; POP; RET" sequence of instructions and 
nSEH with explicit relative "JMP" to payload 
Deliberate exception has to be caused 
(inherently by sending malformed buffer) 
“POP; POP; RET” passes the execution flow to 
the nSEH's JMP, which afterwards jumps to the 
payload at the end of the buffer 
Effective as the stack canary bypass method 
(too) as exception is triggered (and handled) 
before the canary/cookie value is checked 
FSec 2014, Varaždin (Croatia) September 17th, 2014 27
SEH bypass (visual) 
FSec 2014, Varaždin (Croatia) September 17th, 2014 28
ROP 
Return-Oriented Programming 
Attacker executes carefully chosen machine 
instruction sequences called “gadgets” 
Each gadget ends with an instruction RET (e.g. 
“INC EAX; RET”) 
ROP “chain” consists of gadget memory 
locations (sequentially popped and executed) 
Provides a fully functional language that can be 
used to perform any operation desired (usually 
to disable DEP) 
Semi-automated process of making a wanted 
ROP “chain” (mona.py) 
FSec 2014, Varaždin (Croatia) September 17th, 2014 29
ROP (disable DEP) 
Taken from: https://www.corelan.be 
FSec 2014, Varaždin (Croatia) September 17th, 2014 30
ROP (visual) 
FSec 2014, Varaždin (Croatia) September 17th, 2014 31
Heap spray 
Top payload delivery method used in browser 
exploits (and recent high profile attacks) 
Takes advantage of the fact that the heap 
management is deterministic 
Attacker needs to be able to deliver the 
payload in the right location in memory before 
triggering the bug that leads to EIP control 
A good heap spray (if done right) will end up 
allocating a chunk of memory at a predictable 
location, after a certain amount of allocations 
At the end (predictable) heap address needs to 
be put into EIP 
FSec 2014, Varaždin (Croatia) September 17th, 2014 32
Heap spray (visual) 
FSec 2014, Varaždin (Croatia) September 17th, 2014 33
Demo time 
FSec 2014, Varaždin (Croatia) September 17th, 2014 34
Questions? 
FSec 2014, Varaždin (Croatia) September 17th, 2014 35

More Related Content

What's hot

Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545Kernel TLV
 
Patterns for JVM languages JokerConf
Patterns for JVM languages JokerConfPatterns for JVM languages JokerConf
Patterns for JVM languages JokerConfJaroslaw Palka
 
Building Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCCBuilding Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCCKernel TLV
 
Crypto With OpenSSL
Crypto With OpenSSLCrypto With OpenSSL
Crypto With OpenSSLZhi Guan
 
Non blocking io with netty
Non blocking io with nettyNon blocking io with netty
Non blocking io with nettyZauber
 
The TCP/IP stack in the FreeBSD kernel COSCUP 2014
The TCP/IP stack in the FreeBSD kernel COSCUP 2014The TCP/IP stack in the FreeBSD kernel COSCUP 2014
The TCP/IP stack in the FreeBSD kernel COSCUP 2014Kevin Lo
 
[Deprecated] Integrating libSyntax into the compiler pipeline
[Deprecated] Integrating libSyntax into the compiler pipeline[Deprecated] Integrating libSyntax into the compiler pipeline
[Deprecated] Integrating libSyntax into the compiler pipelineYusuke Kita
 
VLANs in the Linux Kernel
VLANs in the Linux KernelVLANs in the Linux Kernel
VLANs in the Linux KernelKernel TLV
 
What is new in Go 1.8
What is new in Go 1.8What is new in Go 1.8
What is new in Go 1.8John Hua
 
Pf: the OpenBSD packet filter
Pf: the OpenBSD packet filterPf: the OpenBSD packet filter
Pf: the OpenBSD packet filterGiovanni Bechis
 
Non-blocking synchronization — what is it and why we (don't?) need it
Non-blocking synchronization — what is it and why we (don't?) need itNon-blocking synchronization — what is it and why we (don't?) need it
Non-blocking synchronization — what is it and why we (don't?) need itAlexey Fyodorov
 
Socket programming with php
Socket programming with phpSocket programming with php
Socket programming with phpElizabeth Smith
 
ToroDB: scaling PostgreSQL like MongoDB / Álvaro Hernández Tortosa (8Kdata)
ToroDB: scaling PostgreSQL like MongoDB / Álvaro Hernández Tortosa (8Kdata)ToroDB: scaling PostgreSQL like MongoDB / Álvaro Hernández Tortosa (8Kdata)
ToroDB: scaling PostgreSQL like MongoDB / Álvaro Hernández Tortosa (8Kdata)Ontico
 
June8 presentation
June8 presentationJune8 presentation
June8 presentationnicobn
 
[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...
[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese...Moabi.com
 
Parsing JSON Really Quickly: Lessons Learned
Parsing JSON Really Quickly: Lessons LearnedParsing JSON Really Quickly: Lessons Learned
Parsing JSON Really Quickly: Lessons LearnedDaniel Lemire
 
FreeRTOS Xilinx Vivado: Hello World!
FreeRTOS Xilinx Vivado: Hello World!FreeRTOS Xilinx Vivado: Hello World!
FreeRTOS Xilinx Vivado: Hello World!Vincent Claes
 
NSC #2 - D2 02 - Benjamin Delpy - Mimikatz
NSC #2 - D2 02 - Benjamin Delpy - MimikatzNSC #2 - D2 02 - Benjamin Delpy - Mimikatz
NSC #2 - D2 02 - Benjamin Delpy - MimikatzNoSuchCon
 

What's hot (20)

Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545
 
Patterns for JVM languages JokerConf
Patterns for JVM languages JokerConfPatterns for JVM languages JokerConf
Patterns for JVM languages JokerConf
 
Building Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCCBuilding Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCC
 
Crypto With OpenSSL
Crypto With OpenSSLCrypto With OpenSSL
Crypto With OpenSSL
 
Non blocking io with netty
Non blocking io with nettyNon blocking io with netty
Non blocking io with netty
 
The TCP/IP stack in the FreeBSD kernel COSCUP 2014
The TCP/IP stack in the FreeBSD kernel COSCUP 2014The TCP/IP stack in the FreeBSD kernel COSCUP 2014
The TCP/IP stack in the FreeBSD kernel COSCUP 2014
 
[Deprecated] Integrating libSyntax into the compiler pipeline
[Deprecated] Integrating libSyntax into the compiler pipeline[Deprecated] Integrating libSyntax into the compiler pipeline
[Deprecated] Integrating libSyntax into the compiler pipeline
 
VLANs in the Linux Kernel
VLANs in the Linux KernelVLANs in the Linux Kernel
VLANs in the Linux Kernel
 
What is new in Go 1.8
What is new in Go 1.8What is new in Go 1.8
What is new in Go 1.8
 
Pf: the OpenBSD packet filter
Pf: the OpenBSD packet filterPf: the OpenBSD packet filter
Pf: the OpenBSD packet filter
 
Non-blocking synchronization — what is it and why we (don't?) need it
Non-blocking synchronization — what is it and why we (don't?) need itNon-blocking synchronization — what is it and why we (don't?) need it
Non-blocking synchronization — what is it and why we (don't?) need it
 
Socket programming with php
Socket programming with phpSocket programming with php
Socket programming with php
 
ToroDB: scaling PostgreSQL like MongoDB / Álvaro Hernández Tortosa (8Kdata)
ToroDB: scaling PostgreSQL like MongoDB / Álvaro Hernández Tortosa (8Kdata)ToroDB: scaling PostgreSQL like MongoDB / Álvaro Hernández Tortosa (8Kdata)
ToroDB: scaling PostgreSQL like MongoDB / Álvaro Hernández Tortosa (8Kdata)
 
June8 presentation
June8 presentationJune8 presentation
June8 presentation
 
[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...
[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese...
 
Parsing JSON Really Quickly: Lessons Learned
Parsing JSON Really Quickly: Lessons LearnedParsing JSON Really Quickly: Lessons Learned
Parsing JSON Really Quickly: Lessons Learned
 
FreeRTOS Xilinx Vivado: Hello World!
FreeRTOS Xilinx Vivado: Hello World!FreeRTOS Xilinx Vivado: Hello World!
FreeRTOS Xilinx Vivado: Hello World!
 
NSC #2 - D2 02 - Benjamin Delpy - Mimikatz
NSC #2 - D2 02 - Benjamin Delpy - MimikatzNSC #2 - D2 02 - Benjamin Delpy - Mimikatz
NSC #2 - D2 02 - Benjamin Delpy - Mimikatz
 
opt-mem-trx
opt-mem-trxopt-mem-trx
opt-mem-trx
 
skipfish
skipfishskipfish
skipfish
 

Viewers also liked

2014 – Year of Broken Name Generator(s)
2014 – Year of Broken Name Generator(s)2014 – Year of Broken Name Generator(s)
2014 – Year of Broken Name Generator(s)Miroslav Stampar
 
sqlmap - security development in Python
sqlmap - security development in Pythonsqlmap - security development in Python
sqlmap - security development in PythonMiroslav Stampar
 
Heuristic methods used in sqlmap
Heuristic methods used in sqlmapHeuristic methods used in sqlmap
Heuristic methods used in sqlmapMiroslav Stampar
 
It all starts with the ' (SQL injection from attacker's point of view)
It all starts with the ' (SQL injection from attacker's point of view)It all starts with the ' (SQL injection from attacker's point of view)
It all starts with the ' (SQL injection from attacker's point of view)Miroslav Stampar
 
sqlmap - why (not how) it works?
sqlmap - why (not how) it works?sqlmap - why (not how) it works?
sqlmap - why (not how) it works?Miroslav Stampar
 
Spot the Web Vulnerability
Spot the Web VulnerabilitySpot the Web Vulnerability
Spot the Web VulnerabilityMiroslav Stampar
 
DNS exfiltration using sqlmap
DNS exfiltration using sqlmapDNS exfiltration using sqlmap
DNS exfiltration using sqlmapMiroslav Stampar
 
Non-Esoteric XSS Tips & Tricks
Non-Esoteric XSS Tips & TricksNon-Esoteric XSS Tips & Tricks
Non-Esoteric XSS Tips & TricksMiroslav Stampar
 

Viewers also liked (11)

test
testtest
test
 
Curious Case of SQLi
Curious Case of SQLiCurious Case of SQLi
Curious Case of SQLi
 
2014 – Year of Broken Name Generator(s)
2014 – Year of Broken Name Generator(s)2014 – Year of Broken Name Generator(s)
2014 – Year of Broken Name Generator(s)
 
sqlmap - Under the Hood
sqlmap - Under the Hoodsqlmap - Under the Hood
sqlmap - Under the Hood
 
sqlmap - security development in Python
sqlmap - security development in Pythonsqlmap - security development in Python
sqlmap - security development in Python
 
Heuristic methods used in sqlmap
Heuristic methods used in sqlmapHeuristic methods used in sqlmap
Heuristic methods used in sqlmap
 
It all starts with the ' (SQL injection from attacker's point of view)
It all starts with the ' (SQL injection from attacker's point of view)It all starts with the ' (SQL injection from attacker's point of view)
It all starts with the ' (SQL injection from attacker's point of view)
 
sqlmap - why (not how) it works?
sqlmap - why (not how) it works?sqlmap - why (not how) it works?
sqlmap - why (not how) it works?
 
Spot the Web Vulnerability
Spot the Web VulnerabilitySpot the Web Vulnerability
Spot the Web Vulnerability
 
DNS exfiltration using sqlmap
DNS exfiltration using sqlmapDNS exfiltration using sqlmap
DNS exfiltration using sqlmap
 
Non-Esoteric XSS Tips & Tricks
Non-Esoteric XSS Tips & TricksNon-Esoteric XSS Tips & Tricks
Non-Esoteric XSS Tips & Tricks
 

Similar to Riding the Overflow - Then and Now

Reverse Engineering for exploit writers
Reverse Engineering for exploit writersReverse Engineering for exploit writers
Reverse Engineering for exploit writersamiable_indian
 
Nibin - Reverse Engineering for exploit writers - ClubHack2008
Nibin - Reverse Engineering for exploit writers - ClubHack2008Nibin - Reverse Engineering for exploit writers - ClubHack2008
Nibin - Reverse Engineering for exploit writers - ClubHack2008ClubHack
 
Linux network namespaces
Linux network namespacesLinux network namespaces
Linux network namespacesMike Wilson
 
Varnish, the high performance valhalla?
Varnish, the high performance valhalla?Varnish, the high performance valhalla?
Varnish, the high performance valhalla?Jeroen van Dijk
 
Pegasus - automate, recover, and debug scientific computations
Pegasus - automate, recover, and debug scientific computationsPegasus - automate, recover, and debug scientific computations
Pegasus - automate, recover, and debug scientific computationsRafael Ferreira da Silva
 
What you need to know about ceph
What you need to know about cephWhat you need to know about ceph
What you need to know about cephEmma Haruka Iwao
 
Recipes for Running Spark Streaming Applications in Production-(Tathagata Das...
Recipes for Running Spark Streaming Applications in Production-(Tathagata Das...Recipes for Running Spark Streaming Applications in Production-(Tathagata Das...
Recipes for Running Spark Streaming Applications in Production-(Tathagata Das...Spark Summit
 
Hadoop spark performance comparison
Hadoop spark performance comparisonHadoop spark performance comparison
Hadoop spark performance comparisonarunkumar sadhasivam
 
Squash Those IoT Security Bugs with a Hardened System Profile
Squash Those IoT Security Bugs with a Hardened System ProfileSquash Those IoT Security Bugs with a Hardened System Profile
Squash Those IoT Security Bugs with a Hardened System ProfileSteve Arnold
 
Scaling ArangoDB on Mesosphere DCOS
Scaling ArangoDB on Mesosphere DCOSScaling ArangoDB on Mesosphere DCOS
Scaling ArangoDB on Mesosphere DCOSMax Neunhöffer
 
Drupal and Varnish Reverse Proxy
Drupal and Varnish Reverse ProxyDrupal and Varnish Reverse Proxy
Drupal and Varnish Reverse ProxyVFXCode
 
You're Off the Hook: Blinding Security Software
You're Off the Hook: Blinding Security SoftwareYou're Off the Hook: Blinding Security Software
You're Off the Hook: Blinding Security SoftwareCylance
 
Ceph Day Beijing: Big Data Analytics on Ceph Object Store
Ceph Day Beijing: Big Data Analytics on Ceph Object Store Ceph Day Beijing: Big Data Analytics on Ceph Object Store
Ceph Day Beijing: Big Data Analytics on Ceph Object Store Ceph Community
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the wayOleg Podsechin
 
Ceph Day Taipei - Ceph Tiering with High Performance Architecture
Ceph Day Taipei - Ceph Tiering with High Performance Architecture Ceph Day Taipei - Ceph Tiering with High Performance Architecture
Ceph Day Taipei - Ceph Tiering with High Performance Architecture Ceph Community
 

Similar to Riding the Overflow - Then and Now (20)

Reverse Engineering for exploit writers
Reverse Engineering for exploit writersReverse Engineering for exploit writers
Reverse Engineering for exploit writers
 
Nibin - Reverse Engineering for exploit writers - ClubHack2008
Nibin - Reverse Engineering for exploit writers - ClubHack2008Nibin - Reverse Engineering for exploit writers - ClubHack2008
Nibin - Reverse Engineering for exploit writers - ClubHack2008
 
Linux network namespaces
Linux network namespacesLinux network namespaces
Linux network namespaces
 
wtf is in Java/JDK/wtf7?
wtf is in Java/JDK/wtf7?wtf is in Java/JDK/wtf7?
wtf is in Java/JDK/wtf7?
 
Varnish, the high performance valhalla?
Varnish, the high performance valhalla?Varnish, the high performance valhalla?
Varnish, the high performance valhalla?
 
Pegasus - automate, recover, and debug scientific computations
Pegasus - automate, recover, and debug scientific computationsPegasus - automate, recover, and debug scientific computations
Pegasus - automate, recover, and debug scientific computations
 
What you need to know about ceph
What you need to know about cephWhat you need to know about ceph
What you need to know about ceph
 
Panama.pdf
Panama.pdfPanama.pdf
Panama.pdf
 
JS everywhere 2011
JS everywhere 2011JS everywhere 2011
JS everywhere 2011
 
Recipes for Running Spark Streaming Applications in Production-(Tathagata Das...
Recipes for Running Spark Streaming Applications in Production-(Tathagata Das...Recipes for Running Spark Streaming Applications in Production-(Tathagata Das...
Recipes for Running Spark Streaming Applications in Production-(Tathagata Das...
 
Hadoop spark performance comparison
Hadoop spark performance comparisonHadoop spark performance comparison
Hadoop spark performance comparison
 
Squash Those IoT Security Bugs with a Hardened System Profile
Squash Those IoT Security Bugs with a Hardened System ProfileSquash Those IoT Security Bugs with a Hardened System Profile
Squash Those IoT Security Bugs with a Hardened System Profile
 
Scaling ArangoDB on Mesosphere DCOS
Scaling ArangoDB on Mesosphere DCOSScaling ArangoDB on Mesosphere DCOS
Scaling ArangoDB on Mesosphere DCOS
 
Drupal and Varnish Reverse Proxy
Drupal and Varnish Reverse ProxyDrupal and Varnish Reverse Proxy
Drupal and Varnish Reverse Proxy
 
Smashing The Stack
Smashing The StackSmashing The Stack
Smashing The Stack
 
You're Off the Hook: Blinding Security Software
You're Off the Hook: Blinding Security SoftwareYou're Off the Hook: Blinding Security Software
You're Off the Hook: Blinding Security Software
 
Java 10, Java 11 and beyond
Java 10, Java 11 and beyondJava 10, Java 11 and beyond
Java 10, Java 11 and beyond
 
Ceph Day Beijing: Big Data Analytics on Ceph Object Store
Ceph Day Beijing: Big Data Analytics on Ceph Object Store Ceph Day Beijing: Big Data Analytics on Ceph Object Store
Ceph Day Beijing: Big Data Analytics on Ceph Object Store
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the way
 
Ceph Day Taipei - Ceph Tiering with High Performance Architecture
Ceph Day Taipei - Ceph Tiering with High Performance Architecture Ceph Day Taipei - Ceph Tiering with High Performance Architecture
Ceph Day Taipei - Ceph Tiering with High Performance Architecture
 

More from Miroslav Stampar

sqlmap - "One Tiny Step At a Time"
sqlmap - "One Tiny Step At a Time"sqlmap - "One Tiny Step At a Time"
sqlmap - "One Tiny Step At a Time"Miroslav Stampar
 
Why everybody should do CTF / Wargames?
Why everybody should do CTF / Wargames?Why everybody should do CTF / Wargames?
Why everybody should do CTF / Wargames?Miroslav Stampar
 
Improving Network Intrusion Detection with Traffic Denoise
Improving Network Intrusion Detection with Traffic DenoiseImproving Network Intrusion Detection with Traffic Denoise
Improving Network Intrusion Detection with Traffic DenoiseMiroslav Stampar
 
APT Attacks on Critical Infrastructure
APT Attacks on Critical InfrastructureAPT Attacks on Critical Infrastructure
APT Attacks on Critical InfrastructureMiroslav Stampar
 
WARNING: Do Not Feed the Bears
WARNING: Do Not Feed the BearsWARNING: Do Not Feed the Bears
WARNING: Do Not Feed the BearsMiroslav Stampar
 
Data Retrieval over DNS in SQL Injection Attacks
Data Retrieval over DNS in SQL Injection AttacksData Retrieval over DNS in SQL Injection Attacks
Data Retrieval over DNS in SQL Injection AttacksMiroslav Stampar
 

More from Miroslav Stampar (9)

sqlmap - "One Tiny Step At a Time"
sqlmap - "One Tiny Step At a Time"sqlmap - "One Tiny Step At a Time"
sqlmap - "One Tiny Step At a Time"
 
Blind WAF identification
Blind WAF identificationBlind WAF identification
Blind WAF identification
 
sqlmap internals
sqlmap internalssqlmap internals
sqlmap internals
 
Why everybody should do CTF / Wargames?
Why everybody should do CTF / Wargames?Why everybody should do CTF / Wargames?
Why everybody should do CTF / Wargames?
 
sqlmap internals
sqlmap internalssqlmap internals
sqlmap internals
 
Improving Network Intrusion Detection with Traffic Denoise
Improving Network Intrusion Detection with Traffic DenoiseImproving Network Intrusion Detection with Traffic Denoise
Improving Network Intrusion Detection with Traffic Denoise
 
APT Attacks on Critical Infrastructure
APT Attacks on Critical InfrastructureAPT Attacks on Critical Infrastructure
APT Attacks on Critical Infrastructure
 
WARNING: Do Not Feed the Bears
WARNING: Do Not Feed the BearsWARNING: Do Not Feed the Bears
WARNING: Do Not Feed the Bears
 
Data Retrieval over DNS in SQL Injection Attacks
Data Retrieval over DNS in SQL Injection AttacksData Retrieval over DNS in SQL Injection Attacks
Data Retrieval over DNS in SQL Injection Attacks
 

Recently uploaded

Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaRTTS
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...Product School
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Frank van Harmelen
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2DianaGray10
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)Ralf Eggert
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupCatarinaPereira64715
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoTAnalytics
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Thierry Lestable
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxAbida Shariff
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...Sri Ambati
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyJohn Staveley
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesBhaskar Mitra
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...Product School
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutesconfluent
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
 

Recently uploaded (20)

Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 

Riding the Overflow - Then and Now

  • 1. Riding the Overflow – Then and Now Miroslav Štampar (mstampar@zsis.hr)
  • 2. tl;dr FSec 2014, Varaždin (Croatia) September 17th, 2014 2
  • 3. Buffer overflow (a.k.a.) Buffer overrun An anomaly where a program, while writing data to the buffer, overruns its boundary, thus overwriting adjacent memory location(s) Commonly associated with programming languages C and C++ (no boundary checking) Stack-based (e.g. statically allocated built-in array at compile time) – overwriting stack elements Heap-based (e.g. dynamically allocated malloc() array at run time) – overwriting heap internal structures (e.g. linked list pointers) FSec 2014, Varaždin (Croatia) September 17th, 2014 3
  • 4. Stack-based overflow FSec 2014, Varaždin (Croatia) September 17th, 2014 4
  • 5. Heap-based overflow FSec 2014, Varaždin (Croatia) September 17th, 2014 5
  • 6. Vulnerable code (stack-based) FSec 2014, Varaždin (Croatia) September 17th, 2014 6
  • 7. Vulnerable code (heap-based) FSec 2014, Varaždin (Croatia) September 17th, 2014 7
  • 8. History  1961 - Burroughs 5000 (executable space protection)  1972 - Computer Security Technology Planning Study (buffer overflow as an idea)  1988 - Morris worm (earliest exploitation – gets() in fingerd)  1995 - Buffer overflow rediscovered (Bugtraq)  1996 - “Smashing the Stack for Fun and Profit” (Aleph One)  1997 - “Return-into-lib(c) exploits” (Solar Designer)  2000 - The Linux PaX project  2001 - Code Red (IIS 5.0); Heap spraying (MS01-033)  2003 - SQL Slammer (MsSQL 2000); Microsoft VS 2003 flag /GS  2004 - NX on Linux (kernel 2.6.8); DEP on Windows (XP SP2); Egg hunting (skape)  2005 - ASLR on Linux (kernel 2.6.12); GCC flag -fstack-protector  2007 - ASLR on Windows (Vista); ROP (Sebastian Krahmer) FSec 2014, Varaždin (Croatia) September 17th, 2014 8
  • 9. Stack canaries (a.k.a.) Stack cookies, Stack-Smashing Protector (SSP) Named for analogy to a canary in a coal mine Implemented by the compiler Placing a small (e.g. random) integer value to stack just before the return pointer In order to overwrite the return pointer (and thus take control of the process) the canary value would also be overwritten This value is checked to make sure it has not changed before a routine uses the return pointer from the stack FSec 2014, Varaždin (Croatia) September 17th, 2014 9
  • 10. ASCII armor Generally maps important library addresses (e.g. libc) to a memory range containing a NULL byte (e.g. 0x00****** - 0x0100******) Makes it hard to construct address or pass arguments by exploiting string functions (e.g. strcpy()) Not effective when NULL (i.e. 0x00) byte is not an issue (rarely) Easily bypassable by using PLT (Procedure Language Table) entries in case of position independent binary FSec 2014, Varaždin (Croatia) September 17th, 2014 10
  • 11. SEH Structured Exception Handler Implemented by the compiler Pointer to the exception handler is added to the stack in the form of the “Exception Registration Record” (SEH) and “Next Exception Registration Record” (nSEH) If the buffer is overflown and (junk) data is written to the SEH (located eight bytes after ESP), invalid handler is called due to the inherently raised exception (i.e. STATUS_ACCESS_VIOLATION), thus preventing successful execution of used payload FSec 2014, Varaždin (Croatia) September 17th, 2014 11
  • 12. SEH (chain) FSec 2014, Varaždin (Croatia) September 17th, 2014 12
  • 13. SEHOP Structured Exception Handler Overwrite Protection Blocks exploits that use (highly popular) SEH overwrite method Enabled by default on Windows Server 2008, disabled on Windows Vista SP1 and Windows 7 Symbolic exception registration record appended to the end of exception handler list Integrity of exception handler chain is broken if symbolic record can't be reached and/or if it's found to be invalid FSec 2014, Varaždin (Croatia) September 17th, 2014 13
  • 14. SafeSEH Safe Structured Exception Handling (a.k.a.) Software-enforced DEP All exception handlers' entry points collected to a designated read-only table collected at the compilation time Safe Exception Handler Table Attempt to execute any unregistered exception handler will result in the immediate program termination FSec 2014, Varaždin (Croatia) September 17th, 2014 14
  • 15. DEP/NX Data Execution Prevention/No eXecute (a.k.a.) Non-executable stack, Execute Disable, Exec Shield (Linux), W^X (FreeBSD) Set of hardware and software technologies that perform additional checks on memory Provides protection for all memory pages that are not specifically marked as executable Processor must support hardware-enforced mechanism (NX/EVP/XD) Executables and libraries have to be specifically linked (problems with older software) FSec 2014, Varaždin (Croatia) September 17th, 2014 15
  • 16. ASLR Address Space Layout Randomization Introduces the randomness into the address space of process Positions of key data areas are randomly scattered (i.e. dynamic/shared libraries, heap and stack) Its strength is based upon the low chance of an attacker guessing the locations of randomly placed areas Executables and dynamic/shared libraries have to be specifically linked (problems with older software) FSec 2014, Varaždin (Croatia) September 17th, 2014 16
  • 17. Safe functions Well-written functions that automatically perform buffer management (including boundary checking), reducing the occurrence and impact of buffer overflows Usually by introducing explicit parameter size FSec 2014, Varaždin (Croatia) September 17th, 2014 17
  • 18. NOP sled (a.k.a.) NOP slide, NOP ramp Oldest and most widely known method for stack buffer overflow exploitation Large sequence of NOP (no-operation) instructions meant to “slide” the CPU's execution flow Used when jump location has to be given (payload), while it's impossible to be exactly predicted Today widely used in high profile exploits utilizing “Heap spraying” method (e.g. browsers) FSec 2014, Varaždin (Croatia) September 17th, 2014 18
  • 19. NOP sled (visual) FSec 2014, Varaždin (Croatia) September 17th, 2014 19
  • 20. ret2libc (a.k.a.) ret2system, arc injection Overwriting the return address with location of a function that is already loaded in the binary or via shared library Required arguments are also provided through stack overwrite Shared library libc(.so) is always linked to executables on UNIX style systems and provides useful calls (e.g. system()) Dynamic library kernel32(.dll) is always loaded by executables on Win32 style systems and provides useful calls (e.g. WinExec()) FSec 2014, Varaždin (Croatia) September 17th, 2014 20
  • 21. ret2libc (visual) FSec 2014, Varaždin (Croatia) September 17th, 2014 21
  • 22. ret2reg Return-to-register (e.g. ESP, EAX, etc.) (a.k.a.) Trampolining Also, variants like ret2pop, ret2ret, etc. We overwrite the EIP with the address of an existing instruction that would jump to the location of a register Preferred choice is the register pointing to the location inside our buffer (usually ESP) Much more reliable method than NOP sled Without the need for extra room for NOP sled and without having to guess stack offset FSec 2014, Varaždin (Croatia) September 17th, 2014 22
  • 23. ret2reg (visual) FSec 2014, Varaždin (Croatia) September 17th, 2014 23
  • 24. Egg hunting Used in reduced buffer space situations Allows usage of a small payload (“egg hunter”) to find the actual (bigger) payload The final payload must be somewhere in memory (i.e. stack, heap or secondary buffer) prepended with the unique marking string (2x4 bytes) called “egg” (e.g. “w00tw00t”) Searching memory byte at a time Memory “peeking” with syscall mechanism(s) to bypass access violation issues Egg hunter types: SEH, IsBadReadPtr, NtDisplayString, NtAccessCheckAndAuditAlarm FSec 2014, Varaždin (Croatia) September 17th, 2014 24
  • 25. Egg hunter (NtDisplayString) loop_inc_page: or dx, 0x0fff // Add PAGE_SIZE-1 to edx loop_inc_one: inc edx // Increment our pointer by one loop_check: push edx // Save edx push 0x43 // Push NtDisplayString pop eax // Pop into eax int 0x2e // Perform the syscall cmp al, 0x05 // Did we get 0xc0000005 (ACCESS_VIOLATION) ? pop edx // Restore edx loop_check_8_valid: je loop_inc_page // Yes, invalid ptr, go to the next page is_egg: mov eax, 0x50905090 // Throw our egg in eax mov edi, edx // Set edi to the pointer we validated scasd // Compare the dword in edi to eax jnz loop_inc_one // No match? Increment the pointer by one scasd // Compare the dword in edi to eax again (which is now edx + 4) jnz loop_inc // No match? Increment the pointer by one matched: jmp edi // Found the egg. Jump 8 bytes past it into our code. FSec 2014, Varaždin (Croatia) September 17th, 2014 25
  • 26. Egg hunting (visual) FSec 2014, Varaždin (Croatia) September 17th, 2014 26
  • 27. SEH bypass SEH is highly flawed against buffer overflows Overwrite (last in chain) SEH with address of "POP; POP; RET" sequence of instructions and nSEH with explicit relative "JMP" to payload Deliberate exception has to be caused (inherently by sending malformed buffer) “POP; POP; RET” passes the execution flow to the nSEH's JMP, which afterwards jumps to the payload at the end of the buffer Effective as the stack canary bypass method (too) as exception is triggered (and handled) before the canary/cookie value is checked FSec 2014, Varaždin (Croatia) September 17th, 2014 27
  • 28. SEH bypass (visual) FSec 2014, Varaždin (Croatia) September 17th, 2014 28
  • 29. ROP Return-Oriented Programming Attacker executes carefully chosen machine instruction sequences called “gadgets” Each gadget ends with an instruction RET (e.g. “INC EAX; RET”) ROP “chain” consists of gadget memory locations (sequentially popped and executed) Provides a fully functional language that can be used to perform any operation desired (usually to disable DEP) Semi-automated process of making a wanted ROP “chain” (mona.py) FSec 2014, Varaždin (Croatia) September 17th, 2014 29
  • 30. ROP (disable DEP) Taken from: https://www.corelan.be FSec 2014, Varaždin (Croatia) September 17th, 2014 30
  • 31. ROP (visual) FSec 2014, Varaždin (Croatia) September 17th, 2014 31
  • 32. Heap spray Top payload delivery method used in browser exploits (and recent high profile attacks) Takes advantage of the fact that the heap management is deterministic Attacker needs to be able to deliver the payload in the right location in memory before triggering the bug that leads to EIP control A good heap spray (if done right) will end up allocating a chunk of memory at a predictable location, after a certain amount of allocations At the end (predictable) heap address needs to be put into EIP FSec 2014, Varaždin (Croatia) September 17th, 2014 32
  • 33. Heap spray (visual) FSec 2014, Varaždin (Croatia) September 17th, 2014 33
  • 34. Demo time FSec 2014, Varaždin (Croatia) September 17th, 2014 34
  • 35. Questions? FSec 2014, Varaždin (Croatia) September 17th, 2014 35