Nightmare Course

repository·master·Indexed 25 days ago

https://github.com/guyinatuxedo/nightmare

An educational course on binary exploitation and reverse engineering using CTF challenges and write-ups. The course covers x86 and x64 assembly architecture, Intel syntax, register usage, stack management, and debugging with gdb-gef. It includes practical guides on disassembling binaries with objdump and identifying common assembly patterns such as loops and conditional logic.

Tokens
137.3K
Snippets
206
Records
500
Agent score
85%

What's inside Nightmare

  1. Overview of Nightmare course

    master
    Nightmare is a binary exploitation and reverse engineering course structured around CTF (Capture The Flag) challenges. It is designed to be a linear learning path with over 90 challenges, each accompanied by documented write-ups that explain the process from receiving a binary to developing a successful exploit. The course utilizes open-source tools to ensure accessibility.
  2. Overview of the 'auth' binary (picoCTF are you root)

    master

    The auth binary is a 64-bit ELF executable used for a heap grooming exploitation challenge. It features a command-line interface that manages user sessions and authorization levels.

    Security Protections:

    • Arch: amd64-64-little
    • RELRO: Partial RELRO
    • Stack: Canary found
    • NX: NX enabled
    • PIE: No PIE (0x400000)

    Available Commands:

    • show: Displays current user and authorization level.
    • login [name]: Logs in as the specified name.
    • set-auth [level]: Sets authorization level (must be < 5).
    • get-flag: Prints the flag (requires authorization level 5).
    • reset: Logs out and resets authorization level.
    • quit: Exits the program.
  3. Overview of hacklu 2015 stackstuff challenge

    master

    The stackstuff challenge is a binary exploitation task where the objective is to read the contents of the flag file. The target is a 64-bit ELF executable with the following security properties:

    • Architecture: amd64-64-little
    • RELRO: No RELRO
    • Stack: No canary found
    • NX: NX enabled
    • PIE: PIE enabled

    Note that while the binary does not produce immediate output upon execution, it binds to a network port (e.g., 1514) which can be identified using netstat.

    $ file stackstuff
    stackstuff: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=f46fbf9b159f6a1a31893faf7f771ca186a2ce8d, not stripped
    
    $ pwn checksec stackstuff
    [*] '/Hackery/pod/modules/partial_overwrite/hacklu15_stackstuff/stackstuff'
        Arch:     amd64-64-little
        RELRO:    No RELRO
        Stack:    No canary found
        NX:       NX enabled
        PIE:      PIE enabled
  4. Overview of Nightmare course objectives

    master

    Nightmare is a course focused on Binary Exploitation and Reverse Engineering using CTF (Capture The Flag) challenges.

    • Binary Exploitation: Leveraging bugs in compiled code to achieve unintended functionality, typically aiming for code execution.
    • Reverse Engineering: The process of analyzing a binary to understand its internal logic to facilitate exploitation.
    • Primary Objectives: Most challenges aim to either obtain a root shell (code execution) or retrieve a specific CTF flag from the binary.
  5. Understand Uninitialized Variable Bugs

    master

    An uninitialized variable is a variable that is declared but not assigned a value. In C, an uninitialized variable inherits the value of whatever was previously stored at that specific memory location.

    If a function declares and initializes a variable, and a subsequent function call uses the same memory address for a new (uninitialized) variable, the new variable will contain the old value. This behavior can be exploited in security contexts (e.g., during reads or comparisons) or can lead to unpredictable logic bugs.

    #include <stdio.h>
    
    void trashed(void)
    {
        int x = 0xfacade;
        printf("Integer 0 Declared at:\t%p\n", &x);
        printf("Integer 0 Value:\t\t0x%x\n\n", x);
    }
    
    void scatterd(void)
    {
    	int y;
        printf("Integer 1 Declared at:\t%p\n", &y);
        printf("Integer 1 Value:\t\t0x%x\n\n", y);
    
    	if (y == 0xfacade)
        {
            puts("Play your game, and walk away.\n");
        }
    }
    
    int main()
    {
        // ... execution flow ...
        trashed();
        scatterd();
    }
  6. Understand Assembly Architecture (x86 vs x64)

    master

    Assembly code is the low-level code executed directly by the processor. This guide focuses on Intel syntax.

    Key architectures covered:

    • x64 (64-bit ELF): The modern standard. Uses 8-byte registers and passes function arguments via registers.
    • x86 (32-bit ELF): Older standard. Uses 4-byte registers and passes function arguments onto the stack.

    To visualize high-level code (like C) as assembly, you can use a decompiler such as Ghidra.

  7. Analyze the popping_caps binary security mitigations

    master

    The popping_caps binary is an ELF 64-bit LSB shared object running on amd64. It uses libc 2.27 (Ubuntu GLIBC 2.27-3ubuntu1), which supports tcache.

    Security Mitigations:

    • RELRO: No RELRO
    • Stack: Canary found
    • NX: NX enabled
    • PIE: PIE enabled

    Key Features:

    • Provides a libc infoleak (address of system) upon startup.
    • Provides 7 total actions (malloc, free, write, or bye) before exiting.
    • The bye() function calls malloc(0x38) before exiting.
    $ pwn checksec popping_caps
    [*] '/Hackery/pod/modules/44-more_tcache/csaw19_popping_caps1/popping_caps'
        Arch:     amd64-64-little
        RELRO:    No RELRO
        Stack:    Canary found
        NX:       NX enabled
        PIE:      PIE enabled
    $ file popping_caps
    popping_caps: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=0b94b47318011a2516372524e7aaa0caeda06c79, not stripped
  8. H3 Machine Architecture Overview

    master

    The H3 Machine is a 16-bit stack machine with no general-purpose registers. It operates on 32-bit words and has 1 MiB of total memory (2^16 word-addressed 32-bit words).

    Special-Purpose Registers (16-bit):

    • IP: Instruction Pointer
    • SP: Stack Pointer
    • FR: Flag Register

    Flag Register (FR) Bits:

    • 0x0001: Zero flag (set when 0x00000000 is pushed; cleared otherwise).
    • 0x0002: Carry flag (set on arithmetic overflow; cleared otherwise).
    • 0x8000: Flag flag (set when the top value of the stack at HALT is considered the flag).

    Memory & Loading:

    • Memory is word-addressed (32-bit words).
    • Word 0x0000 should contain 0x00000000 by convention.
    • On load: IP is initialized to 0x0001, SP and FR to 0x0000.
  9. Analyze Seccon 2019 Quals Sum binary security properties

    master

    The sum binary is a 64-bit ELF executable with the following security configurations:

    • Arch: amd64-64-little
    • RELRO: Partial RELRO
    • Stack: Canary found
    • NX: NX enabled
    • PIE: No PIE (0x400000)

    It uses libc.so from Ubuntu GLIBC 2.27-3ubuntu1.

    Behavioral observation: The program accepts a sequence of integers. A 0 terminates the sequence. Inputting 6 integers causes a segmentation fault, suggesting a potential buffer overflow or stack corruption.

    $ pwn checksec sum_ccafa40ee6a5a675341787636292bf3c84d17264
    [*] '/home/guyinatuxedo/Desktop/seccon/sum/sum_ccafa40ee6a5a675341787636292bf3c84d17264'
        Arch:     amd64-64-little
        RELRO:    Partial RELRO
        Stack:    Canary found
        NX:       NX enabled
        PIE:      No PIE (0x400000)