Network Security
Firewalls
Section titled “Firewalls”A firewall is a network security device or software that monitors and filters incoming and outgoing Network traffic based on an organization’s security policies.
Firewall Types
Section titled “Firewall Types”| Type | OSI Layer | Inspection Depth | Example |
|---|---|---|---|
| Packet filtering | L3 (Network) | Source/destination IP, port, protocol | iptables, nftables, PF |
| Stateful inspection | L3-L4 | Connection state tracking | iptables with conntrack, PF |
| Application-layer | L7 | Application protocol content | ModSecurity, AWS WAF |
| Next-generation (NGFW) | L3-L7 | All of the above + IPS, TLS inspection | Palo Alto, Fortinet, pfSense |
| Web Application (WAF) | L7 | HTTP/HTTPS request/response | Cloudflare WAF, AWS WAF, ModSecurity |
Stateful Inspection
Section titled “Stateful Inspection”Stateful firewalls maintain a connection table that tracks the state of each connection. They Understand the difference between a new connection, an established connection, and a related Connection.
# nftables example: stateful firewall rulesnft add table inet filternft 'add chain inet filter input { type filter hook input priority 0; policy drop; }'nft 'add chain inet filter output { type filter hook output priority 0; policy accept; }'nft 'add chain inet filter forward { type filter hook forward priority 0; policy drop; }'
# Allow established/related connectionsnft add rule inet filter input ct state established,related accept
# Allow loopbacknft add rule inet filter input iif lo accept
# Allow SSH (rate limited)nft add rule inet filter input tcp dport 22 ct state new limit rate 10/minute accept
# Allow HTTPSnft add rule inet filter input tcp dport 443 ct state new accept
# Log and drop everything elsenft add rule inet filter input log prefix "nft-drop: " dropWeb Application Firewall (WAF)
Section titled “Web Application Firewall (WAF)”A WAF operates at layer 7 and inspects HTTP/HTTPS traffic for malicious payloads. It is the last Line of defense against web application attacks (after secure coding practices and input Validation).
WAF rules target specific attack patterns:
| Attack Type | WAF Detection Pattern |
|---|---|
| SQL injection | ' OR``UNION SELECT``--``; DROP |
| XSS | <script``onerror=``javascript: |
| Path traversal | ../``%2e%2e%2f``..%2f |
| Remote code exec | eval(``exec(``system(``cmd= |
| SSRF | 169.254.169.254``metadata.google.internal |
WAF limitations:
- WAFs are signature-based and cannot detect novel attacks
- False positives can block legitimate traffic
- WAFs do not fix underlying vulnerabilities — they mask them
- Encrypted traffic (HTTPS) requires TLS termination before WAF inspection
- Attackers can encode payloads to bypass pattern matching
Default Deny
Section titled “Default Deny”The most important firewall principle: default deny. All traffic is denied unless explicitly Allowed. The alternative (default allow) requires you to enumerate every possible attack, which is Impossible.
# Default deny (correct)iptables -P INPUT DROPiptables -P FORWARD DROPiptables -P OUTPUT ACCEPT # Typically allow outbound
# Then add specific allow rulesiptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPTiptables -A INPUT -p tcp --dport 443 -j ACCEPTNetwork Segmentation
Section titled “Network Segmentation”Network segmentation divides a network into smaller zones with different security policies. Each Zone represents a trust boundary.
Segmentation Models
Section titled “Segmentation Models”VLAN-based Segmentation
Section titled “VLAN-based Segmentation”VLANs (Virtual Local Area Networks) operate at layer 2 and segment a physical network into logical Broadcast domains. Traffic between VLANs must pass through a router or layer 3 switch, where Firewall rules can be applied.
VLAN 10: Management (switches, hypervisors, IPMI)VLAN 20: Production (application servers)VLAN 30: Database (database servers, no internet access)VLAN 40: Development (dev/test environments)VLAN 50: Guest/IoT (isolated, internet-only)# Linux bridge VLAN configurationip link add name br0 type bridgeip link set dev br0 upip link set dev eth0 master br0bridge vlan add dev eth0 vid 10bridge vlan add dev br0 vid 10 pvid untaggedDMZ Architecture
Section titled “DMZ Architecture”A DMZ (Demilitarized Zone) is a network segment that sits between the internal network and the Internet, hosting publicly accessible services.
graph LR
Internet --> FW1[External Firewall]
FW1 --> DMZ[DMZ Zone]
FW1 --> FW2[Internal Firewall]
FW2 --> Internal[Internal Network]
DMZ --> WebServer[Web Server]
DMZ --> MailServer[Mail Server]
Internal --> AppServer[App Server]
Internal --> Database[(Database)]DMZ firewall rules:
| Direction | Rule |
|---|---|
| Internet to DMZ | Allow specific ports (80, 443) |
| DMZ to Internet | Allow established connections |
| DMZ to Internal | Allow specific ports to app tier |
| Internal to DMZ | Allow established connections |
| Internal to Internet | Allow outbound (proxy/NAT) |
| Internet to Internal | Deny all |
Microsegmentation
Section titled “Microsegmentation”Microsegmentation applies security policies at the workload level (container, VM, process) rather Than the network level. It is the network-level implementation of zero trust.
| Technology | Environment | Mechanism |
|---|---|---|
| Kubernetes NetworkPolicy | Kubernetes | Pod-to-pod rules |
| Istio/Envoy | Service mesh | mTLS + authorization policies |
| Calico | Kubernetes | eBPF-based network policy |
| VMware NSX | Virtualization | VM-level microsegmentation |
| AWS Security Groups | Cloud | ENI-level rules |
# Kubernetes NetworkPolicy: deny all ingress to database, allow only from app podapiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata: name: database-policy namespace: productionspec: podSelector: matchLabels: app: database policyTypes: - Ingress ingress: - from: - podSelector: matchLabels: app: api-server ports: - port: 5432 protocol: TCPVirtual Private Networks (VPN)
Section titled “Virtual Private Networks (VPN)”A VPN creates an encrypted tunnel over a public network, allowing secure communication between Remote hosts and a private network.
VPN Protocols
Section titled “VPN Protocols”| Protocol | Encryption | Speed | Audit Status | Key Feature |
|---|---|---|---|---|
| WireGuard | ChaCha20-Poly1305 | Very fast | Small, audited codebase | Modern, minimal, kernel-integrated |
| IPsec | AES-GCM, IKEv2 | Fast | Mature, complex | Suite of protocols, OS-native |
| OpenVPN | AES-256-GCM | Moderate | Mature, audited | Flexible, TLS-based |
| SSTP | TLS 1.2+ | Moderate | Microsoft | Windows-native, traverses firewalls |
WireGuard
Section titled “WireGuard”WireGuard is the recommended VPN protocol for new deployments. It is simple (4,000 lines of kernel Code vs OpenVPN’s 100,000+), fast (in-kernel, modern crypto), and secure (formally verified subset, Small attack surface).
# /etc/wireguard/wg0.conf (server)[Interface]PrivateKey = <server-private-key>Address = 10.0.0.1/24ListenPort = 51820PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADEPostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
[Peer]PublicKey = <client-public-key>AllowedIPs = 10.0.0.2/32# /etc/wireguard/wg0.conf (client)[Interface]PrivateKey = <client-private-key>Address = 10.0.0.2/24DNS = 1.1.1.1, 1.0.0.1
[Peer]PublicKey = <server-public-key>Endpoint = vpn.example.com:51820AllowedIPs = 10.0.0.0/24, 192.168.1.0/24PersistentKeepalive = 25IPsec operates at the network layer (L3) and provides site-to-site and remote access VPN. It Consists of two protocols:
- IKE (Internet Key Exchange): Manages key negotiation (IKEv2 is current)
- ESP (Encapsulating Security Payload): Provides encryption and authentication
# StrongSwan IPsec configuration (site-to-site)config setup charondebug="ike 2, knl 2, cfg 2"
conn site-to-site left=10.1.0.1 leftsubnet=10.1.0.0/24 leftid=@site-a.example.com leftcert=site-a.pem right=203.0.113.1 rightsubnet=10.2.0.0/24 rightid=@site-b.example.com rightcert=site-b.pem ike=aes256gcm16-sha384-ecp384! esp=aes256gcm16-ecp384! keyexchange=ikev2 auto=startIntrusion Detection and Prevention (IDS/IPS)
Section titled “Intrusion Detection and Prevention (IDS/IPS)”IDS vs IPS
Section titled “IDS vs IPS”| Aspect | IDS (Detection) | IPS (Prevention) |
|---|---|---|
| Action | Alerts on suspicious activity | Actively blocks suspicious traffic |
| Deployment | Span port, tap (passive) | Inline (active) |
| Risk | Low (no traffic impact) | Higher (false positives block traffic) |
| Visibility | Full traffic visibility | May miss encrypted traffic |
Detection Methods
Section titled “Detection Methods”| Method | How It Works | Strengths | Weaknesses |
|---|---|---|---|
| Signature-based | Matches known attack patterns | Low false positive rate | Cannot detect novel attacks |
| Anomaly-based | Establishes baseline, flags deviations | Detects unknown attacks | High false positive rate |
| Heuristic-based | Analyzes protocol behavior and traffic patterns | Good at protocol attacks | Requires tuning |
| Behavior-based | Monitors system/process behavior | Detects lateral movement | Complex to configure |
Snort / Suricata
Section titled “Snort / Suricata”Snort and Suricata are open-source IDS/IPS engines that use rule-based detection.
# Suricata rule examples# Detect SQL injection attemptalert http $EXTERNAL_NET any -> $HOME_NET 80 (msg:"ET WEB SQL Injection"; flow:established,to_server; content:"UNION"; nocase; http_uri; content:"SELECT"; nocase; http_uri; distance:0; reference:url,owasp.org/www-community/attacks/SQL_Injection; classtype:web-application-attack; sid:1000001; rev:1;)
# Detect port scanalert tcp $EXTERNAL_NET any -> $HOME_NET any (msg:"PORTSCAN Detected"; flags:S; threshold:type both, track by_src, count 30, seconds 60; classtype:attempted-recon; sid:1000002; rev:1;)
# Detect known malicious IPdrop ip [192.0.2.1, 198.51.100.0/24] any -> $HOME_NET any (msg:"Known Malicious IP"; sid:1000003; rev:1;)Zeek (Bro)
Section titled “Zeek (Bro)”Zeek is a network analysis framework that provides protocol-level analysis rather than signature Matching. It logs all network activity and generates detailed connection, DNS, HTTP, SSL, and file Transfer logs.
# Zeek script to detect SSH brute force@load base/protocols/ssh@load base/frameworks/notice
event ssh_auth_failed(c: connection, auth: bool, msg: string) { if ( !auth ) { NOTICE([$note=SSH::Brute_Force_Attacker, $msg=fmt("SSH brute force from %s", c$id$orig_h), $conn=c, $identifier=c$id$orig_h]); }}Zero Trust Networking
Section titled “Zero Trust Networking”Zero trust networking eliminates implicit trust based on network location. Every request must be Authenticated, authorized, and encrypted regardless of where it originates.
BeyondCorp Model
Section titled “BeyondCorp Model”Google’s BeyondCorp (published in 2014) is the foundational model for zero trust networking. Its Principles:
- Authenticate, not authorize: Every device and user must authenticate before accessing any resource
- Access based on device and user state: Not just credentials, but device posture, location, and behavior
- No special network access: VPNs are replaced by per-application access
- Dynamic access control: Policies are evaluated per-request, not per-connection
Implementation Architecture
Section titled “Implementation Architecture”graph TD
User[User + Device] --> IdP[Identity Provider]
IdP --> PE[Policy Engine]
PE --> PEP[Policy Enforcement Point]
PEP --> App[Application]
User -->|Device Trust| PE
User -->|User Identity| IdP
PE -->|Allow/Deny| PEPComponents:
| Component | Purpose | Implementation |
|---|---|---|
| Identity Provider | Centralized authentication + device trust | Okta, Azure AD, Keycloak |
| Policy Engine | Evaluate access requests against policies | OPA, Cedar, custom |
| Policy Enforcement Point | Enforce decisions at the resource | Envoy, service mesh, API gateway |
| Access Proxy | Per-application secure access | BeyondCorp Enterprise, Tailscale |
| Device Trust | Evaluate device health and compliance | MDM, certificates, posture |
Tailscale as Zero Trust
Section titled “Tailscale as Zero Trust”Tailscale is a WireGuard-based mesh VPN that implements zero trust principles:
- Identity-based: Access is based on identity (SSO), not IP addresses
- No open ports: Services are not exposed to the internet; access requires authentication
- ACL-based: Fine-grained access control per resource
- Key management: WireGuard keys are distributed via a control plane, not manually
// tailscale ACL (tailnet policy file){ "acls": [ // Allow all users to access their own devices { "action": "accept", "src": ["autogroup:member"], "dst": ["autogroup:self:*"] }, // Allow dev team to access staging servers on port 443 { "action": "accept", "src": ["group:dev"], "dst": ["tag:staging:443"] }, // Allow on-call engineers to access production database { "action": "accept", "src": ["group:oncall"], "dst": ["tag:prod-db:5432"] }, // Deny everything else { "action": "deny", "src": ["*"], "dst": ["*:*"] }, ], "tags": ["tag:staging", "tag:prod-db"],}DNS Security
Section titled “DNS Security”DNSSEC
Section titled “DNSSEC”DNSSEC (Domain Name System Security Extensions) adds cryptographic signatures to DNS records, Enabling DNS response authentication. It prevents DNS cache poisoning and spoofing.
| Record Type | Purpose |
|---|---|
| DNSKEY | Public key for the zone |
| RRSIG | Signature over a record set (RRset) |
| DS | Delegation signer — links child zone to parent |
| NSEC/NSEC3 | Proves non-existence of a record (authenticated denial) |
Chain of trust:
Root Zone (trust anchor) └── .com zone (signed by root) └── example.com zone (signed by .com) └── www.example.com A record (signed by example.com)DNS over HTTPS (DoH) and DNS over TLS (DoT)
Section titled “DNS over HTTPS (DoH) and DNS over TLS (DoT)”| Protocol | Port | Encryption | Standard |
|---|---|---|---|
| DoH | 443 | HTTPS | RFC 8484 |
| DoT | 853 | TLS | RFC 7858 |
Both encrypt DNS queries between the client and the resolver, preventing eavesdropping and Manipulation of DNS responses in transit. They do not encrypt queries between the resolver and the Authoritative name server.
Reference Standards: NIST SP 800-41 (Firewall Guidelines), NIST SP 800-207 (Zero Trust Architecture), RFC 6014 (DNSSEC Operational Practices), RFC 7208 (SPF), RFC 6376 (DKIM), RFC 7489 (DMARC), RFC 8446 (TLS 1.3), RFC 8484 (DNS over HTTPS), IEEE 802.1X (Port-Based Network Access Control), MITRE ATT&CK (Tactic: Lateral Movement).
Summary
Section titled “Summary”This topic covers the essential concepts and techniques related to network security, including key principles and practical applications.
Key concepts include:
- core concepts and definitions
- key principles and frameworks
- practical applications
- common techniques and methods
- evaluation and critical analysis
A thorough understanding of these concepts, combined with regular practice and review, is essential for mastery of this topic.
Worked Examples
Section titled “Worked Examples”Worked examples demonstrating the application of key concepts are covered in the detailed sub-pages linked above.