Labs / Defensive Tools / Block and contain: the host, the wire and the data

Lab 3 of 3 · Block and contain: the host, the wire and the data

Data-leak controls: catching a secret on its way out

Match a confidential marker in forwarded traffic, watch it, block it, and see why HTTPS hides it.

Start this lab 5 steps

The idea

Maren looks after IT at Brontë & Sloane, a law firm. Every confidential case has a matter code, and one of them, BS-7731, must never leave the network. Staff upload case notes to an outside file-sharing site every day.

Data-leak prevention (DLP) watches traffic on its way out for sensitive content, then flags or blocks it. Maren puts a content match on the egress router, the one device every outgoing packet crosses. First an iptables rule only counts, then it drops, while ordinary notes still pass. The last step shows the limit: over HTTPS the border sees only encrypted bytes, and the same upload goes straight through.

The router reads the address, not the note
The router reads the address, not the note
A match with no target only counts
A match with no target only counts
DROP sends nothing back
DROP sends nothing back
Only the marked bytes are dropped at the border
Only the marked bytes are dropped at the border
The rule runs, but finds nothing
The rule runs, but finds nothing

Steps

  1. A secret leaves in cleartext

    A paralegal uploads a case note to an outside file-sharing site, and the note carries the confidential matter code BS-7731. Nothing at the border stops it by default. A router forwards what it is given.

    Record the traffic on the egress as the upload crosses. The site is plain HTTP, so the whole request, matter code included, travels in cleartext: unencrypted, readable by anyone on the path. That is what makes the leak possible, and its detection too.

    workstation:~# curl -sS 'http://10.0.2.10/upload?note=BS-7731-confidential'
  2. Monitor mode: count what is leaving

    A DLP control first has to see. Add a rule to the egress's forwarding chain that matches the bytes of the matter code in any forwarded packet. -m string does the search, and --algo bm picks Boyer-Moore, a fast way to find a string in a run of bytes.

    The rule has no target (-j), so it only counts the packets it matches and lets them through. That is monitor mode: you learn how much is leaving before you break anything.

    egress:~# iptables -I FORWARD 1 -p tcp -m string --string "BS-7731" --algo bm
    workstation:~# curl -s -m6 -o /dev/null -w 'http=%{http_code}\n' 'http://10.0.2.10/upload?note=BS-7731-confidential'
    egress:~# iptables -L FORWARD 1 -n -v
  3. Enforce: drop the leak

    Monitor mode showed the leak. Now stop it. Give the same match a target, -j DROP, and the border discards any forwarded packet carrying the matter code before it reaches the outside. -R FORWARD 1 replaces the monitor rule in place with the enforcing one: the same match, with a target this time.

    egress:~# iptables -R FORWARD 1 -p tcp -m string --string "BS-7731" --algo bm -j DROP
    workstation:~# curl -s -m6 -o /dev/null -w 'http=%{http_code}\n' 'http://10.0.2.10/upload?note=BS-7731-confidential'
  4. Only the marked data

    A content match stops exactly what it matches and nothing else. An ordinary note with no matter code uploads normally. So does a note about a different matter, BS-9002, because the rule looks for BS-7731, not for every matter code. That precision is the point, and also the weakness.

    workstation:~# curl -s -m6 -o /dev/null -w 'http=%{http_code}\n' 'http://10.0.2.10/upload?note=lunch-at-noon'
    workstation:~# curl -s -m6 -o /dev/null -w 'http=%{http_code}\n' 'http://10.0.2.10/upload?note=BS-9002-review'
    workstation:~# curl -s -m6 -o /dev/null -w 'http=%{http_code}\n' 'http://10.0.2.10/upload?note=BS-7731-confidential'
  5. The blind spot: HTTPS hides it

    The outside site also serves HTTPS. Upload the very same note over https:// and the matter code is inside the TLS session, encrypted from the workstation all the way to the site. The border still runs the content match on every TCP packet, but all it sees now is ciphertext (encrypted bytes), so the bytes BS-7731 are nowhere to find.

    -k tells curl to skip the certificate check. The site's certificate is signed by the lab's own authority, and the point here is what the border can read, not whether the site is trusted.

    workstation:~# curl -sk -m6 -o /dev/null -w 'http=%{http_code}\n' 'https://10.0.2.10/upload?note=BS-7731-confidential'
    workstation:~# curl -s -m6 -o /dev/null -w 'http=%{http_code}\n' 'http://10.0.2.10/upload?note=BS-7731-confidential'

Run these steps on real machines

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab