SlideShare a Scribd company logo
Buffer Overflow Attacks and Their
        Countermeasures




      118232K – NDY Tharindu
Buffer Overflow: the Basics
●   Buffer overflow problems always have been associated with
    security vulnerabilities.
●   A buffer is a contiguous allocated chunk of memory, such as
    an array or a pointer in C.
●   In C and C++, there are no automatic bounds checking on
    the buffer, which means a user can write past a buffer.


    int main () {
        int buffer[10];
        buffer[20] = 10;
    }
Problem with the program
●   The above C program is a valid program, and
    every compiler can compile it without any
    errors.
●   However, the program attempts to write
    beyond the allocated memory for the buffer.
●   Programs written in C/C++ languages, where
    more focus is given to the programming
    efficiency and code length than to the security
    aspect.
Memory layout of a Process
                        primarily the program code, i.e., a series of executable
                        program instructions.




                               initialized and uninitialized
                               global data



                               allocated at run time




                            The heap holds dynamic variables. To
                            allocate memory, the heap uses the malloc
                            function or the new operator.




        The stack is used to store function call-by
        arguments, local variables and values of selected
        registers
Example
void function (int a, int b, int c) {
    char buffer1[5];
    char buffer2[10]
                                            FP is need to access a, b, c, buffer1 and buffer2 variables.
}
                                        ●



                                        ●   All these variables are cleaned up from the stack as the
int main() {                                function terminates


    function(1,2,3);
}




                       10 bytes
                                  5 bytes
                                                frame
                                                pointer
Example 2
void function (char *str) {
char buffer[16];
strcpy (buffer, str);
}
int main () {
    char *str = "This is greater than 16 bytes"; // length of str = 27 bytes
    function (str);
}
    ●   Guaranteed to cause unexpected behavior.
    ●   String (str) of 27 bytes has been copied to a location (buffer) that has been allocated for only 16 bytes.
    ●   The extra bytes run past the buffer and overwrites the space allocated for the FP & return addresses.
    ●   This, in turn, corrupts the process stack.

        This is a example how buffer overflow can overwrite a function's return address,
    ●   which in turn can alter the program's execution path.
    ●   Recall that a function's return address is the address of the next instruction in memory, which is executed
        immediately after the function returns. Hacker might get a root shell by adding execution path to such code.
    ●   Or place the code we are trying to execute in the buffer's overflowing area
Buffer Overflow Countermeasures
●   The solutions proposed for buffer overflow problems mainly
    target the prevention of large-scale system attacks through
    the loopholes described above.


●   None of the methods described above can claim to prevent
    all possible attacks.


●   Write secure code:
    C library functions such as strcpy (), strcat (), sprintf () and
    vsprintf () operate on null terminated strings and perform no
    bounds checking.
Presentation buffer overflow attacks and theircountermeasures
Ad

Recommended

Buffer Overflow Demo by Saurabh Sharma
Buffer Overflow Demo by Saurabh Sharma
n|u - The Open Security Community
 
Buffer Overflows
Buffer Overflows
Sumit Kumar
 
Buffer overflow attacks
Buffer overflow attacks
Kapil Nagrale
 
Buffer Overflow Attacks
Buffer Overflow Attacks
harshal kshatriya
 
Buffer overflow null
Buffer overflow null
nullowaspmumbai
 
Buffer overflow
Buffer overflow
Evgeni Tsonev
 
Control hijacking
Control hijacking
Prachi Gulihar
 
Buffer overflow attacks
Buffer overflow attacks
Sandun Perera
 
08 - Return Oriented Programming, the chosen one
08 - Return Oriented Programming, the chosen one
Alexandre Moneger
 
2.Format Strings
2.Format Strings
phanleson
 
Buffer Overflows Shesh Jun 3 09
Buffer Overflows Shesh Jun 3 09
dhanya.sumeru
 
System Hacking Tutorial #1 - Introduction to Vulnerability and Type of Vulner...
System Hacking Tutorial #1 - Introduction to Vulnerability and Type of Vulner...
sanghwan ahn
 
Leak kernel pointer by exploiting uninitialized uses in Linux kernel
Leak kernel pointer by exploiting uninitialized uses in Linux kernel
JinbumPark
 
Buffer overflow explained
Buffer overflow explained
Teja Babu
 
Course lecture - An introduction to the Return Oriented Programming
Course lecture - An introduction to the Return Oriented Programming
Jonathan Salwan
 
Auditing the Opensource Kernels
Auditing the Opensource Kernels
Silvio Cesare
 
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
 
C format string vulnerability
C format string vulnerability
sluge
 
Indicators of compromise: From malware analysis to eradication
Indicators of compromise: From malware analysis to eradication
Michael Boman
 
PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...
PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...
Rouven Weßling
 
Cppcheck
Cppcheck
PVS-Studio
 
Format string vunerability
Format string vunerability
nuc13us
 
Static Code Analysis and Cppcheck
Static Code Analysis and Cppcheck
Zachary Blair
 
Zn task - defcon russia 20
Zn task - defcon russia 20
DefconRussia
 
Metasploit Humla for Beginner
Metasploit Humla for Beginner
n|u - The Open Security Community
 
A Check of the Open-Source Project WinSCP Developed in Embarcadero C++ Builder
A Check of the Open-Source Project WinSCP Developed in Embarcadero C++ Builder
Andrey Karpov
 
Introduction to ida python
Introduction to ida python
geeksec80
 
CNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: Shellcode
Sam Bowne
 
Ceh v5 module 06 trojans and backdoors
Ceh v5 module 06 trojans and backdoors
Vi Tính Hoàng Nam
 
Ceh v5 module 20 buffer overflow
Ceh v5 module 20 buffer overflow
Vi Tính Hoàng Nam
 

More Related Content

What's hot (20)

08 - Return Oriented Programming, the chosen one
08 - Return Oriented Programming, the chosen one
Alexandre Moneger
 
2.Format Strings
2.Format Strings
phanleson
 
Buffer Overflows Shesh Jun 3 09
Buffer Overflows Shesh Jun 3 09
dhanya.sumeru
 
System Hacking Tutorial #1 - Introduction to Vulnerability and Type of Vulner...
System Hacking Tutorial #1 - Introduction to Vulnerability and Type of Vulner...
sanghwan ahn
 
Leak kernel pointer by exploiting uninitialized uses in Linux kernel
Leak kernel pointer by exploiting uninitialized uses in Linux kernel
JinbumPark
 
Buffer overflow explained
Buffer overflow explained
Teja Babu
 
Course lecture - An introduction to the Return Oriented Programming
Course lecture - An introduction to the Return Oriented Programming
Jonathan Salwan
 
Auditing the Opensource Kernels
Auditing the Opensource Kernels
Silvio Cesare
 
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
 
C format string vulnerability
C format string vulnerability
sluge
 
Indicators of compromise: From malware analysis to eradication
Indicators of compromise: From malware analysis to eradication
Michael Boman
 
PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...
PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...
Rouven Weßling
 
Cppcheck
Cppcheck
PVS-Studio
 
Format string vunerability
Format string vunerability
nuc13us
 
Static Code Analysis and Cppcheck
Static Code Analysis and Cppcheck
Zachary Blair
 
Zn task - defcon russia 20
Zn task - defcon russia 20
DefconRussia
 
Metasploit Humla for Beginner
Metasploit Humla for Beginner
n|u - The Open Security Community
 
A Check of the Open-Source Project WinSCP Developed in Embarcadero C++ Builder
A Check of the Open-Source Project WinSCP Developed in Embarcadero C++ Builder
Andrey Karpov
 
Introduction to ida python
Introduction to ida python
geeksec80
 
CNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: Shellcode
Sam Bowne
 
08 - Return Oriented Programming, the chosen one
08 - Return Oriented Programming, the chosen one
Alexandre Moneger
 
2.Format Strings
2.Format Strings
phanleson
 
Buffer Overflows Shesh Jun 3 09
Buffer Overflows Shesh Jun 3 09
dhanya.sumeru
 
System Hacking Tutorial #1 - Introduction to Vulnerability and Type of Vulner...
System Hacking Tutorial #1 - Introduction to Vulnerability and Type of Vulner...
sanghwan ahn
 
Leak kernel pointer by exploiting uninitialized uses in Linux kernel
Leak kernel pointer by exploiting uninitialized uses in Linux kernel
JinbumPark
 
Buffer overflow explained
Buffer overflow explained
Teja Babu
 
Course lecture - An introduction to the Return Oriented Programming
Course lecture - An introduction to the Return Oriented Programming
Jonathan Salwan
 
Auditing the Opensource Kernels
Auditing the Opensource Kernels
Silvio Cesare
 
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
 
C format string vulnerability
C format string vulnerability
sluge
 
Indicators of compromise: From malware analysis to eradication
Indicators of compromise: From malware analysis to eradication
Michael Boman
 
PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...
PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...
Rouven Weßling
 
Format string vunerability
Format string vunerability
nuc13us
 
Static Code Analysis and Cppcheck
Static Code Analysis and Cppcheck
Zachary Blair
 
Zn task - defcon russia 20
Zn task - defcon russia 20
DefconRussia
 
A Check of the Open-Source Project WinSCP Developed in Embarcadero C++ Builder
A Check of the Open-Source Project WinSCP Developed in Embarcadero C++ Builder
Andrey Karpov
 
Introduction to ida python
Introduction to ida python
geeksec80
 
CNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: Shellcode
Sam Bowne
 

Viewers also liked (18)

Ceh v5 module 06 trojans and backdoors
Ceh v5 module 06 trojans and backdoors
Vi Tính Hoàng Nam
 
Ceh v5 module 20 buffer overflow
Ceh v5 module 20 buffer overflow
Vi Tính Hoàng Nam
 
Ceh v5 module 18 linux hacking
Ceh v5 module 18 linux hacking
Vi Tính Hoàng Nam
 
Ceh v5 module 02 footprinting
Ceh v5 module 02 footprinting
Vi Tính Hoàng Nam
 
Ceh v5 module 04 enumeration
Ceh v5 module 04 enumeration
Vi Tính Hoàng Nam
 
Anatomy of a Buffer Overflow Attack
Anatomy of a Buffer Overflow Attack
Rob Gillen
 
6 buffer overflows
6 buffer overflows
drewz lin
 
Buffer Overflow
Buffer Overflow
Kaustubh Padwad
 
Ceh v5 module 05 system hacking
Ceh v5 module 05 system hacking
Vi Tính Hoàng Nam
 
Buffer Overflow exploitation
Buffer Overflow exploitation
Zakaria SMAHI
 
Phishing--The Entire Story of a Dark World
Phishing--The Entire Story of a Dark World
Avishek Datta
 
An Introduction of SQL Injection, Buffer Overflow & Wireless Attack
An Introduction of SQL Injection, Buffer Overflow & Wireless Attack
TechSecIT
 
Buffer overflow attacks
Buffer overflow attacks
Joe McCarthy
 
Problem tree analysis
Problem tree analysis
Mzimasi Ndongeni
 
Introduction To Problem Analysis
Introduction To Problem Analysis
Elijah Ezendu
 
Buffer Overflow Countermeasures, DEP, Security Assessment
Buffer Overflow Countermeasures, DEP, Security Assessment
Amar Myana
 
Types of cyber attacks
Types of cyber attacks
krishh sivakrishna
 
P H I S H I N G
P H I S H I N G
bensonoo
 
Ceh v5 module 06 trojans and backdoors
Ceh v5 module 06 trojans and backdoors
Vi Tính Hoàng Nam
 
Ceh v5 module 20 buffer overflow
Ceh v5 module 20 buffer overflow
Vi Tính Hoàng Nam
 
Anatomy of a Buffer Overflow Attack
Anatomy of a Buffer Overflow Attack
Rob Gillen
 
6 buffer overflows
6 buffer overflows
drewz lin
 
Buffer Overflow exploitation
Buffer Overflow exploitation
Zakaria SMAHI
 
Phishing--The Entire Story of a Dark World
Phishing--The Entire Story of a Dark World
Avishek Datta
 
An Introduction of SQL Injection, Buffer Overflow & Wireless Attack
An Introduction of SQL Injection, Buffer Overflow & Wireless Attack
TechSecIT
 
Buffer overflow attacks
Buffer overflow attacks
Joe McCarthy
 
Introduction To Problem Analysis
Introduction To Problem Analysis
Elijah Ezendu
 
Buffer Overflow Countermeasures, DEP, Security Assessment
Buffer Overflow Countermeasures, DEP, Security Assessment
Amar Myana
 
P H I S H I N G
P H I S H I N G
bensonoo
 
Ad

Similar to Presentation buffer overflow attacks and theircountermeasures (20)

2 buffer overflows
2 buffer overflows
Karthic Rao
 
Buffer OverFlow
Buffer OverFlow
Rambabu Duddukuri
 
1.Buffer Overflows
1.Buffer Overflows
phanleson
 
Exploiting Memory Overflows
Exploiting Memory Overflows
Ankur Tyagi
 
StackOverflow
StackOverflow
Susam Pal
 
Stack-Based Buffer Overflows
Stack-Based Buffer Overflows
Daniel Tumser
 
Exploitation Crash Course
Exploitation Crash Course
UTD Computer Security Group
 
What
What
anity
 
Smashing The Stack
Smashing The Stack
Daniele Bellavista
 
AllBits presentation - Lower Level SW Security
AllBits presentation - Lower Level SW Security
AllBits BVBA (freelancer)
 
test
test
aaro11
 
127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux
Sam Bowne
 
Bt0067 c programming and data structures2
Bt0067 c programming and data structures2
Techglyphs
 
Ch 18: Source Code Auditing
Ch 18: Source Code Auditing
Sam Bowne
 
fjfh mjgkj jkhglkjh jhlkh lhlkkhl kjhjkhjk
fjfh mjgkj jkhglkjh jhlkh lhlkkhl kjhjkhjk
ahmed8790
 
Introduction to Stack Buffer Over‌flow for beginners
Introduction to Stack Buffer Over‌flow for beginners
Khashayar Fereidani
 
C - aptitude3
C - aptitude3
Srikanth
 
C aptitude questions
C aptitude questions
Srikanth
 
CNIT 127: Ch 2: Stack overflows on Linux
CNIT 127: Ch 2: Stack overflows on Linux
Sam Bowne
 
Low Level Exploits
Low Level Exploits
hughpearse
 
2 buffer overflows
2 buffer overflows
Karthic Rao
 
1.Buffer Overflows
1.Buffer Overflows
phanleson
 
Exploiting Memory Overflows
Exploiting Memory Overflows
Ankur Tyagi
 
StackOverflow
StackOverflow
Susam Pal
 
Stack-Based Buffer Overflows
Stack-Based Buffer Overflows
Daniel Tumser
 
What
What
anity
 
AllBits presentation - Lower Level SW Security
AllBits presentation - Lower Level SW Security
AllBits BVBA (freelancer)
 
127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux
Sam Bowne
 
Bt0067 c programming and data structures2
Bt0067 c programming and data structures2
Techglyphs
 
Ch 18: Source Code Auditing
Ch 18: Source Code Auditing
Sam Bowne
 
fjfh mjgkj jkhglkjh jhlkh lhlkkhl kjhjkhjk
fjfh mjgkj jkhglkjh jhlkh lhlkkhl kjhjkhjk
ahmed8790
 
Introduction to Stack Buffer Over‌flow for beginners
Introduction to Stack Buffer Over‌flow for beginners
Khashayar Fereidani
 
C - aptitude3
C - aptitude3
Srikanth
 
C aptitude questions
C aptitude questions
Srikanth
 
CNIT 127: Ch 2: Stack overflows on Linux
CNIT 127: Ch 2: Stack overflows on Linux
Sam Bowne
 
Low Level Exploits
Low Level Exploits
hughpearse
 
Ad

Presentation buffer overflow attacks and theircountermeasures

  • 1. Buffer Overflow Attacks and Their Countermeasures 118232K – NDY Tharindu
  • 2. Buffer Overflow: the Basics ● Buffer overflow problems always have been associated with security vulnerabilities. ● A buffer is a contiguous allocated chunk of memory, such as an array or a pointer in C. ● In C and C++, there are no automatic bounds checking on the buffer, which means a user can write past a buffer. int main () { int buffer[10]; buffer[20] = 10; }
  • 3. Problem with the program ● The above C program is a valid program, and every compiler can compile it without any errors. ● However, the program attempts to write beyond the allocated memory for the buffer. ● Programs written in C/C++ languages, where more focus is given to the programming efficiency and code length than to the security aspect.
  • 4. Memory layout of a Process primarily the program code, i.e., a series of executable program instructions. initialized and uninitialized global data allocated at run time The heap holds dynamic variables. To allocate memory, the heap uses the malloc function or the new operator. The stack is used to store function call-by arguments, local variables and values of selected registers
  • 5. Example void function (int a, int b, int c) { char buffer1[5]; char buffer2[10] FP is need to access a, b, c, buffer1 and buffer2 variables. } ● ● All these variables are cleaned up from the stack as the int main() { function terminates function(1,2,3); } 10 bytes 5 bytes frame pointer
  • 6. Example 2 void function (char *str) { char buffer[16]; strcpy (buffer, str); } int main () { char *str = "This is greater than 16 bytes"; // length of str = 27 bytes function (str); } ● Guaranteed to cause unexpected behavior. ● String (str) of 27 bytes has been copied to a location (buffer) that has been allocated for only 16 bytes. ● The extra bytes run past the buffer and overwrites the space allocated for the FP & return addresses. ● This, in turn, corrupts the process stack. This is a example how buffer overflow can overwrite a function's return address, ● which in turn can alter the program's execution path. ● Recall that a function's return address is the address of the next instruction in memory, which is executed immediately after the function returns. Hacker might get a root shell by adding execution path to such code. ● Or place the code we are trying to execute in the buffer's overflowing area
  • 7. Buffer Overflow Countermeasures ● The solutions proposed for buffer overflow problems mainly target the prevention of large-scale system attacks through the loopholes described above. ● None of the methods described above can claim to prevent all possible attacks. ● Write secure code: C library functions such as strcpy (), strcat (), sprintf () and vsprintf () operate on null terminated strings and perform no bounds checking.