Skip to content
Tutorials Center
My learning

Topics

Lesson 27 of 53 ยท Network, Wireless and Cloud Security

Network Attacks and How to Defend Against Them

Understand sniffing, ARP spoofing, DNS poisoning and man-in-the-middle attacks, and learn the defenses: TLS, segmentation and IDS/IPS, with runnable stand-ins.

Most network protocols were designed in a friendlier era. Ethernet, ARP, DNS and plain HTTP all assume that the other machines on the network tell the truth. An attacker who gets onto the same network segment can exploit that trust: listen to traffic, lie about who owns an address, or sit between two parties and relay everything they say.

This lesson explains the classic network attacks at the concept level and, more importantly, the layers that stop them. You will not find attack tooling here. The real packet captures and spoofing tools need a network and administrator rights, so they cannot run on this site, and anything like them belongs only in your own isolated lab. What you can run are stand-ins: small programs that work on made-up data and show how a defender notices the attack.

Four classic network attacks

Sniffing Reading traffic that is not encrypted.
ARP spoofing Lying about which MAC owns an IP.
DNS poisoning Planting a false name-to-address answer.
Man in the middle Relaying and reading both directions.

All four rely on trust that was never verified.

1 / 2

Sniffing: reading what passes by

A sniffer captures packets and decodes them. On its own that is a normal diagnostic technique, and administrators use it daily (see Networking Essentials for Security for what packets contain). It becomes an attack when someone captures traffic they are not entitled to see.

What an observer can read depends on where they sit and on what is encrypted:

  • On an old shared medium (a hub, or an open Wi-Fi network) every machine hears every frame.
  • On a modern switched network a host normally sees only its own traffic and broadcasts, unless the attacker redirects traffic (see ARP spoofing below) or controls a device on the path.
  • Anything sent in clear text, such as old HTTP, FTP, Telnet or unencrypted email protocols, is fully readable, passwords included.

The defense is simple to state: assume the network is hostile and encrypt everything that matters. Use HTTPS, SSH, SFTP and TLS-protected email, and disable the clear-text versions of services where you can.

ARP spoofing

Inside a local network, devices find each other by MAC address. The Address Resolution Protocol (ARP) maps an IP address to the MAC address that owns it: "Who has 192.168.1.1? Tell me." Any machine can answer, and ARP has no authentication. Most systems will even accept an answer nobody asked for (a gratuitous ARP) and update their table.

In an ARP spoofing (or ARP poisoning) attack, a machine on the same segment announces that the gateway's IP address belongs to its MAC address. Victims then send their outbound traffic to the attacker, who can read it, change it or drop it. If the attacker forwards the traffic on to the real gateway, the victim notices nothing, which is the classic man-in-the-middle (MITM) position.

sequenceDiagram
    participant V as Victim
    participant A as Attacker (same LAN)
    participant G as Gateway
    A->>V: "192.168.1.1 is at the attacker's MAC" (false)
    V->>A: Traffic meant for the gateway
    A->>G: Forwarded, possibly modified
    G->>A: Reply
    A->>V: Reply relayed back

A man in the middle created by a false ARP answer; the victim's table now points to the wrong MAC.

Notice the limits. ARP spoofing only works on the same local segment, which is why segmentation matters, and it does not break TLS: the attacker sees encrypted bytes unless the victim clicks through a certificate warning.

How defenders notice and prevent it

  • Dynamic ARP Inspection (DAI) on managed switches compares ARP messages with a trusted table (often built from DHCP snooping) and drops forged ones.
  • Port security limits how many MAC addresses a switch port may use.
  • Static ARP entries for critical hosts, such as the gateway, are practical only on small networks.
  • Monitoring tools watch the ARP table for the pattern "one IP now has a different MAC" or "one MAC claims several IPs".

The first stand-in below applies that last idea to sample data.

JS Stand-in: detect conflicting ARP mappings

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

No output.

Rule 1 is a strong signal. Rule 2 needs judgment: a router or a host with several addresses legitimately claims more than one IP, so a real monitor keeps an allow-list of known multi-address devices. This stand-in only reads a list; a real tool captures live ARP traffic.

DNS poisoning

The Domain Name System turns names such as shop.example into IP addresses. A resolver caches the answers it gets. In DNS poisoning (cache poisoning), an attacker gets a false answer into that cache, so everyone who uses the resolver is sent to the attacker's address when they ask for the real name.

Old resolvers were weak because the only things an attacker had to guess were a 16-bit transaction ID and the source port. Modern resolvers randomize both and validate more carefully, which makes classic off-path poisoning far harder. Attackers who sit on the path, or who compromise a registrar account or a DNS provider login, can still change records, and that is usually the more realistic risk today.

Defenses include:

  • DNSSEC: records are digitally signed, so a resolver that validates can reject forged data. Adoption is partial, and it protects integrity, not privacy.
  • Encrypted DNS (DNS over TLS or HTTPS) between the client and the resolver, which stops local tampering.
  • Keeping resolvers patched, restricting who may query them, and protecting registrar and DNS-provider accounts with strong MFA and registry locks.
  • TLS certificates as the backstop: even if a name resolves to the wrong address, the attacker's server cannot present a valid certificate for your domain.

That last point leads to the most important defense of all.

Man in the middle and why TLS matters

A man in the middle can be created in many ways: ARP spoofing, a rogue Wi-Fi access point (see Wireless Security), poisoned DNS or a compromised router. The defense does not need to prevent every one of them if the connection is protected end to end.

TLS gives a connection three properties:

  1. Confidentiality: an observer sees only encrypted bytes.
  2. Integrity: tampering is detected.
  3. Authentication: the client checks that the server holds a certificate, issued by a trusted authority, for the name it asked for.

The third property is what defeats a MITM. The attacker can redirect packets but cannot produce a valid certificate for shop.example. The attack only succeeds if the user ignores a browser warning, if the attacker holds a trusted certificate (for example through a mis-issued one or a corporate inspection proxy), or if the client does not verify certificates properly.

Developers sometimes weaken this protection by turning off certificate verification to "make the error go away". That one line converts TLS into encryption with nobody checked on the other end. Never do it, even in test code that might reach production. Cryptography Essentials covers certificates and TLS in more depth.

Other helpful settings:

  • HSTS tells browsers to use HTTPS only for your domain, which defeats attempts to downgrade a visit to plain HTTP.
  • Redirect HTTP to HTTPS and keep certificates renewed (expired ones train users to click through warnings).
  • Use modern TLS versions and disable old protocol versions.

Segmentation and IDS/IPS

Two network-level controls limit how far any attack can go.

Segmentation divides a network into zones, such as users, servers, guest devices and building systems, with a firewall or access list between them that allows only needed traffic. A compromised printer on a guest segment then cannot ARP-spoof the finance servers because it never shares a broadcast domain with them. VLANs and firewalls provide the boundaries. Segmentation also shrinks the blast radius of the lateral movement described later in this chapter.

An intrusion detection system (IDS) watches traffic or hosts and raises alerts. An intrusion prevention system (IPS) sits inline and can also block. Two broad detection styles exist:

  • Signature-based: matches known bad patterns. Precise, but blind to anything new.
  • Anomaly-based: learns what is normal and flags deviations. Can catch new behavior, but produces more false alarms.

Neither replaces the other controls. Encrypted traffic hides content from a network IDS, which is one reason host logs matter too (see Logging, Monitoring and SIEM Basics).

The second stand-in is a tiny anomaly rule: it counts ARP replies per source in a time window and flags a source that is far noisier than the rest.

JS Stand-in: a tiny IDS rate rule

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

No output.

A real IDS has many more signals, but the shape is the same: count, compare with a threshold or baseline, raise an alert, and tune the threshold to keep false positives manageable.

Defense checklist. Encrypt in transit everywhere, turn on HSTS, enable DHCP snooping and Dynamic ARP Inspection on managed switches, segment by trust level, protect your DNS provider and registrar accounts with MFA, and send network and DNS logs to a central place.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why does ARP spoofing only work on the local network segment?

    ARP resolves IP addresses to MAC addresses inside a single broadcast domain. That is why segmenting a network limits the attack.
  2. 2. What is the most important protection against a man in the middle who redirects traffic?

    The attacker can redirect packets but cannot present a valid certificate for your domain, so a client that verifies certificates detects the attack.
  3. 3. In the ARP stand-in, which finding is the strongest sign of poisoning?

    An IP changing owner, especially the gateway's IP, is the classic signature. The same MAC repeating an IP is normal.
  4. 4. What does an IPS do that an IDS does not?

    An IDS detects and alerts. An IPS is placed in the traffic path and can drop or reset suspicious connections.

Summary

  • Basic network protocols trust the sender, which attackers on the same segment can abuse.
  • Sniffing reads clear-text traffic; the answer is to encrypt everything that matters.
  • ARP spoofing creates a man in the middle on a local segment; defend with DHCP snooping, Dynamic ARP Inspection, port security and monitoring.
  • DNS poisoning plants false answers; defend with patched resolvers, DNSSEC, encrypted DNS and protected DNS accounts.
  • TLS with certificate verification is the central defense against MITM; never disable verification.
  • Segmentation limits reach, and IDS/IPS detect or block unusual traffic.
  • The stand-ins used sample data only; real captures and tools belong in your own lab.

Next: Wireless Security.