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.
Steps
-
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 withjq, a tool that filters JSON. Herejqloads 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 -
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 anymeans "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 likeLOCALso 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.uripoints Suricata at the request's URL;contentis the text to find there.nocasemakes the match ignore capitals.sidandrev: 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
-
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 -
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
exportanywhere 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 -
Tune it to the exact path
Make the rule say exactly what you mean: a GET whose URL is
/admin/exportand nothing else. Twocontentmatches do it.http.method; content:"GET"pins the method.http.uri; content:"/admin/export"; startswith; endswithsays the URL must begin and end with that exact path./reports/export-guideneither 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