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

What's hot (20)

PDF
SSRF workshop
Ivan Novikov
 
PPTX
Understanding Cross-site Request Forgery
Daniel Miessler
 
PPTX
Web Cache Poisoning
KuldeepPandya5
 
PDF
Broken access controls
Akansha Kesharwani
 
PPTX
Deep dive into ssrf
n|u - The Open Security Community
 
PPTX
Ssrf
Ilan Mindel
 
PPTX
Encryption
keith dias
 
PPTX
Owasp top 10 vulnerabilities
OWASP Delhi
 
PPTX
Cross Site Scripting ( XSS)
Amit Tyagi
 
PDF
Thick Client Penetration Testing.pdf
SouvikRoy114738
 
PPTX
Introduction to path traversal attack
Prashant Hegde
 
PPT
Cross Site Request Forgery Vulnerabilities
Marco Morana
 
PPTX
Secure coding guidelines
Sathyanarayana Panduranga
 
PPTX
SSRF exploit the trust relationship
n|u - The Open Security Community
 
DOCX
Zero-Day Vulnerability and Heuristic Analysis
Ahmed Banafa
 
PPTX
Web application attacks
hruth
 
PDF
Secure Code Review 101
Narudom Roongsiriwong, CISSP
 
PPTX
Virus and worms
Vikas Sharma
 
PPTX
A2 - broken authentication and session management(OWASP thailand chapter Apri...
Noppadol Songsakaew
 
PPTX
Website hacking and prevention (All Tools,Topics & Technique )
Jay Nagar
 
SSRF workshop
Ivan Novikov
 
Understanding Cross-site Request Forgery
Daniel Miessler
 
Web Cache Poisoning
KuldeepPandya5
 
Broken access controls
Akansha Kesharwani
 
Encryption
keith dias
 
Owasp top 10 vulnerabilities
OWASP Delhi
 
Cross Site Scripting ( XSS)
Amit Tyagi
 
Thick Client Penetration Testing.pdf
SouvikRoy114738
 
Introduction to path traversal attack
Prashant Hegde
 
Cross Site Request Forgery Vulnerabilities
Marco Morana
 
Secure coding guidelines
Sathyanarayana Panduranga
 
SSRF exploit the trust relationship
n|u - The Open Security Community
 
Zero-Day Vulnerability and Heuristic Analysis
Ahmed Banafa
 
Web application attacks
hruth
 
Secure Code Review 101
Narudom Roongsiriwong, CISSP
 
Virus and worms
Vikas Sharma
 
A2 - broken authentication and session management(OWASP thailand chapter Apri...
Noppadol Songsakaew
 
Website hacking and prevention (All Tools,Topics & Technique )
Jay Nagar
 

Viewers also liked (20)

PDF
How to find_vulnerability_in_software
sanghwan ahn
 
PDF
Shellcoding, an Introduction
Daniele Bellavista
 
PDF
Game Engine
Daniele Bellavista
 
PDF
A Stealthy Stealers - Spyware Toolkit and What They Do
sanghwan ahn
 
PDF
References Are 'Nice' Pointers
Gail Carmichael
 
PPTX
Programmazione Genetica per l'Inferenza di Reti di Kauffman
Daniele Bellavista
 
PPTX
Algorithms
Nitin Reddy Katkam
 
PPTX
Buffer Overflow Demo by Saurabh Sharma
n|u - The Open Security Community
 
PDF
Design and Implementation of GCC Register Allocation
Kito Cheng
 
PDF
Light talk @ coscup 2011 : Incremental Global Prelink for Android
Kito Cheng
 
PDF
System Hacking Tutorial #2 - Buffer Overflow - Overwrite EIP
sanghwan ahn
 
PPT
Exception handling poirting in gcc
Shiva Chen
 
PDF
Rethinking the debugger
Iulian Dragos
 
PPTX
Buffer overflow
Bach Khoa Da Nang
 
PPTX
FuelPHP
Nitin Reddy Katkam
 
PDF
Android C Library: Bionic 成長計畫
Kito Cheng
 
PDF
System Hacking Tutorial #4 - Buffer Overflow - Return Oriented Programming ak...
sanghwan ahn
 
PDF
Function Call Stack
Gail Carmichael
 
PDF
Ceh v5 module 20 buffer overflow
Vi Tính Hoàng Nam
 
PDF
COSCUP 2014 : open source compiler 戰國時代的軍備競賽
Kito Cheng
 
How to find_vulnerability_in_software
sanghwan ahn
 
Shellcoding, an Introduction
Daniele Bellavista
 
Game Engine
Daniele Bellavista
 
A Stealthy Stealers - Spyware Toolkit and What They Do
sanghwan ahn
 
References Are 'Nice' Pointers
Gail Carmichael
 
Programmazione Genetica per l'Inferenza di Reti di Kauffman
Daniele Bellavista
 
Algorithms
Nitin Reddy Katkam
 
Buffer Overflow Demo by Saurabh Sharma
n|u - The Open Security Community
 
Design and Implementation of GCC Register Allocation
Kito Cheng
 
Light talk @ coscup 2011 : Incremental Global Prelink for Android
Kito Cheng
 
System Hacking Tutorial #2 - Buffer Overflow - Overwrite EIP
sanghwan ahn
 
Exception handling poirting in gcc
Shiva Chen
 
Rethinking the debugger
Iulian Dragos
 
Buffer overflow
Bach Khoa Da Nang
 
Android C Library: Bionic 成長計畫
Kito Cheng
 
System Hacking Tutorial #4 - Buffer Overflow - Return Oriented Programming ak...
sanghwan ahn
 
Function Call Stack
Gail Carmichael
 
Ceh v5 module 20 buffer overflow
Vi Tính Hoàng Nam
 
COSCUP 2014 : open source compiler 戰國時代的軍備競賽
Kito Cheng
 
Ad

Similar to Buffer overflow explained (20)

PPT
Buffer Overflows
Sumit Kumar
 
PPTX
antoanthongtin_Lesson 3- Software Security (1).pptx
23162024
 
PDF
Lecture #15: Buffer Overflow Attack (Non Malicious Attack)
Dr. Ramchandra Mangrulkar
 
ODP
BufferOverflow - Offensive point of View
Toe Khaing
 
DOCX
What
anity
 
PDF
Buffer overflow null
nullowaspmumbai
 
PPT
Buffer OverFlow
Rambabu Duddukuri
 
PPTX
Stack-Based Buffer Overflows
Daniel Tumser
 
PPTX
Buffer overflows
Sandun Perera
 
PDF
Advanced Arm Exploitation
Himanshu Khokhar Jaat
 
PDF
Ch 18: Source Code Auditing
Sam Bowne
 
PDF
Presentation buffer overflow attacks and theircountermeasures
tharindunew
 
PDF
Low Level Exploits
hughpearse
 
PPSX
Buffer overflow
Ambuj Kumar
 
PPTX
Control hijacking
Prachi Gulihar
 
PDF
Exploitation Crash Course
UTD Computer Security Group
 
PPT
6 buffer overflows
drewz lin
 
ODP
Introduction to Binary Exploitation
Cysinfo Cyber Security Community
 
PDF
CNIT 127: Ch 18: Source Code Auditing
Sam Bowne
 
PPSX
Ids 008 buffer overflow
jyoti_lakhani
 
Buffer Overflows
Sumit Kumar
 
antoanthongtin_Lesson 3- Software Security (1).pptx
23162024
 
Lecture #15: Buffer Overflow Attack (Non Malicious Attack)
Dr. Ramchandra Mangrulkar
 
BufferOverflow - Offensive point of View
Toe Khaing
 
What
anity
 
Buffer overflow null
nullowaspmumbai
 
Buffer OverFlow
Rambabu Duddukuri
 
Stack-Based Buffer Overflows
Daniel Tumser
 
Buffer overflows
Sandun Perera
 
Advanced Arm Exploitation
Himanshu Khokhar Jaat
 
Ch 18: Source Code Auditing
Sam Bowne
 
Presentation buffer overflow attacks and theircountermeasures
tharindunew
 
Low Level Exploits
hughpearse
 
Buffer overflow
Ambuj Kumar
 
Control hijacking
Prachi Gulihar
 
Exploitation Crash Course
UTD Computer Security Group
 
6 buffer overflows
drewz lin
 
Introduction to Binary Exploitation
Cysinfo Cyber Security Community
 
CNIT 127: Ch 18: Source Code Auditing
Sam Bowne
 
Ids 008 buffer overflow
jyoti_lakhani
 
Ad

More from Teja Babu (9)

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

Recently uploaded (20)

PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
July Patch Tuesday
Ivanti
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Python basic programing language for automation
DanialHabibi2
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 

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