Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 37 ยท Threats and Models

Common Network Attacks and How to Spot Them

Understand sniffing, spoofing, ARP poisoning, man-in-the-middle, DNS attacks and denial of service at a conceptual level, and run defensive detectors in Python.

Network attacks fall into a small number of families. Knowing the family tells you what evidence to look for and which control to reach for. This lesson describes the attacks conceptually, because understanding the mechanism is what a defender needs. It does not give step-by-step attack instructions or working tools. Instead you will write detectors: small programs that look at log or packet data and raise an alarm, the same logic that real intrusion detection systems use.

All data in the examples is fabricated and all addresses are from documentation ranges.

Passive attacks: sniffing and eavesdropping

A sniffer captures packets that pass by. On a shared medium, such as open Wi-Fi or a hub, every device can see others' traffic. On a modern switched network a device normally sees only its own traffic, but a compromised switch, a mirrored port or a tap can reveal more. Sniffing is passive: nothing changes, so it is hard to detect. The defence is therefore encryption: if the data is protected by TLS or a VPN, captured packets are noise. Protocols that send credentials in clear text (Telnet, FTP, HTTP basic authentication) should be retired.

Spoofing

Spoofing means forging an identity field so that traffic appears to come from somewhere it does not.

  • IP spoofing: forged source addresses, often used in floods and reflection attacks. Defence: ingress and egress filtering at the network edge so packets with impossible source addresses are dropped (BCP 38), and cryptographic authentication that does not depend on addresses.
  • MAC spoofing: copying another device's hardware address. Defence: port security and 802.1X authentication.
  • ARP spoofing / poisoning: on a local network, a device sends false answers to "who has this IP address?" so that traffic meant for the gateway goes to the attacker. Defence: dynamic ARP inspection on switches, static entries for critical hosts, and encryption so the redirected traffic is useless.
  • DNS spoofing / cache poisoning: false DNS answers send users to the wrong address. Defence: DNSSEC, randomised ports and query IDs, and TLS certificate checking.
  • Email spoofing: forged sender. Defence: SPF, DKIM and DMARC.

Man-in-the-middle (MITM)

In a man-in-the-middle attack, the attacker sits between two parties and can read or change what passes. Spoofing is usually how the attacker gets into the path. Defences concentrate on authentication plus encryption: if the client verifies the server's certificate and the session is encrypted and authenticated, a middleman cannot read or modify it without being noticed. This is why a browser warning about a certificate must never be clicked away.

sequenceDiagram
    participant C as Client
    participant M as Attacker in the path
    participant S as Server
    C->>M: request (believes M is S)
    M->>S: forwards or alters request
    S->>M: response
    M->>C: forwards or alters response
    Note over C,S: TLS with certificate checking makes this fail visibly

The classic MITM picture. Verified TLS breaks the attacker's position.

Denial of service

A denial-of-service (DoS) attack exhausts a resource so legitimate users cannot be served; a distributed one (DDoS) uses many machines. Families:

  • Volumetric: saturate the bandwidth. Defence: upstream scrubbing services and CDNs.
  • Protocol: abuse protocol state, such as SYN floods that fill a server's half-open connection table. Defence: SYN cookies, rate limits.
  • Application layer: many expensive requests, for example a slow search page. Defence: caching, rate limiting, WAF rules.
  • Amplification: a small spoofed request triggers a large response aimed at the victim (misconfigured DNS or NTP servers). Defence: close open resolvers, filter spoofed sources.

Detector 1: a port-scan and SYN-flood alarm

A scan or flood has a clear signature in connection logs: one source touching many ports or sending many SYNs. Here is the core of the detection logic on fabricated log lines.

Python Detect scanning and SYN floods in a log

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Thresholds are the tuning knob: too low and you alert on every busy client, too high and a slow scan slips through. Real systems also look at timing and use allow-lists for known scanners such as your own vulnerability tool.

Detector 2: spotting ARP poisoning

On a healthy LAN each IP address maps to one MAC address. If the same IP suddenly maps to a different MAC, or one MAC claims many IPs, something is wrong. Tools such as arpwatch implement exactly this idea.

Python Detect conflicting ARP answers

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A mismatch is not always an attack: failover pairs and virtual IPs legitimately move between MACs. That is why alerts need context, and why alerts about your gateway deserve fast attention.

Other attack types worth knowing

  • Password attacks: guessing or reusing credentials against remote services such as SSH or VPN portals. Defence: key-based login, multi-factor authentication, rate limiting, lockout.
  • Replay: capturing a valid message and sending it again. Defence: nonces, timestamps and sequence numbers in the protocol.
  • Session hijacking: stealing a session token. Defence: TLS, secure and short-lived cookies.
  • Rogue devices and rogue access points: unauthorised hardware connected to your network. Defence: 802.1X, network access control, wireless scanning.
  • Malware command and control: infected machines calling home. Defence: egress filtering, DNS monitoring, detection of unusual outbound traffic.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Why is encryption the main defence against packet sniffing?

    Sniffing is passive and hard to prevent entirely, so you make the captured data useless with encryption such as TLS or a VPN.
  2. 2. ARP spoofing works on which kind of network?

    ARP resolves IP addresses to MAC addresses on a local segment, and plain ARP has no authentication.
  3. 3. Which control directly limits SYN floods against a server?

    SYN cookies avoid keeping state for half-open connections, and rate limits cap how many an address can send.
  4. 4. In the port-scan detector, what does the threshold on distinct ports represent?

    A normal client talks to few ports; a scanner touches many. The threshold trades false alarms against missed slow scans.
  5. 5. What stops a man-in-the-middle from silently altering an HTTPS session?

    The client verifies the server's certificate, and TLS protects the records, so tampering is detected.

Summary

  • Attacks come in families: sniffing, spoofing, man-in-the-middle, denial of service, credential attacks, replay and rogue devices.
  • Encryption plus authentication defeats sniffing and MITM; filtering and rate limits blunt spoofing and floods.
  • Detection logic is simple counting and comparing: ports per source, SYN ratios, IP-to-MAC changes.
  • Thresholds need tuning and context to avoid false alarms.
  • Never practise attacks on networks you do not own; build detectors instead.

Next: Threat Modelling with STRIDE and Data Flow Diagrams