SlideShare a Scribd company logo
1 of 33
Buffer Overflow – Smashing The Stack
Tomer Zait - Application Security Engineer
root@kali:~# whoami
ironSourceTomer Zait
• Application Security Engineer at
• Practical Software Engineer (Ort Singalovsky)
• Offensive Security Certified Professional (OSCP)
• OpenSource Projects:
o PyMultitor
o HackMe Credit
o AutoBrowser
o SubDomain Analyzer
o Proxist
• 1st Place at The Israel Cyber Challenge, 2014
Today we will focus on:
• Past Events
• What Is Stack
• Assembly – Registers
• Stack Overflow
• Shell Code
• Exploit Development
Past Events
• Exploits a buffer overflow vulnerability in Microsoft DCOM RPC interface.
• Worm downloads a copy of mblast.exe to compromised host from infecting host via TFTP
and runs commands to execute it.
• mblast.exe attempts to carry out SYN flood attack on windowsupdate.com as well as
scanning/infecting other hosts.
BLASTER WORM
Hex dump of the Blaster worm
• DOS attack on windowsupdate.com failed - the regular domain name is
windowsupdate.microsoft.com.
• Windowsupdate.com was just a pointer to the windowsupdate.microsoft.com - so
Microsoft just decomissioned it.
BLASTER WORM - EFFECTS
• August 11, 2003: Original version of the worm appears on the internet.
• August 12, 2003: The number of infected systems is reported at 30,000.
• August 15, 2003:The number of infected systems is reported at 423,000.
• August 16, 2003: DDoS attack against windowsupdate.com starts.
(Largely unsuccessful because that url is merely a redirect to the real site,
windowsupdate.microsoft.com)
• January 28, 2005: The creator of the "B" variant of MSBlaster is sentenced to 18 months in
jail.
BLASTER WORM - TIMELINE
• Exploits a buffer overflow vulnerability in Microsoft NET BIOS interface (MS08-067).
• Dictionary attack on ADMIN$ shares.
• Creates DLL-based AutoRun trojan on attached removable drives.
• Downloads daily from any of 250 pseudorandom domains over 5 TLDs (Top-level domains).
• Updates self to Conficker B, C or D.
CONFICKER WORM
• Account lockout policies being reset automatically.
• Certain Microsoft Windows services such as Automatic Updates, Background Intelligent
Transfer Service (BITS), Windows Defender and Windows Error Reporting disabled.
• Domain controllers responding slowly to client requests.
• Congestion on local area networks (ARP flood as consequence of network scan).
• Web sites related to antivirus software or the Windows Update service becoming
inaccessible
CONFICKER WORM - EFFECTS
• Discovered in early November 2008.
• The French Navy computer network, was infected with Conficker on 15 January 2009.
• An infection of Manchester City Council's IT system caused an estimated £1.5m worth of
disruption in February 2009.
• The estimated number of infected computers ranged from almost 9 million to 15 million.
• Microsoft has reported the total number of infected computers detected by its
antimalware products has remained steady at around 1.7 million from mid-2010 to mid-
2011.
CONFICKER WORM - TIMELINE
What Is Stack
It's a special region of your computer's memory that stores temporary variables created by
each function (including the main() function),
The stack is a “LIFO” (last in , first out) data structure.
Principal operations:
• push adds an element to the collection.
• pop removes the last element that was added.
• Stack Real Life example is weapon's magazine
STACK - EXPLANATION
Assembly – Registers
On today’s average WinTel CPU you have 9 32bit registers (w/o flag registers).
Their names are:
EAX: Extended Accumulator Register
EBX: Extended Base Register
ECX: Extended Counter Register
EDX: Extended Data Register
ESI: Extended Source Index
EDI: Extended Destination Index
EBP: Extended Base Pointer
ESP: Extended Stack Pointer
EIP: Extended Instruction Pointer
CPU REGISTERS
The ESP register serves as an indirect memory operand pointing to the top of the stack at any
time.
WORD takes 2 bytes In memory.
• When a word value is pushed onto the stack, the assembler decreases the ESP (Stack
Pointer) register by 2.
• When a word value is popped off the stack, the assembler increases the ESP register by 2.
ESP REGISTER
The instruction pointer register points to the memory addresswhich the processor will next
attempt to execute.
it cannot be directly accessed in 16-bit or 32-bit mode,
but a sequence like the following can be written to put the address of next_line into eax:
call next_line
next_line:
pop eax
This sequence of instructions generates position-independent code because call takes an
instruction-pointer-relative immediate operand describing the offset in bytes of the target
instruction from the next instruction (in this case 0).
EIP REGISTER
Stack Overflow
A stack overflow is an undesirable condition in which a particular computer program tries to
use more memory space than the call stack has available.
In programming, the call stack is a buffer that stores requests that need to be handled.
The size of a call stack depends on various factors.
It is usually defined at the start of a program.
Its size can depend on the architecture of the computer on which the program runs,
the language in which the program is written,
and the total amount of available memory in the system.
When a stack overflow occurs as a result of a program's excessive demand for memory space,
that program (and sometimes the entire computer) may crash.
STACK OVERFLOW - EXPLANATION
Shell Code
# Metasploit generated – write.exe – x86 – Windows XP Pro SP2
shellcode="x68x97x4Cx80x7CxB8x4Dx11x86x7CxFFxD0”;
Let’s disassemble these bytes into instructions :
You don’t need to run this code to figure out what it will do.
SHELLCODE - WINDOWS XP PRO SP2 32BIT (1)
C:shellcode>"c:program filesnasmndisasm.exe" -b 32 c:tmpshellcode.bin
00000000 68974C807C push dword 0x7c804c97
00000005 B84D11867C mov eax,0x7c86114d
0000000A FFD0 call eax
If the exploit is indeed written for Windows XP Pro SP2 then this will happen:
at 0x7c804c97 on XP SP2, we find (windbg output) :
So push dword 0x7c804c97 will push “Write” onto the stack.
SHELLCODE - WINDOWS XP PRO SP2 32BIT (2)
0:001> d 0x7c804c97
7c804c97 57 72 69 74 65 00 42 61-73 65 43 68 65 63 6b 41 Write.BaseCheckA
7c804ca7 70 70 63 6f 6d 70 61 74-43 61 63 68 65 00 42 61 ppcompatCache.Ba
7c804cb7 73 65 43 6c 65 61 6e 75-70 41 70 70 63 6f 6d 70 seCleanupAppcomp
7c804cc7 61 74 43 61 63 68 65 00-42 61 73 65 43 6c 65 61 atCache.BaseClea
7c804cd7 6e 75 70 41 70 70 63 6f-6d 70 61 74 43 61 63 68 nupAppcompatCach
7c804ce7 65 53 75 70 70 6f 72 74-00 42 61 73 65 44 75 6d eSupport.BaseDum
7c804cf7 70 41 70 70 63 6f 6d 70-61 74 43 61 63 68 65 00 pAppcompatCache.
7c804d07 42 61 73 65 46 6c 75 73-68 41 70 70 63 6f 6d 70 BaseFlushAppcomp
Next, 0x7c86114d is moved into eax and a call eax is made.
At 0x7c86114d, we find :
Conclusion : this code will execute “write” (=wordpad).
SHELLCODE - WINDOWS XP PRO SP2 32BIT (3)
0:001> ln 0x7c86114d
(7c86114d) kernel32!WinExec | (7c86123c) kernel32!`string'
Exact matches:
kernel32!WinExec =
SHELLCODE TEST - WINDOWS XP PRO SP2 32BIT
char code[] = "x68x97x4Cx80x7CxB8x4Dx11x86x7CxFFxD0";
int main(int argc, char **argv) {
int (*func)();
func = (int (*)()) code;
(int)(*func)();
}
Exploit Development
VULNERABLE CODE - EXAMPLE
#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]);
}
VULNERABLE CODE - EXPLOTION
This code takes an argument from the command line and copies it to a local stack variable c.
This works fine for command line arguments smaller than 12 characters (as you can see in
figure B below).
Any arguments larger than 11 characters long will result in corruption of the stack.
(The maximum number of characters that is safe is one less than the size of the buffer here
because in the C programming language strings are terminated by a zero byte character.
A twelve-character input thus requires thirteen bytes to store, the input followed by the
sentinel zero byte. The zero byte then ends up overwriting a memory location that's one byte
beyond the end of the buffer.)
THE PROGRAM STACK IN foo() WITH VARIOUS INPUTS (1)
A. - Before data is copied.
THE PROGRAM STACK IN foo() WITH VARIOUS INPUTS (2)
B. - "hello" is the first
command line argument.
THE PROGRAM STACK IN foo() WITH VARIOUS INPUTS (3)
A. - Before data is copied.
VULNERABLE CODE - SUMMARY
Notice in figure C above, when an argument larger than 11 bytes is supplied on the command
line foo() overwrites local stack data, the saved frame pointer, and most importantly,
the return address. When foo() returns it pops the return address off the stack and jumps to
that address (i.e. starts executing instructions from that address).
Thus, the attacker has overwritten the return address with a pointer to the stack buffer char
c[12], which now contains attacker-supplied data.
In an actual stack buffer overflow exploit the string of "A"'s would instead be shellcode suitable
to the platform and desired function.
If this program had special privileges (e.g. the SUID bit set to run as the superuser),
then the attacker could use this vulnerability to gain superuser privileges on the affected
machine.
{ THANK YOU
1. Wikipedia - http://www.wikipedia.org/
2. Corelan Team- https://www.corelan.be/
3. Natashenka - http://natashenka.ca/
BIBLIOGRAPHY

More Related Content

What's hot

Dc 12 Chiueh
Dc 12 ChiuehDc 12 Chiueh
Dc 12 Chiueh
wollard
 
Track c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eveTrack c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eve
chiportal
 
LCU14 302- How to port OP-TEE to another platform
LCU14 302- How to port OP-TEE to another platformLCU14 302- How to port OP-TEE to another platform
LCU14 302- How to port OP-TEE to another platform
Linaro
 
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CanSecWest
 

What's hot (20)

Select and poll functions
Select and poll functionsSelect and poll functions
Select and poll functions
 
Davide Berardi - Linux hardening and security measures against Memory corruption
Davide Berardi - Linux hardening and security measures against Memory corruptionDavide Berardi - Linux hardening and security measures against Memory corruption
Davide Berardi - Linux hardening and security measures against Memory corruption
 
Windows persistence presentation
Windows persistence presentationWindows persistence presentation
Windows persistence presentation
 
Reverse engineering Swisscom's Centro Grande Modem
Reverse engineering Swisscom's Centro Grande ModemReverse engineering Swisscom's Centro Grande Modem
Reverse engineering Swisscom's Centro Grande Modem
 
ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!
 
Dc 12 Chiueh
Dc 12 ChiuehDc 12 Chiueh
Dc 12 Chiueh
 
Np unit iv i
Np unit iv iNp unit iv i
Np unit iv i
 
Penetration Testing and Intrusion Detection System
Penetration Testing and Intrusion Detection SystemPenetration Testing and Intrusion Detection System
Penetration Testing and Intrusion Detection System
 
Track c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eveTrack c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eve
 
Embedding Linux On The Encore Simputer
Embedding Linux On The Encore SimputerEmbedding Linux On The Encore Simputer
Embedding Linux On The Encore Simputer
 
TRENDnet IP Camera Multiple Vulnerabilities
TRENDnet IP Camera Multiple VulnerabilitiesTRENDnet IP Camera Multiple Vulnerabilities
TRENDnet IP Camera Multiple Vulnerabilities
 
Building
BuildingBuilding
Building
 
LCU14 302- How to port OP-TEE to another platform
LCU14 302- How to port OP-TEE to another platformLCU14 302- How to port OP-TEE to another platform
LCU14 302- How to port OP-TEE to another platform
 
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
 
Readme
ReadmeReadme
Readme
 
Dsd lab Practical File
Dsd lab Practical FileDsd lab Practical File
Dsd lab Practical File
 
Take a Jailbreak -Stunning Guards for iOS Jailbreak- by Kaoru Otsuka
Take a Jailbreak -Stunning Guards for iOS Jailbreak- by Kaoru OtsukaTake a Jailbreak -Stunning Guards for iOS Jailbreak- by Kaoru Otsuka
Take a Jailbreak -Stunning Guards for iOS Jailbreak- by Kaoru Otsuka
 
Buffer overflow attacks
Buffer overflow attacksBuffer overflow attacks
Buffer overflow attacks
 
Andrea Righi - Spying on the Linux kernel for fun and profit
Andrea Righi - Spying on the Linux kernel for fun and profitAndrea Righi - Spying on the Linux kernel for fun and profit
Andrea Righi - Spying on the Linux kernel for fun and profit
 
Anatomy of a Buffer Overflow Attack
Anatomy of a Buffer Overflow AttackAnatomy of a Buffer Overflow Attack
Anatomy of a Buffer Overflow Attack
 

Similar to Buffer overflow – Smashing The Stack

Shellcoding in linux
Shellcoding in linuxShellcoding in linux
Shellcoding in linux
Ajin Abraham
 
Chapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structuChapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structu
EstelaJeffery653
 
Low Level Exploits
Low Level ExploitsLow Level Exploits
Low Level Exploits
hughpearse
 
Finding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyFinding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated Disassembly
Priyanka Aash
 

Similar to Buffer overflow – Smashing The Stack (20)

Buffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the StackBuffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the Stack
 
Shellcoding in linux
Shellcoding in linuxShellcoding in linux
Shellcoding in linux
 
Dive into exploit development
Dive into exploit developmentDive into exploit development
Dive into exploit development
 
Writing Metasploit Plugins
Writing Metasploit PluginsWriting Metasploit Plugins
Writing Metasploit Plugins
 
Web (dis)assembly
Web (dis)assemblyWeb (dis)assembly
Web (dis)assembly
 
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
 
Chapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structuChapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structu
 
Stack-Based Buffer Overflows
Stack-Based Buffer OverflowsStack-Based Buffer Overflows
Stack-Based Buffer Overflows
 
PVS-Studio, a solution for resource intensive applications development
PVS-Studio, a solution for resource intensive applications developmentPVS-Studio, a solution for resource intensive applications development
PVS-Studio, a solution for resource intensive applications development
 
Low Level Exploits
Low Level ExploitsLow Level Exploits
Low Level Exploits
 
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
 
[2007 CodeEngn Conference 01] dual5651 - Windows 커널단의 후킹
[2007 CodeEngn Conference 01] dual5651 - Windows 커널단의 후킹[2007 CodeEngn Conference 01] dual5651 - Windows 커널단의 후킹
[2007 CodeEngn Conference 01] dual5651 - Windows 커널단의 후킹
 
Code Red Security
Code Red SecurityCode Red Security
Code Red Security
 
First Steps Developing Embedded Applications using Heterogeneous Multi-core P...
First Steps Developing Embedded Applications using Heterogeneous Multi-core P...First Steps Developing Embedded Applications using Heterogeneous Multi-core P...
First Steps Developing Embedded Applications using Heterogeneous Multi-core P...
 
Swug July 2010 - windows debugging by sainath
Swug July 2010 - windows debugging by sainathSwug July 2010 - windows debugging by sainath
Swug July 2010 - windows debugging by sainath
 
fg.workshop: Software vulnerability
fg.workshop: Software vulnerabilityfg.workshop: Software vulnerability
fg.workshop: Software vulnerability
 
Finding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyFinding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated Disassembly
 
AAME ARM Techcon2013 003v02 Software Development
AAME ARM Techcon2013 003v02  Software DevelopmentAAME ARM Techcon2013 003v02  Software Development
AAME ARM Techcon2013 003v02 Software Development
 
Shellcode Disassembling - Reverse Engineering
Shellcode Disassembling - Reverse EngineeringShellcode Disassembling - Reverse Engineering
Shellcode Disassembling - Reverse Engineering
 
Stuxnet dc9723
Stuxnet dc9723Stuxnet dc9723
Stuxnet dc9723
 

More from Tomer Zait

More from Tomer Zait (6)

Escaping the python sandbox
Escaping the python sandboxEscaping the python sandbox
Escaping the python sandbox
 
The evolution of credential hijacking
The evolution of credential hijackingThe evolution of credential hijacking
The evolution of credential hijacking
 
PyMultiTor
PyMultiTorPyMultiTor
PyMultiTor
 
PyMultitor
PyMultitorPyMultitor
PyMultitor
 
Hacking 101 for developers
Hacking 101 for developersHacking 101 for developers
Hacking 101 for developers
 
Java - abstract class methods
Java - abstract class methodsJava - abstract class methods
Java - abstract class methods
 

Recently uploaded

%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 

Recently uploaded (20)

Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 

Buffer overflow – Smashing The Stack

  • 1. Buffer Overflow – Smashing The Stack Tomer Zait - Application Security Engineer
  • 2. root@kali:~# whoami ironSourceTomer Zait • Application Security Engineer at • Practical Software Engineer (Ort Singalovsky) • Offensive Security Certified Professional (OSCP) • OpenSource Projects: o PyMultitor o HackMe Credit o AutoBrowser o SubDomain Analyzer o Proxist • 1st Place at The Israel Cyber Challenge, 2014
  • 3. Today we will focus on: • Past Events • What Is Stack • Assembly – Registers • Stack Overflow • Shell Code • Exploit Development
  • 5. • Exploits a buffer overflow vulnerability in Microsoft DCOM RPC interface. • Worm downloads a copy of mblast.exe to compromised host from infecting host via TFTP and runs commands to execute it. • mblast.exe attempts to carry out SYN flood attack on windowsupdate.com as well as scanning/infecting other hosts. BLASTER WORM Hex dump of the Blaster worm
  • 6. • DOS attack on windowsupdate.com failed - the regular domain name is windowsupdate.microsoft.com. • Windowsupdate.com was just a pointer to the windowsupdate.microsoft.com - so Microsoft just decomissioned it. BLASTER WORM - EFFECTS
  • 7. • August 11, 2003: Original version of the worm appears on the internet. • August 12, 2003: The number of infected systems is reported at 30,000. • August 15, 2003:The number of infected systems is reported at 423,000. • August 16, 2003: DDoS attack against windowsupdate.com starts. (Largely unsuccessful because that url is merely a redirect to the real site, windowsupdate.microsoft.com) • January 28, 2005: The creator of the "B" variant of MSBlaster is sentenced to 18 months in jail. BLASTER WORM - TIMELINE
  • 8. • Exploits a buffer overflow vulnerability in Microsoft NET BIOS interface (MS08-067). • Dictionary attack on ADMIN$ shares. • Creates DLL-based AutoRun trojan on attached removable drives. • Downloads daily from any of 250 pseudorandom domains over 5 TLDs (Top-level domains). • Updates self to Conficker B, C or D. CONFICKER WORM
  • 9. • Account lockout policies being reset automatically. • Certain Microsoft Windows services such as Automatic Updates, Background Intelligent Transfer Service (BITS), Windows Defender and Windows Error Reporting disabled. • Domain controllers responding slowly to client requests. • Congestion on local area networks (ARP flood as consequence of network scan). • Web sites related to antivirus software or the Windows Update service becoming inaccessible CONFICKER WORM - EFFECTS
  • 10. • Discovered in early November 2008. • The French Navy computer network, was infected with Conficker on 15 January 2009. • An infection of Manchester City Council's IT system caused an estimated £1.5m worth of disruption in February 2009. • The estimated number of infected computers ranged from almost 9 million to 15 million. • Microsoft has reported the total number of infected computers detected by its antimalware products has remained steady at around 1.7 million from mid-2010 to mid- 2011. CONFICKER WORM - TIMELINE
  • 12. It's a special region of your computer's memory that stores temporary variables created by each function (including the main() function), The stack is a “LIFO” (last in , first out) data structure. Principal operations: • push adds an element to the collection. • pop removes the last element that was added. • Stack Real Life example is weapon's magazine STACK - EXPLANATION
  • 14. On today’s average WinTel CPU you have 9 32bit registers (w/o flag registers). Their names are: EAX: Extended Accumulator Register EBX: Extended Base Register ECX: Extended Counter Register EDX: Extended Data Register ESI: Extended Source Index EDI: Extended Destination Index EBP: Extended Base Pointer ESP: Extended Stack Pointer EIP: Extended Instruction Pointer CPU REGISTERS
  • 15. The ESP register serves as an indirect memory operand pointing to the top of the stack at any time. WORD takes 2 bytes In memory. • When a word value is pushed onto the stack, the assembler decreases the ESP (Stack Pointer) register by 2. • When a word value is popped off the stack, the assembler increases the ESP register by 2. ESP REGISTER
  • 16. The instruction pointer register points to the memory addresswhich the processor will next attempt to execute. it cannot be directly accessed in 16-bit or 32-bit mode, but a sequence like the following can be written to put the address of next_line into eax: call next_line next_line: pop eax This sequence of instructions generates position-independent code because call takes an instruction-pointer-relative immediate operand describing the offset in bytes of the target instruction from the next instruction (in this case 0). EIP REGISTER
  • 18. A stack overflow is an undesirable condition in which a particular computer program tries to use more memory space than the call stack has available. In programming, the call stack is a buffer that stores requests that need to be handled. The size of a call stack depends on various factors. It is usually defined at the start of a program. Its size can depend on the architecture of the computer on which the program runs, the language in which the program is written, and the total amount of available memory in the system. When a stack overflow occurs as a result of a program's excessive demand for memory space, that program (and sometimes the entire computer) may crash. STACK OVERFLOW - EXPLANATION
  • 20. # Metasploit generated – write.exe – x86 – Windows XP Pro SP2 shellcode="x68x97x4Cx80x7CxB8x4Dx11x86x7CxFFxD0”; Let’s disassemble these bytes into instructions : You don’t need to run this code to figure out what it will do. SHELLCODE - WINDOWS XP PRO SP2 32BIT (1) C:shellcode>"c:program filesnasmndisasm.exe" -b 32 c:tmpshellcode.bin 00000000 68974C807C push dword 0x7c804c97 00000005 B84D11867C mov eax,0x7c86114d 0000000A FFD0 call eax
  • 21. If the exploit is indeed written for Windows XP Pro SP2 then this will happen: at 0x7c804c97 on XP SP2, we find (windbg output) : So push dword 0x7c804c97 will push “Write” onto the stack. SHELLCODE - WINDOWS XP PRO SP2 32BIT (2) 0:001> d 0x7c804c97 7c804c97 57 72 69 74 65 00 42 61-73 65 43 68 65 63 6b 41 Write.BaseCheckA 7c804ca7 70 70 63 6f 6d 70 61 74-43 61 63 68 65 00 42 61 ppcompatCache.Ba 7c804cb7 73 65 43 6c 65 61 6e 75-70 41 70 70 63 6f 6d 70 seCleanupAppcomp 7c804cc7 61 74 43 61 63 68 65 00-42 61 73 65 43 6c 65 61 atCache.BaseClea 7c804cd7 6e 75 70 41 70 70 63 6f-6d 70 61 74 43 61 63 68 nupAppcompatCach 7c804ce7 65 53 75 70 70 6f 72 74-00 42 61 73 65 44 75 6d eSupport.BaseDum 7c804cf7 70 41 70 70 63 6f 6d 70-61 74 43 61 63 68 65 00 pAppcompatCache. 7c804d07 42 61 73 65 46 6c 75 73-68 41 70 70 63 6f 6d 70 BaseFlushAppcomp
  • 22. Next, 0x7c86114d is moved into eax and a call eax is made. At 0x7c86114d, we find : Conclusion : this code will execute “write” (=wordpad). SHELLCODE - WINDOWS XP PRO SP2 32BIT (3) 0:001> ln 0x7c86114d (7c86114d) kernel32!WinExec | (7c86123c) kernel32!`string' Exact matches: kernel32!WinExec =
  • 23. SHELLCODE TEST - WINDOWS XP PRO SP2 32BIT char code[] = "x68x97x4Cx80x7CxB8x4Dx11x86x7CxFFxD0"; int main(int argc, char **argv) { int (*func)(); func = (int (*)()) code; (int)(*func)(); }
  • 25. VULNERABLE CODE - EXAMPLE #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]); }
  • 26.
  • 27. VULNERABLE CODE - EXPLOTION This code takes an argument from the command line and copies it to a local stack variable c. This works fine for command line arguments smaller than 12 characters (as you can see in figure B below). Any arguments larger than 11 characters long will result in corruption of the stack. (The maximum number of characters that is safe is one less than the size of the buffer here because in the C programming language strings are terminated by a zero byte character. A twelve-character input thus requires thirteen bytes to store, the input followed by the sentinel zero byte. The zero byte then ends up overwriting a memory location that's one byte beyond the end of the buffer.)
  • 28. THE PROGRAM STACK IN foo() WITH VARIOUS INPUTS (1) A. - Before data is copied.
  • 29. THE PROGRAM STACK IN foo() WITH VARIOUS INPUTS (2) B. - "hello" is the first command line argument.
  • 30. THE PROGRAM STACK IN foo() WITH VARIOUS INPUTS (3) A. - Before data is copied.
  • 31. VULNERABLE CODE - SUMMARY Notice in figure C above, when an argument larger than 11 bytes is supplied on the command line foo() overwrites local stack data, the saved frame pointer, and most importantly, the return address. When foo() returns it pops the return address off the stack and jumps to that address (i.e. starts executing instructions from that address). Thus, the attacker has overwritten the return address with a pointer to the stack buffer char c[12], which now contains attacker-supplied data. In an actual stack buffer overflow exploit the string of "A"'s would instead be shellcode suitable to the platform and desired function. If this program had special privileges (e.g. the SUID bit set to run as the superuser), then the attacker could use this vulnerability to gain superuser privileges on the affected machine.
  • 33. 1. Wikipedia - http://www.wikipedia.org/ 2. Corelan Team- https://www.corelan.be/ 3. Natashenka - http://natashenka.ca/ BIBLIOGRAPHY

Editor's Notes

  1. להסביר לאנשים לא להדליף את ההרצאה הפנימית. היא סודית.