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
Ad

Recommended

6 buffer overflows
6 buffer overflows
drewz lin
 
Buffer overflow
Buffer overflow
قصي نسور
 
Buffer overflow attacks
Buffer overflow attacks
Joe McCarthy
 
Buffer overflow attacks
Buffer overflow attacks
Kapil Nagrale
 
Local File Inclusion to Remote Code Execution
Local File Inclusion to Remote Code Execution
n|u - The Open Security Community
 
Penetration Testing Basics
Penetration Testing Basics
Rick Wanner
 
Social Engineering Attacks & Principles
Social Engineering Attacks & Principles
LearningwithRayYT
 
Caffe Latte Attack
Caffe Latte Attack
AirTight Networks
 
Ch02 System Threats and Risks
Ch02 System Threats and Risks
Information Technology
 
Buffer Overflow Attacks
Buffer Overflow Attacks
harshal kshatriya
 
NMap
NMap
Pritesh Raka
 
Email hacking
Email hacking
ShreyaBhoje
 
Chapter 5 Planning for Security-students.ppt
Chapter 5 Planning for Security-students.ppt
Shruthi48
 
OWASP Top 10 - 2017
OWASP Top 10 - 2017
HackerOne
 
Buffer overflow
Buffer overflow
Evgeni Tsonev
 
Software security
Software security
Roman Oliynykov
 
Chapter 3: Information Security Framework
Chapter 3: Information Security Framework
Nada G.Youssef
 
Network Security: Physical security
Network Security: Physical security
lalithambiga kamaraj
 
Penetration Security Testing
Penetration Security Testing
Sanjulika Rastogi
 
Understanding NMAP
Understanding NMAP
Phannarith Ou, G-CISO
 
Denial of service
Denial of service
garishma bhatia
 
DDoS Attack PPT by Nitin Bisht
DDoS Attack PPT by Nitin Bisht
Nitin Bisht
 
Security awareness
Security awareness
Josh Chandler
 
Security threats
Security threats
Qamar Farooq
 
Secure Code Warrior - Cross site scripting
Secure Code Warrior - Cross site scripting
Secure Code Warrior
 
OS Fingerprinting
OS Fingerprinting
Rashmika Nawaratne
 
Introduction to Social engineering | Techniques of Social engineering
Introduction to Social engineering | Techniques of Social engineering
Prem Lamsal
 
Cyber Kill Chain.pptx
Cyber Kill Chain.pptx
Vivek Chauhan
 
How to find_vulnerability_in_software
How to find_vulnerability_in_software
sanghwan ahn
 
Shellcoding, an Introduction
Shellcoding, an Introduction
Daniele Bellavista
 

More Related Content

What's hot (20)

Ch02 System Threats and Risks
Ch02 System Threats and Risks
Information Technology
 
Buffer Overflow Attacks
Buffer Overflow Attacks
harshal kshatriya
 
NMap
NMap
Pritesh Raka
 
Email hacking
Email hacking
ShreyaBhoje
 
Chapter 5 Planning for Security-students.ppt
Chapter 5 Planning for Security-students.ppt
Shruthi48
 
OWASP Top 10 - 2017
OWASP Top 10 - 2017
HackerOne
 
Buffer overflow
Buffer overflow
Evgeni Tsonev
 
Software security
Software security
Roman Oliynykov
 
Chapter 3: Information Security Framework
Chapter 3: Information Security Framework
Nada G.Youssef
 
Network Security: Physical security
Network Security: Physical security
lalithambiga kamaraj
 
Penetration Security Testing
Penetration Security Testing
Sanjulika Rastogi
 
Understanding NMAP
Understanding NMAP
Phannarith Ou, G-CISO
 
Denial of service
Denial of service
garishma bhatia
 
DDoS Attack PPT by Nitin Bisht
DDoS Attack PPT by Nitin Bisht
Nitin Bisht
 
Security awareness
Security awareness
Josh Chandler
 
Security threats
Security threats
Qamar Farooq
 
Secure Code Warrior - Cross site scripting
Secure Code Warrior - Cross site scripting
Secure Code Warrior
 
OS Fingerprinting
OS Fingerprinting
Rashmika Nawaratne
 
Introduction to Social engineering | Techniques of Social engineering
Introduction to Social engineering | Techniques of Social engineering
Prem Lamsal
 
Cyber Kill Chain.pptx
Cyber Kill Chain.pptx
Vivek Chauhan
 
Chapter 5 Planning for Security-students.ppt
Chapter 5 Planning for Security-students.ppt
Shruthi48
 
OWASP Top 10 - 2017
OWASP Top 10 - 2017
HackerOne
 
Chapter 3: Information Security Framework
Chapter 3: Information Security Framework
Nada G.Youssef
 
Network Security: Physical security
Network Security: Physical security
lalithambiga kamaraj
 
Penetration Security Testing
Penetration Security Testing
Sanjulika Rastogi
 
DDoS Attack PPT by Nitin Bisht
DDoS Attack PPT by Nitin Bisht
Nitin Bisht
 
Secure Code Warrior - Cross site scripting
Secure Code Warrior - Cross site scripting
Secure Code Warrior
 
Introduction to Social engineering | Techniques of Social engineering
Introduction to Social engineering | Techniques of Social engineering
Prem Lamsal
 
Cyber Kill Chain.pptx
Cyber Kill Chain.pptx
Vivek Chauhan
 

Viewers also liked (20)

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

Similar to Buffer overflow explained (20)

Buffer Overflows
Buffer Overflows
Sumit Kumar
 
Lecture #15: Buffer Overflow Attack (Non Malicious Attack)
Lecture #15: Buffer Overflow Attack (Non Malicious Attack)
Dr. Ramchandra Mangrulkar
 
BufferOverflow - Offensive point of View
BufferOverflow - Offensive point of View
Toe Khaing
 
What
What
anity
 
Buffer overflow null
Buffer overflow null
nullowaspmumbai
 
Buffer overflow
Buffer overflow
Abu Juha Ahmed Muid
 
Buffer OverFlow
Buffer OverFlow
Rambabu Duddukuri
 
Stack-Based Buffer Overflows
Stack-Based Buffer Overflows
Daniel Tumser
 
Buffer overflows
Buffer overflows
Sandun Perera
 
Advanced Arm Exploitation
Advanced Arm Exploitation
Himanshu Khokhar Jaat
 
Ch 18: Source Code Auditing
Ch 18: Source Code Auditing
Sam Bowne
 
Presentation buffer overflow attacks and theircountermeasures
Presentation buffer overflow attacks and theircountermeasures
tharindunew
 
Low Level Exploits
Low Level Exploits
hughpearse
 
Buffer overflow
Buffer overflow
Ambuj Kumar
 
Control hijacking
Control hijacking
Prachi Gulihar
 
Exploitation Crash Course
Exploitation Crash Course
UTD Computer Security Group
 
Introduction to Binary Exploitation
Introduction to Binary Exploitation
Cysinfo Cyber Security Community
 
CNIT 127: Ch 18: Source Code Auditing
CNIT 127: Ch 18: Source Code Auditing
Sam Bowne
 
Ids 008 buffer overflow
Ids 008 buffer overflow
jyoti_lakhani
 
Golf teamlearnerlecture
Golf teamlearnerlecture
kairistiona
 
Buffer Overflows
Buffer Overflows
Sumit Kumar
 
Lecture #15: Buffer Overflow Attack (Non Malicious Attack)
Lecture #15: Buffer Overflow Attack (Non Malicious Attack)
Dr. Ramchandra Mangrulkar
 
BufferOverflow - Offensive point of View
BufferOverflow - Offensive point of View
Toe Khaing
 
What
What
anity
 
Stack-Based Buffer Overflows
Stack-Based Buffer Overflows
Daniel Tumser
 
Ch 18: Source Code Auditing
Ch 18: Source Code Auditing
Sam Bowne
 
Presentation buffer overflow attacks and theircountermeasures
Presentation buffer overflow attacks and theircountermeasures
tharindunew
 
Low Level Exploits
Low Level Exploits
hughpearse
 
CNIT 127: Ch 18: Source Code Auditing
CNIT 127: Ch 18: Source Code Auditing
Sam Bowne
 
Ids 008 buffer overflow
Ids 008 buffer overflow
jyoti_lakhani
 
Golf teamlearnerlecture
Golf teamlearnerlecture
kairistiona
 
Ad

More from Teja Babu (9)

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

Recently uploaded (20)

OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
Edge AI and Vision Alliance
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Impelsys Inc.
 
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
Safe Software
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
Edge AI and Vision Alliance
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Impelsys Inc.
 
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
Safe Software
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 

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