SlideShare a Scribd company logo
Introduction to Software
Exploitation
Faheem & Ali
Ebryx (pvt) Ltd
Reference:
http://opensecuritytraining.info/Expl
oits1.html
Purpose of the course
•Give you a deep understanding of the
mechanics of software exploitation
•Demonstration of buffer overflow attack
•Custom Shell-code writing and executing
•Exploit finding techniques
http://opensecuritytraining.info/Exploits1.html
Lets get down to business
http://opensecuritytraining.info/Exploits1.html
What are we trying to achieve?
•Arbitrary code execution
•Examples
–Forcing ssh to give you root access to the power
grid (like Trinity in the previous slide!)
–Bypassing authentication checks.
–Forcing a privileged administrator process to
execute code your normally wouldn’t be able to.
–Etc….
http://opensecuritytraining.info/Exploits1.html
You are presented with the following program….
This worked in the movies…
What arbitrary code execution do we want? Go_shell() would be nice!http://opensecuritytraining.info/Exploits1.html
Real life
Sayyyyy what?
http://opensecuritytraining.info/Exploits1.html
x86 Review Lab
•The EBP register points to the base of the stack
frame. Local variables, which are stored on the
stack, are referenced via this base pointer.
•Every time a function is called, a new stack
frame is setup so that the function has its own
fresh context (its own clean set of local
variables).
•The call instruction also puts a return address
on the stack so that the function knows where
to return execution to.http://opensecuritytraining.info/Exploits1.html
Boring…. Let’s investigate
Stack (grows downwards)
Junk
Junk
Junk
Junk
Junk
Junk
Junk
Main() just called
http://opensecuritytraining.info/Exploits1.html
Stack (grows downwards)
Return address into main
Main’s saved frame pointer
(ebp)
Char password[64];
Junk
Junk
Junk
Junk
Authorize() just called
The top of authorize()’s stack frame
stores main()’s saved frame pointer
(0xbffff5f8) as well as the return address
to return execution too once authorize()
is finished (0x080483b)http://opensecuritytraining.info/Exploits1.html
Stack (grows downwards)
Return address into main
Main’s saved frame pointer
(ebp)
“password”
Junk
Junk
Junk
Junk
Authorize() just called
Notice the 64 byte difference between
the top of the stack (esp) and the base
of the frame (ebp). These are the 64
bytes we created to store password.
Also worth noting is that where
password is stored on the stack is 68
bytes away from the saved return
address into main…
http://opensecuritytraining.info/Exploits1.html
f password is more than the 64 bytes than we allocated for it on the stack?
The instruction pointer ends up pointing to 0x41414141, which is “AAAA.” This means
we can cause arbitrary code execution since we can set the instruction pointer.http://opensecuritytraining.info/Exploits1.html
Since 0x41414141 is arbitrary, we have achieved our goal of “Arbitrary code execution.”
However, 0x41414141 isn’t very useful since it just crashes the program
(because 0x41414141 points to nowhere). Remember what we want to achieve is
execution of go_shell() since that does something useful (gives us administrator access).
To achieve this, we first fill up the password[64] buffer with 64 bytes of junk, then 4 extra
bytes of junk to overwrite the saved frame pointer, and then also write 4 bytes
representing the address of go_shell().
http://opensecuritytraining.info/Exploits1.html
Oh, Yeahh we corrupted that stack! We are now executing go_shell()’s code!
http://opensecuritytraining.info/Exploits1.html
It’s more useful for us to put this all together outside of a debugger.
he unix pipe “|” is to redirect output of our command (cat payload;cat) and use it as
he input for simple_login. We have to put the extra “cat” in the command to echo
ommands to the shell we will spawn, otherwise an EOF is sent and the shell closes
mmediately before we can actually execute any programs.
http://opensecuritytraining.info/Exploits1.html
Shellcode
•So that’s nice, but it isn’t quite “Arbitrary code
execution” since we are relying on simple_login
to contain this root shell spawning code
prepackaged (not realistic).
•How do we insert our own arbitrary code into
the program to execute?
http://opensecuritytraining.info/Exploits1.html
Shellcode 2
•Among other places, we can actually just insert
this code into the program through a typical
input medium. In other words, when
simple_login attempts to read in our password
guess, we can feed it in an executable program.
•Thus the password[64] buffer will end up
containing a small standalone program that we
will later execute by redirecting the overwritten
stored return address to the address of buffer!
http://opensecuritytraining.info/Exploits1.html
Properties of shellcode
•Aims to be small since it often has to fit in small
input buffers.
•Position independent (can’t make any
assumptions about program state when it
begins executing)
•Should contain no null characters (many
standard string copying library calls terminate
upon seeing a null character)
•Must be self contained in an executable section
(shouldn’t reference data in data sections, etc).
http://opensecuritytraining.info/Exploits1.html
Example shellcode payloads
1)Execute a shell
2)Add an Administrator user
3)Download and install a rootkit
4)Connect back to attacker controlled server and
wait for commands
5)Etc…
http://opensecuritytraining.info/Exploits1.html
Hello, World! - Linux
http://opensecuritytraining.info/Exploits1.html
Can we use it as shellcode?
What are the problems here?
http://opensecuritytraining.info/Exploits1.html
Can we use it as shellcode?
1)Null bytes are bad. Basically every standard library function is going
to treat those null characters as terminators and end up truncating
our program.
2)Not position independent. That 0x80490a4 address referenced is
going to be meaningless when we inject this into another program.
http://opensecuritytraining.info/Exploits1.html
he extended (eax, ebx, ecx…) x86 registers are 32 bit. So when we attempt to
Move a less than 32 bit value to one of them (mov eax, 0x4), the compiler pads the
alue with 0. If we instead move the immediate value to the appropriately sized
ersion of the registers, the null padding will not be added.
ecall:
ax = 32 bits, ax = 16 bits, al = 8 bits
We still have 1 null byte left. What if we actually need to use a null byte in our code
Somewhere like when we are trying to exit with a status code of 0? What about
that pesky string address we are still referencing? Suggestions?
http://opensecuritytraining.info/Exploits1.html
pting to achieve position independence and our reliance on that fixed string address.
-We can create a null byte to use by performing xor ebx, ebx
- Store the string we want to print/reference on the stack, and then just pass
esp
to the system call!
But wait, the code still won’t work as shellcode.
Challenge: What did Corey do wrong??
http://opensecuritytraining.info/Exploits1.html
Corey burned a good hour trying to figure this mystery out…
Standard library functions also truncate on the new line byte (0x0a)! Hence 0x0a
Is bad like null bytes!
http://opensecuritytraining.info/Exploits1.html
The easy way out….
cally I just changed the newline character to another exclamation point to get rid of
ibc copy problem, and to put emphasis on how hard we are owning these programs.
u are jaded you might just think I’m cheating here…http://opensecuritytraining.info/Exploits1.html
New goal!
•Previously we forced the simple login program
to execute go_shell(). By overwriting the saved
return address and thereby setting the eip to
go_shell()’s start.
•But we want to use our new toy, our snazzy
shellcode.
•How do we get our shellcode into the program
so we can overflow the return address again and
set eip to execute our shellcode?
http://opensecuritytraining.info/Exploits1.html
Game Plan
•Instead of spraying a bunch of junk into the
password buffer to get to the saved return
address, we will first input our shellcode’s
opcodes. (This is perfectly acceptable program
input).
•Then, we will change the eip of the program to
point to the password buffer, where are
shellcode’s opcode is stored!
http://opensecuritytraining.info/Exploits1.html
For ease I created a hello_shell.pl script which just prints out our shellcode’s
opcodes, making it easier to inject into the password[64] buffer in the simple
login program.
http://opensecuritytraining.info/Exploits1.html
member, when overflowing the password[64] buffer of the simple_login program
overwrite the eip, we first filled password with 64 bytes of junk (0x41), 4 additional
tes of junk to overwrite the saved frame pointer, and then 4 bytes representing the
dress with which we were going to overwrite the saved return address with.
AAAAAA…. 64 times><AAAA><0x080482aa>
Old payload…
http://opensecuritytraining.info/Exploits1.html
New Payload
Heres what we are going for…
<NOP.NOP.NOP><SHELLCODE OPS><AAAA><Address of password buffer>
• <NOP.NOP.NOP><SHELLCODE OPS> still needs to be
a total of 64 bytes combined.
• Recall, NOPS are just do nothing instructions, so
when eip points to the password buffer, it will just
‘do nothing’ until it starts hitting the shellcode op
codes.
•sizeof<NOPS> = 64 – sizeof<SHELLCODE OPS>
http://opensecuritytraining.info/Exploits1.html
•First we build the <NOPS><SHELLCODE>
portion of the shellcode
•Still need the <AAAA><Address of Password
Buffer> part of the payload
•We need to determine the address of the
password bufferhttp://opensecuritytraining.info/Exploits1.html
•We set a break point after the gets() call that
reads in the buffer so we can try to find out
shellcode on the stack
•Looks like 0xbffff594 lies in the middle of our
NOPS, so the password buffer must be there.
We will make this our target eip.http://opensecuritytraining.info/Exploits1.html
Final Payload Construction
•We now have the
<NOPS><Shellcode><AAAA><address of
password buffer> payload complete
•Let’s use it!
http://opensecuritytraining.info/Exploits1.html
•We just forced simple_login to execute
arbitrary code that we injected into it!!!
•In reality, an attacker would want to do
something more useful than just print a
message.
•What would you do if you wanted to execute
arbitrary code but the architecture forbid you
from executing the password buffer as if it were
code?
http://opensecuritytraining.info/Exploits1.html
Something more useful!
http://opensecuritytraining.info/Exploits1.html

More Related Content

PDF
Basic buffer overflow part1
PDF
Introduction to ida python
PPT
Php manish
PPTX
Introduction to Python for Security Professionals
PDF
Static Analysis of PHP Code – IPC Berlin 2016
PDF
What is the Joomla Framework and why do we need it?
PDF
The why and how of moving to php 8
Basic buffer overflow part1
Introduction to ida python
Php manish
Introduction to Python for Security Professionals
Static Analysis of PHP Code – IPC Berlin 2016
What is the Joomla Framework and why do we need it?
The why and how of moving to php 8

What's hot (20)

PPT
Python - Introduction
PDF
CNIT 126 13: Data Encoding
PDF
Python build your security tools.pdf
PDF
Low Level Exploits
PDF
PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...
PDF
fg.workshop: Software vulnerability
PDF
Dynamic Binary Instrumentation
PPTX
Reversing malware analysis training part4 assembly programming basics
PDF
Python for Penetration testers
PDF
Basic Concepts in Python
PPT
Hacking with hhvm
PPTX
Java Bytecode Fundamentals - JUG.lv
PPTX
Python programming introduction
PPTX
Python basics
PDF
Course lecture - An introduction to the Return Oriented Programming
PDF
Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...
PPTX
Monitoring distributed (micro-)services
PPTX
Full Python in 20 slides
PPTX
Operating Systems - A Primer
PDF
How to really obfuscate your pdf malware
Python - Introduction
CNIT 126 13: Data Encoding
Python build your security tools.pdf
Low Level Exploits
PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...
fg.workshop: Software vulnerability
Dynamic Binary Instrumentation
Reversing malware analysis training part4 assembly programming basics
Python for Penetration testers
Basic Concepts in Python
Hacking with hhvm
Java Bytecode Fundamentals - JUG.lv
Python programming introduction
Python basics
Course lecture - An introduction to the Return Oriented Programming
Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...
Monitoring distributed (micro-)services
Full Python in 20 slides
Operating Systems - A Primer
How to really obfuscate your pdf malware
Ad

Viewers also liked (20)

PPTX
BSides Algiers - Metasploit framework - Oussama Elhamer
PPTX
Metasploit for information gathering
PDF
Metasploit Humla for Beginner
PPTX
Metasploit
PPT
Metasploit-TOI-Ebryx-PVT-Ltd
PDF
Informationssicherheit im Übersetzungsprozess
PDF
Penetration test
PPTX
Static PIE, How and Why - Metasploit's new POSIX payload: Mettle
PDF
Webinar Metasploit Framework - Academia Clavis
PPTX
Slide Palestra "Metasploit Framework"
PDF
Scrum Überblick Teil 1
PDF
Oscp preparation
PDF
Network Packet Analysis
PPT
Writing Metasploit Plugins
PDF
Metasploit Basics
PDF
Packet analysis (Basic)
PDF
Wi-Fi Hotspot Attacks
PPTX
Finalppt metasploit
PDF
Prepare Yourself to Become Infosec Professional
PPTX
DC612 Day - Hands on Penetration Testing 101
BSides Algiers - Metasploit framework - Oussama Elhamer
Metasploit for information gathering
Metasploit Humla for Beginner
Metasploit
Metasploit-TOI-Ebryx-PVT-Ltd
Informationssicherheit im Übersetzungsprozess
Penetration test
Static PIE, How and Why - Metasploit's new POSIX payload: Mettle
Webinar Metasploit Framework - Academia Clavis
Slide Palestra "Metasploit Framework"
Scrum Überblick Teil 1
Oscp preparation
Network Packet Analysis
Writing Metasploit Plugins
Metasploit Basics
Packet analysis (Basic)
Wi-Fi Hotspot Attacks
Finalppt metasploit
Prepare Yourself to Become Infosec Professional
DC612 Day - Hands on Penetration Testing 101
Ad

Similar to Tranning-2 (20)

PPTX
Anatomy of a Buffer Overflow Attack
PDF
Linux Shellcode disassembling
PPTX
Steelcon 2014 - Process Injection with Python
PDF
Shellcode Disassembling - Reverse Engineering
PDF
Eusecwest
PDF
Dive into exploit development
ODP
How secure is your code?
PDF
Structured Exception Handler Exploitation
PDF
writing self-modifying code and utilizing advanced assembly techniques
PDF
64-bit Loki
PPTX
Advanced malwareanalysis training session2 botnet analysis part1
PDF
DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...
PDF
Shellcoding in linux
PPTX
Post exploitation techniques on OSX and Iphone, EuSecWest 2009
PPT
Packer Genetics: The selfish code
PPTX
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
PPTX
Vulnerability, exploit to metasploit
PDF
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
PPTX
Stack-Based Buffer Overflows
PDF
Common technique in Bypassing Stuff in Python.
Anatomy of a Buffer Overflow Attack
Linux Shellcode disassembling
Steelcon 2014 - Process Injection with Python
Shellcode Disassembling - Reverse Engineering
Eusecwest
Dive into exploit development
How secure is your code?
Structured Exception Handler Exploitation
writing self-modifying code and utilizing advanced assembly techniques
64-bit Loki
Advanced malwareanalysis training session2 botnet analysis part1
DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...
Shellcoding in linux
Post exploitation techniques on OSX and Iphone, EuSecWest 2009
Packer Genetics: The selfish code
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
Vulnerability, exploit to metasploit
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Stack-Based Buffer Overflows
Common technique in Bypassing Stuff in Python.

Tranning-2

  • 1. Introduction to Software Exploitation Faheem & Ali Ebryx (pvt) Ltd Reference: http://opensecuritytraining.info/Expl oits1.html
  • 2. Purpose of the course •Give you a deep understanding of the mechanics of software exploitation •Demonstration of buffer overflow attack •Custom Shell-code writing and executing •Exploit finding techniques http://opensecuritytraining.info/Exploits1.html
  • 3. Lets get down to business http://opensecuritytraining.info/Exploits1.html
  • 4. What are we trying to achieve? •Arbitrary code execution •Examples –Forcing ssh to give you root access to the power grid (like Trinity in the previous slide!) –Bypassing authentication checks. –Forcing a privileged administrator process to execute code your normally wouldn’t be able to. –Etc…. http://opensecuritytraining.info/Exploits1.html
  • 5. You are presented with the following program…. This worked in the movies… What arbitrary code execution do we want? Go_shell() would be nice!http://opensecuritytraining.info/Exploits1.html
  • 7. x86 Review Lab •The EBP register points to the base of the stack frame. Local variables, which are stored on the stack, are referenced via this base pointer. •Every time a function is called, a new stack frame is setup so that the function has its own fresh context (its own clean set of local variables). •The call instruction also puts a return address on the stack so that the function knows where to return execution to.http://opensecuritytraining.info/Exploits1.html
  • 8. Boring…. Let’s investigate Stack (grows downwards) Junk Junk Junk Junk Junk Junk Junk Main() just called http://opensecuritytraining.info/Exploits1.html
  • 9. Stack (grows downwards) Return address into main Main’s saved frame pointer (ebp) Char password[64]; Junk Junk Junk Junk Authorize() just called The top of authorize()’s stack frame stores main()’s saved frame pointer (0xbffff5f8) as well as the return address to return execution too once authorize() is finished (0x080483b)http://opensecuritytraining.info/Exploits1.html
  • 10. Stack (grows downwards) Return address into main Main’s saved frame pointer (ebp) “password” Junk Junk Junk Junk Authorize() just called Notice the 64 byte difference between the top of the stack (esp) and the base of the frame (ebp). These are the 64 bytes we created to store password. Also worth noting is that where password is stored on the stack is 68 bytes away from the saved return address into main… http://opensecuritytraining.info/Exploits1.html
  • 11. f password is more than the 64 bytes than we allocated for it on the stack? The instruction pointer ends up pointing to 0x41414141, which is “AAAA.” This means we can cause arbitrary code execution since we can set the instruction pointer.http://opensecuritytraining.info/Exploits1.html
  • 12. Since 0x41414141 is arbitrary, we have achieved our goal of “Arbitrary code execution.” However, 0x41414141 isn’t very useful since it just crashes the program (because 0x41414141 points to nowhere). Remember what we want to achieve is execution of go_shell() since that does something useful (gives us administrator access). To achieve this, we first fill up the password[64] buffer with 64 bytes of junk, then 4 extra bytes of junk to overwrite the saved frame pointer, and then also write 4 bytes representing the address of go_shell(). http://opensecuritytraining.info/Exploits1.html
  • 13. Oh, Yeahh we corrupted that stack! We are now executing go_shell()’s code! http://opensecuritytraining.info/Exploits1.html
  • 14. It’s more useful for us to put this all together outside of a debugger. he unix pipe “|” is to redirect output of our command (cat payload;cat) and use it as he input for simple_login. We have to put the extra “cat” in the command to echo ommands to the shell we will spawn, otherwise an EOF is sent and the shell closes mmediately before we can actually execute any programs. http://opensecuritytraining.info/Exploits1.html
  • 15. Shellcode •So that’s nice, but it isn’t quite “Arbitrary code execution” since we are relying on simple_login to contain this root shell spawning code prepackaged (not realistic). •How do we insert our own arbitrary code into the program to execute? http://opensecuritytraining.info/Exploits1.html
  • 16. Shellcode 2 •Among other places, we can actually just insert this code into the program through a typical input medium. In other words, when simple_login attempts to read in our password guess, we can feed it in an executable program. •Thus the password[64] buffer will end up containing a small standalone program that we will later execute by redirecting the overwritten stored return address to the address of buffer! http://opensecuritytraining.info/Exploits1.html
  • 17. Properties of shellcode •Aims to be small since it often has to fit in small input buffers. •Position independent (can’t make any assumptions about program state when it begins executing) •Should contain no null characters (many standard string copying library calls terminate upon seeing a null character) •Must be self contained in an executable section (shouldn’t reference data in data sections, etc). http://opensecuritytraining.info/Exploits1.html
  • 18. Example shellcode payloads 1)Execute a shell 2)Add an Administrator user 3)Download and install a rootkit 4)Connect back to attacker controlled server and wait for commands 5)Etc… http://opensecuritytraining.info/Exploits1.html
  • 19. Hello, World! - Linux http://opensecuritytraining.info/Exploits1.html
  • 20. Can we use it as shellcode? What are the problems here? http://opensecuritytraining.info/Exploits1.html
  • 21. Can we use it as shellcode? 1)Null bytes are bad. Basically every standard library function is going to treat those null characters as terminators and end up truncating our program. 2)Not position independent. That 0x80490a4 address referenced is going to be meaningless when we inject this into another program. http://opensecuritytraining.info/Exploits1.html
  • 22. he extended (eax, ebx, ecx…) x86 registers are 32 bit. So when we attempt to Move a less than 32 bit value to one of them (mov eax, 0x4), the compiler pads the alue with 0. If we instead move the immediate value to the appropriately sized ersion of the registers, the null padding will not be added. ecall: ax = 32 bits, ax = 16 bits, al = 8 bits We still have 1 null byte left. What if we actually need to use a null byte in our code Somewhere like when we are trying to exit with a status code of 0? What about that pesky string address we are still referencing? Suggestions? http://opensecuritytraining.info/Exploits1.html
  • 23. pting to achieve position independence and our reliance on that fixed string address. -We can create a null byte to use by performing xor ebx, ebx - Store the string we want to print/reference on the stack, and then just pass esp to the system call! But wait, the code still won’t work as shellcode. Challenge: What did Corey do wrong?? http://opensecuritytraining.info/Exploits1.html
  • 24. Corey burned a good hour trying to figure this mystery out… Standard library functions also truncate on the new line byte (0x0a)! Hence 0x0a Is bad like null bytes! http://opensecuritytraining.info/Exploits1.html
  • 25. The easy way out…. cally I just changed the newline character to another exclamation point to get rid of ibc copy problem, and to put emphasis on how hard we are owning these programs. u are jaded you might just think I’m cheating here…http://opensecuritytraining.info/Exploits1.html
  • 26. New goal! •Previously we forced the simple login program to execute go_shell(). By overwriting the saved return address and thereby setting the eip to go_shell()’s start. •But we want to use our new toy, our snazzy shellcode. •How do we get our shellcode into the program so we can overflow the return address again and set eip to execute our shellcode? http://opensecuritytraining.info/Exploits1.html
  • 27. Game Plan •Instead of spraying a bunch of junk into the password buffer to get to the saved return address, we will first input our shellcode’s opcodes. (This is perfectly acceptable program input). •Then, we will change the eip of the program to point to the password buffer, where are shellcode’s opcode is stored! http://opensecuritytraining.info/Exploits1.html
  • 28. For ease I created a hello_shell.pl script which just prints out our shellcode’s opcodes, making it easier to inject into the password[64] buffer in the simple login program. http://opensecuritytraining.info/Exploits1.html
  • 29. member, when overflowing the password[64] buffer of the simple_login program overwrite the eip, we first filled password with 64 bytes of junk (0x41), 4 additional tes of junk to overwrite the saved frame pointer, and then 4 bytes representing the dress with which we were going to overwrite the saved return address with. AAAAAA…. 64 times><AAAA><0x080482aa> Old payload… http://opensecuritytraining.info/Exploits1.html
  • 30. New Payload Heres what we are going for… <NOP.NOP.NOP><SHELLCODE OPS><AAAA><Address of password buffer> • <NOP.NOP.NOP><SHELLCODE OPS> still needs to be a total of 64 bytes combined. • Recall, NOPS are just do nothing instructions, so when eip points to the password buffer, it will just ‘do nothing’ until it starts hitting the shellcode op codes. •sizeof<NOPS> = 64 – sizeof<SHELLCODE OPS> http://opensecuritytraining.info/Exploits1.html
  • 31. •First we build the <NOPS><SHELLCODE> portion of the shellcode •Still need the <AAAA><Address of Password Buffer> part of the payload •We need to determine the address of the password bufferhttp://opensecuritytraining.info/Exploits1.html
  • 32. •We set a break point after the gets() call that reads in the buffer so we can try to find out shellcode on the stack •Looks like 0xbffff594 lies in the middle of our NOPS, so the password buffer must be there. We will make this our target eip.http://opensecuritytraining.info/Exploits1.html
  • 33. Final Payload Construction •We now have the <NOPS><Shellcode><AAAA><address of password buffer> payload complete •Let’s use it! http://opensecuritytraining.info/Exploits1.html
  • 34. •We just forced simple_login to execute arbitrary code that we injected into it!!! •In reality, an attacker would want to do something more useful than just print a message. •What would you do if you wanted to execute arbitrary code but the architecture forbid you from executing the password buffer as if it were code? http://opensecuritytraining.info/Exploits1.html

Editor's Notes