Learn / Stage 1: Foundations / Lesson 1.1

$ lesson 1.1 --stage foundations

How a Computer Works

Before you can secure a machine you need to know what is inside it. This lesson walks through the CPU, memory, storage, binary and the boot process, and at every step shows where attackers strike and how defenders respond.

  • Stage 1 Foundations
  • Level Beginner
  • 45 min
  • 6 sections, quiz, lab

Start the lesson Jump to the lab

By the end of this lesson you can

  • Explain what the CPU, RAM and storage each do, and why RAM is volatile
  • Follow the fetch, decode, execute cycle and say why the instruction pointer matters
  • Convert between binary, decimal and hex, and identify a file by its magic bytes
  • Describe the UEFI boot chain, Secure Boot and how bootkits attack it
1.1.01

The big picture: five parts, one idea

Every computer you will ever defend, from a ₹8,000 phone to a rack server in a Mumbai data centre, follows the same pattern. Something takes input, something processes it, something remembers it for now, something stores it for later, and something sends output.

The design most machines still use comes from the stored program idea described by John von Neumann and colleagues in 1945: program instructions and data live in the same memory, and the processor fetches both from there. That single decision is why a bug can make a computer treat attacker supplied data as instructions. Keep that thought; half of exploitation grows from it.

Block diagram of a computer: the CPU with control unit, ALU and registers, connected to RAM, storage, input and output over busesCPUControlunitALUmaths, logicRegisters + cachetiny, fastestRAMworking memory, volatileStorageSSD or HDD, keeps dataInputkeyboard, network, micOutputscreen, network, speakersystem bus: address, data and control lines (in modern PCs, PCIe links and memory channels)
The CPU does the work, RAM holds what is being worked on, storage keeps things after power off, and buses connect them.

Why should a security learner care about hardware at all? Because every attack eventually lands somewhere physical: a value in a CPU register, a password sitting in RAM, a deleted file still on a disk, or malicious code hiding in firmware that runs before Windows even starts. Defenders who understand the machine know where to look.

1.1.02

The CPU: fetch, decode, execute, billions of times a second

The CPU (central processing unit) only ever does one simple loop. It fetches the next instruction from memory, decodes what it means, executes it, and moves on. A 3 GHz core has a clock that ticks three billion times per second, and modern cores finish several instructions per tick by working on many at once in a pipeline.

Parts worth knowing

  • Control unit: reads instructions and directs everything else.
  • ALU (arithmetic logic unit): adds, compares, does AND, OR, XOR. Encryption and hashing are mostly huge numbers of these simple operations.
  • Registers: a handful of tiny storage slots inside the CPU. Two matter a lot in security: the instruction pointer (RIP on 64-bit x86) holds the address of the next instruction, and the stack pointer (RSP) tracks the top of the stack.
  • Cores and threads: a 6 core CPU is six processors on one chip. Simultaneous multithreading (Intel calls it Hyper-Threading) lets one core run two instruction streams.
  • Instruction set: the vocabulary a CPU understands. Laptops and servers mostly speak x86-64; phones, Apple M series Macs and many cloud servers speak ARM. Malware compiled for one will not run on the other without translation.

Watch one instruction go through the CPU

Click Next, or use the arrow keys.

    1. Fetch

    The control unit reads the address in the instruction pointer, say 0x401000, and pulls the bytes stored there from cache or RAM.

    Bytes fetched: 48 01 D8

    2. Decode

    The decoder works out that 48 01 D8 means add rax, rbx: add the value in register RBX to register RAX.

    3. Execute

    The ALU adds the two numbers. If RAX held 40 and RBX held 2, RAX now holds 42. Flags are updated too, for example whether the result was zero.

    4. Write back and advance

    The result is stored, and the instruction pointer moves to the next instruction, 0x401003. Then the loop repeats.

    5. Where attacks hit

    If an attacker can change the value in the instruction pointer, the CPU will happily fetch their bytes next. Classic buffer overflow exploits do exactly this by overwriting a saved return address on the stack. The CPU has no idea anything is wrong.

    1.1.03

    Memory: why RAM forgets and why that matters

    Storage is arranged as a hierarchy. The closer to the CPU, the faster and smaller it is.

    Memory hierarchy pyramid: registers at the top, then CPU cache, RAM, and SSD or hard disk at the bottomRegistersCPU cache L1 L2 L3RAMSSD and hard diskfastersmallercostlier per GBslowerbiggerkeeps data at power off
    Data moves up the pyramid when it is needed and down when it is not.
    Memory hierarchy sizes and speeds
    LevelTypical sizeRough access timeKeeps data at power off?
    Registersa few hundred bytesunder 1 nsNo
    L1 / L2 / L3 cacheKB to tens of MBabout 1 to 40 nsNo
    RAM (DDR4, DDR5)8 to 64 GB on a PCabout 50 to 100 nsNo
    NVMe SSD256 GB to several TBtens of microsecondsYes
    Hard disk (HDD)1 TB and upseveral millisecondsYes

    Numbers are typical orders of magnitude, not exact specs. The jump from RAM to a hard disk is roughly a hundred thousand times slower.

    RAM is volatile: it needs power to hold data. Everything a running program uses lives there: the document you are typing, decrypted files, session tokens and, very often, passwords in plain form for a short time.

    1.1.04

    Storage: disks, partitions and the myth of delete

    A hard disk stores bits magnetically on spinning platters. An SSD stores them as charge in flash memory cells, with no moving parts, which is why it is so much faster. Both present themselves to the OS as a long row of numbered blocks.

    Partitions and partition tables

    A disk is split into partitions, and a small table at the start records where each begins and ends.

    MBR versus GPT
    MBR (older)GPT (modern)
    Introduced1983 with PC DOS 2.0with UEFI, in the 2000s
    Max disk sizeabout 2 TiB with 512 byte sectorsabout 9.4 ZB, effectively unlimited
    Partitions4 primary (more via an extended partition)128 by default on Windows
    Firmwarelegacy BIOSUEFI
    Resiliencesingle copy at the startbackup header at the end of the disk, plus checksums

    Each partition is then formatted with a file system such as NTFS or ext4, which keeps an index of file names and where their blocks are. You will meet those in the next lesson.

    Delete does not mean gone

    When you delete a file, the file system usually just marks its blocks as free and removes the index entry. The bytes stay on the disk until something overwrites them. That is how forensic tools recover deleted photos and chats. SSDs complicate this: the TRIM command tells the drive which blocks are unused, and the drive may erase them in the background, so recovery from SSDs is much less reliable.

    1.1.05

    Binary and hex: the language under everything

    A computer only stores two states, on and off, written as 1 and 0. One of these is a bit. Eight bits make a byte, which can hold 28 = 256 different values, from 0 to 255.

    Each bit position is worth double the one to its right: 128, 64, 32, 16, 8, 4, 2, 1. To read 0100 0001, add the positions that are on: 64 + 1 = 65.

    Byte builder: flip the bits

    Each switch is one bit. Turn them on and watch the same byte as decimal, hex and a text character. Or type a number from 0 to 255.

    Decimal
    Hex
    Binary
    ASCII

    Why hexadecimal?

    Long binary strings are hard to read, so we use base 16. Hex digits go 0 to 9 and then A to F (A = 10, F = 15). The trick is that one hex digit is exactly four bits, so a byte is always two hex digits: 0100 0001 becomes 0x41. Memory addresses, MAC addresses, colours on the web, hashes and file contents in a hex editor are all written this way.

    Number conversions
    DecimalBinaryHexWhere you see it
    650100 00010x41ASCII letter A
    1270111 11110x7Ffirst byte of every Linux ELF program
    2551111 11110xFF255.255.255.0 subnet masks, maximum byte
    77 and 900100 1101 0101 10104D 5AMZ, the first two bytes of every Windows .exe and .dll

    ASCII maps numbers to characters (65 is A, 97 is a, 48 is the digit 0). Unicode (usually stored as UTF-8) extends this to every script, including Devanagari, which matters for phishing because some letters from different scripts look identical.

    File signatures: the extension can lie, the bytes rarely do

    Common magic bytes
    File typeFirst bytes (hex)As text
    Windows program (.exe, .dll)4D 5AMZ
    Linux program (ELF)7F 45 4C 46.ELF
    PDF25 50 44 46%PDF
    ZIP, and anything built on ZIP (.docx, .xlsx, .apk, .jar)50 4B 03 04PK..
    PNG image89 50 4E 47.PNG
    1.1.06

    Boot process: from power button to login screen

    Booting is a relay race. Each runner checks the next one and hands over control. Security depends on every hand-off being trustworthy, because whatever runs first can control everything after it.

    Follow a modern UEFI boot

    Use Next or the arrow keys.

      1. Power on

      The power supply stabilises and the CPU starts executing at a fixed address that points into firmware stored on a flash chip on the motherboard.

      2. Firmware and POST

      The firmware (UEFI on almost all PCs since about 2012, legacy BIOS before that) runs the Power-On Self Test: checks RAM, CPU and basic devices. Beep codes or an error screen here usually mean a hardware fault.

      3. Secure Boot check

      UEFI reads its boot order and finds the boot loader file on the EFI System Partition, for example \EFI\Microsoft\Boot\bootmgfw.efi. With Secure Boot on, it verifies the file's digital signature against trusted keys stored in firmware before running it.

      4. Boot loader

      Windows Boot Manager or GRUB (on Linux) loads the operating system kernel into RAM. GRUB is also where you can pick between two installed systems.

      5. Kernel

      The kernel (ntoskrnl.exe on Windows, vmlinuz on Linux) takes over the hardware, loads drivers and mounts the main file system.

      6. First process

      On Linux the kernel starts PID 1, usually systemd, which starts every service. On Windows the session manager smss.exe starts wininit.exe and winlogon.exe, which start services and the login screen.

      7. Login

      You sign in, your user session and desktop start, and startup programs run. This last step is a favourite place for malware to add itself.

      BIOS versus UEFI
      Legacy BIOSUEFI
      Era1980s to about 2012standard on PCs since Windows 8
      Mode16-bit, tiny code size32 or 64-bit, much richer
      DiskMBRGPT (MBR supported only through legacy compatibility mode, CSM)
      Signature checksnoneSecure Boot
      Windows 11not supportedrequired, with TPM 2.0

      Flashcards: do you remember?

      Tap a card to flip it. Try to answer in your head first; recalling is what makes it stick.

      Quick quiz

      Instant feedback on every answer. Score 70% or more to pass this lesson's quiz.

      Q1Which component holds the data of programs that are running right now?

      Q2An attachment is named marksheet.pdf but its first bytes are 4D 5A. What is it really?

      Q3Binary 1100 1000 is which decimal number?

      Q4Why do incident responders capture RAM before switching a suspicious machine off?

      Q5What did the BlackLotus bootkit (2023) show?

      Q6Which statement about deleting a file on a hard disk is true?

      0 / 6

      Hands-on lab

      lab30 to 45 minutesyour own machines only

      Lab: look inside your own machine

      You need: A laptop or PC with VirtualBox installed, and an Ubuntu 24.04 LTS ISO (free from ubuntu.com). Windows steps use your own Windows PC.

      1. Create a VM and choose the firmware type

        In VirtualBox click New, pick the Ubuntu ISO, and give it 2 CPUs, 4 GB RAM and a 25 GB disk. Before the first boot open Settings, System, Motherboard (switch to Expert mode if you do not see it) and note whether Enable EFI is ticked. Install Ubuntu.

      2. Take a snapshot

        With the VM powered off, open the VM's Snapshots view and click Take. Name it clean-install. You can now break anything and roll back in seconds.

      3. Check BIOS or UEFI from inside Linux

        $ [ -d /sys/firmware/efi ] && echo UEFI || echo 'Legacy BIOS'
        $ sudo mokutil --sb-state

        mokutil reports whether Secure Boot is on (install it with sudo apt install mokutil if missing). Now power off, flip the EFI setting, and try booting again. A system installed in UEFI mode will not boot in legacy mode: you just saw why the firmware type matters.

        Flip it back before continuing.

      4. Inspect CPU, RAM and disks

        $ lscpu | head -20
        $ free -h
        $ lsblk -f
        $ sudo fdisk -l /dev/sda | head

        Find the architecture (x86_64), number of CPUs, total RAM, and whether the disk label type is gpt or dos (MBR).

      5. Read magic bytes

        $ head -c 4 /bin/ls | xxd
        $ cp /bin/ls ~/holiday.pdf
        $ file ~/holiday.pdf
        $ head -c 4 ~/holiday.pdf | xxd

        The copy is named like a PDF but file and the bytes 7f45 4c46 say ELF program. Delete it after: rm ~/holiday.pdf.

      6. Check your real Windows PC

        On your own Windows machine press Win + R, run msinfo32, and read BIOS Mode (UEFI or Legacy) and Secure Boot State. Turn on File name extensions in File Explorer if it is off.

      You are done when: You can say your VM's firmware type, Secure Boot state, CPU architecture and partition table type, and you identified a file by its bytes instead of its name.

      Download the lab checklist (.txt)

      Key takeaways

      • The CPU only fetches, decodes and executes. Whoever controls the instruction pointer controls the machine.
      • RAM holds live secrets and live evidence; it disappears at power off.
      • Deleted is not erased. Full disk encryption protects discarded and stolen drives.
      • Hex is binary made readable: one hex digit per four bits. Trust magic bytes over file extensions.
      • The boot chain is only as strong as its first link. Keep Secure Boot on and firmware updated.

      Finished the sections, quiz and lab? Mark the lesson complete. Progress is saved only in this browser.