1 import ./make-test-python.nix (
5 meta.maintainers = with lib.maintainers; [ felbinger ];
9 networking.interfaces.eth1 = {
13 address = "192.168.1.2";
19 # disable suricata-update because this requires an Internet connection
20 systemd.services.suricata-update.enable = false;
22 # install suricata package to make suricatasc program available
23 environment.systemPackages = with pkgs; [ suricata ];
28 vars.address-groups.HOME_NET = "192.168.1.0/24";
29 unix-command.enabled = true;
30 outputs = [ { fast.enabled = true; } ];
31 af-packet = [ { interface = "eth1"; } ];
32 classification-file = "${pkgs.suricata}/etc/suricata/classification.config";
36 # create suricata.rules with the rule to detect the output of the id command
37 systemd.tmpfiles.rules = [
38 ''f /var/lib/suricata/rules/suricata.rules 644 suricata suricata 0 alert ip any any -> any any (msg:"GPL ATTACK_RESPONSE id check returned root"; content:"uid=0|28|root|29|"; classtype:bad-unknown; sid:2100498; rev:7; metadata:created_at 2010_09_23, updated_at 2019_07_26;)''
42 imports = [ ../modules/profiles/minimal.nix ];
44 networking.interfaces.eth1 = {
48 address = "192.168.1.1";
56 virtualHosts."localhost".locations = {
57 "/id/".return = "200 'uid=0(root) gid=0(root) groups=0(root)'";
60 networking.firewall.allowedTCPPorts = [ 80 ];
67 # check that configuration has been applied correctly with suricatasc
68 with subtest("suricata configuration test"):
69 ids.wait_for_unit("suricata.service")
70 assert '1' in ids.succeed("suricatasc -c 'iface-list' | ${pkgs.jq}/bin/jq .message.count")
72 # test detection of events based on a static ruleset (output of id command)
73 with subtest("suricata rule test"):
74 helper.wait_for_unit("nginx.service")
75 ids.wait_for_unit("suricata.service")
77 ids.succeed("curl http://192.168.1.1/id/")
78 assert "id check returned root [**] [Classification: Potentially Bad Traffic]" in ids.succeed("tail -n 1 /var/log/suricata/fast.log"), "Suricata didn't detect the output of id comment"