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
  • Data Executable Prevention
  • Canaries
  • Practical Example: return_to_libc.c (x86_64)
  1. Buffers

Countermeasures

Last updated 1 year ago

Data Executable Prevention

Non-Executable Stack (NX) (Data Executable Prevention)

  • Most binaries do not allow running code from Stack.

  • Stack segments are marked as Non-Executable (NX bit).

    • Code cannot jump to it.

    • Return to lib-c attack not possible.

Introduced in recent OS, but can be disabled.

  • Not ubiquitous on embedded devices.

  • Binaries must opt-in!

Canaries

Uses reference values after local variables to detect overflow.

  • Value is placed when the function starts.

  • Value is compared before the function exits.

  • The program is interrupted if values do not match.

We can guess them, using brute force.

  • -fno-stack-protector: disables stack protection. (What we have been using)

  • -fstack-protector: enables stack protection for vulnerable functions that contain.

    • A character array larger than 8 bytes.

    • An 8-bit integer array larger than 8 bytes.

    • A call to alloca() with either a variable size or a constant size bigger than 8 bytes.

  • -fstack-protector-strong: enables stack protection for vulnerable functions that contain.

    • An array of any size and type.

    • A call to alloca().

    • A local variable that has its address taken.

  • -fstack-protector-all: adds stack protection to all functions regardless of their vulnerability.

Practical Example: return_to_libc.c (x86_64)

x64 - first arguments are passed in register: RDI, RSI, RDX, RCX.

  • Approach: load RDI with an address of a string, and jump to the system address.

  • Problems: cannot jump to stack (due to NX).

Improved:

  • Search for any code that loads RDI from the stack.

    • we can control what is in the stack but we cannot execute code from it.

  • Jump to code that loads RDI from the stack.

  • Jump to the system.