NullSector

Welcome to the beginning of your hacking journey. Before you can break into systems, exploit vulnerabilities, or write malicious code, you need to understand what you're actually attacking. This isn't optional knowledgeโ€”it's the foundation everything else is built on.

This chapter will teach you how computers actually work. Not the simplified version you learned in school, but the real, technical truth. By the end, you'll understand computers better than 95% of people using them every day.

Why This Matters for Hacking

Every hack exploits some fundamental aspect of how computers work. Buffer overflows exploit memory management. Code injection exploits how CPUs execute instructions. Privilege escalation exploits operating system design. If you don't understand the fundamentals, you're just copying code without knowing why it works.

What is a Computer? (The Real Answer)

Let's start with the most basic question: What actually is a computer? The answer is simpler than you think, but understanding it deeply will change how you see every digital device around you.

A computer is a machine that follows instructions. That's it. It doesn't "think," it doesn't "understand," and it has no intelligence whatsoever. It's a very fast, very obedient machine that does exactly what you tell it to do.

The Key Insight

Computers are deterministic machines. Given the same input and the same instructions, they will ALWAYS produce the same output. Always. This predictability is both their greatest strength and their biggest vulnerability.

When you "hack" a computer, you're not outsmarting an intelligent opponent. You're finding ways to give it instructions it wasn't supposed to receive, or making it misinterpret the instructions it has.

The Four Fundamental Parts

Every computerโ€”from your phone to a supercomputerโ€”has exactly four fundamental components. Understanding these is critical because every attack targets one or more of them.

1. Input

What it is: Any way information enters the computer.

Examples: Keyboard, mouse, microphone, camera, network interface, USB devices, sensors, touchscreen.

Why hackers care: Input is where attacks begin. If you can control what data enters a system, you can often control the system itself. SQL injection, XSS, buffer overflowsโ€”they all start with malicious input.

2. Processing (CPU)

What it is: The "brain" that executes instructions.

What it does: Math, logic, comparisons, moving data around. Despite being called a "brain," it's actually incredibly dumbโ€”it just does these simple operations extremely fast (billions per second).

Why hackers care: The CPU doesn't care if instructions are legitimate or malicious. If you can inject your code into memory and make the CPU execute it, you own the system.

3. Storage/Memory

Two types:

โ€ข RAM: Fast, temporary, volatile (clears when power off)

โ€ข Disk: Slower, permanent, persistent

Why hackers care: Most attacks target RAM because that's where programs are actively running. Buffer overflows, heap exploits, code injectionโ€”these all manipulate memory.

4. Output

What it is: Any way information leaves the computer.

Examples: Monitor, speakers, printer, network connection, LED lights.

Why hackers care: Output can leak sensitive data. Screen capture malware, network sniffing, keyloggersโ€”they intercept output. Even electromagnetic emissions can be captured (TEMPEST attacks).

How These Parts Work Together

Let's trace what happens when you do something simple, like pressing a key on your keyboard. Understanding this flow is crucial because exploits interrupt or manipulate this process.

Real Example: You press the "A" key 1. INPUT: Your finger presses the physical key - Two metal contacts touch, completing a circuit - Keyboard's microcontroller detects the circuit closure - Converts key position to a "scan code" (0x1E for "A") 2. INPUT โ†’ PROCESSING: Data travels to the CPU - Scan code sent over USB cable (or wireless) - Arrives at computer's USB controller - Generates an interrupt (special signal to CPU) - CPU stops what it's doing and handles the keyboard event 3. PROCESSING: CPU processes the input - Reads scan code from USB controller - Checks: Is Shift pressed? Caps Lock on? - Converts scan code to ASCII (65 for uppercase "A") - Tells the active program "user pressed A" 4. PROCESSING โ†’ STORAGE: Character stored - If you're typing in a text editor, "A" goes into RAM - Specifically, into the text buffer for that document - Memory address might be something like 0x7FFE2A40 5. STORAGE โ†’ OUTPUT: Result displayed - Text editor tells graphics system to draw "A" - Graphics card reads font data from memory - Renders pixels to display the letter - You see "A" appear on screen Total time: About 10-50 milliseconds (1/100th of a second)

The Hacker's Perspective

Every step in that process is a potential attack vector:

  • Input stage: USB Rubber Ducky attacks inject malicious keystrokes
  • Processing stage: Kernel exploits hijack interrupt handlers
  • Storage stage: Buffer overflows corrupt memory
  • Output stage: Screen capture malware steals display data

Understanding Scale: How Fast is "Fast"?

When we say computers are "fast," most people don't grasp the actual scale. Let's put it in perspective with real numbers.

Action Time What the CPU Does in That Time
You blink 300 milliseconds 1.05 billion instructions (3.5 GHz CPU)
You snap your fingers 150 milliseconds 525 million instructions
You say "hello" 500 milliseconds 1.75 billion instructions
Heart beats once 1 second 3.5 billion instructions
Access RAM 100 nanoseconds 350 instructions
Access SSD 100 microseconds 350,000 instructions
Access HDD 10 milliseconds 35 million instructions

To put this in human terms: If one CPU instruction took 1 second, then accessing RAM would take 4 months, accessing an SSD would take 3 years, and accessing a hard drive would take 317 years. This speed difference is why understanding memory hierarchy matters.

The Restaurant Metaphor

Think of your computer like a restaurant kitchen:

  • CPU = The Chef: Fast, skilled, but can only work on one dish at a time (per core)
  • RAM = The Counter Space: Right next to the chef, holds ingredients for current orders
  • SSD = The Refrigerator: In the same room, takes a few seconds to walk to and grab ingredients
  • HDD = The Storage Room: Down the hallway, takes much longer to retrieve items
  • Internet = The Grocery Store: Across town, could take minutes or hours to get what you need

A good chef (CPU) keeps everything they need on the counter (RAM) so they don't waste time walking to the fridge (SSD) or storage room (HDD). That's why programs copy data from disk into RAM before using it!

Real-World Example: Opening a File

Let's walk through what happens when you open a document. I'll show you EVERY step, like explaining to someone who's never used a computer before.

๐Ÿ“„ Opening "homework.docx" - The Complete Journey
// You double-click homework.docx STEP 1: Mouse Click Detection - Your finger presses mouse button - Mouse sensor detects button press - Sends signal through USB cable - Computer receives: "Left click at coordinates (450, 320)" - OS checks: "What's at position (450, 320)?" - Answer: "homework.docx icon" STEP 2: Operating System Takes Control - OS looks up file information - Reads file metadata from disk: * File name: homework.docx * File size: 2,456,789 bytes (about 2.4 MB) * Location on disk: Sector 45,678 of Drive C: * File type: .docx (Microsoft Word document) - OS checks: "What program opens .docx files?" - Answer: "Microsoft Word (WINWORD.EXE)" STEP 3: Loading Microsoft Word (if not already running) - OS finds WINWORD.EXE on disk - File location: C:\Program Files\Microsoft Office\Word.exe - File size: ~150 MB - OS creates a new process (gives it memory space) - Copies Word's code from SSD into RAM * Time taken: ~500 milliseconds * 1.75 billion CPU instructions executed during this time - Word is now "running" (exists in RAM, CPU executing its code) STEP 4: Word Requests the Document - Word asks OS: "Please load homework.docx" - OS reads file from SSD: * Finds file at Sector 45,678 * Reads 2,456,789 bytes * Time taken: ~50 milliseconds - Copies all bytes into RAM - Memory address: 0x7FFE5000 (example) STEP 5: Word Processes the Document - Word reads bytes from RAM (not from disk anymore!) - Interprets .docx format (it's actually a ZIP file containing XML) - Extracts text, formatting, images - Converts to internal representation - All happening in RAM, very fast STEP 6: Displaying on Screen - Word tells graphics system: "Draw this text here, that image there" - Graphics card reads font files from RAM - Renders pixels (tiny dots that make up your screen) - Sends pixel data to monitor through cable - You see your document appear! TOTAL TIME: About 1-2 seconds (mostly loading Word) // Key Insight: After loading, everything happens in RAM. // The file on disk never changes unless you click "Save" // All your edits happen in RAM first, then get written back to disk
๐ŸŽฏ HANDS-ON EXERCISE: See This Yourself!

Try this on your own computer right now:

  1. Open Task Manager (Ctrl+Shift+Esc on Windows, Activity Monitor on Mac)
  2. Look at the "Performance" tab - you'll see RAM usage
  3. Note current RAM usage - let's say it's 4.2 GB
  4. Open a large program (Chrome, Photoshop, a game)
  5. Watch RAM usage jump up - maybe to 6.5 GB
  6. Close the program
  7. Watch RAM usage drop back down

You just witnessed programs being loaded into RAM and removed from RAM! The program files on your disk didn't change at allโ€”they're still there. But the active, running copy in RAM was created and destroyed.

How CPUs Actually Work

The CPU is called the "brain" of the computer, but that's misleading. It's not intelligent. It's a very fast calculator that follows instructions blindly. Understanding exactly how it works is critical for exploitation.

The Fetch-Execute Cycle

Every CPU in the world does the same basic process, billions of times per second. This cycle is so fundamental that if you understand it, you understand how all programs run.

// The Fetch-Execute Cycle (4 Steps): 1. FETCH // CPU reads the instruction pointer (IP/PC register) // This register holds a memory address instructionPointer = 0x00401000 // Example address instruction = readFromRAM(instructionPointer) // Gets instruction bytes from that address 2. DECODE // CPU's control unit interprets the instruction bytes // Determines what operation to perform bytes = "48 89 E5" // Example: Move RSP to RBP (x86-64) operation = decode(bytes) // Identifies which data/registers are needed 3. EXECUTE // CPU performs the actual operation if (operation == "ADD") -> performAddition() if (operation == "MOVE") -> moveData() if (operation == "JUMP") -> changeInstructionPointer() // Math, logic, data movement, or control flow 4. STORE // Write result back to memory or register writeResult(destination, result) instructionPointer += instructionSize // Move to next instruction updateFlags(zero, carry, overflow) // Then repeat. Forever. Until power off. while (computerIsOn) { fetch() decode() execute() store() }

The Recipe Metaphor

Imagine you're following a recipe to bake a cake. The fetch-execute cycle works exactly like this:

  • FETCH: Read the next line of the recipe ("Add 2 cups of flour")
  • DECODE: Understand what it means (need flour, need measuring cup, need mixing bowl)
  • EXECUTE: Actually do it (measure 2 cups, pour into bowl)
  • STORE: Update your state (bowl now has flour in it, move to next recipe line)

The CPU is like you following this recipe, but instead of baking a cake, it's executing program instructions. And instead of doing one step per minute, it does 3.5 BILLION steps per second!

Let's trace a real example with actual assembly code:

// Example: Calculate (5 + 3) and store result // Assembly Code: MOV EAX, 5 ; Move 5 into register EAX ADD EAX, 3 ; Add 3 to EAX MOV [result], EAX ; Store EAX to memory address "result" // Step-by-step execution: Instruction 1: MOV EAX, 5 FETCH: CPU reads instruction from memory (address 0x00401000) DECODE: "MOV register, immediate value" EXECUTE: Copy value 5 into EAX register STORE: EAX now contains 5, IP = 0x00401003 Instruction 2: ADD EAX, 3 FETCH: CPU reads instruction from memory (address 0x00401003) DECODE: "ADD register, immediate value" EXECUTE: ALU adds 3 to EAX (5 + 3 = 8) STORE: EAX now contains 8, IP = 0x00401006 Instruction 3: MOV [result], EAX FETCH: CPU reads instruction from memory (address 0x00401006) DECODE: "MOV memory address, register" EXECUTE: Copy EAX value to memory STORE: Memory address "result" now contains 8, IP = 0x0040100A // Total time on 3.5 GHz CPU: About 3 nanoseconds
๐Ÿงฎ Let's Make This SUPER Clear - Adding Two Numbers

Imagine you're a first-grader and I ask you to add 5 + 3. Here's what your brain does:

  1. Read the problem: "5 + 3" (FETCH)
  2. Understand it: "Oh, I need to add two numbers" (DECODE)
  3. Do the math: "5... 6, 7, 8!" (EXECUTE)
  4. Write the answer: "8" on your paper (STORE)

That's EXACTLY what the CPU does! Except:

  • Instead of reading from paper, it reads from RAM
  • Instead of writing on paper, it writes to RAM or registers
  • Instead of taking 10 seconds, it takes 0.000000003 seconds (3 nanoseconds)

What is GHz? Why Does CPU Speed Matter?

You've seen specs like "3.5 GHz" or "4.2 GHz" when looking at CPUs. Here's what that actually means and why it's important for performance and security.

Understanding CPU Speed

Hz (Hertz): One cycle per second

MHz (Megahertz): One million cycles per second

GHz (Gigahertz): One billion cycles per second

A 3.5 GHz CPU completes 3.5 billion clock cycles every second. In most cases, one instruction takes one cycle, so that's roughly 3.5 billion instructions per second.

But modern CPUs are more complex. They use techniques like:

This complexity creates vulnerabilities. Spectre and Meltdown (famous CPU attacks from 2018) exploited speculative execution and branch prediction to leak secret data from memory.

Why This Matters for Hacking

The CPU is blind to code origin. It cannot tell the difference between:

  • Legitimate program code written by developers
  • Malicious shellcode injected by an attacker
  • Data that looks like code due to memory corruption

If you can place your instructions in memory and redirect the instruction pointer to them, the CPU will execute them. That's code executionโ€”the ultimate goal of many exploits.

CPU Registers: The Fastest Memory

CPUs have tiny, ultra-fast storage locations called registers. These are even faster than RAM and sit directly inside the CPU. Understanding registers is essential for reading assembly code and understanding exploits.

// Common x86-64 Registers (64-bit): General Purpose Registers (store data, do math): RAX - Accumulator (often holds return values) RBX - Base register RCX - Counter register (used in loops) RDX - Data register RSI - Source index (string/memory operations) RDI - Destination index (string/memory operations) R8-R15 - Additional general registers (x86-64 only) Special Purpose Registers: RIP - Instruction Pointer (address of next instruction) RSP - Stack Pointer (top of the stack) RBP - Base Pointer (bottom of current stack frame) RFLAGS - Status flags (zero, carry, overflow, etc.) // Why hackers care: // - Buffer overflows aim to overwrite RIP to hijack control // - Stack overflows corrupt RBP and RSP to crash or exploit // - Return-oriented programming chains gadgets using RAX, RDI, etc.

The Pocket Metaphor

Think of registers as the CPU's pockets. Imagine you're doing homework:

  • Your pockets (registers): Hold your pen, eraser, maybe a calculator - things you need RIGHT NOW
  • Your desk (RAM): Holds your textbook, notebook, papers - things you're actively using
  • Your backpack (SSD/HDD): Holds everything else - old homework, other books

Reaching into your pocket (register) is instant. Reaching across your desk (RAM) takes a moment. Opening your backpack (storage) takes much longer. The CPU works the same way!

๐ŸŽฎ INTERACTIVE EXAMPLE: Register Usage in a Loop

Let's say we want to add up numbers from 1 to 5. Here's how registers are used:

// High-level code: int sum = 0; for (int i = 1; i <= 5; i++) { sum += i; } // What the CPU actually does (assembly): MOV RAX, 0 ; RAX = sum (starts at 0) MOV RCX, 1 ; RCX = i (counter starts at 1) loop_start: ADD RAX, RCX ; sum = sum + i INC RCX ; i++ (increment counter) CMP RCX, 5 ; Compare i with 5 JLE loop_start ; If i <= 5, jump back to loop_start // Final result: RAX contains 15 (1+2+3+4+5) // Let's trace it step by step: Iteration 1: RAX=0, RCX=1 โ†’ RAX += 1 โ†’ RAX=1, RCX=2 Iteration 2: RAX=1, RCX=2 โ†’ RAX += 2 โ†’ RAX=3, RCX=3 Iteration 3: RAX=3, RCX=3 โ†’ RAX += 3 โ†’ RAX=6, RCX=4 Iteration 4: RAX=6, RCX=4 โ†’ RAX += 4 โ†’ RAX=10, RCX=5 Iteration 5: RAX=10, RCX=5 โ†’ RAX += 5 โ†’ RAX=15, RCX=6 Loop exits: RCX > 5, so we stop // Total instructions executed: about 30 // Total time on 3.5 GHz CPU: about 8 nanoseconds

This is what EVERY for-loop becomes when your code runs. The CPU uses registers to keep track of everything - the sum, the counter, the limit. It's all just numbers being moved around and compared!

Memory Architecture: RAM vs Storage

This is where most confusion happens. People mix up RAM and storage constantly. Understanding the difference is absolutely critical for hacking because most exploits target memory (RAM), not storage.

The Fundamental Difference

Let's use an analogy that actually makes sense:

RAM = Your Desk Surface

Imagine your desk where you're working right now. The papers and tools you have spread out are like RAM:

  • Fast access: Just reach out and grab what you need
  • Limited space: Desk only holds so much
  • Temporary: Clear the desk at end of day
  • Active work: What you're using RIGHT NOW

When you need a new document, you pull it from the filing cabinet (storage) and put it on your desk (RAM).

Storage = Your Filing Cabinet

The filing cabinet next to your desk is like storage (HDD/SSD):

  • Slow access: Get up, walk over, find folder, pull it out
  • Massive space: Can hold thousands of documents
  • Permanent: Files stay even when you go home
  • Long-term storage: Everything you MIGHT need later

Files stay in the cabinet until you need them. Then you copy them to your desk to work with them.

Now let's look at the technical reality:

Property RAM SSD HDD
Speed ~100 nanoseconds ~100 microseconds (1000ร— slower) ~10 milliseconds (100,000ร— slower)
Typical Size 8-64 GB 256 GB - 4 TB 500 GB - 20 TB
Persistence Volatile (clears when power off) Non-volatile (permanent) Non-volatile (permanent)
Purpose Running programs Storing files Storing files
Technology Electronic (transistors) Electronic (flash memory) Mechanical (spinning disk)
Attack Surface Buffer overflows, code injection, memory leaks Rootkits, hidden files, data recovery Same as SSD + slower

Process Memory Layout

When a program runs, its memory is organized in a very specific way. This layout is the same for (almost) every program on (almost) every operating system. Understanding it is mandatory for exploitation.

Virtual Memory Layout (Typical 64-bit Process) HIGH MEMORY (0xFFFFFFFFFFFFFFFF) โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ KERNEL SPACE โ”‚ โ† OS lives here (user can't access) โ”‚ (Operating System Memory) โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค 0x7FFFFFFFFFFF (user space limit) โ”‚ โ”‚ โ”‚ STACK โ”‚ โ† Grows DOWN (toward lower addresses) โ”‚ [Function Calls] โ”‚ Local variables, return addresses โ”‚ [Local Variables] โ”‚ Function parameters โ”‚ | โ”‚ Each function call adds a "frame" โ”‚ | โ”‚ โ”‚ โ†“ โ”‚ Size: typically 1-8 MB โ”‚ โ”‚ Limited by OS (stack overflow if exceeded) โ”‚ โ”‚ โ”‚ (Unused Memory) โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ†‘ โ”‚ โ”‚ | โ”‚ โ”‚ | โ”‚ โ”‚ HEAP โ”‚ โ† Grows UP (toward higher addresses) โ”‚ [Dynamic Allocations] โ”‚ malloc(), new, calloc() โ”‚ [Objects/Arrays] โ”‚ Must manually free (memory leaks if not) โ”‚ โ”‚ Size: limited by available RAM โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ .bss โ”‚ โ† Uninitialized global/static vars โ”‚ (Zeroed Memory) โ”‚ Automatically initialized to 0 โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ .data โ”‚ โ† Initialized global/static vars โ”‚ (Read/Write Data) โ”‚ Has actual values at program start โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ .rodata โ”‚ โ† Read-only data โ”‚ (Constants, Strings) โ”‚ String literals, const variables โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ .text โ”‚ โ† Program code (executable) โ”‚ (Machine Code) โ”‚ READ-ONLY, EXECUTABLE โ”‚ โ”‚ Contains actual CPU instructions โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ LOW MEMORY (0x0000000000000000)

Attack Vectors by Memory Region

Stack attacks:

  • Buffer overflow: Write past array bounds, corrupt return address
  • Stack canary bypass: Defeat protection mechanisms
  • Format string: Use printf() bugs to read/write stack

Heap attacks:

  • Heap overflow: Corrupt heap metadata or adjacent allocations
  • Use-after-free: Access memory after it's been freed
  • Double-free: Free same memory twice, corrupt heap state

Code section attacks:

  • Return-oriented programming (ROP): Chain existing code snippets
  • Code cave injection: Find unused space in .text to hide code

Stack vs Heap: The Critical Difference

These two memory regions are used for different purposes and have completely different characteristics. Understanding both is essential. Let me explain this like you're 5 years old, then we'll get technical.

The Lego Metaphor (For Complete Beginners)

THE STACK = Building a Tower of Lego Blocks

  • You can only add blocks to the top (PUSH)
  • You can only remove blocks from the top (POP)
  • Very organized, very fast
  • Limited height (you'll run out of blocks)
  • Automatic: when you're done with a block, it goes back automatically

THE HEAP = A Messy Toy Box

  • You can put toys anywhere in the box
  • You can take toys out from anywhere
  • More flexible, but slower to find things
  • Much bigger box (more space)
  • Manual: YOU must remember to put toys back, or the box gets cluttered forever

The Stack (Technical Reality)

Purpose: Function calls and local variables

How it works:

  • Last-In-First-Out (LIFO) structure
  • Automatic memory management
  • Very fast (just pointer arithmetic)
  • Fixed size (typically 1-8 MB)
  • Grows downward in memory

What's stored:

  • Return addresses (where to go after function ends)
  • Function parameters
  • Local variables
  • Saved register values

Lifetime: Variables die when function returns

The Heap (Technical Reality)

Purpose: Dynamic memory allocation

How it works:

  • Random access structure
  • Manual memory management (you must free)
  • Slower (complex allocation algorithms)
  • Large size (limited by available RAM)
  • Grows upward in memory

What's stored:

  • Objects created with new/malloc
  • Large arrays or data structures
  • Data that must outlive function calls
  • Dynamically sized collections

Lifetime: Until you explicitly free it

Here's a code example showing both:

Example in C: void functionExample() { // STACK allocations (automatic): int localVar = 42; // Dies when function returns char buffer[100]; // Dies when function returns int* pointer; // Pointer itself is on stack // HEAP allocation (manual): pointer = malloc(1000); // 1000 bytes allocated on heap // Must call free(pointer) later! // pointer itself is on stack (dies when function returns) // but the memory it points to is on heap (stays until freed) strcpy(buffer, "Hello"); // Writes to stack strcpy(pointer, "World"); // Writes to heap // If we return without free(pointer), MEMORY LEAK! free(pointer); // Manually free heap memory } Stack Frame for functionExample(): [Return Address] โ† Where to jump when function ends [Saved Base Pointer] โ† Previous stack frame [localVar = 42] โ† 4 bytes [buffer[100]] โ† 100 bytes [pointer] โ† 8 bytes (64-bit address) Heap allocation: 0x01234000: [1000 bytes] โ† malloc returned this address What happens on return: - Stack frame destroyed (all local variables gone) - Heap memory still exists (at 0x01234000) - If we forgot free(), memory leaks forever!

Binary & Hexadecimal: The Language of Computers

Computers don't understand numbers the way humans do. They only understand electricity: ON or OFF. This creates a binary (base-2) system that's fundamental to everything in computing.

Why Binary?

At the physical level, computers use transistorsโ€”tiny switches that are either ON (1) or OFF (0). That's it. You can't have a transistor that's "kinda on" or "70% on." It's digital: binary.

Every piece of data in a computerโ€”numbers, text, images, videos, programsโ€”is ultimately represented as a sequence of 1s and 0s.

Understanding Bits and Bytes

Bit: A single binary digit (0 or 1). The smallest unit of data.

Byte: 8 bits grouped together. Can represent 256 different values (0-255).

Why 8? Historical reasons, but also practical: 8 bits is enough to represent all letters, numbers, and symbols (ASCII uses 7-8 bits per character).

Counting in Binary

Humans use base-10 (decimal) because we have 10 fingers. Computers use base-2 (binary) because they have 2 states. Let's see how counting works:

Decimal Binary Explanation
0 0000 All switches OFF
1 0001 Rightmost switch ON
2 0010 Next switch ON, carry over
3 0011 Both right switches ON
4 0100 Carry over again
5 0101 4 + 1
15 1111 All 4 switches ON
255 11111111 All 8 switches ON (1 byte max)

Hexadecimal: Binary Made Readable

Binary gets really long really fast. For example, the number 4,294,967,295 in binary is: 11111111111111111111111111111111 (32 digits!).

This is annoying for humans to read and write. So we use hexadecimal (base-16) as shorthand. Each hex digit represents 4 binary digits.

Hexadecimal digits (0-15): 0 = 0000 4 = 0100 8 = 1000 C = 1100 1 = 0001 5 = 0101 9 = 1001 D = 1101 2 = 0010 6 = 0110 A = 1010 E = 1110 3 = 0011 7 = 0111 B = 1011 F = 1111 Example conversions: Binary: 11010110 10111001 Hex: D6 B9 Together: 0xD6B9 (hex notation uses 0x prefix) Decimal: 255 Binary: 11111111 Hex: 0xFF Memory address example: Binary: 0111111111111111111111111111111111111111111110000000000000000000 Hex: 0x7FFFFFFFFFFFE000 (much easier to read!)

You'll see hex everywhere in hacking: memory addresses, shellcode, network packets, file signatures, color codes. Get comfortable with it.

How Computers Represent Text

Text is just numbers with an agreed-upon mapping. The most common is ASCII (American Standard Code for Information Interchange).

ASCII Examples: Character Decimal Binary Hex 'A' 65 01000001 0x41 'B' 66 01000010 0x42 'a' 97 01100001 0x61 '0' 48 00110000 0x30 ' ' (space) 32 00100000 0x20 '\n' (newline) 10 00001010 0x0A String "Hi" in memory: H = 0x48 i = 0x69 \0 = 0x00 (null terminator marks end of string) In hex: 48 69 00

Why this matters for hacking: When you inject code or manipulate data, you're often working with raw bytes in hex. SQL injection might involve ASCII codes. Buffer overflows require understanding how strings are stored. Shellcode is written in hex bytes.

๐ŸŽจ HANDS-ON: Convert Your Name to Binary and Hex

Let's convert the name "Bob" to binary and hex. Follow along with your own name!

// Converting "Bob" to computer language: 'B' = 66 in decimal (ASCII table) = 01000010 in binary = 0x42 in hex 'o' = 111 in decimal = 01101111 in binary = 0x6F in hex 'b' = 98 in decimal = 01100010 in binary = 0x62 in hex // Full string "Bob" in memory: Decimal: 66 111 98 0 โ† null terminator ends string Hex: 42 6F 62 00 Binary: 01000010 01101111 01100010 00000000 // In a hex editor, you'd see: 42 6F 62 00 // That's "Bob"! The computer stores text as numbers!

Try it yourself: Pick a short word and look up each letter in an ASCII table. Convert to hex. That's exactly how it's stored in memory!

Why Do Computers Use Binary?

This is a question every beginner asks. The answer is surprisingly simple: physics and reliability.

โšก The Engineering Reality

Binary (2 states) is EASY to build and detect:

  • High voltage (5V) = 1
  • Low voltage (0V) = 0

With just two states, even if there's electrical noise or interference, it's easy to tell them apart. Is the voltage above 2.5V? It's a 1. Below? It's a 0. Simple!

Why not use 10 states (decimal)?

  • 0 = 0V, 1 = 0.5V, 2 = 1.0V, 3 = 1.5V... 9 = 4.5V
  • Problem: These voltages are too close together
  • Tiny electrical noise could turn a 4 into a 5
  • Reading would be slow and error-prone
  • Circuits would be much more complex

Binary = Fast, Reliable, Simple

Transistors are perfect for binary: they're either ON or OFF. This makes computers incredibly fast and reliable. Yes, it means numbers get long (11111111 instead of 255), but computers don't care about lengthโ€”they care about speed and accuracy.

Hexadecimal Deep Dive: Why Hackers Love It

Every hacker, reverse engineer, and security researcher lives in hexadecimal. Let me show you why it's so powerful.

Why Hex is Perfect for Memory

  • 1 hex digit = exactly 4 bits
  • 2 hex digits = exactly 1 byte
  • 8 hex digits = exactly 4 bytes (32-bit)
  • 16 hex digits = exactly 8 bytes (64-bit)

This perfect alignment makes it trivial to convert between hex and binary. No calculator neededโ€”just memorize the 16 digits!

Hex in Real Hacking Scenarios

  • Memory addresses: 0x7FFFFFFFFFFF
  • Shellcode: \x90\x90\x90 (NOP sled)
  • File signatures: PNG = 89 50 4E 47
  • Network packets: IP = 0xC0A80101
  • Color codes: #FFFFFF (white)
  • Unicode: ๐Ÿ˜€ = U+1F600
๐Ÿ” REAL EXAMPLE: Reading a Hex Dump

When you open a file in a hex editor, you see something like this. Let me teach you how to read it like a pro:

// Hex dump of a simple text file: Offset Hex Values ASCII 00000000 48 65 6C 6C 6F 20 57 6F 72 6C 64 21 Hello World! 0000000C 0A 54 68 69 73 20 69 73 20 61 20 74 ยทThis is a t 00000018 65 73 74 2E 00 est.ยท // Let's decode the first line byte by byte: 48 = 'H' (72 in decimal) 65 = 'e' (101 in decimal) 6C = 'l' (108 in decimal) 6C = 'l' (108 in decimal) 6F = 'o' (111 in decimal) 20 = ' ' (32 in decimal - space character) 57 = 'W' (87 in decimal) 6F = 'o' (111 in decimal) 72 = 'r' (114 in decimal) 6C = 'l' (108 in decimal) 64 = 'd' (100 in decimal) 21 = '!' (33 in decimal) // Second line starts with 0A: 0A = '\n' (10 in decimal - newline character) // That's why the text continues on the next line! // Notice the pattern: // - Readable text looks like: 40-7E in hex (ASCII printable) // - Control characters: 00-1F (non-printable) // - Special characters: 20 (space), 0A (newline), 00 (null)

Pro tip: Experienced hackers can read hex dumps and immediately spot patterns:

  • 00 00 00 00 = NULL bytes (empty or padding)
  • 90 90 90 90 = NOP sled (common in exploits)
  • FF FF FF FF = -1 or max value
  • DE AD BE EF = "DEADBEEF" (magic number, debug marker)

Converting Between Number Systems: The Easy Way

Let me give you simple tricks that make conversion effortless. No complicated math required!

๐Ÿงฎ CONVERSION CHEAT SHEET

BINARY โ†’ HEX (Super Easy):

// Group binary digits into sets of 4, convert each group: Binary: 11010110 10111001 Group: 1101 0110 1011 1001 Hex: D 6 B 9 Result: 0xD6B9 // Memorize this table (only 16 entries!): 0000=0 0100=4 1000=8 1100=C 0001=1 0101=5 1001=9 1101=D 0010=2 0110=6 1010=A 1110=E 0011=3 0111=7 1011=B 1111=F

HEX โ†’ DECIMAL (Mental Math Trick):

// Each hex digit position is a power of 16: 0xFF = ? F in the 16^0 place = 15 ร— 1 = 15 F in the 16^1 place = 15 ร— 16 = 240 Total = 240 + 15 = 255 0x100 = ? 1 in the 16^2 place = 1 ร— 256 = 256 // Common values to memorize: 0x10 = 16 0x100 = 256 0x1000 = 4096 0xFF = 255 0xFFFF = 65535 0xFFFFFFFF = 4294967295

DECIMAL โ†’ HEX (Division Method):

// Convert 1234 to hex: 1234 รท 16 = 77 remainder 2 โ†’ rightmost digit = 2 77 รท 16 = 4 remainder 13 โ†’ next digit = D (13 in hex) 4 รท 16 = 0 remainder 4 โ†’ leftmost digit = 4 Result: 0x4D2 // Verify: 4ร—256 + 13ร—16 + 2ร—1 = 1024 + 208 + 2 = 1234 โœ“

Bitwise Operations: The Hacker's Secret Weapon

Now that you understand binary, let me show you the operations that make hacking possible. These are used in encryption, obfuscation, exploitation, and malware.

โš™๏ธ THE BITWISE OPERATORS
// AND (&) - Both bits must be 1: 1010 (10 in decimal) & 1100 (12 in decimal) ------ 1000 (8 in decimal) // Use case: Masking bits (hiding/extracting specific bits) // OR (|) - At least one bit must be 1: 1010 (10) | 1100 (12) ------ 1110 (14) // Use case: Setting specific bits (turning bits ON) // XOR (^) - Bits must be different: 1010 (10) ^ 1100 (12) ------ 0110 (6) // Use case: Encryption, checksums, finding differences // NOT (~) - Flip all bits: ~ 1010 (10) ------ 0101 (5 in 4-bit, but usually 0xFFFFFFF5 in 32-bit) // Use case: Creating inverse masks, bit manipulation // LEFT SHIFT (<<) - Move bits left, fill with 0: 1010 << 1 = 10100 (20) // Multiply by 2 1010 << 2 = 101000 (40) // Multiply by 4 // Use case: Fast multiplication by powers of 2 // RIGHT SHIFT (>>) - Move bits right, discard extras: 1010 >> 1 = 0101 (5) // Divide by 2 1010 >> 2 = 0010 (2) // Divide by 4 // Use case: Fast division by powers of 2
๐Ÿ” REAL HACKING EXAMPLE: Simple XOR Encryption

XOR is used in everything from malware obfuscation to cryptography. Here's why it's so powerful:

// XOR has a magical property: A ^ B ^ B = A // This means XOR is its own inverse! Original message: "Hi" Encryption key: 0x5A (90 in decimal) // Encrypt 'H' (0x48): 0x48 // 'H' = 01001000 ^ 0x5A // Key = 01011010 ------ 0x12 // Encrypted = 00010010 // Encrypt 'i' (0x69): 0x69 // 'i' = 01101001 ^ 0x5A // Key = 01011010 ------ 0x33 // Encrypted = 00110011 Encrypted message: 0x12 0x33 (gibberish!) // Now decrypt (use same operation!): 0x12 // Encrypted 'H' ^ 0x5A // Same key ------ 0x48 // Back to 'H'! 0x33 // Encrypted 'i' ^ 0x5A // Same key ------ 0x69 // Back to 'i'! // This is why malware uses XOR to hide strings! // Antivirus can't detect "malicious.dll" if it's XOR'd // At runtime, malware XORs it back to get the real string

Why hackers love XOR: It's fast (one CPU instruction), reversible (same operation encrypts and decrypts), and simple to implement. Many malware samples XOR their strings to avoid detection. When reverse engineering, if you see lots of XOR operations, suspect obfuscation!

Why hackers love XOR: It's fast (one CPU instruction), reversible (same operation encrypts and decrypts), and simple to implement. Many malware samples XOR their strings to avoid detection. When reverse engineering, if you see lots of XOR operations, suspect obfuscation!

Operating Systems: The Ultimate Control Program

The Operating System (OS) is the most important program on your computer. It's the boss, the manager, the referee. Every other program must ask the OS for permission to do anything. Understanding this hierarchy is CRITICAL for hacking.

What is an Operating System? (Really)

An OS is a program that manages all other programs. It's the intermediary between hardware (CPU, RAM, disk, network) and software (apps, games, browsers).

The Restaurant Metaphor

Think of your computer as a restaurant:

  • Hardware = The Kitchen: Stoves, ovens, refrigerators (CPU, RAM, disk)
  • Operating System = The Head Chef: Coordinates everything, assigns tasks, manages resources
  • Programs = Line Cooks: Each does a specific job (make salads, grill meat, bake desserts)
  • Users = Customers: Place orders, receive food

Line cooks (programs) can't just walk into the kitchen and use whatever they want. They must ask the head chef (OS) for permission. "Can I use the oven?" "Can I access the refrigerator?" The OS controls access to all resources.

The Four Core Jobs of an Operating System

1. Process Management

What: Running multiple programs at once

How:

  • Creates processes (running programs)
  • Schedules CPU time (time-slicing)
  • Switches between processes (context switching)
  • Terminates processes when done

You have 100+ processes running right now, but only a few CPU cores. The OS rapidly switches between them (thousands of times per second) to create the illusion of parallelism.

2. Memory Management

What: Allocating RAM to programs

How:

  • Allocates memory to each process
  • Isolates process memory (security!)
  • Implements virtual memory
  • Swaps to disk when RAM is full

Each program thinks it has all the RAM to itself. The OS creates this illusion using virtual memory, mapping virtual addresses to physical RAM.

3. File System Management

What: Organizing data on disk

How:

  • Creates/deletes files and folders
  • Reads/writes file data
  • Manages permissions
  • Maintains file metadata

Programs don't directly access the disk. They ask the OS: "Please read file X" and the OS handles the hardware details.

4. Device Management

What: Controlling hardware

How:

  • Communicates with hardware via drivers
  • Manages keyboard, mouse, display
  • Controls network cards, USB devices
  • Handles interrupts from hardware

Each piece of hardware has a driver (specialized software) that tells the OS how to talk to it. Programs don't touch hardware directlyโ€”they go through the OS.

User Mode vs Kernel Mode: The Security Boundary

This is THE most important concept in OS security. Every exploit's goal is to cross this boundary.

๐Ÿ›ก๏ธ THE SECURITY WALL
// Two execution modes in every CPU: USER MODE (Ring 3 - Least Privileged) // Where all normal programs run // Restricted access to: - Cannot directly access hardware - Cannot access other processes' memory - Cannot execute privileged CPU instructions - Cannot modify OS memory - Must ask OS for everything Examples: Chrome, Word, games, your code KERNEL MODE (Ring 0 - Full Privileges) // Where the OS kernel runs // Unrestricted access to: + Can directly control all hardware + Can access ANY memory address + Can execute ALL CPU instructions + Can modify anything, anywhere + Complete control of the computer Examples: Windows kernel, Linux kernel, device drivers // How programs cross the boundary: SYSTEM CALLS (syscalls) // Programs request OS services: open("/etc/passwd") โ†’ "OS, please open this file" malloc(1024) โ†’ "OS, please give me 1 KB of memory" send(socket, data) โ†’ "OS, please send this over the network" fork() โ†’ "OS, please create a new process" // Each syscall temporarily switches to kernel mode // OS validates the request, does the work, returns to user mode

Why Hackers Care: Privilege Escalation

The attacker's goal: Go from User Mode to Kernel Mode

When you initially compromise a system (via a web exploit, phishing, etc.), you're running in user mode with limited privileges. You can't:

  • Install rootkits or kernel backdoors
  • Read other users' files
  • Disable antivirus or security tools
  • Persist across reboots

Privilege escalation exploits find bugs in the OS kernel or drivers that allow user-mode code to execute kernel-mode code. Once you're in kernel mode, you're godโ€”you control everything.

Processes vs Threads: Understanding Concurrency

Programs don't just run linearly. Modern software uses processes and threads to do multiple things at once. Let me break this down super clearly.

The Office Metaphor

PROCESS = An Entire Company

  • Has its own office space (memory space)
  • Has its own resources (files, network connections)
  • Isolated from other companies (can't access their stuff)
  • Expensive to create (need to buy/rent office space)
  • If the company goes bankrupt (crashes), it doesn't affect other companies

THREAD = An Employee Within a Company

  • Shares the office space with other employees (shared memory)
  • Can access company resources (same files, same data)
  • Cheap to create (just hire another person)
  • Works on different tasks simultaneously
  • If one employee causes a disaster (crashes), it can take down the whole company
๐Ÿ”„ REAL EXAMPLE: Chrome Browser

Chrome uses both processes and threads cleverly for security and performance:

// Chrome's Architecture: Main Process (chrome.exe) โ†’ Thread 1: UI rendering โ†’ Thread 2: User input handling โ†’ Thread 3: Network management Tab Process 1 (chrome.exe --type=renderer) // Separate process for google.com tab โ†’ Thread 1: JavaScript execution โ†’ Thread 2: HTML/CSS rendering โ†’ Thread 3: Image decoding Tab Process 2 (chrome.exe --type=renderer) // Separate process for facebook.com tab โ†’ Thread 1: JavaScript execution โ†’ Thread 2: HTML/CSS rendering GPU Process (chrome.exe --type=gpu-process) // Handles graphics acceleration // WHY separate processes per tab? SECURITY: If google.com gets hacked, it can't access facebook.com's memory (different processes) STABILITY: If one tab crashes, other tabs keep working ISOLATION: Each tab is sandboxed (limited privileges) // Open Task Manager and look for "chrome.exe" // You'll see 10+ processes! Each is isolated.

File Systems: How Data is Actually Stored

When you "save a file," what actually happens? Where does it go? How does the computer find it again? File systems are the answerโ€”and understanding them is crucial for finding hidden data, recovering deleted files, and hiding malware.

The File System's Job

Your disk is just billions of bytes. The file system organizes these bytes into files and folders, creating the structure you see in File Explorer/Finder.

What File Systems Do

  • Organize data: Create hierarchy (folders, subfolders, files)
  • Track locations: Remember where each file's bytes are on disk
  • Manage metadata: Store file names, sizes, dates, permissions
  • Allocate space: Find empty space for new files
  • Handle deletion: Mark space as available for reuse

Common File Systems

  • NTFS: Windows (supports permissions, encryption, large files)
  • FAT32: USB drives (simple, compatible, 4 GB file limit)
  • exFAT: Modern USB drives (no 4 GB limit)
  • ext4: Linux (journaling, reliability)
  • APFS: macOS (encryption, snapshots, SSD-optimized)

How Files are Actually Stored

Let me show you what happens at the bit level when you save a file. This will blow your mind.

๐Ÿ’พ COMPLETE FILE SAVE WALKTHROUGH
// You save "hello.txt" containing "Hello World!" (12 bytes) STEP 1: File System Metadata Creation // OS creates a file entry in the file system table Filename: "hello.txt" Size: 12 bytes Created: 2025-12-14 10:30:45 Modified: 2025-12-14 10:30:45 Permissions: Read/Write for owner Location: Starting at Sector 45,678 STEP 2: Find Free Space on Disk // File system checks allocation table // Finds empty sectors: 45,678 - 45,679 Sector 45,678: FREE (512 bytes available) Sector 45,679: FREE (512 bytes available) // Marks them as IN USE STEP 3: Write Data to Disk // Physical disk operation Disk Head Position: Move to track 120, sector 45,678 Write Bytes: Address 0x0000B1A000: 48 65 6C 6C 6F 20 57 6F 72 6C 64 21 H e l l o W o r l d ! STEP 4: Update File System Table // Record the mapping: "hello.txt" โ†’ Sector 45,678 File Allocation Table (FAT) update: Entry 12,345: "hello.txt" starts at sector 45,678 Sector 45,678: Next sector = END_OF_FILE STEP 5: Flush Caches // Ensure data is physically written (not just in RAM cache) fsync() โ†’ Force write to disk // DONE! File is permanently stored on disk // When you open "hello.txt" later: 1. OS looks up "hello.txt" in file system table 2. Finds: "starts at sector 45,678" 3. Reads sector 45,678 from disk into RAM 4. Returns bytes to program: "Hello World!"

Why Deleted Files Aren't Really Deleted

This is one of the most important things you'll learn. When you "delete" a file, it's not actually erased. Let me show you why.

๐Ÿ—‘๏ธ THE TRUTH ABOUT FILE DELETION
// You delete "hello.txt" from your computer What you think happens: - File data is erased from disk - Space is now empty (all zeros) - File is gone forever What ACTUALLY happens: BEFORE deletion: Filename: "hello.txt" Size: 12 bytes Location: Sector 45,678 Status: IN USE Sector 45,678 contents: 48 65 6C 6C 6F 20 57 6F 72 6C 64 21 H e l l o W o r l d ! AFTER deletion: Filename: ~"ello.txt" โ† First character marked as deleted Size: 12 bytes Location: Sector 45,678 Status: FREE โ† ONLY THIS CHANGES! Sector 45,678 contents: 48 65 6C 6C 6F 20 57 6F 72 6C 64 21 H e l l o W o r l d ! โ†‘ DATA IS STILL THERE! // The OS just marks the space as "available for reuse" // The actual data bytes remain unchanged until overwritten What happens next: Scenario 1: You save a new file - OS finds sector 45,678 is marked FREE - Writes new file data over the old data - "Hello World!" is NOW actually gone (overwritten) Scenario 2: You use file recovery software - Software scans for sectors marked FREE - Finds "Hello World!" still there! - Reconstructs the file - File is recovered! // This is why: // - Forensics experts can recover "deleted" evidence // - You need to "secure delete" sensitive data (overwrite with random bytes) // - SSDs have "TRIM" to actually erase deleted data // - Military uses "7-pass wipe" (overwrite 7 times with random data)

Pro tip: If you need to securely delete something, use tools like shred (Linux), sdelete (Windows), or srm (Mac) that overwrite the data multiple times before marking it free.

File Permissions: Who Can Do What

Every file has permissions that control who can read, write, or execute it. Understanding permissions is essential for privilege escalation and maintaining access after compromise.

๐Ÿ” UNIX/LINUX PERMISSIONS (The Golden Standard)
// Run "ls -l" in Linux and you see: -rwxr-xr-- 1 alice staff 1234 Dec 14 10:30 myfile.txt // Let's decode this: - โ† File type: - = regular file, d = directory, l = link rwx โ† Owner permissions (alice) r-x โ† Group permissions (staff) r-- โ† Everyone else permissions // Permission meanings: r = read (4) โ†’ Can view file contents w = write (2) โ†’ Can modify file contents x = execute (1) โ†’ Can run file as a program - = no permission // Broken down: Owner (alice): rwx = read + write + execute = 7 Group (staff): r-x = read + execute = 5 Others: r-- = read only = 4 // In numeric notation: 754 chmod 754 myfile.txt โ† Sets these permissions // Common permission patterns: 644 = rw-r--r-- โ†’ Regular file (you can edit, others can read) 755 = rwxr-xr-x โ†’ Executable (you can run it, so can others) 700 = rwx------ โ†’ Private (only you can access) 777 = rwxrwxrwx โ†’ Wide open (DANGEROUS! anyone can do anything)

Hacker's Perspective: Finding Misconfigurations

Attackers look for permission mistakes:

  • World-writable files: find / -perm -002 -type f finds files anyone can modify
  • SUID binaries: Programs that run with owner's privileges (often root)
  • Weak directory permissions: drwxrwxrwx lets attackers plant malicious files
  • Readable sensitive files: /etc/shadow should be 000 or 400

One misconfigured permission can be the entry point for privilege escalation. Always check permissions when pentesting!

Program Execution: From Code to Running Process

How does a program actually start running? What happens between double-clicking an icon and seeing the program window? Understanding this process is fundamental to exploitation, reverse engineering, and malware analysis.

The Complete Execution Journey

๐Ÿš€ LAUNCHING A PROGRAM: The Full Story
// You double-click "notepad.exe" PHASE 1: OS Receives the Request 1. Mouse click generates interrupt 2. OS identifies icon location: C:\Windows\System32\notepad.exe 3. OS checks: Do you have permission to execute this file? 4. Permission granted โ†’ proceed PHASE 2: File Validation 5. Read file header (first few bytes) 6. Check file signature: // Windows EXE files start with "MZ" (0x4D5A) // Linux ELF files start with 0x7F454C46 7. Valid executable โ†’ proceed 8. Parse PE header (Windows) or ELF header (Linux) - Entry point address (where to start execution) - Required DLLs/libraries - Memory requirements - Relocation information PHASE 3: Process Creation 9. OS creates new process control block (PCB) 10. Assign Process ID (PID): 4532 11. Allocate virtual address space (4 GB on 32-bit, huge on 64-bit) 12. Set up memory regions: - Code section (.text) - Data section (.data, .bss) - Heap (initially small, grows as needed) - Stack (typically 1-8 MB) PHASE 4: Loading the Executable 13. Read notepad.exe from disk (~200 KB) 14. Copy .text section to memory (code) 15. Copy .data section to memory (initialized variables) 16. Zero out .bss section (uninitialized variables) 17. Map sections to virtual addresses PHASE 5: Dynamic Linking 18. Load required DLLs: - kernel32.dll (core Windows functions) - user32.dll (UI functions) - gdi32.dll (graphics) 19. Resolve imported functions: // Notepad calls CreateWindowEx() from user32.dll // Linker finds CreateWindowEx address and patches it in 20. Apply relocations (adjust addresses if needed) PHASE 6: Initialization 21. Run DLL initialization code (DllMain) 22. Set up exception handlers 23. Initialize C runtime library (CRT) 24. Set instruction pointer to entry point PHASE 7: Execution Begins 25. CPU starts fetching instructions from entry point 26. Program's main() or WinMain() function executes 27. Notepad creates its window, loads UI 28. Enters message loop (waits for user input) Total time: ~100-300 milliseconds // Every program on your computer went through this!

What is an Executable File?

Let's peek inside a .exe or binary file and see what it actually contains. This knowledge is essential for reverse engineering and malware analysis.

๐Ÿ“ฆ INSIDE AN EXECUTABLE FILE
// Structure of a Windows PE (Portable Executable) file: โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ DOS Header (64 bytes) โ”‚ โ”‚ // Starts with "MZ" (Mark Zbikowski signature) โ”‚ โ”‚ // For backwards compatibility with DOS โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ DOS Stub (variable size) โ”‚ โ”‚ // Tiny program that prints: โ”‚ โ”‚ // "This program cannot be run in DOS mode" โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ PE Header (248 bytes) โ”‚ โ”‚ // Signature: "PE\0\0" (0x50450000) โ”‚ โ”‚ // Machine type, timestamp, characteristics โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ Optional Header โ”‚ โ”‚ - Entry point address (0x00401000) โ”‚ โ”‚ - Image base (0x00400000) โ”‚ โ”‚ - Stack/heap sizes โ”‚ โ”‚ - Subsystem (GUI or Console) โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ Section Table โ”‚ โ”‚ // Describes each section of the program โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ .text Section (CODE) โ”‚ โ”‚ // Actual machine code instructions โ”‚ โ”‚ // Read-only, executable โ”‚ โ”‚ 48 89 E5 48 83 EC 20 E8 F4 02 00 00 ... โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ .data Section (INITIALIZED DATA) โ”‚ โ”‚ // Global variables with initial values โ”‚ โ”‚ int counter = 42; โ†’ stored here โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ .rdata Section (READ-ONLY DATA) โ”‚ โ”‚ // String literals, constants โ”‚ โ”‚ "Hello World\0" โ†’ stored here โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ .idata Section (IMPORT TABLE) โ”‚ โ”‚ // List of DLLs and functions needed โ”‚ โ”‚ kernel32.dll: CreateFileA, ReadFile, ... โ”‚ โ”‚ user32.dll: MessageBoxA, CreateWindow.. โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ .reloc Section (RELOCATIONS) โ”‚ โ”‚ // How to adjust addresses if loaded at โ”‚ โ”‚ // different memory address than expected โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ // When you reverse engineer malware, you're reading these sections! // Tools like IDA Pro, Ghidra, x64dbg parse this structure

Networking Basics: How Computers Talk to Each Other

Everything you do onlineโ€”browsing websites, sending messages, playing gamesโ€”involves networking. Let me show you how data travels across the internet, from your computer to servers around the world.

The Simplest Explanation of the Internet

The internet is just millions of computers connected together, passing messages to each other. That's it. No magic, no mysteryโ€”just data hopping from computer to computer until it reaches its destination.

The Postal Service Metaphor

Imagine sending a letter to someone across the country:

  • Your letter = Data packet: Contains the message and addresses
  • Your mailbox = Your computer: Where the letter starts
  • Post offices = Routers: Pass the letter along toward destination
  • Delivery route = Network path: Might go through many post offices
  • Recipient's mailbox = Destination server: Where letter ends up
  • Return address = IP address: So they can reply to you

Just like mail, internet data is broken into "packets" (like letters) that travel independently and might take different routes to reach the destination!

IP Addresses: The Internet's Phone Numbers

Every device on the internet needs a unique address so data knows where to go. That's an IP address.

๐ŸŒ IP ADDRESSES EXPLAINED
// IPv4 Address (most common today): 192.168.1.100 // Format: Four numbers (0-255) separated by dots // Each number is 1 byte (8 bits) // Total: 4 bytes = 32 bits // Breaking it down: 192 = 11000000 in binary 168 = 10101000 in binary 1 = 00000001 in binary 100 = 01100100 in binary Full binary: 11000000 10101000 00000001 01100100 Hexadecimal: 0xC0A80164 // Special IP ranges: 127.0.0.1 โ†’ Localhost (your own computer) 192.168.x.x โ†’ Private network (home/office) 10.x.x.x โ†’ Private network (large companies) 0.0.0.0 โ†’ Invalid/any address 255.255.255.255 โ†’ Broadcast (send to everyone on network) // IPv6 Address (newer, much longer): 2001:0db8:85a3:0000:0000:8a2e:0370:7334 // 128 bits total (vs 32 bits for IPv4) // Allows 340 undecillion addresses (yes, that's a real number) // IPv4 only had 4 billion addresses (not enough!)

That's enough to get you started! You now understand computers better than most people ever will. These fundamentals are the foundation for everything in hacking.

โ† Back to Roadmap Next: Chapter 02 - Linux Fundamentals โ†’