SlideShare ist ein Scribd-Unternehmen logo
1 von 8
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

08 - Return Oriented Programming, the chosen one
08 - Return Oriented Programming, the chosen one08 - Return Oriented Programming, the chosen one
08 - Return Oriented Programming, the chosen oneAlexandre Moneger
 
2.Format Strings
2.Format Strings2.Format Strings
2.Format Stringsphanleson
 
Buffer Overflows Shesh Jun 3 09
Buffer Overflows Shesh Jun 3 09Buffer Overflows Shesh Jun 3 09
Buffer Overflows Shesh Jun 3 09dhanya.sumeru
 
System Hacking Tutorial #1 - Introduction to Vulnerability and Type of Vulner...
System Hacking Tutorial #1 - Introduction to Vulnerability and Type of Vulner...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 kernelLeak kernel pointer by exploiting uninitialized uses in Linux kernel
Leak kernel pointer by exploiting uninitialized uses in Linux kernelJinbumPark
 
Buffer overflow explained
Buffer overflow explainedBuffer overflow explained
Buffer overflow explainedTeja Babu
 
Course lecture - An introduction to the Return Oriented Programming
Course lecture - An introduction to the Return Oriented ProgrammingCourse lecture - An introduction to the Return Oriented Programming
Course lecture - An introduction to the Return Oriented ProgrammingJonathan Salwan
 
Auditing the Opensource Kernels
Auditing the Opensource KernelsAuditing the Opensource Kernels
Auditing the Opensource KernelsSilvio 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...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 vulnerabilityC format string vulnerability
C format string vulnerabilitysluge
 
Indicators of compromise: From malware analysis to eradication
Indicators of compromise: From malware analysis to eradicationIndicators of compromise: From malware analysis to eradication
Indicators of compromise: From malware analysis to eradicationMichael 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...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 vunerabilityFormat string vunerability
Format string vunerabilitynuc13us
 
Static Code Analysis and Cppcheck
Static Code Analysis and CppcheckStatic Code Analysis and Cppcheck
Static Code Analysis and CppcheckZachary Blair
 
Zn task - defcon russia 20
Zn task  - defcon russia 20Zn task  - defcon russia 20
Zn task - defcon russia 20DefconRussia
 
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++ BuilderA Check of the Open-Source Project WinSCP Developed in Embarcadero C++ Builder
A Check of the Open-Source Project WinSCP Developed in Embarcadero C++ BuilderAndrey Karpov
 
Introduction to ida python
Introduction to ida pythonIntroduction to ida python
Introduction to ida pythongeeksec80
 
CNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: ShellcodeCNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: ShellcodeSam Bowne
 

Was ist angesagt? (20)

08 - Return Oriented Programming, the chosen one
08 - Return Oriented Programming, the chosen one08 - Return Oriented Programming, the chosen one
08 - Return Oriented Programming, the chosen one
 
2.Format Strings
2.Format Strings2.Format Strings
2.Format Strings
 
Buffer Overflows Shesh Jun 3 09
Buffer Overflows Shesh Jun 3 09Buffer Overflows Shesh Jun 3 09
Buffer Overflows Shesh Jun 3 09
 
System Hacking Tutorial #1 - Introduction to Vulnerability and Type of Vulner...
System Hacking Tutorial #1 - Introduction to Vulnerability and Type of Vulner...System Hacking Tutorial #1 - Introduction to Vulnerability and Type of Vulner...
System Hacking Tutorial #1 - Introduction to Vulnerability and Type of Vulner...
 
Leak kernel pointer by exploiting uninitialized uses in Linux kernel
Leak kernel pointer by exploiting uninitialized uses in Linux kernelLeak kernel pointer by exploiting uninitialized uses in Linux kernel
Leak kernel pointer by exploiting uninitialized uses in Linux kernel
 
Buffer overflow explained
Buffer overflow explainedBuffer overflow explained
Buffer overflow explained
 
Course lecture - An introduction to the Return Oriented Programming
Course lecture - An introduction to the Return Oriented ProgrammingCourse lecture - An introduction to the Return Oriented Programming
Course lecture - An introduction to the Return Oriented Programming
 
Auditing the Opensource Kernels
Auditing the Opensource KernelsAuditing the Opensource Kernels
Auditing the Opensource Kernels
 
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...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...
 
C format string vulnerability
C format string vulnerabilityC format string vulnerability
C format string vulnerability
 
Indicators of compromise: From malware analysis to eradication
Indicators of compromise: From malware analysis to eradicationIndicators of compromise: From malware analysis to eradication
Indicators of compromise: From malware analysis to eradication
 
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...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...
 
Cppcheck
CppcheckCppcheck
Cppcheck
 
Format string vunerability
Format string vunerabilityFormat string vunerability
Format string vunerability
 
Static Code Analysis and Cppcheck
Static Code Analysis and CppcheckStatic Code Analysis and Cppcheck
Static Code Analysis and Cppcheck
 
Zn task - defcon russia 20
Zn task  - defcon russia 20Zn task  - defcon russia 20
Zn task - defcon russia 20
 
Metasploit Humla for Beginner
Metasploit Humla for BeginnerMetasploit Humla for Beginner
Metasploit Humla for Beginner
 
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++ BuilderA 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
 
Introduction to ida python
Introduction to ida pythonIntroduction to ida python
Introduction to ida python
 
CNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: ShellcodeCNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: Shellcode
 

Andere mochten auch

Ceh v5 module 06 trojans and backdoors
Ceh v5 module 06 trojans and backdoorsCeh v5 module 06 trojans and backdoors
Ceh v5 module 06 trojans and backdoorsVi Tính Hoàng Nam
 
Ceh v5 module 20 buffer overflow
Ceh v5 module 20 buffer overflowCeh v5 module 20 buffer overflow
Ceh v5 module 20 buffer overflowVi Tính Hoàng Nam
 
Anatomy of a Buffer Overflow Attack
Anatomy of a Buffer Overflow AttackAnatomy of a Buffer Overflow Attack
Anatomy of a Buffer Overflow AttackRob Gillen
 
6 buffer overflows
6   buffer overflows6   buffer overflows
6 buffer overflowsdrewz lin
 
Buffer Overflow exploitation
Buffer Overflow exploitationBuffer Overflow exploitation
Buffer Overflow exploitationZakaria SMAHI
 
Phishing--The Entire Story of a Dark World
Phishing--The Entire Story of a Dark WorldPhishing--The Entire Story of a Dark World
Phishing--The Entire Story of a Dark WorldAvishek Datta
 
An Introduction of SQL Injection, Buffer Overflow & Wireless Attack
An Introduction of SQL Injection, Buffer Overflow & Wireless AttackAn Introduction of SQL Injection, Buffer Overflow & Wireless Attack
An Introduction of SQL Injection, Buffer Overflow & Wireless AttackTechSecIT
 
Buffer overflow attacks
Buffer overflow attacksBuffer overflow attacks
Buffer overflow attacksJoe McCarthy
 
Introduction To Problem Analysis
Introduction To Problem AnalysisIntroduction To Problem Analysis
Introduction To Problem AnalysisElijah Ezendu
 
Buffer Overflow Countermeasures, DEP, Security Assessment
Buffer Overflow Countermeasures, DEP, Security AssessmentBuffer Overflow Countermeasures, DEP, Security Assessment
Buffer Overflow Countermeasures, DEP, Security AssessmentAmar Myana
 
P H I S H I N G
P H I S H I N GP H I S H I N G
P H I S H I N Gbensonoo
 

Andere mochten auch (18)

Ceh v5 module 06 trojans and backdoors
Ceh v5 module 06 trojans and backdoorsCeh v5 module 06 trojans and backdoors
Ceh v5 module 06 trojans and backdoors
 
Ceh v5 module 20 buffer overflow
Ceh v5 module 20 buffer overflowCeh v5 module 20 buffer overflow
Ceh v5 module 20 buffer overflow
 
Ceh v5 module 18 linux hacking
Ceh v5 module 18 linux hackingCeh v5 module 18 linux hacking
Ceh v5 module 18 linux hacking
 
Ceh v5 module 02 footprinting
Ceh v5 module 02 footprintingCeh v5 module 02 footprinting
Ceh v5 module 02 footprinting
 
Ceh v5 module 04 enumeration
Ceh v5 module 04 enumerationCeh v5 module 04 enumeration
Ceh v5 module 04 enumeration
 
Anatomy of a Buffer Overflow Attack
Anatomy of a Buffer Overflow AttackAnatomy of a Buffer Overflow Attack
Anatomy of a Buffer Overflow Attack
 
6 buffer overflows
6   buffer overflows6   buffer overflows
6 buffer overflows
 
Buffer Overflow
Buffer OverflowBuffer Overflow
Buffer Overflow
 
Ceh v5 module 05 system hacking
Ceh v5 module 05 system hackingCeh v5 module 05 system hacking
Ceh v5 module 05 system hacking
 
Buffer Overflow exploitation
Buffer Overflow exploitationBuffer Overflow exploitation
Buffer Overflow exploitation
 
Phishing--The Entire Story of a Dark World
Phishing--The Entire Story of a Dark WorldPhishing--The Entire Story of a Dark World
Phishing--The Entire Story of a Dark World
 
An Introduction of SQL Injection, Buffer Overflow & Wireless Attack
An Introduction of SQL Injection, Buffer Overflow & Wireless AttackAn Introduction of SQL Injection, Buffer Overflow & Wireless Attack
An Introduction of SQL Injection, Buffer Overflow & Wireless Attack
 
Buffer overflow attacks
Buffer overflow attacksBuffer overflow attacks
Buffer overflow attacks
 
Problem tree analysis
Problem tree analysisProblem tree analysis
Problem tree analysis
 
Introduction To Problem Analysis
Introduction To Problem AnalysisIntroduction To Problem Analysis
Introduction To Problem Analysis
 
Buffer Overflow Countermeasures, DEP, Security Assessment
Buffer Overflow Countermeasures, DEP, Security AssessmentBuffer Overflow Countermeasures, DEP, Security Assessment
Buffer Overflow Countermeasures, DEP, Security Assessment
 
Types of cyber attacks
Types of cyber attacksTypes of cyber attacks
Types of cyber attacks
 
P H I S H I N G
P H I S H I N GP H I S H I N G
P H I S H I N G
 

Ähnlich wie Presentation buffer overflow attacks and theircountermeasures

Ähnlich wie Presentation buffer overflow attacks and theircountermeasures (20)

Introduction to c part -3
Introduction to c   part -3Introduction to c   part -3
Introduction to c part -3
 
Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!
 
Embedded C programming session10
Embedded C programming  session10Embedded C programming  session10
Embedded C programming session10
 
TLPI - 6 Process
TLPI - 6 ProcessTLPI - 6 Process
TLPI - 6 Process
 
C programming session10
C programming  session10C programming  session10
C programming session10
 
0100_Embeded_C_CompilationProcess.pdf
0100_Embeded_C_CompilationProcess.pdf0100_Embeded_C_CompilationProcess.pdf
0100_Embeded_C_CompilationProcess.pdf
 
C programming session9 -
C programming  session9 -C programming  session9 -
C programming session9 -
 
Parallel Programming
Parallel ProgrammingParallel Programming
Parallel Programming
 
Java Memory Model
Java Memory ModelJava Memory Model
Java Memory Model
 
Buffer overflow tutorial
Buffer overflow tutorialBuffer overflow tutorial
Buffer overflow tutorial
 
The Silence of the Canaries
The Silence of the CanariesThe Silence of the Canaries
The Silence of the Canaries
 
Data structure week 1
Data structure week 1Data structure week 1
Data structure week 1
 
C tour Unix
C tour UnixC tour Unix
C tour Unix
 
presentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.pptpresentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.ppt
 
Quiz 9
Quiz 9Quiz 9
Quiz 9
 
Storage class
Storage classStorage class
Storage class
 
GPU Programming on CPU - Using C++AMP
GPU Programming on CPU - Using C++AMPGPU Programming on CPU - Using C++AMP
GPU Programming on CPU - Using C++AMP
 
Dynamic Memory Allocation in C
Dynamic Memory Allocation in CDynamic Memory Allocation in C
Dynamic Memory Allocation in C
 
C aptitude questions
C aptitude questionsC aptitude questions
C aptitude questions
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3
 

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.