Notes - MCS
Analysis and Exploration of Vulnerabilities
Notes - MCS
Analysis and Exploration of Vulnerabilities
  • Analysis and Exploration of Vulnerabilities
  • Vulnerabilities
    • Vulnerabilities
      • CIA Triad
      • Vulnerability Sources
    • Vulnerability Tracking
    • Vulnerability Disclosure
  • Vulnerability Assessment of Networked Systems
    • Vulnerability Research
    • Vulnerability Assessment
    • Penetration Test
      • Scope
    • Types of Assessments
    • Vulnerability Management Life Cycle
  • Enumeration and Information Leakage
    • Network access
    • Information leakage
    • Errors
    • Web Sources and Support Files
    • Cookies
    • Ports
    • Banners
    • OS Fingerprinting
  • Injection
    • CWE-74
    • How it works
    • Common Pitfalls
    • CWE-89 SQL Injection
    • Using SQL
    • Things to consider
    • The NULL plate
    • SQLi types
    • SQL Injection - Avoiding
    • CWE-78 OS Command Injection
    • Command Override
    • Argument Exploitation
    • GTFOBins and LOLBAS
    • Environmental Variables
    • Parameter Expansion
    • Code Injection - CWE-94
    • Avoiding OS Injection
  • Broken Authentication
    • OWASP A2
    • HTTP Basics
    • HTTP Communication
    • Authentication
    • Authentication Flow State
    • Referer Header
    • SESSION ID
    • Cookies (RFC 6265)
    • JWT - JSON Web Tokens
  • XSS Cross Site Scripting
    • Prevalence and Detectability
    • Reflected XSS
    • Stored XSS
    • DOM XSS
    • Cross Site Request Forgery
    • Avoiding XSS
    • Same Origin Policy
  • Concurrency
    • Concurrency
    • CWE-361 - 7PK - Time and State
    • Basic Time Related CWEs
      • CWE-362 – Race Condition
    • Serializability
    • Database ACID characteristic
    • State Related CWEs
    • Basic Side Effects Related CWEs (Covert Channel)
    • Covert Timing Channel
    • Meltdown Type
  • Buffers
    • Buffer Overflow
    • Popularity decline
    • Potentially Vulnerable Software
    • Dominant prevalence
    • Vulnerabilities in languages (mostly C/C++)
    • Why? Memory Structure 101
    • CWE-120 Classic Overflow
      • Practical Examples
    • Stack Based Vulnerabilities
    • Stack Smashing
    • Countermeasures
    • ROP
Powered by GitBook
On this page
  • Practical Example: program_flow.c
  • Practical Example: return_to_libc.c
  1. Buffers

Stack Smashing

A stack smashing attack is a specific type of security exploit that takes advantage of a buffer overflow vulnerability in a program to compromise its integrity and potentially execute arbitrary code.

What about writing the correct values to the stack?

  • Some value to RBP.

  • An address belonging to the process in RIP.

When the message ends the flow will be restored.

  • That is, stored RBP and stored RIP are loaded into the registers.

  • The stack frame will start at RBP.

  • Program jump to the address in RIP.

If the addresses aren't in a mapped area, the program will receive a SIGSEV.

Practical Example: program_flow.c

void secret(){
    printf("Secret message\n");
    exit(0);
}
char foo(int size, char* arg){
    char buffer[8];
    memcpy(buffer, arg, size);
    return buffer[0];
}
int main(int argc, char* argv[]){
    char buffer[64];
    printf("%p\n", &secret);
    
    FILE *fp = fopen(argv[1], "r");
    int size = fread(buffer, 1, 64, fp);
    fclose(fp);
    
    foo(size, buffer);
    return 0;
}

Flow:

  • Reads data from file;

  • Calls foo function with size and buffer;

  • foo has an overflowing memcpy.

  • secret function is never called.

Attack: Overflow the buffer:

  • writing over stored $RBP.

  • writing over stored $RIP, placing &secret there.

Consider ASLR to be disabled.

Attack strategy:

  • Overwrite buffer over RBP/RIP

How to find the addresses?

  • If we have the source code: printf("%p\n", secret)

  • If we don't: gdb or bruteforce.

Practical Example: return_to_libc.c

Instead of returning to a program function, it is possible to jump to other locations.

  • In theory, to any segment that is allocated to the program.

  • In practice, permission mechanisms limit the available segments.

Segments for libraries have several generic libraries.

  • In particular: system().

  • Is mostly executable.

The stack can be executable, but it isn't on recent systems.

Return to libc

  • Build “fake” Stack frame and call system() with one argument.

    • The argument is the command to execute (e.g. a reverse shell).

  • Must take into consideration calling convention.

    • Which is architecture-dependent.

Arguments are passed in the stack.

  • Approach: store values to the stack so that the system is called with a payload.

    • Then call the system.

Last updated 1 year ago

Typical Flow