TExcelTAD
Home › Computer Networking › Network Security Basics

Network Security Basics

Networks were originally built among trusted research institutions; most core protocols (Ethernet, ARP, IP, DNS, SMTP) have no built-in authentication. Network security is about adding protection around and on top of them. This lesson surveys the main goals, threats and defences you have met throughout the course.

Goals: the CIA triad

Goal Meaning Threat example Defence example
Confidentiality only authorised parties can read data sniffing Wi-Fi, ARP spoofing TLS, VPNs, WPA3
Integrity data isn't altered undetected tampering in transit, DNS forgery MACs/signatures, TLS, DNSSEC
Availability services stay reachable DDoS, SYN floods rate limiting, CDNs, SYN cookies, redundancy

Common attacks by layer

Layer Attack Idea Defence
2 MAC flooding overflow the switch table so it floods like a hub port security
2 ARP spoofing claim the gateway's IP with your MAC Dynamic ARP Inspection, TLS
2 Rogue DHCP hand out a malicious gateway/DNS DHCP snooping
3 IP spoofing forge the source address ingress filtering (BCP 38)
4 SYN flood exhaust half-open connection slots SYN cookies
4 Port scanning find open services firewalls, minimise exposed services
7 DNS spoofing / cache poisoning forge DNS answers DNSSEC, random ports and IDs, DoH
7 Credential stuffing, brute force try many passwords rate limiting, MFA
All DDoS overwhelm with traffic from many sources CDNs/scrubbing, anycast, autoscaling

Port scanning: what the responses reveal

A scanner such as nmap sends a SYN to each port and classifies the reply. This simulation uses the same logic:

python · try it yourself
# How a host and its firewall answer a SYN on each port.
host = {22: "listening", 80: "listening", 443: "listening", 3306: "closed"}
firewall_drops = {3389, 5432}

def probe(port):
    if port in firewall_drops:
        return "filtered", "no reply (firewall drops it)"
    if host.get(port) == "listening":
        return "open", "SYN+ACK (scanner then sends RST)"
    return "closed", "RST"

for port in [22, 80, 443, 3306, 3389, 5432, 8080]:
    state, reply = probe(port)
    print(f"{port:>5}/tcp  {state:<8} {reply}")
   22/tcp  open     SYN+ACK (scanner then sends RST)
   80/tcp  open     SYN+ACK (scanner then sends RST)
  443/tcp  open     SYN+ACK (scanner then sends RST)
 3306/tcp  closed   RST
 3389/tcp  filtered no reply (firewall drops it)
 5432/tcp  filtered no reply (firewall drops it)
 8080/tcp  closed   RST
bash
nmap -sS -p 22,80,443,3306,3389 scanme.example.org

Sample output:

text
PORT     STATE    SERVICE
22/tcp   open     ssh
80/tcp   open     http
443/tcp  open     https
3306/tcp closed   mysql
3389/tcp filtered ms-wbt-server

Note: Only scan networks you own or have written permission to test. Unauthorised scanning is illegal in many countries.

Integrity with message authentication codes

A checksum like CRC-32 catches accidents, not attackers: anyone can recompute it. To detect deliberate tampering you need a MAC (message authentication code) computed with a secret key, such as HMAC-SHA256:

python · try it yourself
import hashlib
import hmac
import zlib

key = b"secret shared by sender and receiver"
message = b"transfer 100 to account 1234"

crc = zlib.crc32(message)
tag = hmac.new(key, message, hashlib.sha256).hexdigest()

forged = b"transfer 900 to account 6666"
print("attacker recomputes the CRC:", zlib.crc32(forged) != crc, "-> CRC gives no protection")
forged_tag_guess = hmac.new(b"attacker's guess", forged, hashlib.sha256).hexdigest()
print("HMAC check on forged message:", hmac.compare_digest(forged_tag_guess,
      hmac.new(key, forged, hashlib.sha256).hexdigest()))
print("HMAC check on genuine message:", hmac.compare_digest(tag, hmac.new(key, message, hashlib.sha256).hexdigest()))
attacker recomputes the CRC: True -> CRC gives no protection
HMAC check on forged message: False
HMAC check on genuine message: True

hmac.compare_digest compares in constant time, so an attacker can't learn the correct tag byte by byte from timing differences.

Rate limiting: a token bucket

Login endpoints, APIs and DNS servers limit how fast one client may send requests. The token bucket is the classic algorithm: tokens drip into a bucket at a fixed rate, each request costs one, and an empty bucket means "429 Too Many Requests":

python · try it yourself
class TokenBucket:
    def __init__(self, capacity, rate_per_s):
        self.capacity, self.rate = capacity, rate_per_s
        self.tokens, self.last = capacity, 0.0

    def allow(self, now):
        self.tokens = min(self.capacity, self.tokens + (now - self.last) * self.rate)
        self.last = now
        if self.tokens >= 1:
            self.tokens -= 1
            return True
        return False

bucket = TokenBucket(capacity=5, rate_per_s=1)
times = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 1.6, 2.0, 2.1, 6.0, 6.1]
log = []
for t in times:
    log.append(f"{t}s:{'ok' if bucket.allow(t) else '429'}")
print("  ".join(log[:6]))
print("  ".join(log[6:]))
0s:ok  0.1s:ok  0.2s:ok  0.3s:ok  0.4s:ok  0.5s:429
0.6s:429  1.6s:ok  2.0s:429  2.1s:ok  6.0s:ok  6.1s:ok

A burst of 5 login attempts is allowed, then the client is held to about one per second. Real systems combine this with account lockouts and MFA.

Defence in depth and zero trust

No single control is enough. Defence in depth layers them: firewalls at the edge, segmentation with VLANs and internal firewalls, encryption everywhere (TLS even inside the data centre), strong authentication, patching, logging and monitoring (IDS such as Suricata or Zeek, centralised logs).

The modern zero trust model goes further: being "inside the network" grants nothing. Every request is authenticated and authorised based on user identity and device state, wherever it comes from. VPN-less access proxies and service meshes with mutual TLS are typical implementations.

Tip: The highest-value habits are boring: keep devices patched, close every port you don't need (check with ss -tulpn), use TLS everywhere, enable MFA, and don't expose admin interfaces (SSH, RDP, databases) to the whole Internet.

Go further: Networking for Security goes through every layer with its attacks, detection and fixes, and Network Security covers assessment, segmentation, firewalls and IDS.

Test yourself

Which security goal does a DDoS attack target?

  1. Confidentiality
  2. Integrity
  3. Availability
  4. Non-repudiation

A scanner sends a SYN and gets no reply at all. How does nmap classify the port?

  1. Open
  2. Closed
  3. Filtered
  4. Listening

Why is CRC-32 not enough to protect a message from tampering?

  1. It is too slow
  2. Anyone can recompute it for a modified message because it uses no secret key
  3. It only works on IPv6
  4. It is encrypted