Computer Fundamentals
A complete beginner's guide to understanding how computers work at a fundamental level. This is the foundation you need before learning to hack anything.
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.
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.
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.
Try this on your own computer right now:
- Open Task Manager (Ctrl+Shift+Esc on Windows, Activity Monitor on Mac)
- Look at the "Performance" tab - you'll see RAM usage
- Note current RAM usage - let's say it's 4.2 GB
- Open a large program (Chrome, Photoshop, a game)
- Watch RAM usage jump up - maybe to 6.5 GB
- Close the program
- 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.
Let's trace a real example with actual assembly code:
Imagine you're a first-grader and I ask you to add 5 + 3. Here's what your brain does:
- Read the problem: "5 + 3" (FETCH)
- Understand it: "Oh, I need to add two numbers" (DECODE)
- Do the math: "5... 6, 7, 8!" (EXECUTE)
- 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:
- Pipelining: Start executing next instruction before current one finishes
- Multiple cores: 4 cores = 4 instructions simultaneously
- Hyper-threading: Each core pretends to be 2 cores
- Out-of-order execution: Reorder instructions for efficiency
- Branch prediction: Guess which code path will be taken
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.
Let's say we want to add up numbers from 1 to 5. Here's how registers are used:
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.
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 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:
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.
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).
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.
Let's convert the name "Bob" to binary and hex. Follow along with your own name!
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.
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
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:
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!
BINARY โ HEX (Super Easy):
HEX โ DECIMAL (Mental Math Trick):
DECIMAL โ HEX (Division Method):
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.
XOR is used in everything from malware obfuscation to cryptography. Here's why it's so powerful:
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 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.
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.
Chrome uses both processes and threads cleverly for security and performance:
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.
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.
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.
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
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.
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.
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.
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.