Network IDS and detection as code
Lessons on Suricata and sigma-cli: what a flow id, an interface name, a status word, or a tag does not prove.
- 24 lessons
- 4.5 h of reading
- 2 topics
Detections are code: they have inputs, expected outputs, and bugs. These lessons treat Suricata rules and Sigma rules that way, with sample captures and log lines that prove a rule fires and pull-request checks that keep it working.
Every exercise runs on saved lab captures and sample logs, so results repeat exactly.
Suricata
12 lessons
- 01Suricata offline: run a lab capture through the IDS and read eve.jsonReplay a saved lab pcap through Suricata with the ET Open ruleset, then use jq on eve.json to read alerts alongside the DNS, TLS, and flow records that explain them.11 min
- 02Suricata local rules: write one for your network and tune a noisy oneWrite a local Suricata rule that flags DNS lookups of a retired internal domain, test it against a lab capture, and suppress a noisy ET rule for one known host with a threshold entry.12 min
- 03Suricata: an eve.json alert row is a signature matchAn eve.json row with event_type alert means one signature matched. signature_id names it. Category, severity, and action are labels from the rule, not a verdict.11 min
- 04Suricata: stop tuning and write the false positiveStop adding exceptions when the next one would widen past a single known source. Leave the rule in place and write the false positive on the remaining alerts.11 min
- 05Suricata: a dns or flow row is not an alertIn eve.json, event_type names the kind of row. A dns or flow row is a protocol record. Write that type before any other field, and do not file it as a signature match.11 min
- 06Suricata: a stats counter is not the finding listA stats row’s detect counter is how many alerts the engine tallied for the run. It does not name signatures. Write the counter and the run, then cite alert rows for any signature you claim.11 min
- 07Suricata: the row timestamp is not the filenameThe timestamp on an eve.json row is the event time in that record. A time inside the capture’s filename is your label. Write the row’s timestamp, and do not schedule from the filename.11 min
- 08Suricata: the host field is who wrote the eventWhen an eve.json row has a host field, that is the machine that wrote the record. src_ip is an address in the traffic. Write them separately, and do not call the replay laptop the source of the packets.11 min
- 09Suricata: app_proto is not the destination portapp_proto is the protocol Suricata assigned to the flow. The destination port is a number on the packet. Write both, and do not name the application from the port alone.11 min
- 10Suricata: tx_id is one transactiontx_id numbers one transaction inside a flow, such as a single HTTP request. A second value is another transaction on that same flow, not a second computer.11 min
- 11Suricata: flow_id is not the signature idflow_id is the sensor’s identifier for one flow. signature_id is which rule matched. Two alerts can share a flow and name different rules. Write both ids, and do not merge the rules because the flow id matches.11 min
- 12Suricata: in_iface is the sensor interfacein_iface is the interface name on the sensor that produced the record. src_ip is an address in the traffic. Write them separately, and do not call the interface name the client.11 min
sigma-cli
12 lessons
- 01sigma-cli: convert one detection into Splunk and Microsoft Sentinel queriesInstall sigma-cli and its backend plugins, convert a Sigma rule for suspicious certutil downloads into SPL and KQL, and check the field mappings each pipeline applied.11 min
- 02Detection as code: lint and convert a Sigma rules repository in CIRun sigma check and a conversion step on every pull request to a detection repository, so broken YAML, missing fields, and rules that no longer convert are caught before they reach the SIEM.11 min
- 03sigma-cli: exit code 0 can still be the wrong queryA sigma convert that exits 0 only means a query was printed. Line each YAML field up with the query text, then try one lab event that must not match.12 min
- 04When the same rule’s counts disagree, compare the questionIf Suricata and a converted query report different counts, write both with their units. Compare the window, the field, the rule revision, and any filter one side applied.12 min
- 05sigma-cli: a check issue is a linter row, not a hitsigma check prints validator issues. The severity on that table is the linter’s label. Write the issue name and the file. Do not file it as a detection that fired in the SIEM.11 min
- 06sigma-cli: a saved query needs its pipeline in the headerA converted query file is usable when the header names the rule id, the backend, and the pipelines. A hit count on a file with no header cannot be tied to a rule.12 min
- 07sigma-cli: level is a label in the YAMLThe level field is the rule author’s label. It is not a hit count and it is not the severity column from sigma check. Write it as a label, and do not page from the word alone.11 min
- 08sigma-cli: the index clause is part of the queryThe index or table token in a converted query is which store the search reads. The YAML logsource is the author’s category. Write both, and do not treat a hit count as comparable when those tokens differ.12 min
- 09sigma-cli: the title is not the rule idThe id field identifies the Sigma rule. The title is a label another file can reuse. Cite the id when you name a rule, and do not treat a shared title as one detection.12 min
- 10sigma-cli: timeframe is not the search windowA timeframe in the detection is the span the author wrote into the rule. The earliest and latest bounds are the span the search actually used. Write both, and do not swap them.12 min
- 11sigma-cli: status is a lifecycle wordThe status field is where the author placed the rule, such as test or stable. It is not a hit count and it is not the level. A lab row from a test rule is still a row.11 min
- 12sigma-cli: tags are not log fieldsTags on a Sigma rule are keywords the author attached. They are not columns in the log and not a search you ran. Write them as tags. Do not file hits of the tag string as the rule’s hits.12 min