SEC/Lesson 5 of 7/8 min read
Network Attacks and Defense
Reconnaissance and port scanning, sniffing, spoofing, ARP poisoning, man-in-the-middle, DNS attacks, DoS and DDoS, firewalls, IDS and IPS, VPNs, network segmentation and Wi-Fi security.
On this page
Attack phases
Network attacks usually follow a pattern (the cyber kill chain): reconnaissance, weaponization, delivery, exploitation, installation, command and control, actions on objectives. Defenders try to break the chain as early as possible.
Reconnaissance
Reconnaissance gathers information about a target.
- Passive: no direct contact. WHOIS, DNS records, certificate transparency logs (subdomains), search engines, leaked credentials, job postings revealing the tech stack, Shodan.
- Active: touches the target. Ping sweeps, port scans, banner grabbing, directory brute forcing.
Port Scanning
Port scanning finds which ports are open and which services and versions run on them.
| Scan | How | Notes |
|---|---|---|
| TCP connect | Full three-way handshake | Reliable, logged by the target |
| SYN (half-open) | Send SYN, read SYN-ACK, reply RST | Faster, stealthier, needs raw sockets |
| UDP | Send UDP, wait for ICMP unreachable | Slow and ambiguous |
| FIN / NULL / Xmas | Unusual flag combinations | Probe firewall and OS behavior |
Nmap
Nmap is the standard scanner.
nmap -sS -sV -O -p- 10.0.0.5 # SYN scan all ports, detect versions and OS
nmap -sn 10.0.0.0/24 # ping sweep: which hosts are upPort states: open (service listening), closed (reachable, no service, RST), filtered (no response, a firewall drops it).
Packet Sniffing
Packet sniffing captures traffic on a network (Wireshark, tcpdump). On a shared medium or a hub everyone sees everything; on a switch an attacker must first redirect traffic (ARP spoofing, MAC flooding to make the switch fail open). Defense: encrypt everything (TLS, SSH, VPN), so captured packets are useless.
Spoofing
IP Spoofing
IP spoofing forges the source IP address of packets. Replies go to the forged address, so it is mostly used for one-way attacks: floods, reflection and amplification DDoS. Defense: ISPs apply ingress filtering (BCP 38) to drop packets with source addresses that cannot originate from that network.
ARP Spoofing
ARP has no authentication. In ARP spoofing (ARP poisoning), the attacker sends forged ARP replies claiming "the gateway's IP is at my MAC", so victims send their traffic through the attacker.
Defenses: Dynamic ARP Inspection on switches, static ARP entries for critical hosts, port security, and end-to-end encryption.
Man-in-the-Middle
In a man-in-the-middle (MITM) attack, the attacker secretly relays and possibly alters communication between two parties who believe they talk directly.
Ways in: ARP spoofing, rogue Wi-Fi access points (evil twin), DNS spoofing, compromised routers, malicious proxies.
- SSL stripping: downgrade a user's HTTPS request to HTTP and proxy it. Stopped by HSTS (and HSTS preload).
- Fake certificates: browsers warn, unless the user clicks through or a rogue root CA is installed.
Defenses: TLS everywhere with certificate validation, HSTS, certificate pinning for mobile apps, mutual TLS between services, and VPNs on untrusted networks.
DNS attacks
DNS Spoofing
DNS spoofing returns a forged answer for a domain, sending the victim to an attacker-controlled IP.
DNS Cache Poisoning
DNS cache poisoning injects forged records into a recursive resolver's cache, so every user of that resolver is redirected until the TTL expires. The 2008 Kaminsky attack made this practical by racing many forged responses guessing the 16-bit transaction ID.
Defenses: source port randomization (more entropy to guess), DNSSEC (cryptographically signed records), and encrypted DNS (DoH, DoT) between clients and resolvers.
Other DNS abuses: DNS tunneling (exfiltrating data in queries), domain hijacking (stolen registrar accounts), and subdomain takeover (a CNAME pointing to a deprovisioned cloud resource someone else can claim).
DoS
A denial of service (DoS) attack exhausts a resource (bandwidth, CPU, memory, connection tables, application threads) so legitimate users cannot be served.
DDoS
A distributed denial of service (DDoS) attack comes from many sources at once, usually a botnet of compromised devices (IoT cameras and routers, as with Mirai), so it cannot be blocked by a single IP.
| Layer | Attack | Target |
|---|---|---|
| Volumetric (L3/L4) | UDP floods, amplification | Bandwidth |
| Protocol (L4) | SYN flood, Ping of Death, fragmentation | Connection state tables |
| Application (L7) | HTTP floods, Slowloris, expensive search queries | Server CPU and threads |
Amplification Attack
An amplification attack sends small requests with a spoofed source IP (the victim's) to open servers that reply with much larger responses. The victim is flooded with replies.
| Protocol | Approximate amplification |
|---|---|
| DNS (open resolvers, ANY queries) | 28 to 54x |
NTP (monlist) | ~556x |
| Memcached (UDP) | up to 51,000x |
DDoS defenses
- Absorb: anycast CDNs and scrubbing services (Cloudflare, AWS Shield, Akamai) with huge capacity.
- Filter: rate limiting, SYN cookies, geo or ASN blocking, dropping malformed packets, upstream blackholing.
- Design: autoscaling, caching, timeouts on slow clients, making expensive endpoints require authentication.
- Do not run open resolvers, NTP or memcached reachable from the internet.
Firewall
A firewall filters traffic between networks by rules, default-deny ideally.
| Type | Inspects | Notes |
|---|---|---|
| Packet filter (stateless) | Each packet's IPs, ports, protocol | Fast, simple ACLs; cannot tell replies from new connections |
| Stateful Firewall | Connection state | Allows replies to established connections automatically |
| Proxy / application gateway | Full application protocol | Deep control, slower |
| Next-generation (NGFW) | Applications, users, threats | Adds DPI, IPS, TLS inspection |
| Host-based | Traffic on one machine | iptables/nftables, Windows Firewall |
Rules are processed top-down, first match wins; end with an explicit deny all. Filter egress too, to stop malware from calling home.
Web Application Firewall
A web application firewall (WAF) inspects HTTP traffic for attack patterns (SQL injection, XSS, known exploits) and blocks them at L7. Useful as a virtual patch and for bot mitigation, but bypassable with encoding tricks; it complements secure code, it does not replace it.
Intrusion Detection System
An intrusion detection system (IDS) monitors traffic or hosts and alerts on suspicious activity. An IPS (intrusion prevention system) sits inline and can block it.
| Signature-based | Anomaly-based | |
|---|---|---|
| How | Matches known attack patterns | Flags deviation from a learned baseline |
| Strength | Accurate for known attacks, few false positives | Can catch new (zero-day) attacks |
| Weakness | Misses unknown attacks | More false positives |
- NIDS: watches network traffic (Snort, Suricata, Zeek).
- HIDS: watches a host's logs, files and processes (OSSEC, Wazuh).
Alert outcomes: true positive (real attack caught), false positive (benign flagged), false negative (attack missed, the dangerous one), true negative.
VPN
A VPN creates an encrypted tunnel over an untrusted network.
- Remote access VPN: a user's device to the corporate network.
- Site-to-site VPN: links two networks (an office to a cloud VPC).
- Protocols: IPsec (network layer; AH for integrity, ESP for encryption; tunnel vs transport mode), TLS/SSL VPNs (OpenVPN), WireGuard (modern, small, fast).
VPNs protect traffic in transit, but a VPN that grants access to the whole internal network is a big risk if a single laptop is compromised. Zero trust access gateways replace it with per-application access.
Network Segmentation
Network segmentation divides a network into zones (with VLANs, subnets and firewalls) so a compromise in one zone cannot spread freely (limits lateral movement). Examples: separate guest Wi-Fi, isolate payment systems (PCI DSS), put databases in private subnets reachable only from app servers.
DMZ
A DMZ (demilitarized zone) is a perimeter network for public-facing servers (web, mail, DNS). The internet can reach the DMZ, the DMZ can reach only specific internal services, and the internet cannot reach the internal network directly.
internet ── firewall ── DMZ (web, mail) ── firewall ── internal networkWireless security
| Protocol | Status |
|---|---|
| WEP | Broken (RC4, IV reuse); cracked in minutes |
| WPA (TKIP) | Deprecated |
| WPA2 (AES-CCMP) | Common; PSK networks vulnerable to offline handshake cracking with weak passphrases; KRACK attack (patched) |
| WPA3 | Current standard |
WPA3
WPA3 replaces the pre-shared-key handshake with SAE (Simultaneous Authentication of Equals), which resists offline dictionary attacks and provides forward secrecy. Enterprise networks use 802.1X with RADIUS so each user has their own credentials.
Other wireless threats: evil twin access points, deauthentication attacks, WPS PIN brute force (disable WPS).
Quick revision
- Recon: passive (OSINT, DNS, CT logs) then active (Nmap scans). Only scan with permission.
- ARP spoofing and rogue Wi-Fi enable MITM; TLS, HSTS and certificate validation defeat it.
- DNS cache poisoning is countered by randomization, DNSSEC and encrypted DNS.
- DDoS: volumetric, protocol and application layer; amplification abuses spoofed UDP; absorb with anycast scrubbing.
- Stateful firewalls track connections; WAFs filter HTTP attacks; default deny, filter egress.
- IDS alerts, IPS blocks; signature-based misses zero-days, anomaly-based has more false positives.
- VPNs encrypt tunnels (IPsec, WireGuard); segmentation and DMZs limit lateral movement.
- Use WPA3 (SAE) or WPA2-Enterprise; WEP is broken.