How the Internet Works — A Security Engineer's View
TCP/IP, DNS, HTTP, TLS — every layer's attack surfaces explained from first principles. What happens in the network when you type a URL.
// Part 01
Why Every Security Engineer Must Understand the Network
Security tools — firewalls, IDS systems, packet capture, network monitoring — all operate at the network layer. An attacker who understands TCP/IP can craft packets that evade detection. A defender who does not understand TCP/IP cannot interpret what those tools are telling them. Network literacy is not optional background knowledge for a security engineer. It is the foundation everything else is built on.
This module answers one question from first principles: what happens when you type https://bank.example.com into a browser? Every step in that journey — DNS resolution, TCP connection, TLS handshake, HTTP request, HTTP response — is an attack surface. By the end, you will know exactly where attackers intercept, redirect, forge, and eavesdrop on network traffic.
The internet is not a single network. It is a collection of autonomous systems — networks owned by ISPs, universities, governments, and companies — that agree to route packets between each other using a shared set of protocols. Those protocols were designed in the 1970s and 1980s with trust, not security, as the primary design goal. Security was retrofitted on top. This is why so many fundamental attacks still work.
// Part 02
The TCP/IP Model — Every Layer Is an Attack Surface
The TCP/IP model describes how data moves from one machine to another by breaking the problem into layers. Each layer adds its own header information, passes the data to the layer below it, and the receiving end strips each layer in reverse. Understanding which layer each attack targets makes security architecture comprehensible.
| Layer | What It Does | Key Protocols | Attack Examples |
|---|---|---|---|
| Application | The data the user sees — web pages, emails, files. This is where browsers, email clients, and APIs live. | HTTP, HTTPS, DNS, SMTP, FTP, SSH | SQL injection, XSS, phishing, DNS poisoning, credential theft |
| Transport | Breaks application data into segments and ensures reliable delivery (TCP) or fast fire-and-forget delivery (UDP). | TCP, UDP | SYN flood, port scanning, session hijacking, TCP reset attacks |
| Internet | Routes packets between networks using IP addresses. Does not guarantee delivery — best effort. | IP, ICMP | IP spoofing, ICMP redirect attacks, BGP hijacking, fragmentation attacks |
| Network Access | Moves data between devices on the same physical network using MAC addresses. Also called the Link layer. | Ethernet, ARP, Wi-Fi (802.11) | ARP poisoning, MAC flooding, rogue Wi-Fi access points, VLAN hopping |
The key security insight: each layer trusts the layer above and below it. The Transport layer does not verify whether the IP address it received from the Internet layer is the legitimate origin. The Application layer does not verify that the TCP connection it received is not being proxied by an attacker. This trust model is where most network attacks live.
🎯 Pro Tip
When analysing a network attack, always identify which layer it operates at first. ARP poisoning is a Layer 2 (Network Access) attack — a firewall operating at Layer 3 (Internet) will not stop it because the firewall never sees ARP traffic. Understanding layers prevents you from applying the wrong defence to the right problem.
// Part 03
IP Addresses and Routing — What Actually Moves a Packet
IP Addresses
Every device on the internet has an IP address — a number that identifies its location on the network. IPv4 uses 32-bit addresses written in dotted-decimal notation: 192.168.1.1. IPv6 uses 128-bit addresses: 2001:0db8:85a3::8a2e:0370:7334. The internet ran out of IPv4 addresses in 2011, which is why Network Address Translation (NAT) is ubiquitous — multiple devices share one public IP behind a router.
IP spoofing — setting a false source IP on a packet — is trivially easy. The Internet Protocol does not authenticate source addresses. A packet claiming to come from 1.2.3.4 may actually come from 99.99.99.99. This is the foundation of many attacks: reflection attacks that use spoofed source IPs to direct responses at a victim, and it is why you cannot trust an IP address as proof of identity.
Routing — How Packets Find Their Destination
Routers are the post offices of the internet. Each router maintains a routing table — a list of network prefixes and which direction to send packets matching each prefix. Packets hop from router to router, each making a local forwarding decision, until they reach the destination. The traceroute (or tracert on Windows) command shows every hop a packet takes.
$ traceroute google.com traceroute to google.com (142.250.80.46), 30 hops max 1 192.168.1.1 (your home router) 1.2 ms 2 10.10.0.1 (your ISP's first router) 5.8 ms 3 72.14.232.1 (Google's network edge) 18.4 ms 4 142.250.80.46 (google.com) 19.1 ms
The Border Gateway Protocol (BGP) is the routing protocol that determines how these inter-network routes are chosen. BGP hijacking — announcing false routes to attract traffic meant for another network — has been used to redirect internet traffic, intercept communications, and conduct surveillance. A BGP error in 2010 briefly redirected 15% of internet traffic through China Telecom. BGP has no authentication built in; this is a known design flaw with no universal fix deployed.
Private vs Public Addresses
Three IP ranges are reserved for private networks: 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16. These addresses are not routed on the public internet — they are used inside corporate networks, data centres, and home networks. Network Address Translation (NAT) maps private addresses to a public IP at the network boundary. This matters for security: when a scanner finds 192.168.x.x addresses in a web response or DNS record, it has learned about internal network structure — information that should never be exposed.
// Part 04
TCP — Reliable Delivery and Its Attack Surface
The Three-Way Handshake
TCP (Transmission Control Protocol) provides reliable, ordered delivery. Before any data is exchanged, TCP establishes a connection using a three-way handshake:
Client → Server: SYN (I want to connect, my sequence number starts at X) Server → Client: SYN-ACK (Acknowledged. My sequence number starts at Y) Client → Server: ACK (Acknowledged. Connection established.) [DATA TRANSFER BEGINS] Either party → FIN → FIN-ACK → ACK (connection teardown)
Every web request, SSH session, and email starts with this handshake. The handshake creates state on the server — the server must remember every half-open connection (SYN received, SYN-ACK sent, ACK not yet received).
SYN Flood — Exhausting Server State
A SYN flood attack exploits the three-way handshake by sending massive numbers of SYN packets with spoofed source IPs. The server sends SYN-ACK responses to addresses that never complete the handshake, maintaining state for each half-open connection. When the connection table fills up, the server cannot accept legitimate connections. This is a Denial of Service attack at the Transport layer.
SYN cookies are the standard mitigation — the server encodes connection state into the sequence number rather than storing it in memory, so spoofed SYNs do not exhaust resources. Most modern operating systems enable SYN cookies automatically.
Port Scanning — Mapping the Attack Surface
TCP ports range from 0 to 65535. Services listen on specific ports: HTTP on 80, HTTPS on 443, SSH on 22, FTP on 21. Port scanning sends connection attempts to every port to discover which services are running. nmap is the standard tool:
$ nmap -sV -p 1-65535 192.168.1.1 PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.9 80/tcp open http nginx 1.22.1 443/tcp open https nginx 1.22.1 3306/tcp open mysql MySQL 8.0.32 ← database exposed to network 6379/tcp open redis Redis 7.0 ← unauthenticated by default
Every open port is a potential entry point. A Redis instance exposed on port 6379 with default (no authentication) configuration has been used to compromise systems by overwriting SSH authorized_keys files. The attack is trivial once the port scan reveals the exposure.
Session Hijacking
TCP connections are identified by source IP, source port, destination IP, and destination port, plus sequence numbers. If an attacker can predict or observe the sequence numbers and has a position on the network path, they can inject packets into an existing TCP session — session hijacking. Before HTTPS was ubiquitous, this was used to steal authenticated web sessions over public Wi-Fi.
// Part 05
DNS — How Names Become Addresses and How Attackers Abuse It
The Domain Name System (DNS) translates human-readable domain names (google.com) into IP addresses (142.250.80.46). It is the phone book of the internet, and it is involved in almost every internet communication.
How DNS Resolution Works
You type: https://bank.example.com Step 1: Check local cache — has your computer looked this up recently? Step 2: Ask your configured DNS resolver (usually your ISP or 8.8.8.8) Step 3: Resolver asks a Root DNS server: "Who handles .com?" Step 4: Root server: "Ask the .com TLD servers" Step 5: Resolver asks .com TLD: "Who handles example.com?" Step 6: TLD server: "Ask ns1.example.com" Step 7: Resolver asks ns1.example.com: "What is bank.example.com?" Step 8: ns1.example.com: "It is 93.184.216.34" Step 9: Resolver caches the answer for the TTL duration, returns to you Total time: 10-100ms on first lookup, <1ms from cache
DNS Record Types
DNS stores more than IP addresses. The common record types each serve a different purpose:
DNS Attack Types
DNS Cache Poisoning: A resolver caches DNS responses for the TTL (time-to-live) duration. If an attacker can inject a forged DNS response into the resolver's cache — either by predicting the transaction ID or exploiting an unpatched resolver — all users of that resolver will receive the false IP address until the TTL expires. The Kaminsky attack (2008) demonstrated this at scale against every major DNS resolver. DNSSEC (DNS Security Extensions) cryptographically signs DNS records to prevent this, but adoption remains incomplete.
DNS Hijacking: Rather than poisoning a cache, the attacker modifies the authoritative DNS record itself. This requires compromising the domain registrar account or the authoritative DNS server. In 2019, a wave of DNS hijacking attacks targeted government and corporate domains by compromising registrar accounts with weak credentials, redirecting traffic to attacker-controlled infrastructure where valid TLS certificates were obtained via ACME/Let's Encrypt.
Subdomain Takeover: An organisation uses a CNAME record pointing api.example.com to a third-party service (myapp.service.io). The organisation stops using the service but forgets to remove the CNAME record. The subdomain on the third-party service is now unregistered — anyone can claim it. An attacker registers the same subdomain on the provider and now controls api.example.com. This enables cookie theft if the main domain shares cookies with subdomains, phishing, and content injection.
DNS over HTTPS (DoH) and DNS over TLS (DoT): Traditional DNS is sent in plaintext — anyone between you and your resolver can see every domain you visit. DoH and DoT encrypt DNS queries. This protects user privacy but also means network defenders lose visibility into DNS-based threat intelligence (blocking malicious domains at the DNS layer). This is the privacy vs security trade-off inherent in DNS encryption.
🎯 Pro Tip
DNS is involved in almost every cyberattack. Malware calls home via DNS. C2 servers use domain generation algorithms that register new domains daily. Data exfiltration encodes stolen data in DNS query subdomains. Every security platform — SIEM, threat intelligence, firewalls — does DNS-based detection. Understanding DNS is not optional networking knowledge; it is a core security skill.
// Part 06
HTTP — The Protocol That Powers the Web (and Leaks Everything)
HTTP (Hypertext Transfer Protocol) is the application-layer protocol that web browsers use to request pages and APIs use to exchange data. It is a text-based, stateless request-response protocol. Stateless means each request is independent — the server does not remember the previous request. Cookies exist specifically to add state on top of this stateless protocol.
Anatomy of an HTTP Request
GET /account/dashboard HTTP/1.1 Host: bank.example.com User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate, br Cookie: session_id=abc123def456; user_pref=dark_mode Referer: https://bank.example.com/login Connection: keep-alive
Security-relevant information visible in this single request: the exact browser and operating system (User-Agent), the previous page visited (Referer), the session identifier (Cookie), and the requested resource path. In HTTP (not HTTPS), this is all visible to anyone on the network path.
HTTP Methods and Their Security Implications
HTTP Response Headers — Your Security Configuration
HTTP response headers sent by the server tell the browser how to behave. Security-relevant headers prevent common web attacks:
HTTP/1.1 200 OK Content-Type: text/html; charset=UTF-8 Strict-Transport-Security: max-age=31536000; includeSubDomains ← force HTTPS Content-Security-Policy: default-src 'self'; script-src 'self' ← prevent XSS X-Frame-Options: DENY ← prevent clickjacking X-Content-Type-Options: nosniff ← prevent MIME sniffing Referrer-Policy: strict-origin-when-cross-origin ← control Referer header Set-Cookie: session=abc123; HttpOnly; Secure; SameSite=Strict ← protect cookies
A server missing Strict-Transport-Security allows downgrade attacks — an attacker who intercepts the first HTTP request can prevent the HTTPS upgrade. Missing Content-Security-Policy means any injected script runs with the page's full permissions. Missing HttpOnly on cookies means JavaScript can steal them. These headers are a five-minute configuration that prevents entire classes of attack.
// Part 07
TLS — What HTTPS Actually Does and What It Does Not
TLS (Transport Layer Security) is the protocol that encrypts HTTP traffic to create HTTPS. When you see the padlock icon in a browser, TLS is active. Understanding what TLS actually provides — and what it does not — is critical because a surprising number of attacks work against HTTPS targets.
The TLS Handshake — Step by Step
1. Client Hello Client → Server "I support TLS 1.2 and 1.3. Here are the cipher suites I support. My random value: [32 random bytes]" 2. Server Hello + Certificate Server → Client "We will use TLS 1.3 with AES-256-GCM-SHA384. My random value: [32 random bytes] Here is my certificate (signed by DigiCert, proves I am bank.example.com)" 3. Client Verifies Certificate Client checks: - Is the certificate signed by a trusted Certificate Authority? - Does the domain on the cert match the domain I requested? - Is the certificate expired? - Has it been revoked? (OCSP check) 4. Key Exchange (Elliptic Curve Diffie-Hellman) Client and server exchange key material. Each derives the same session keys independently. A passive eavesdropper cannot derive the keys even if they captured all traffic. (This is Perfect Forward Secrecy — keys are ephemeral, not reused) 5. Client Finished / Server Finished Both sides confirm the handshake succeeded. All subsequent traffic is encrypted with the derived session keys.
What TLS Protects
TLS provides three security properties when functioning correctly:
What TLS Does NOT Protect
Additionally, TLS does not protect against:
• Malicious servers with valid certificates: Let's Encrypt will issue a free certificate to any domain — including phishing sites. A perfect HTTPS padlock on bank-secure-login.com means only that the connection to the fake site is encrypted, not that the site is legitimate.
• TLS interception (SSL inspection): Corporate networks and security appliances often perform "man-in-the-middle" TLS inspection — the appliance terminates the TLS connection, inspects the plaintext, then re-encrypts to the destination. From the browser's perspective, TLS looks valid because the corporate CA is trusted. This is legal on corporate equipment but breaks the privacy guarantee for employees.
• Client-side attacks: Malware on the endpoint can read data after decryption, before it reaches the network. The network is encrypted; the browser's memory is not.
Certificate Transparency
Every TLS certificate issued by a public CA must be logged in a public Certificate Transparency (CT) log. This means you can see every certificate ever issued for any domain — including certificates issued for subdomains you did not know existed. Tools like crt.sh and censys.io query CT logs and are standard reconnaissance tools for both attackers discovering attack surface and defenders auditing their certificate inventory.
// Part 08
Putting It Together — The Full Journey of an HTTPS Request
Here is the complete sequence of events when a user types https://bank.example.com/login and presses Enter — with every attack vector annotated:
// Part 09
What This Looks Like at Work — Reading a Packet Capture
// Part 10
Interview Prep — 5 Questions With Complete Answers
// Part 11
Common Network Misunderstandings That Create Vulnerabilities
🎯 Key Takeaways
- ✓The TCP/IP model has four layers (Application, Transport, Internet, Network Access) and each layer is an independent attack surface. A firewall at Layer 3 does not stop ARP poisoning at Layer 2. Match the defence to the layer of the attack.
- ✓IP spoofing — forging the source IP address on packets — is trivially easy because the Internet Protocol has no authentication for source addresses. IP addresses cannot be used as proof of identity. BGP hijacking exploits routing protocol trust to redirect internet traffic at scale.
- ✓The TCP three-way handshake establishes state on the server. SYN flood attacks exhaust this state by sending SYNs without completing the handshake. Port scanning maps attack surfaces by probing which ports have services listening.
- ✓DNS translates names to IP addresses through a chain of resolvers and authoritative servers. DNS cache poisoning injects false records; DNS hijacking modifies authoritative records; subdomain takeover claims abandoned CNAME destinations; DNS exfiltration encodes stolen data as subdomain labels. DNS is involved in almost every attack chain.
- ✓TLS provides confidentiality (encryption), integrity (tamper detection), and authentication (certificate verification) for data in transit. It does not protect data at the server, does not validate that the site is legitimate, and does not protect against server-side vulnerabilities. The padlock means the connection is encrypted, not that the site is safe.
- ✓HTTP exposes significant information in headers — User-Agent, Referer, cookies, and request paths are all visible to network observers in plaintext HTTP. Security-relevant response headers (HSTS, CSP, X-Frame-Options, X-Content-Type-Options, SameSite cookies) prevent entire classes of attack with simple server configuration.
- ✓The TLS handshake uses Diffie-Hellman key exchange to derive session keys that are never transmitted — even a passive observer who recorded the full handshake cannot decrypt the session without the private key. Perfect Forward Secrecy means ephemeral keys are used per session, so compromise of the server private key does not decrypt past sessions.
- ✓The complete journey of an HTTPS request crosses seven distinct attack surfaces: DNS resolution, TCP connection, TLS handshake, HTTP request, server processing, HTTP response, and browser rendering. Attackers choose the weakest link — understanding all seven is what separates a security engineer from someone who just knows HTTPS exists.
- ✓Certificate Transparency logs record every TLS certificate issued by public CAs. Monitoring CT logs for your domain detects DNS hijacking (new certificates issued for your domain you did not request), shadow IT (subdomains you did not know existed), and certificate misuse.
- ✓Network literacy is not optional for security engineers. Firewalls, IDS/IPS, SIEM, packet capture, network-based threat detection — all require understanding what you are looking at. An analyst who cannot read a packet capture cannot do incident response at the network layer.
What comes next
In Module 03, you get hands-on with the operating system every security professional lives in — Linux. File permissions, processes, users, logs, and the specific commands that appear on every incident response and penetration test engagement.
Module 03 → Linux for Security EngineersDiscussion
0Have a better approach? Found something outdated? Share it — your knowledge helps everyone learning here.