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
  1. Buffers

ROP

Return Oriented Programming: Execute code already present in the program.

  • Each snippet is composed of some instructions + RET.

  • RET pops RIP from the stack.

Program flow is controlled by values in the stack.

  • The attacker puts values in a stack pointing to gadgets.

  • When a gadget ends, the code jumps to the next gadget.

Any program can be constructed as long as there are gadgets available.

  • When Good Instructions Go Bad: Generalizing Return-Oriented Programming to RISC [1] - Buchanan, E.; Roemer, R.; Shacham, H.; Savage, S.

  • Return-Oriented Programming: Exploits Without Code Injection [2] - Shacham, Hovav; Buchanan, Erik; Roemer, Ryan; Savage, Stefan.

ROP Attacks: Chain gadgets to execute malicious code.

A gadget is a suite of instructions that end by the branch instruction ret (Intel) or the equivalent on ARM.

  • Intel examples:

    • pop eax ; ret xor ebx, ebx ; ret

  • ARM examples:

    • pop {r4, pc} str r1, [r0] ; bx lr

Objective: Use gadgets instead of classical shellcodes.

Because x86 instructions aren't aligned, a gadget can contain another gadget.

f7c7070000000f9545c3 → test edi, 0x7 ; setnz byte ptr [rbp-0x3d] ;
  c7070000000f9545c3 → mov dword ptr [rdi], 0xf000000 ; xchg ebp, eax ; ret

Doesn't work on RISC architectures like ARM, MIPS, SPARC...

Using ROP, the stack is subverted to create a jump sequence. It contains:

  • Values to be loaded;

  • Addresses to other gadgets;

  • May also contain arguments to functions called.

Gadgets are present in program code and loaded libraries.

  • Each function available provides one gadget;

  • Plus misaligned access.

Why?

  • It can bypass several security mechanisms.

Practical Example: return_to_libc.c (x86_64)

Payload strategy:

  • All addresses are 8 bytes;

  • Buffer: padding with 16 bytes (buffer + RBP);

  • Gadget address: ?? -> rop --search “pop rdi; ret”

    • pop RDI: load command address into RDI;

    • ret: load system address into RIP;

  • Command address: ?? -> grep /bin/sh

    • Approaches: Find a string already in RAM (better); add the payload after the system address (if required);

  • System address: ?? -> print system

Last updated 1 year ago