SlideShare a Scribd company logo
Buffer Overflow Explained
What is buffer overflow?
How a buffer overflow happens
How to avoid overrun?
What is buffer overflow?
• Buffer overflow are responsible for many
vulnerabilities in operating system as well as
application programs.
• It’s a quiet technical freaky , it includes
program source code , assembler listing , and
debugging usage , which almost scares away
lot of people without solid programming
knowledge.
Cause :
Buffer overflow attack have been there for a long
time. It still exists partly because of the
carelessness of the developer in the code.
Prevention :
Avoid writing bad codes
How a buffer overflow happens ?
• The ultimate purpose of any program that runs on a
computer is to process data of some kind.
• Most don’t operate on fixed data, but on data that is
ultimately provided by user, possibly pre-processed in
some fashion.
• The program needs to store data some where in
computer’s memory, and this is point where problem starts
• Buffer overflows are a common vulnerability on all
platforms, but are by far the most commonly exploited bug
on the linux/unix Operating systems.
• Commonly buffer overflows are exploited to change the
flow in a programs execution, so that it points to a different
memory address or overwrites crucial memory segments.
EX :
#include
#include int main(int argc, char **argv)
{
char buff[512];
if(argc < 2)
{
printf('Usage: %s n', argv[0]);
exit(0);
}
strcpy(buff, argv[1]);
printf('Your name: %sn', buff);
return 0;
}
lets try by giving this program a test:
Normal Execution :
Demo@root:~/tut > gcc vuln1.c -o vuln1
Demo@root:~/tut > ./vuln1
Usage: ./vuln1
Demo@root:~/tut > ./vuln1 mercy
Your name: Fr3@k
Demo@root:~/tut >
Demo@root:~/tut > ./vuln1 `perl -e'print 'A' x 516' ` Your name:
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Segmentation fault (core dumped)
As we can see, this program is fully functional, and does what it is required to
do. But lets see what happens when we fill buff (argv[1]) with more than 512
chars:
What happened there?
• The program crashed due to a segmentation fault
- we filled the buffer with more data than it was
defined to hold, ending in an illegal address
violation.
• (Note: if you did not get a core dump it is most
likely because you have not set a limit, at the
command prompt type: ulimit -c unlimited: if this
fails still, make sure you have write access in the
executing directory, and make sure that the file is
not suid, you will not get core dumps on suid
files.)
How to avoid overrun?
Use of safe libraries
• The problem of buffer overflows is common in the C
and C++ languages because they expose low level
representational details of buffers as containers for
data types. Buffer overflows must thus be avoided by
maintaining a high degree of correctness in code which
performs buffer management. It has also long been
recommended to avoid standard library functions
which are not bounds checked, such
as gets, scanf and strcpy.
• Well-written and tested abstract data type libraries
which centralize and automatically perform buffer
management, including bounds checking, can reduce
the occurrence and impact of buffer overflows.
Some Unix operating systems (e.g. OpenBSD, Mac
OS X) ship with executable space protection
(e.g. W^X). Some optional packages include:
PaX
Exec Shield
Openwall
Newer variants of Microsoft Windows also support
executable space protection, called Data Execution
Prevention. Proprietary add-ons include:
– BufferShield
– StackDefender

More Related Content

PPTX
Buffer overflow
PPTX
Attacking thru HTTP Host header
PPTX
Buffer overflow attacks
PPT
6 buffer overflows
PPTX
Buffer overflow
PPTX
Buffer overflow attacks
PPTX
Buffer overflow
PPTX
Unrestricted file upload CWE-434 - Adam Nurudini (ISACA)
Buffer overflow
Attacking thru HTTP Host header
Buffer overflow attacks
6 buffer overflows
Buffer overflow
Buffer overflow attacks
Buffer overflow
Unrestricted file upload CWE-434 - Adam Nurudini (ISACA)

What's hot (20)

PPTX
Security Code Review 101
PDF
OWASP Top 10 Web Application Vulnerabilities
PPT
Hacking web applications
PPT
Cross Site Request Forgery
PPTX
Cross Site Scripting
PPTX
Directory Traversal & File Inclusion Attacks
PPT
PPTX
Waf bypassing Techniques
PPTX
Bug Bounty - Play For Money
PDF
Offzone | Another waf bypass
PDF
Cross site scripting
PPTX
Wireless Penetration Testing
PDF
User Authentication: Passwords and Beyond
PDF
XXE Exposed: SQLi, XSS, XXE and XEE against Web Services
PDF
Cross site scripting attacks and defenses
PPTX
Introduction to IDS & IPS - Part 1
PDF
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
PPTX
PPTX
Footprinting and reconnaissance
PPT
Security Code Review 101
OWASP Top 10 Web Application Vulnerabilities
Hacking web applications
Cross Site Request Forgery
Cross Site Scripting
Directory Traversal & File Inclusion Attacks
Waf bypassing Techniques
Bug Bounty - Play For Money
Offzone | Another waf bypass
Cross site scripting
Wireless Penetration Testing
User Authentication: Passwords and Beyond
XXE Exposed: SQLi, XSS, XXE and XEE against Web Services
Cross site scripting attacks and defenses
Introduction to IDS & IPS - Part 1
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
Footprinting and reconnaissance
Ad

Viewers also liked (20)

PDF
How to find_vulnerability_in_software
PDF
Shellcoding, an Introduction
PDF
Game Engine
PDF
A Stealthy Stealers - Spyware Toolkit and What They Do
PDF
References Are 'Nice' Pointers
PPTX
Programmazione Genetica per l'Inferenza di Reti di Kauffman
PPTX
Algorithms
PPTX
Buffer Overflow Demo by Saurabh Sharma
PDF
Design and Implementation of GCC Register Allocation
PDF
Light talk @ coscup 2011 : Incremental Global Prelink for Android
PDF
System Hacking Tutorial #2 - Buffer Overflow - Overwrite EIP
PPT
Exception handling poirting in gcc
PDF
Rethinking the debugger
PPTX
Buffer overflow
PPTX
PDF
Android C Library: Bionic 成長計畫
PDF
System Hacking Tutorial #4 - Buffer Overflow - Return Oriented Programming ak...
PDF
Function Call Stack
PDF
Ceh v5 module 20 buffer overflow
PDF
COSCUP 2014 : open source compiler 戰國時代的軍備競賽
How to find_vulnerability_in_software
Shellcoding, an Introduction
Game Engine
A Stealthy Stealers - Spyware Toolkit and What They Do
References Are 'Nice' Pointers
Programmazione Genetica per l'Inferenza di Reti di Kauffman
Algorithms
Buffer Overflow Demo by Saurabh Sharma
Design and Implementation of GCC Register Allocation
Light talk @ coscup 2011 : Incremental Global Prelink for Android
System Hacking Tutorial #2 - Buffer Overflow - Overwrite EIP
Exception handling poirting in gcc
Rethinking the debugger
Buffer overflow
Android C Library: Bionic 成長計畫
System Hacking Tutorial #4 - Buffer Overflow - Return Oriented Programming ak...
Function Call Stack
Ceh v5 module 20 buffer overflow
COSCUP 2014 : open source compiler 戰國時代的軍備競賽
Ad

Similar to Buffer overflow explained (20)

PPT
Buffer Overflows
PPTX
antoanthongtin_Lesson 3- Software Security (1).pptx
PDF
Lecture #15: Buffer Overflow Attack (Non Malicious Attack)
ODP
BufferOverflow - Offensive point of View
DOCX
What
PDF
Buffer overflow null
PPT
Buffer OverFlow
PPTX
Stack-Based Buffer Overflows
PPTX
Buffer overflows
PDF
Advanced Arm Exploitation
PDF
Ch 18: Source Code Auditing
PDF
Presentation buffer overflow attacks and theircountermeasures
PDF
Low Level Exploits
PPSX
Buffer overflow
PPTX
Control hijacking
PDF
Exploitation Crash Course
ODP
Introduction to Binary Exploitation
PDF
CNIT 127: Ch 18: Source Code Auditing
PPSX
Ids 008 buffer overflow
PPTX
Golf teamlearnerlecture
Buffer Overflows
antoanthongtin_Lesson 3- Software Security (1).pptx
Lecture #15: Buffer Overflow Attack (Non Malicious Attack)
BufferOverflow - Offensive point of View
What
Buffer overflow null
Buffer OverFlow
Stack-Based Buffer Overflows
Buffer overflows
Advanced Arm Exploitation
Ch 18: Source Code Auditing
Presentation buffer overflow attacks and theircountermeasures
Low Level Exploits
Buffer overflow
Control hijacking
Exploitation Crash Course
Introduction to Binary Exploitation
CNIT 127: Ch 18: Source Code Auditing
Ids 008 buffer overflow
Golf teamlearnerlecture

More from Teja Babu (9)

PPTX
Server hardening
PPTX
Linux
PPT
introduction to computer
PPTX
french wines
PPTX
Cloud computing security
PPTX
Cisco ios
PPT
Cyber crime
PPT
role of students in developing Nation
PPTX
MANET
Server hardening
Linux
introduction to computer
french wines
Cloud computing security
Cisco ios
Cyber crime
role of students in developing Nation
MANET

Recently uploaded (20)

PPTX
Cloud computing and distributed systems.
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Advanced IT Governance
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PDF
Transforming Manufacturing operations through Intelligent Integrations
PDF
cuic standard and advanced reporting.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Cloud computing and distributed systems.
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Chapter 3 Spatial Domain Image Processing.pdf
Advanced IT Governance
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Diabetes mellitus diagnosis method based random forest with bat algorithm
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Advanced Soft Computing BINUS July 2025.pdf
madgavkar20181017ppt McKinsey Presentation.pdf
Transforming Manufacturing operations through Intelligent Integrations
cuic standard and advanced reporting.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

Buffer overflow explained

  • 2. What is buffer overflow? How a buffer overflow happens How to avoid overrun?
  • 3. What is buffer overflow? • Buffer overflow are responsible for many vulnerabilities in operating system as well as application programs. • It’s a quiet technical freaky , it includes program source code , assembler listing , and debugging usage , which almost scares away lot of people without solid programming knowledge.
  • 4. Cause : Buffer overflow attack have been there for a long time. It still exists partly because of the carelessness of the developer in the code. Prevention : Avoid writing bad codes
  • 5. How a buffer overflow happens ? • The ultimate purpose of any program that runs on a computer is to process data of some kind. • Most don’t operate on fixed data, but on data that is ultimately provided by user, possibly pre-processed in some fashion. • The program needs to store data some where in computer’s memory, and this is point where problem starts • Buffer overflows are a common vulnerability on all platforms, but are by far the most commonly exploited bug on the linux/unix Operating systems. • Commonly buffer overflows are exploited to change the flow in a programs execution, so that it points to a different memory address or overwrites crucial memory segments.
  • 6. EX : #include #include int main(int argc, char **argv) { char buff[512]; if(argc < 2) { printf('Usage: %s n', argv[0]); exit(0); } strcpy(buff, argv[1]); printf('Your name: %sn', buff); return 0; }
  • 7. lets try by giving this program a test: Normal Execution : Demo@root:~/tut > gcc vuln1.c -o vuln1 Demo@root:~/tut > ./vuln1 Usage: ./vuln1 Demo@root:~/tut > ./vuln1 mercy Your name: Fr3@k Demo@root:~/tut > Demo@root:~/tut > ./vuln1 `perl -e'print 'A' x 516' ` Your name: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA Segmentation fault (core dumped) As we can see, this program is fully functional, and does what it is required to do. But lets see what happens when we fill buff (argv[1]) with more than 512 chars:
  • 9. • The program crashed due to a segmentation fault - we filled the buffer with more data than it was defined to hold, ending in an illegal address violation. • (Note: if you did not get a core dump it is most likely because you have not set a limit, at the command prompt type: ulimit -c unlimited: if this fails still, make sure you have write access in the executing directory, and make sure that the file is not suid, you will not get core dumps on suid files.)
  • 10. How to avoid overrun?
  • 11. Use of safe libraries • The problem of buffer overflows is common in the C and C++ languages because they expose low level representational details of buffers as containers for data types. Buffer overflows must thus be avoided by maintaining a high degree of correctness in code which performs buffer management. It has also long been recommended to avoid standard library functions which are not bounds checked, such as gets, scanf and strcpy. • Well-written and tested abstract data type libraries which centralize and automatically perform buffer management, including bounds checking, can reduce the occurrence and impact of buffer overflows.
  • 12. Some Unix operating systems (e.g. OpenBSD, Mac OS X) ship with executable space protection (e.g. W^X). Some optional packages include: PaX Exec Shield Openwall Newer variants of Microsoft Windows also support executable space protection, called Data Execution Prevention. Proprietary add-ons include: – BufferShield – StackDefender