Labs / Defensive Tools / Detect and analyse: signatures, sandbox, telemetry and decoys

Lab 4 of 5 · Detect and analyse: signatures, sandbox, telemetry and decoys

Writing a NIDS signature, and tuning out the false alarm

Write a Suricata rule for your own network, load it live, and tune away its false positive.

Start this lab 5 steps

The idea

Yusuf is the security analyst at Eastgate Hospital, and this morning he got a tip: someone may be pulling patient records out through the records server. His sensor runs Suricata with Emerging Threats Open, tens of thousands of community signatures for known scans, malware and exploits.

A network intrusion detection system only catches what its rules describe, though, and no public ruleset knows what matters inside Eastgate: that /admin/export on the records server hands back patient files, and that nothing on the clinical floor should ever ask for it. Yusuf writes that rule, loads it into the running sensor, watches it fire on a mirrored copy of the traffic, finds it also trips on a nurse reading a help page, and tunes it until it catches the real thing alone.

Seen, but no rule cares
Seen, but no rule cares
The header picks the traffic, the options pick the match
The header picks the traffic, the options pick the match
A request that works still alerts
A request that works still alerts
Six letters, two URLs
Six letters, two URLs
Too broad fires on benign traffic; tuning fixes it
Too broad fires on benign traffic; tuning fixes it

Steps

  1. A request no rule notices

    The tip says more: a compromised imaging workstation has been pulling records through /admin/export, the records server's bulk-export path. Yusuf starts by making that request himself, from the imaging station, and looking for it in Suricata's alerts.

    The sensor watches a mirrored copy of every packet between the clinical floor and the records server. It writes each event (a connection, an HTTP request, an alert) as one JSON line in eve.json. You read that file with jq, a tool that filters JSON. Here jq loads the whole file and counts the alerts whose URL names the export path.

    imaging:~# curl -s http://10.0.2.10/admin/export
    analyst:~# jq -s '[.[] | select(.event_type=="alert" and ((.http.url // "") | contains("/admin/export")))] | length' /var/log/suricata/eve.json
  2. What a signature is made of

    A Suricata rule has two parts. The header says which traffic to look at: an action, a protocol, and a direction. alert http any any -> 10.0.2.10 any means "raise an alert on HTTP from anywhere to the records server."

    The options, in parentheses, say what to match and how to label it:

    • msg: the text shown when the rule fires. Start local messages with a tag like LOCAL so your rules stand out from the community's at a glance.
    • flow:to_server,established: only requests on a connection that finished its handshake, never half-open noise.
    • http.uri; content:"export": the heart of it. http.uri points Suricata at the request's URL; content is the text to find there. nocase makes the match ignore capitals.
    • sid and rev: the rule's id and its version. Local rules take sids from 1000000 up, the range left free for your own.

    Eastgate's rules live in one file, local.rules, which Suricata already loads beside the community set. You write your first attempt there, then tell the running sensor to read its rules again.

    analyst:~# suricatasc -c reload-rules
  3. Watch it fire

    Make the suspect request again and look for your rule's alert. The pattern is in the URL of an ordinary GET, so it does not matter that the server answers normally. A signature matches what the traffic contains, not whether anything went wrong.

    imaging:~# curl -s http://10.0.2.10/admin/export
    analyst:~# jq -s '[.[] | select(.event_type=="alert" and .alert.signature=="LOCAL Eastgate records export seen" and ((.http.url // "") | contains("/admin/export")))] | length' /var/log/suricata/eve.json
  4. The false positive

    A rule that fires on the attack is half the job. The other half is not firing on anything else. Your rule looks for the letters export anywhere in the URL, and other pages carry those letters too.

    A nurse opens the records help page, /reports/export-guide, which explains how to request an export. Watch what your rule does with it.

    nurseStation:~# curl -s http://10.0.2.10/reports/export-guide
    analyst:~# jq -s '[.[] | select(.event_type=="alert" and .alert.signature=="LOCAL Eastgate records export seen" and ((.http.url // "") | contains("/reports/export-guide")))] | length' /var/log/suricata/eve.json
  5. Tune it to the exact path

    Make the rule say exactly what you mean: a GET whose URL is /admin/export and nothing else. Two content matches do it. http.method; content:"GET" pins the method.

    http.uri; content:"/admin/export"; startswith; endswith says the URL must begin and end with that exact path. /reports/export-guide neither starts nor ends with it, so it no longer matches. A fresh sid (1000002) keeps the tuned rule separate from the first attempt in the logs.

    analyst:~# suricatasc -c reload-rules
    nurseStation:~# curl -s http://10.0.2.10/reports/export-guide
    imaging:~# curl -s http://10.0.2.10/admin/export
    analyst:~# jq -s '[.[] | select(.event_type=="alert" and .alert.signature=="LOCAL Eastgate records export from clinical" and ((.http.url // "") | contains("/admin/export")))] | length' /var/log/suricata/eve.json
    analyst:~# jq -s '[.[] | select(.event_type=="alert" and .alert.signature=="LOCAL Eastgate records export from clinical" and ((.http.url // "") | contains("/reports/export-guide")))] | length' /var/log/suricata/eve.json

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