Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Network Security

Network security encompasses policies, practices, and technologies designed to protect network infrastructure, data in transit, and connected systems from unauthorized access, misuse, and attacks. It operates at every layer of the network stack — from physical security of cables to application-layer encryption.

Overview

Security is built on three core principles (the CIA Triad):

graph TD
    A[Security CIA Triad] --> B[Confidentiality]
    A --> C[Integrity]
    A --> D[Availability]
    B --> B1[Encryption: TLS, IPsec]
    B --> B2[Access Control: VPN, Firewalls]
    C --> C1[Hashing: SHA-256, HMAC]
    C --> C2[Digital Signatures]
    D --> D1[DDoS Protection]
    D --> D2[Redundancy, Load Balancing]
PrincipleDefinitionMechanism
ConfidentialityOnly authorized parties read dataEncryption, access control
IntegrityData hasn’t been tampered withHashing, MAC, digital signatures
AvailabilitySystems are accessible when neededDDoS mitigation, redundancy
AuthenticationVerifying identityPasswords, certificates, MFA
AuthorizationVerifying permissionsACLs, RBAC
Non-repudiationSender can’t deny sendingDigital signatures, audit logs

Security Layers

graph TD
    A[Network Security] --> B[Perimeter Security]
    A --> C[Transport Security]
    A --> D[Access Control]
    A --> E[VPN/Encryption]
    A --> F[Monitoring & Detection]
    B --> G[Firewalls]
    B --> H[IDS/IPS]
    B --> I[WAF]
    C --> J[TLS/SSL]
    C --> K[IPsec]
    D --> L[802.1X]
    D --> M[RADIUS/TACACS+]
    E --> N[Site-to-Site VPN]
    E --> O[Remote Access VPN]
    F --> P[SIEM]
    F --> Q[NetFlow Analysis]

Threat Categories

CategoryExamplesImpactMitigation
EavesdroppingPacket sniffing, MITMData theftEncryption (TLS/IPsec)
SpoofingIP/MAC spoofingImpersonationAuthentication, ingress filtering
Denial of ServiceSYN flood, DDoSService outageRate limiting, firewalls, CDN
Man-in-the-MiddleARP poisoning, DNS hijackingData interceptionTLS, certificate pinning
Unauthorized AccessBrute force, credential stuffingSystem compromiseFirewalls, MFA, VPN
Replay AttacksCaptured packets retransmittedSession hijackingNonces, timestamps, session tokens
InjectionSQL injection, command injectionCode executionInput validation, WAF
Social EngineeringPhishing, pretextingCredential theftTraining, email filtering

Common Attacks — Deep Dive

SYN Flood (DoS)

Attack sends many SYN packets without completing the TCP handshake, exhausting server resources.

sequenceDiagram
    participant A as Attacker
    participant S as Server
    A->>S: SYN (spoofed source)
    S->>S: Allocate resources
    S-->>A: SYN-ACK (to spoofed IP)
    Note over S: Half-open connection
    A->>S: SYN (another spoofed)
    A->>S: SYN (another spoofed)
    Note over S: Resources exhausted

Mitigations: SYN cookies, rate limiting, firewalls, SYN proxy.

ARP Poisoning (MITM)

Attacker sends fake ARP replies to associate their MAC with another host’s IP.

Scenario: Attacker tells the router “I am 192.168.1.5” and tells the victim “I am the gateway.” All traffic flows through the attacker.

Mitigations: Dynamic ARP Inspection (DAI), static ARP entries, 802.1X.

DNS Spoofing

Attacker corrupts DNS cache to redirect traffic to malicious servers.

Mitigations: DNSSEC, DNS over HTTPS (DoH), DNS over TLS (DoT).

DDoS (Distributed Denial of Service)

Multiple compromised systems attack simultaneously.

TypeLayerExampleVolume
VolumetricL3/L4UDP flood, amplification100+ Gbps
ProtocolL3/L4SYN flood, Ping of DeathModerate
ApplicationL7HTTP flood, SlowlorisLow volume, hard to detect

Mitigations: CDN (Cloudflare, Akamai), BGP Flowspec, scrubbing centers, anycast.

Man-in-the-Middle (MITM)

Attacker intercepts communication between two parties.

AttackLayerTechnique
ARP PoisoningL2Fake ARP replies
DNS SpoofingL7Corrupt DNS responses
SSL StrippingL7Downgrade HTTPS to HTTP
Rogue APL2Fake WiFi access point

Mitigations: TLS (verify certificates), certificate pinning, HSTS, VPN.


Defense Mechanisms

Firewalls

TypeLayerWhat It InspectsExamples
Packet FilterL3/L4IP, port, protocoliptables, ACLs
StatefulL3/L4Connection stateiptables with conntrack
Application (L7)L7HTTP content, URLsModSecurity, WAF
Next-Gen (NGFW)L3-L7Deep packet inspectionPalo Alto, Fortinet

Firewall Rules Example (iptables):

# Allow established connections
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# Allow SSH from trusted network
iptables -A INPUT -p tcp --dport 22 -s 10.0.0.0/8 -j ACCEPT

# Drop everything else
iptables -A INPUT -j DROP

Intrusion Detection/Prevention (IDS/IPS)

TypePlacementActionExamples
IDSPassive (mirror port)Alert onlySnort, Suricata
IPSInlineBlock + AlertSnort (inline), Suricata

Detection Methods:

  • Signature-based: Match known attack patterns (fast, no false positives for known attacks)
  • Anomaly-based: Detect deviations from normal behavior (catches unknown attacks, more false positives)

VPN (Virtual Private Network)

TypeUse CaseProtocol
Site-to-SiteConnect office networksIPsec
Remote AccessEmployee working from homeOpenVPN, WireGuard, IPsec
Client-to-SiteIndividual device to networkSSL VPN, WireGuard

IPsec Modes:

  • Transport: Encrypts payload only (host-to-host)
  • Tunnel: Encrypts entire original packet (site-to-site)

TLS (Transport Layer Security)

sequenceDiagram
    participant C as Client
    participant S as Server
    C->>S: ClientHello (TLS versions, ciphers)
    S->>C: ServerHello (chosen cipher) + Certificate
    C->>C: Verify certificate (CA chain)
    C->>S: Key Exchange (ECDHE)
    Note over C,S: Both derive session keys
    C->>S: Finished (encrypted)
    S->>C: Finished (encrypted)
    Note over C,S: Application data encrypted

TLS 1.3 improvements over 1.2:

  • 1-RTT handshake (vs 2-RTT)
  • Removed weak ciphers (RC4, 3DES, RSA key exchange)
  • 0-RTT resumption
  • Forward secrecy by default (ECDHE only)

802.1X (Network Access Control)

Port-based network access control. Devices must authenticate before gaining network access.

graph LR
    S[Supplicant<br/>Client Device] --> A[Authenticator<br/>Switch/AP]
    A --> R[Authentication Server<br/>RADIUS]
    S -->|"EAP"| A
    A -->|"RADIUS"| R
    R -->|Accept/Reject| A
    A -->|Open/Block Port| S

Zero Trust Architecture

“Never trust, always verify.” Every request is authenticated and authorized regardless of network location.

PrincipleImplementation
Verify explicitlyAuthenticate every request (identity, device, location)
Least privilegeMinimal access, just-in-time (JIT)
Assume breachMicrosegmentation, encryption everywhere

Security Protocols Summary

ProtocolLayerPurposeKey Feature
TLS 1.3L5-L7Transport encryption1-RTT, forward secrecy
IPsecL3Network-layer VPNAH (integrity) + ESP (encryption)
HTTPSL7Secure HTTPTLS + HTTP
SSHL7Secure shellPublic key auth, tunneling
DNSSECL7DNS integrityDigital signatures on DNS records
WPA3L2WiFi securitySAE handshake, 192-bit encryption
MACsecL2Ethernet encryption802.1AE, hop-by-hop

Interview Questions

  1. Q: What is defense in depth? A: Multiple layers of security controls. If one fails, others provide protection. Example: firewall (perimeter) + TLS (transport) + VPN (remote access) + MFA (authentication) + IDS (monitoring) + WAF (application). No single point of failure.

  2. Q: What’s the difference between IDS and IPS? A: IDS (Intrusion Detection System) is passive — monitors traffic and generates alerts but doesn’t block. IPS (Intrusion Prevention System) is inline — actively blocks malicious traffic. IDS has zero false-positive impact on traffic; IPS can block legitimate traffic if misconfigured.

  3. Q: Explain the TLS handshake. A: (1) Client sends supported ciphers. (2) Server picks cipher and sends certificate. (3) Client verifies certificate against CA. (4) Key exchange (ECDHE in TLS 1.3). (5) Both derive session keys. (6) Encrypted communication begins. TLS 1.3 does this in 1 RTT.

  4. Q: What is forward secrecy and why does it matter? A: If a server’s private key is compromised, past sessions remain secure because each session uses ephemeral keys (ECDHE). Without forward secrecy (RSA key exchange), an attacker recording traffic could decrypt all past sessions after stealing the private key. TLS 1.3 requires forward secrecy.

  5. Q: How does a SYN flood attack work and how do you mitigate it? A: Attacker sends many SYN packets (often with spoofed IPs) without completing the handshake. Server allocates resources for each half-open connection until exhausted. Mitigation: SYN cookies (don’t allocate until handshake completes), rate limiting, SYN proxy (firewall completes handshake on server’s behalf).

  6. Q: What is Zero Trust? A: Security model that assumes no implicit trust based on network location. Every request must be authenticated, authorized, and encrypted. Key principles: verify explicitly, least privilege, assume breach. Replaces the traditional “trust internal network” perimeter model.

  7. Q: What is ARP poisoning and how do you prevent it? A: Attacker sends fake ARP replies to associate their MAC address with another host’s IP (e.g., the gateway). All traffic between victim and gateway flows through the attacker. Prevention: Dynamic ARP Inspection (DAI) on switches, static ARP entries for critical hosts, 802.1X authentication.

  8. Q: What’s the difference between TLS and IPsec? A: TLS operates at L5-L7 (application/transport), primarily for HTTPS, and secures application traffic. IPsec operates at L3 (network), encrypting all IP packets, and is used for VPNs. TLS is end-to-end (application to application); IPsec is typically gateway-to-gateway or host-to-network.

Summary

Network security is multi-layered, applying controls at every level of the stack. The CIA triad (confidentiality, integrity, availability) guides security design. Common attacks include eavesdropping, spoofing, DoS, and MITM — each with specific mitigations. Key technologies include firewalls, IDS/IPS, TLS, IPsec, VPNs, and 802.1X. Modern approaches like Zero Trust assume breach and verify every request.

Cross-References

References