SlideShare uma empresa Scribd logo
1 de 40
Baixar para ler offline
Outline
    Introduction to integer overflows
               Automated detection
                          Conclusion




Detecting and exploiting integer overflows

                      Guillaume TOURON

          Laboratoire Verimag, Ensimag - Grenoble INP
              Marie-Laure Potet, Laurent Mounier


                                20/05/11




                                                        1 / 18
Outline
             Introduction to integer overflows
                        Automated detection
                                   Conclusion




Introduction to integer overflows
    Context
    Binary representation
    Integers misinterpretation


Automated detection
   Static binary analysis
   Data flow analysis
   Implementation


Conclusion



                                                 2 / 18
Outline
                                                   Context
               Introduction to integer overflows
                                                   Binary representation
                          Automated detection
                                                   Integers misinterpretation
                                     Conclusion


Work subject

   Subject
   Binary code static analysis for vulnerabilities detection
        Focus on arithmetic problems

   Application security is critical for information systems
        Programming bad practices

   Goals
        Work with a professional environment : IDA Pro
        Develop some analysis to make easier vulnerabilities detection


                                                                                3 / 18
Outline
                                                   Context
               Introduction to integer overflows
                                                   Binary representation
                          Automated detection
                                                   Integers misinterpretation
                                     Conclusion


Work subject

   Subject
   Binary code static analysis for vulnerabilities detection
        Focus on arithmetic problems

   Application security is critical for information systems
        Programming bad practices

   Goals
        Work with a professional environment : IDA Pro
        Develop some analysis to make easier vulnerabilities detection


                                                                                3 / 18
Outline
                                                   Context
               Introduction to integer overflows
                                                   Binary representation
                          Automated detection
                                                   Integers misinterpretation
                                     Conclusion


Work subject

   Subject
   Binary code static analysis for vulnerabilities detection
        Focus on arithmetic problems

   Application security is critical for information systems
        Programming bad practices

   Goals
        Work with a professional environment : IDA Pro
        Develop some analysis to make easier vulnerabilities detection


                                                                                3 / 18
Outline
                                              Context
          Introduction to integer overflows
                                              Binary representation
                     Automated detection
                                              Integers misinterpretation
                                Conclusion


Buffer overflow




                                                                           4 / 18
Outline
                                                    Context
                Introduction to integer overflows
                                                    Binary representation
                           Automated detection
                                                    Integers misinterpretation
                                      Conclusion


Buffer overflow vulnerabilities

   Exploitability
   Integer overflow can lead to buffer overflow
   Buffer overflow can lead to arbitrary code execution

   Integer overflows and buffer overflows top ranked by CWE
   Exploitability (CWE):
       Buffer overflow: High to Very High (3rd )
       Integers overflow: Medium (16th )

   Conclusion
   We have to care about arithmetic overflow and avoid them


                                                                                 5 / 18
Outline
                                                    Context
                Introduction to integer overflows
                                                    Binary representation
                           Automated detection
                                                    Integers misinterpretation
                                      Conclusion


Buffer overflow vulnerabilities

   Exploitability
   Integer overflow can lead to buffer overflow
   Buffer overflow can lead to arbitrary code execution

   Integer overflows and buffer overflows top ranked by CWE
   Exploitability (CWE):
       Buffer overflow: High to Very High (3rd )
       Integers overflow: Medium (16th )

   Conclusion
   We have to care about arithmetic overflow and avoid them


                                                                                 5 / 18
Outline
                                                    Context
                Introduction to integer overflows
                                                    Binary representation
                           Automated detection
                                                    Integers misinterpretation
                                      Conclusion


Buffer overflow vulnerabilities

   Exploitability
   Integer overflow can lead to buffer overflow
   Buffer overflow can lead to arbitrary code execution

   Integer overflows and buffer overflows top ranked by CWE
   Exploitability (CWE):
       Buffer overflow: High to Very High (3rd )
       Integers overflow: Medium (16th )

   Conclusion
   We have to care about arithmetic overflow and avoid them


                                                                                 5 / 18
Outline
                                                  Context
              Introduction to integer overflows
                                                  Binary representation
                         Automated detection
                                                  Integers misinterpretation
                                    Conclusion


x86 integers binary representation

   Basic C types on x86 32 bits:

                 char                 short                     int                long int
    signed   [-128,127]         [-32,768,32,767]          [−231 ,231 − 1]      [−263 ,263 − 1]
    unsigned   [0,255]              [0,65535]               [0,232 − 1]          [0,264 − 1]


   Signed values representation
   For negative values, MSB = 1 (2’s complement representation)

                              e.g −1 = 0xFFFFFFFF




                                                                                             6 / 18
Outline
                                                  Context
              Introduction to integer overflows
                                                  Binary representation
                         Automated detection
                                                  Integers misinterpretation
                                    Conclusion


x86 integers binary representation

   Basic C types on x86 32 bits:

                 char                 short                     int                long int
    signed   [-128,127]         [-32,768,32,767]          [−231 ,231 − 1]      [−263 ,263 − 1]
    unsigned   [0,255]              [0,65535]               [0,232 − 1]          [0,264 − 1]


   Signed values representation
   For negative values, MSB = 1 (2’s complement representation)

                              e.g −1 = 0xFFFFFFFF




                                                                                             6 / 18
Outline
                                                     Context
                 Introduction to integer overflows
                                                     Binary representation
                            Automated detection
                                                     Integers misinterpretation
                                       Conclusion


Dangerousness of misinterpreting

   First issue
   Small negative integers can be interpreted as huge integers

   Dangerous cases:
       Sanity checks
       Copy operations
       Array indexations

   Dangerous functions
   Some famous functions: strncpy, strncat, snprintf, memcpy...
   These functions take a length unsigned parameter


                                                                                  7 / 18
Outline
                                                     Context
                 Introduction to integer overflows
                                                     Binary representation
                            Automated detection
                                                     Integers misinterpretation
                                       Conclusion


Dangerousness of misinterpreting

   First issue
   Small negative integers can be interpreted as huge integers

   Dangerous cases:
       Sanity checks
       Copy operations
       Array indexations

   Dangerous functions
   Some famous functions: strncpy, strncat, snprintf, memcpy...
   These functions take a length unsigned parameter


                                                                                  7 / 18
Outline
                                                     Context
                 Introduction to integer overflows
                                                     Binary representation
                            Automated detection
                                                     Integers misinterpretation
                                       Conclusion


Dangerousness of misinterpreting

   First issue
   Small negative integers can be interpreted as huge integers

   Dangerous cases:
       Sanity checks
       Copy operations
       Array indexations

   Dangerous functions
   Some famous functions: strncpy, strncat, snprintf, memcpy...
   These functions take a length unsigned parameter


                                                                                  7 / 18
Outline
                                                     Context
                 Introduction to integer overflows
                                                     Binary representation
                            Automated detection
                                                     Integers misinterpretation
                                       Conclusion


Dangerousness of misinterpreting

   First issue
   Small negative integers can be interpreted as huge integers

   Dangerous cases:
       Sanity checks
       Copy operations
       Array indexations

   Dangerous functions
   Some famous functions: strncpy, strncat, snprintf, memcpy...
   These functions take a length unsigned parameter


                                                                                  7 / 18
Outline
                                                     Context
                 Introduction to integer overflows
                                                     Binary representation
                            Automated detection
                                                     Integers misinterpretation
                                       Conclusion


Dangerousness of misinterpreting

   First issue
   Small negative integers can be interpreted as huge integers

   Dangerous cases:
       Sanity checks
       Copy operations
       Array indexations

   Dangerous functions
   Some famous functions: strncpy, strncat, snprintf, memcpy...
   These functions take a length unsigned parameter


                                                                                  7 / 18
Outline
                                                             Context
                         Introduction to integer overflows
                                                             Binary representation
                                    Automated detection
                                                             Integers misinterpretation
                                               Conclusion


Dangerousness of misinterpreting

   memcpy example
   void *memcpy(void *dest, const void *src, size t n);

   ⇒ What happens if this value is user-controlled?
   Let’s take an example
   Bad
   #d e f i n e LEN 512
   ...
   void vuln ( char ∗src , i n t s ) {
           c h a r d s t [ LEN ] ;
           int size = s ;
           i f ( s < LEN) {
                  memcpy ( d s t , s r c , s i z e ) ;
           }
   }
   ...
   v u l n ( ” T e s t ” , −1);

                                                                                          8 / 18
Outline
                                                             Context
                         Introduction to integer overflows
                                                             Binary representation
                                    Automated detection
                                                             Integers misinterpretation
                                               Conclusion


Dangerousness of misinterpreting

   memcpy example
   void *memcpy(void *dest, const void *src, size t n);

   ⇒ What happens if this value is user-controlled?
   Let’s take an example
   Bad
   #d e f i n e LEN 512
   ...
   void vuln ( char ∗src , i n t s ) {
           c h a r d s t [ LEN ] ;
           int size = s ;
           i f ( s < LEN) {
                  memcpy ( d s t , s r c , s i z e ) ;
           }
   }
   ...
   v u l n ( ” T e s t ” , −1);

                                                                                          8 / 18
Outline
                                                  Context
              Introduction to integer overflows
                                                  Binary representation
                         Automated detection
                                                  Integers misinterpretation
                                    Conclusion


Dangerousness of misinterpreting

   Analysis
   We have size = −1 (0xFFFFFFFF )
   CPU compares size and 512 as signed values
         ⇒ size < 512 == True


   Vulnerability
   But memcpy takes a unsigned argument, so size = 232 − 1
   By consequences, a buffer overflow occurs

   A potential attacker can take control of flow execution



                                                                               9 / 18
Outline
                                                  Context
              Introduction to integer overflows
                                                  Binary representation
                         Automated detection
                                                  Integers misinterpretation
                                    Conclusion


Dangerousness of misinterpreting

   Analysis
   We have size = −1 (0xFFFFFFFF )
   CPU compares size and 512 as signed values
         ⇒ size < 512 == True


   Vulnerability
   But memcpy takes a unsigned argument, so size = 232 − 1
   By consequences, a buffer overflow occurs

   A potential attacker can take control of flow execution



                                                                               9 / 18
Outline
                                                  Context
              Introduction to integer overflows
                                                  Binary representation
                         Automated detection
                                                  Integers misinterpretation
                                    Conclusion


Dangerousness of misinterpreting

   Analysis
   We have size = −1 (0xFFFFFFFF )
   CPU compares size and 512 as signed values
         ⇒ size < 512 == True


   Vulnerability
   But memcpy takes a unsigned argument, so size = 232 − 1
   By consequences, a buffer overflow occurs

   A potential attacker can take control of flow execution



                                                                               9 / 18
Outline
                                                     Static binary analysis
                 Introduction to integer overflows
                                                     Data flow analysis
                            Automated detection
                                                     Implementation
                                       Conclusion


Pattern matching

   Patterns
   We look for interesting (= dangerous) patterns

   Some patterns:
      Calls to dangerous functions (memcpy, strncpy...)
              Search signed comparisons on unsigned parameters
       Dangerous instructions
        r e p movsd


       Array indexation
        movl $0x2a ,−0 x 2 c(%ebp ,% eax , 4 )




                                                                              10 / 18
Outline
                                                     Static binary analysis
                 Introduction to integer overflows
                                                     Data flow analysis
                            Automated detection
                                                     Implementation
                                       Conclusion


Pattern matching

   Patterns
   We look for interesting (= dangerous) patterns

   Some patterns:
      Calls to dangerous functions (memcpy, strncpy...)
              Search signed comparisons on unsigned parameters
       Dangerous instructions
        r e p movsd


       Array indexation
        movl $0x2a ,−0 x 2 c(%ebp ,% eax , 4 )




                                                                              10 / 18
Outline
                                                     Static binary analysis
                 Introduction to integer overflows
                                                     Data flow analysis
                            Automated detection
                                                     Implementation
                                       Conclusion


Pattern matching

   Patterns
   We look for interesting (= dangerous) patterns

   Some patterns:
      Calls to dangerous functions (memcpy, strncpy...)
              Search signed comparisons on unsigned parameters
       Dangerous instructions
        r e p movsd


       Array indexation
        movl $0x2a ,−0 x 2 c(%ebp ,% eax , 4 )




                                                                              10 / 18
Outline
                                                     Static binary analysis
                 Introduction to integer overflows
                                                     Data flow analysis
                            Automated detection
                                                     Implementation
                                       Conclusion


Pattern matching

   Patterns
   We look for interesting (= dangerous) patterns

   Some patterns:
      Calls to dangerous functions (memcpy, strncpy...)
              Search signed comparisons on unsigned parameters
       Dangerous instructions
        r e p movsd


       Array indexation
        movl $0x2a ,−0 x 2 c(%ebp ,% eax , 4 )




                                                                              10 / 18
Outline
                                                  Static binary analysis
              Introduction to integer overflows
                                                  Data flow analysis
                         Automated detection
                                                  Implementation
                                    Conclusion


Data dependencies

   Looking for interesting data dependencies
       Sensitive parameters (e.g size from memcpy )
       Counter registers (e.g %ecx for rep prefixed instructions)

   Analysis steps
       Scan code to find interesting data
            Sensitive parameters (e.g size for memcpy )
       Backtrack these data for dependencies
       Apply code patterns to exhib vulnerabilities
            Misinterpretation (e.g comparison as signed values)



                                                                           11 / 18
Outline
                                                  Static binary analysis
              Introduction to integer overflows
                                                  Data flow analysis
                         Automated detection
                                                  Implementation
                                    Conclusion


Data dependencies

   Looking for interesting data dependencies
       Sensitive parameters (e.g size from memcpy )
       Counter registers (e.g %ecx for rep prefixed instructions)

   Analysis steps
       Scan code to find interesting data
            Sensitive parameters (e.g size for memcpy )
       Backtrack these data for dependencies
       Apply code patterns to exhib vulnerabilities
            Misinterpretation (e.g comparison as signed values)



                                                                           11 / 18
Outline
                                                  Static binary analysis
              Introduction to integer overflows
                                                  Data flow analysis
                         Automated detection
                                                  Implementation
                                    Conclusion


Data dependencies

   Looking for interesting data dependencies
       Sensitive parameters (e.g size from memcpy )
       Counter registers (e.g %ecx for rep prefixed instructions)

   Analysis steps
       Scan code to find interesting data
            Sensitive parameters (e.g size for memcpy )
       Backtrack these data for dependencies
       Apply code patterns to exhib vulnerabilities
            Misinterpretation (e.g comparison as signed values)



                                                                           11 / 18
Outline
                                                  Static binary analysis
              Introduction to integer overflows
                                                  Data flow analysis
                         Automated detection
                                                  Implementation
                                    Conclusion


Data dependencies

   Looking for interesting data dependencies
       Sensitive parameters (e.g size from memcpy )
       Counter registers (e.g %ecx for rep prefixed instructions)

   Analysis steps
       Scan code to find interesting data
            Sensitive parameters (e.g size for memcpy )
       Backtrack these data for dependencies
       Apply code patterns to exhib vulnerabilities
            Misinterpretation (e.g comparison as signed values)



                                                                           11 / 18
Outline
                                                 Static binary analysis
             Introduction to integer overflows
                                                 Data flow analysis
                        Automated detection
                                                 Implementation
                                   Conclusion


Backward analysis

   Dependencies
   For a block B we have: OUT (B) =                   ∀S∈Successors(B) IN(S)




                                                                               12 / 18
Outline
                                                  Static binary analysis
              Introduction to integer overflows
                                                  Data flow analysis
                         Automated detection
                                                  Implementation
                                    Conclusion


Backward analysis

   Transfer function
   Computes new tainted variables set for a basic block B:

                      IN(B) = F B(StmSeq, OUT (B))


   We must define a subset of x86 (grammar)
        ⇒ Focus on instructions that imply dependencies
   Examples:
       mov [ |s|sx|zx]
       Binary operations (add, addc, sub, sbb, and, xor, or...)



                                                                           13 / 18
Outline
                                                  Static binary analysis
              Introduction to integer overflows
                                                  Data flow analysis
                         Automated detection
                                                  Implementation
                                    Conclusion


Backward analysis

   Transfer function
   Computes new tainted variables set for a basic block B:

                      IN(B) = F B(StmSeq, OUT (B))


   We must define a subset of x86 (grammar)
        ⇒ Focus on instructions that imply dependencies
   Examples:
       mov [ |s|sx|zx]
       Binary operations (add, addc, sub, sbb, and, xor, or...)



                                                                           13 / 18
Outline
                                                  Static binary analysis
              Introduction to integer overflows
                                                  Data flow analysis
                         Automated detection
                                                  Implementation
                                    Conclusion


Backward analysis

   Transfer function
   Computes new tainted variables set for a basic block B:

                      IN(B) = F B(StmSeq, OUT (B))


   We must define a subset of x86 (grammar)
        ⇒ Focus on instructions that imply dependencies
   Examples:
       mov [ |s|sx|zx]
       Binary operations (add, addc, sub, sbb, and, xor, or...)



                                                                           13 / 18
Outline
                                                  Static binary analysis
              Introduction to integer overflows
                                                  Data flow analysis
                         Automated detection
                                                  Implementation
                                    Conclusion


Environment

  Several tools used:
      Binary analysis environment
            IDA Pro
            Very used in security industry
            Powerful, many features available
                 CFG display
                 Several plugins
      API
            First, IDAPython
            API for Python script in IDA Pro
            Then, Paimei Framework
            Layer above IDAPython (easier to use)



                                                                           14 / 18
Outline
                                                Static binary analysis
            Introduction to integer overflows
                                                Data flow analysis
                       Automated detection
                                                Implementation
                                  Conclusion


Output example

  Example on CVE-201-3970




                                                                         15 / 18
Outline
                 Introduction to integer overflows
                            Automated detection
                                       Conclusion


Results

   Pros:
          Automation
          Customization
   Cons:
          False positive
   Improvements:
       Improve data-flow analysis
               Symbolic computation engine ?
          Add more dangerous code patterns
          Allow users to write their own patterns
               Simple generic description language


                                                     16 / 18
Outline
                 Introduction to integer overflows
                            Automated detection
                                       Conclusion


Results

   Pros:
          Automation
          Customization
   Cons:
          False positive
   Improvements:
       Improve data-flow analysis
               Symbolic computation engine ?
          Add more dangerous code patterns
          Allow users to write their own patterns
               Simple generic description language


                                                     16 / 18
Outline
                 Introduction to integer overflows
                            Automated detection
                                       Conclusion


Results

   Pros:
          Automation
          Customization
   Cons:
          False positive
   Improvements:
       Improve data-flow analysis
               Symbolic computation engine ?
          Add more dangerous code patterns
          Allow users to write their own patterns
               Simple generic description language


                                                     16 / 18
Outline
               Introduction to integer overflows
                          Automated detection
                                     Conclusion


General conclusion

   Great subject, interesting people

   First approach in research
        Documentation stage
            Backward analysis
            Vulnerabilities examples
       Implementation experimentation
   Use new tools, techniques and frameworks




                                                   17 / 18
Outline
Introduction to integer overflows
           Automated detection
                      Conclusion




                              Q&A




                                    18 / 18

Mais conteúdo relacionado

Destaque

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Destaque (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

Detecting and exploiting integer overflows

  • 1. Outline Introduction to integer overflows Automated detection Conclusion Detecting and exploiting integer overflows Guillaume TOURON Laboratoire Verimag, Ensimag - Grenoble INP Marie-Laure Potet, Laurent Mounier 20/05/11 1 / 18
  • 2. Outline Introduction to integer overflows Automated detection Conclusion Introduction to integer overflows Context Binary representation Integers misinterpretation Automated detection Static binary analysis Data flow analysis Implementation Conclusion 2 / 18
  • 3. Outline Context Introduction to integer overflows Binary representation Automated detection Integers misinterpretation Conclusion Work subject Subject Binary code static analysis for vulnerabilities detection Focus on arithmetic problems Application security is critical for information systems Programming bad practices Goals Work with a professional environment : IDA Pro Develop some analysis to make easier vulnerabilities detection 3 / 18
  • 4. Outline Context Introduction to integer overflows Binary representation Automated detection Integers misinterpretation Conclusion Work subject Subject Binary code static analysis for vulnerabilities detection Focus on arithmetic problems Application security is critical for information systems Programming bad practices Goals Work with a professional environment : IDA Pro Develop some analysis to make easier vulnerabilities detection 3 / 18
  • 5. Outline Context Introduction to integer overflows Binary representation Automated detection Integers misinterpretation Conclusion Work subject Subject Binary code static analysis for vulnerabilities detection Focus on arithmetic problems Application security is critical for information systems Programming bad practices Goals Work with a professional environment : IDA Pro Develop some analysis to make easier vulnerabilities detection 3 / 18
  • 6. Outline Context Introduction to integer overflows Binary representation Automated detection Integers misinterpretation Conclusion Buffer overflow 4 / 18
  • 7. Outline Context Introduction to integer overflows Binary representation Automated detection Integers misinterpretation Conclusion Buffer overflow vulnerabilities Exploitability Integer overflow can lead to buffer overflow Buffer overflow can lead to arbitrary code execution Integer overflows and buffer overflows top ranked by CWE Exploitability (CWE): Buffer overflow: High to Very High (3rd ) Integers overflow: Medium (16th ) Conclusion We have to care about arithmetic overflow and avoid them 5 / 18
  • 8. Outline Context Introduction to integer overflows Binary representation Automated detection Integers misinterpretation Conclusion Buffer overflow vulnerabilities Exploitability Integer overflow can lead to buffer overflow Buffer overflow can lead to arbitrary code execution Integer overflows and buffer overflows top ranked by CWE Exploitability (CWE): Buffer overflow: High to Very High (3rd ) Integers overflow: Medium (16th ) Conclusion We have to care about arithmetic overflow and avoid them 5 / 18
  • 9. Outline Context Introduction to integer overflows Binary representation Automated detection Integers misinterpretation Conclusion Buffer overflow vulnerabilities Exploitability Integer overflow can lead to buffer overflow Buffer overflow can lead to arbitrary code execution Integer overflows and buffer overflows top ranked by CWE Exploitability (CWE): Buffer overflow: High to Very High (3rd ) Integers overflow: Medium (16th ) Conclusion We have to care about arithmetic overflow and avoid them 5 / 18
  • 10. Outline Context Introduction to integer overflows Binary representation Automated detection Integers misinterpretation Conclusion x86 integers binary representation Basic C types on x86 32 bits: char short int long int signed [-128,127] [-32,768,32,767] [−231 ,231 − 1] [−263 ,263 − 1] unsigned [0,255] [0,65535] [0,232 − 1] [0,264 − 1] Signed values representation For negative values, MSB = 1 (2’s complement representation) e.g −1 = 0xFFFFFFFF 6 / 18
  • 11. Outline Context Introduction to integer overflows Binary representation Automated detection Integers misinterpretation Conclusion x86 integers binary representation Basic C types on x86 32 bits: char short int long int signed [-128,127] [-32,768,32,767] [−231 ,231 − 1] [−263 ,263 − 1] unsigned [0,255] [0,65535] [0,232 − 1] [0,264 − 1] Signed values representation For negative values, MSB = 1 (2’s complement representation) e.g −1 = 0xFFFFFFFF 6 / 18
  • 12. Outline Context Introduction to integer overflows Binary representation Automated detection Integers misinterpretation Conclusion Dangerousness of misinterpreting First issue Small negative integers can be interpreted as huge integers Dangerous cases: Sanity checks Copy operations Array indexations Dangerous functions Some famous functions: strncpy, strncat, snprintf, memcpy... These functions take a length unsigned parameter 7 / 18
  • 13. Outline Context Introduction to integer overflows Binary representation Automated detection Integers misinterpretation Conclusion Dangerousness of misinterpreting First issue Small negative integers can be interpreted as huge integers Dangerous cases: Sanity checks Copy operations Array indexations Dangerous functions Some famous functions: strncpy, strncat, snprintf, memcpy... These functions take a length unsigned parameter 7 / 18
  • 14. Outline Context Introduction to integer overflows Binary representation Automated detection Integers misinterpretation Conclusion Dangerousness of misinterpreting First issue Small negative integers can be interpreted as huge integers Dangerous cases: Sanity checks Copy operations Array indexations Dangerous functions Some famous functions: strncpy, strncat, snprintf, memcpy... These functions take a length unsigned parameter 7 / 18
  • 15. Outline Context Introduction to integer overflows Binary representation Automated detection Integers misinterpretation Conclusion Dangerousness of misinterpreting First issue Small negative integers can be interpreted as huge integers Dangerous cases: Sanity checks Copy operations Array indexations Dangerous functions Some famous functions: strncpy, strncat, snprintf, memcpy... These functions take a length unsigned parameter 7 / 18
  • 16. Outline Context Introduction to integer overflows Binary representation Automated detection Integers misinterpretation Conclusion Dangerousness of misinterpreting First issue Small negative integers can be interpreted as huge integers Dangerous cases: Sanity checks Copy operations Array indexations Dangerous functions Some famous functions: strncpy, strncat, snprintf, memcpy... These functions take a length unsigned parameter 7 / 18
  • 17. Outline Context Introduction to integer overflows Binary representation Automated detection Integers misinterpretation Conclusion Dangerousness of misinterpreting memcpy example void *memcpy(void *dest, const void *src, size t n); ⇒ What happens if this value is user-controlled? Let’s take an example Bad #d e f i n e LEN 512 ... void vuln ( char ∗src , i n t s ) { c h a r d s t [ LEN ] ; int size = s ; i f ( s < LEN) { memcpy ( d s t , s r c , s i z e ) ; } } ... v u l n ( ” T e s t ” , −1); 8 / 18
  • 18. Outline Context Introduction to integer overflows Binary representation Automated detection Integers misinterpretation Conclusion Dangerousness of misinterpreting memcpy example void *memcpy(void *dest, const void *src, size t n); ⇒ What happens if this value is user-controlled? Let’s take an example Bad #d e f i n e LEN 512 ... void vuln ( char ∗src , i n t s ) { c h a r d s t [ LEN ] ; int size = s ; i f ( s < LEN) { memcpy ( d s t , s r c , s i z e ) ; } } ... v u l n ( ” T e s t ” , −1); 8 / 18
  • 19. Outline Context Introduction to integer overflows Binary representation Automated detection Integers misinterpretation Conclusion Dangerousness of misinterpreting Analysis We have size = −1 (0xFFFFFFFF ) CPU compares size and 512 as signed values ⇒ size < 512 == True Vulnerability But memcpy takes a unsigned argument, so size = 232 − 1 By consequences, a buffer overflow occurs A potential attacker can take control of flow execution 9 / 18
  • 20. Outline Context Introduction to integer overflows Binary representation Automated detection Integers misinterpretation Conclusion Dangerousness of misinterpreting Analysis We have size = −1 (0xFFFFFFFF ) CPU compares size and 512 as signed values ⇒ size < 512 == True Vulnerability But memcpy takes a unsigned argument, so size = 232 − 1 By consequences, a buffer overflow occurs A potential attacker can take control of flow execution 9 / 18
  • 21. Outline Context Introduction to integer overflows Binary representation Automated detection Integers misinterpretation Conclusion Dangerousness of misinterpreting Analysis We have size = −1 (0xFFFFFFFF ) CPU compares size and 512 as signed values ⇒ size < 512 == True Vulnerability But memcpy takes a unsigned argument, so size = 232 − 1 By consequences, a buffer overflow occurs A potential attacker can take control of flow execution 9 / 18
  • 22. Outline Static binary analysis Introduction to integer overflows Data flow analysis Automated detection Implementation Conclusion Pattern matching Patterns We look for interesting (= dangerous) patterns Some patterns: Calls to dangerous functions (memcpy, strncpy...) Search signed comparisons on unsigned parameters Dangerous instructions r e p movsd Array indexation movl $0x2a ,−0 x 2 c(%ebp ,% eax , 4 ) 10 / 18
  • 23. Outline Static binary analysis Introduction to integer overflows Data flow analysis Automated detection Implementation Conclusion Pattern matching Patterns We look for interesting (= dangerous) patterns Some patterns: Calls to dangerous functions (memcpy, strncpy...) Search signed comparisons on unsigned parameters Dangerous instructions r e p movsd Array indexation movl $0x2a ,−0 x 2 c(%ebp ,% eax , 4 ) 10 / 18
  • 24. Outline Static binary analysis Introduction to integer overflows Data flow analysis Automated detection Implementation Conclusion Pattern matching Patterns We look for interesting (= dangerous) patterns Some patterns: Calls to dangerous functions (memcpy, strncpy...) Search signed comparisons on unsigned parameters Dangerous instructions r e p movsd Array indexation movl $0x2a ,−0 x 2 c(%ebp ,% eax , 4 ) 10 / 18
  • 25. Outline Static binary analysis Introduction to integer overflows Data flow analysis Automated detection Implementation Conclusion Pattern matching Patterns We look for interesting (= dangerous) patterns Some patterns: Calls to dangerous functions (memcpy, strncpy...) Search signed comparisons on unsigned parameters Dangerous instructions r e p movsd Array indexation movl $0x2a ,−0 x 2 c(%ebp ,% eax , 4 ) 10 / 18
  • 26. Outline Static binary analysis Introduction to integer overflows Data flow analysis Automated detection Implementation Conclusion Data dependencies Looking for interesting data dependencies Sensitive parameters (e.g size from memcpy ) Counter registers (e.g %ecx for rep prefixed instructions) Analysis steps Scan code to find interesting data Sensitive parameters (e.g size for memcpy ) Backtrack these data for dependencies Apply code patterns to exhib vulnerabilities Misinterpretation (e.g comparison as signed values) 11 / 18
  • 27. Outline Static binary analysis Introduction to integer overflows Data flow analysis Automated detection Implementation Conclusion Data dependencies Looking for interesting data dependencies Sensitive parameters (e.g size from memcpy ) Counter registers (e.g %ecx for rep prefixed instructions) Analysis steps Scan code to find interesting data Sensitive parameters (e.g size for memcpy ) Backtrack these data for dependencies Apply code patterns to exhib vulnerabilities Misinterpretation (e.g comparison as signed values) 11 / 18
  • 28. Outline Static binary analysis Introduction to integer overflows Data flow analysis Automated detection Implementation Conclusion Data dependencies Looking for interesting data dependencies Sensitive parameters (e.g size from memcpy ) Counter registers (e.g %ecx for rep prefixed instructions) Analysis steps Scan code to find interesting data Sensitive parameters (e.g size for memcpy ) Backtrack these data for dependencies Apply code patterns to exhib vulnerabilities Misinterpretation (e.g comparison as signed values) 11 / 18
  • 29. Outline Static binary analysis Introduction to integer overflows Data flow analysis Automated detection Implementation Conclusion Data dependencies Looking for interesting data dependencies Sensitive parameters (e.g size from memcpy ) Counter registers (e.g %ecx for rep prefixed instructions) Analysis steps Scan code to find interesting data Sensitive parameters (e.g size for memcpy ) Backtrack these data for dependencies Apply code patterns to exhib vulnerabilities Misinterpretation (e.g comparison as signed values) 11 / 18
  • 30. Outline Static binary analysis Introduction to integer overflows Data flow analysis Automated detection Implementation Conclusion Backward analysis Dependencies For a block B we have: OUT (B) = ∀S∈Successors(B) IN(S) 12 / 18
  • 31. Outline Static binary analysis Introduction to integer overflows Data flow analysis Automated detection Implementation Conclusion Backward analysis Transfer function Computes new tainted variables set for a basic block B: IN(B) = F B(StmSeq, OUT (B)) We must define a subset of x86 (grammar) ⇒ Focus on instructions that imply dependencies Examples: mov [ |s|sx|zx] Binary operations (add, addc, sub, sbb, and, xor, or...) 13 / 18
  • 32. Outline Static binary analysis Introduction to integer overflows Data flow analysis Automated detection Implementation Conclusion Backward analysis Transfer function Computes new tainted variables set for a basic block B: IN(B) = F B(StmSeq, OUT (B)) We must define a subset of x86 (grammar) ⇒ Focus on instructions that imply dependencies Examples: mov [ |s|sx|zx] Binary operations (add, addc, sub, sbb, and, xor, or...) 13 / 18
  • 33. Outline Static binary analysis Introduction to integer overflows Data flow analysis Automated detection Implementation Conclusion Backward analysis Transfer function Computes new tainted variables set for a basic block B: IN(B) = F B(StmSeq, OUT (B)) We must define a subset of x86 (grammar) ⇒ Focus on instructions that imply dependencies Examples: mov [ |s|sx|zx] Binary operations (add, addc, sub, sbb, and, xor, or...) 13 / 18
  • 34. Outline Static binary analysis Introduction to integer overflows Data flow analysis Automated detection Implementation Conclusion Environment Several tools used: Binary analysis environment IDA Pro Very used in security industry Powerful, many features available CFG display Several plugins API First, IDAPython API for Python script in IDA Pro Then, Paimei Framework Layer above IDAPython (easier to use) 14 / 18
  • 35. Outline Static binary analysis Introduction to integer overflows Data flow analysis Automated detection Implementation Conclusion Output example Example on CVE-201-3970 15 / 18
  • 36. Outline Introduction to integer overflows Automated detection Conclusion Results Pros: Automation Customization Cons: False positive Improvements: Improve data-flow analysis Symbolic computation engine ? Add more dangerous code patterns Allow users to write their own patterns Simple generic description language 16 / 18
  • 37. Outline Introduction to integer overflows Automated detection Conclusion Results Pros: Automation Customization Cons: False positive Improvements: Improve data-flow analysis Symbolic computation engine ? Add more dangerous code patterns Allow users to write their own patterns Simple generic description language 16 / 18
  • 38. Outline Introduction to integer overflows Automated detection Conclusion Results Pros: Automation Customization Cons: False positive Improvements: Improve data-flow analysis Symbolic computation engine ? Add more dangerous code patterns Allow users to write their own patterns Simple generic description language 16 / 18
  • 39. Outline Introduction to integer overflows Automated detection Conclusion General conclusion Great subject, interesting people First approach in research Documentation stage Backward analysis Vulnerabilities examples Implementation experimentation Use new tools, techniques and frameworks 17 / 18
  • 40. Outline Introduction to integer overflows Automated detection Conclusion Q&A 18 / 18