buffer overflows what they are and how to avoid them
play

Buffer Overflows: What They Are, and How to Avoid Them Ricardo J. - PowerPoint PPT Presentation

Buffer Overflows: What They Are, and How to Avoid Them Ricardo J. Rodr guez All wrongs reversed rj.rodriguez@unileon.es @RicardoJRdez www.ricardojrodriguez.es Research Institute of Applied Sciences in Cybersecurity University of


  1. Buffer Overflows: What They Are, and How to Avoid Them Ricardo J. Rodr´ ıguez � All wrongs reversed rj.rodriguez@unileon.es ※ @RicardoJRdez ※ www.ricardojrodriguez.es Research Institute of Applied Sciences in Cybersecurity University of Le´ on, Spain April 28, 2015 Mundo Hacker Day 2015 Madrid (Espa˜ na)

  2. $ whoami Ph.D. on Comp. Sci. (Univ. of Zaragoza, Spain) (2013) Senior Researcher at University of Le´ on (Spain) R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 2 / 19

  3. $ whoami Ph.D. on Comp. Sci. (Univ. of Zaragoza, Spain) (2013) Senior Researcher at University of Le´ on (Spain) Performance and safety analysis on critical, complex systems Model-based security analysis Advanced malware analysis NFC security R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 2 / 19

  4. $ whoami Ph.D. on Comp. Sci. (Univ. of Zaragoza, Spain) (2013) Senior Researcher at University of Le´ on (Spain) Performance and safety analysis on critical, complex systems Model-based security analysis Advanced malware analysis NFC security Trainer at NcN, RootedCON, HIP Speaker at NcN, HackLU, RootedCON, STIC CCN-CERT, MalCON, HIP, HITB. . . R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 2 / 19

  5. What is a BOF? (I) void readName () { char username [256]; printf("Username: "); scanf("%s", username ); } R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 3 / 19

  6. What is a BOF? (I) void copyBuffers (char *org, char *dst) void readName () { { char buffer [5000]; char username [256]; strcpy(buffer , org ); printf("Username: "); // Do some stuff into your buffer scanf("%s", username ); strcpy(dst , buffer); } } R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 3 / 19

  7. What is a BOF? (I) void copyBuffers (char *org, char *dst) void readName () { { char buffer [5000]; char username [256]; strcpy(buffer , org ); printf("Username: "); // Do some stuff into your buffer scanf("%s", username ); strcpy(dst , buffer); } } Buffer Overflow (BOF) Memory zone overflow R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 3 / 19

  8. What is a BOF? (I) void copyBuffers (char *org, char *dst) void readName () { { char buffer [5000]; char username [256]; strcpy(buffer , org ); printf("Username: "); // Do some stuff into your buffer scanf("%s", username ); strcpy(dst , buffer); } } Buffer Overflow (BOF) Memory zone overflow It has consequences: Arbitrary code execution Any code can be illegitimately forced to execute by an attacker (!) R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 3 / 19

  9. What is a BOF? (I) void copyBuffers (char *org, char *dst) void readName () { { char buffer [5000]; char username [256]; strcpy(buffer , org ); printf("Username: "); // Do some stuff into your buffer scanf("%s", username ); strcpy(dst , buffer); } } Buffer Overflow (BOF) Memory zone overflow It has consequences: Arbitrary code execution Any code can be illegitimately forced to execute by an attacker (!) Is it used? Common attack vector for malware R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 3 / 19

  10. What is a BOF? (II) Anything else? Causes DoS Application ends unexpectedly (it crashes) R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 4 / 19

  11. What is a BOF? (II) Anything else? Causes DoS Application ends unexpectedly (it crashes) Wikipedia definition (overflow): “a buffer overflow, or buffer overrun, is an anomaly where a program, while writing data to a buffer, overruns the buffer’s boundary and overwrites adjacent memory. This is a special case of violation of memory safety’ ’ Problem trending is growing R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 4 / 19

  12. What is a buffer overflow BOF? (III) (Image source: www.cvedetails.com , date from 1999 to 2015) R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 5 / 19

  13. What is a BOF? (IV) (Image source: www.cvedetails.com , date from 1999 to 2015) R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 6 / 19

  14. What is a BOF? (V) Overflow types Stack-based BOF CPU stack: Local variables storage, procedure parameters. . . Control-flow execution data Return addresses Exception handlers R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 7 / 19

  15. What is a BOF? (V) Overflow types Stack-based BOF CPU stack: Local variables storage, procedure parameters. . . Control-flow execution data Return addresses Exception handlers Consequences: Control-flow hijacking → an attacker controls what is going to be executed R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 7 / 19

  16. What is a BOF? (V) Overflow types Stack-based BOF CPU stack: Local variables storage, procedure parameters. . . Control-flow execution data Return addresses Exception handlers Consequences: Control-flow hijacking → an attacker controls what is going to be executed Heap-based BOF Overwriting of allocated memory ( malloc , allocate ) R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 7 / 19

  17. What is a BOF? (V) Overflow types Stack-based BOF CPU stack: Local variables storage, procedure parameters. . . Control-flow execution data Return addresses Exception handlers Consequences: Control-flow hijacking → an attacker controls what is going to be executed Heap-based BOF Overwriting of allocated memory ( malloc , allocate ) Consequences: Memory corruption, code execution . . . R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 7 / 19

  18. What is a BOF? (VI) Overflow types . . . Off-by-one A loop takes ( n − 1) steps instead of n steps Consequences: Control-flow register may be rewritten (1 byte) R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 8 / 19

  19. What is a BOF? (VI) Overflow types . . . Off-by-one A loop takes ( n − 1) steps instead of n steps Consequences: Control-flow register may be rewritten (1 byte) Buffer Overrun Bottleneck on memory blocks when using CD/DVD writers Buffer overflow → data is corrupted → CD/DVD useless R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 8 / 19

  20. What is a BOF? (VI) Overflow types . . . Off-by-one A loop takes ( n − 1) steps instead of n steps Consequences: Control-flow register may be rewritten (1 byte) Buffer Overrun Bottleneck on memory blocks when using CD/DVD writers Buffer overflow → data is corrupted → CD/DVD useless Integer OF R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 8 / 19

  21. What is a BOF? (VI) Overflow types . . . Off-by-one A loop takes ( n − 1) steps instead of n steps Consequences: Control-flow register may be rewritten (1 byte) Buffer Overrun Bottleneck on memory blocks when using CD/DVD writers Buffer overflow → data is corrupted → CD/DVD useless Integer OF In this talk, we focus on Stack-based BOF R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 8 / 19

  22. What is a BOF? (VII) char A[8]; unsigned short B; Variable A: 8B (1 char → 1B) Variable B: 2B No initialized R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 9 / 19

  23. What is a BOF? (VII) char A[8]; unsigned short B; Variable A: 8B (1 char → 1B) Variable B: 2B No initialized R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 9 / 19

  24. What is a BOF? (VII) char A[8]; unsigned short B; Variable A: 8B (1 char → 1B) Variable B: 2B No initialized Let’s copy a string to A. . . strcpy(A, "cadena"); R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 9 / 19

  25. What is a BOF? (VII) What is the memory content? char A[8]; unsigned short B; Variable A: 8B (1 char → 1B) Variable B: 2B No initialized Let’s copy a string to A. . . strcpy(A, "cadena"); R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 9 / 19

  26. What is a BOF? (VII) What is the memory content? char A[8]; unsigned short B; Variable A: 8B (1 char → 1B) Variable B: 2B No initialized What if we copy a longer string? strcpy(A, " cadena larga"); Let’s copy a string to A. . . strcpy(A, "cadena"); R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 9 / 19

  27. What is a BOF? (VII) What is the memory content? char A[8]; unsigned short B; Variable A: 8B (1 char → 1B) Variable B: 2B No initialized What if we copy a longer string? strcpy(A, " cadena larga"); What is the memory content? Let’s copy a string to A. . . strcpy(A, "cadena"); R.J. Rodr´ ıguez (ULE) Buffer Overflows: What They Are, and How to Avoid Them MHD’15 9 / 19

Recommend


More recommend