Suricata IPS: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
 
(40 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
 +
=Grundlagen und Installation=
 +
*[[Suricata Grundlagen]]
 +
*[[Suricata Installation]]
 +
*[[Chrome Dev Tools]]
 +
 +
=Versuchsaufbau=
 +
{{#drawio:ips-netz}}
 +
 
=IPS=
 
=IPS=
*Wir können mit iptables Pakete abfangen und einer QUEUE übergeben
+
*Wir können mit nf/iptables Pakete abfangen und einer QUEUE übergeben
 
*Diese QUEUE wird von suricata gelesen und ihrem REGELWERK übergeben.
 
*Diese QUEUE wird von suricata gelesen und ihrem REGELWERK übergeben.
 
*Wenn das Paket mit einer Regel übereinstimmt, wird eine Aktion ausgelöst.
 
*Wenn das Paket mit einer Regel übereinstimmt, wird eine Aktion ausgelöst.
Zeile 11: Zeile 19:
 
* '''vim /etc/suricata/suricata.yaml'''
 
* '''vim /etc/suricata/suricata.yaml'''
 
<pre>
 
<pre>
 +
%YAML 1.1
 +
---
 +
# Variablen für die Adressgruppen festlegen
 +
vars:
 +
  address-groups:
 +
    LAN: "[172.17.213.0/24]"
 +
    DMZ: "[10.88.213.0/24]"
 +
    SERVER: "[172.16.213.0/24]"
 +
    INT: "[$LAN,$DMZ,$SERVER]"
 +
    HOME_NET: "$INT"
 +
    EXTERNAL_NET: "!$INT"
 +
 +
#Suricate nimmt die Pakete von NF/IPtables wieder auf
 +
nfq:
 +
  mode: repeat
 +
  repeat-mark: 1
 +
  repeat-mask: 1
 +
 +
 +
# Standard-Log-Verzeichnis
 +
default-log-dir: /var/log/suricata/
 +
 +
# Statistiken aktivieren
 +
stats:
 +
  enabled: yes
 +
  interval: 8
 +
 +
# Ausgaben konfigurieren
 +
outputs:
 +
  - fast:
 +
      enabled: yes
 +
      filename: fast.log
 +
      append: yes
 +
  - alert-debug:
 +
      enabled: yes
 +
      filename: alert-debug.log
 +
      append: yes
 +
  - stats:
 +
      enabled: yes
 +
      filename: stats.log
 +
      append: yes
 +
      totals: yes
 +
      threads: no
 +
  - eve-log:
 +
      enabled: yes
 +
      filetype: regular
 +
      filename: eve.json
 +
      types:
 +
        - alert
 +
        - http
 +
        - dns
 +
        - tls
 +
        - flow
 +
        - ssh
 +
        - stats
 +
 +
 +
# Logging-Einstellungen
 +
logging:
 +
  default-log-level: notice
 +
  outputs:
 +
  - console:
 +
      enabled: yes
 +
  - file:
 +
      enabled: yes
 +
      level: info
 +
      filename: suricata.log
 +
 +
 +
 +
# PID-Datei
 +
pid-file: /var/run/suricata.pid
 +
 +
# Coredump-Einstellungen
 +
coredump:
 +
  max-dump: unlimited
 +
 +
# Host-Modus
 +
host-mode: auto
 +
 +
# Unix-Befehlseingabe konfigurieren
 +
unix-command:
 +
  enabled: yes
 +
  filename: /var/run/suricata-command.socket
 +
 +
# Engine-Analyse-Einstellungen
 +
engine-analysis:
 +
  rules-fast-pattern: yes
 +
  rules: yes
  
%YAML 1.1
+
# Defragmentierungseinstellungen
---
+
defrag:
vars:
+
  memcap: 32mb
  address-groups:
+
  hash-size: 65536
    LAN: "[172.16.1''xx''.0/24]"
+
  trackers: 65535
    DMZ: "[10.0.1''xx''.0/24]"
+
  max-frags: 65535
    INTERNAL: "[$LAN,$DMZ]"
+
  prealloc: yes
    EXTERNAL_NET: "!$INTERNAL"
+
  timeout: 60
default-log-dir: /var/log/suricata/
+
 
stats:
+
# Standardregelverzeichnis
  enabled: yes
+
default-rule-path: /etc/suricata/rules
  interval: 8
+
 
outputs:
+
# Regel-Dateien
  - fast:
+
rule-files:
      enabled: yes
+
  - local.rules
      filename: fast.log
+
 
      append: yes
+
# Klassifikationsdatei
  - alert-debug:
+
classification-file: /etc/suricata/classification.config
      enabled: yes
+
 
      filename: alert-debug.log
+
 
      append: yes
+
 
  - stats:
+
# Referenzkonfigurationsdatei
      enabled: yes
+
reference-config-file: /etc/suricata/reference.config
      filename: stats.log
+
app-layer:
      append: yes       # append to file (yes) or overwrite it (no)
+
  protocols:
      totals: yes      # stats for all threads merged together
+
    http:
      threads: no       # per thread stats
+
      enabled: yes
logging:
+
    tls:
  default-log-level: notice
+
      enabled: yes
  outputs:
+
    dcerpc:
  - console:
+
       enabled: yes
      enabled: yes
+
    smb:
  - file:
+
      enabled: yes
      enabled: yes
+
    ftp:
      level: info
+
      enabled: yes
      filename: suricata.log
+
    ssh:
      # type: json
+
      enabled: yes
af-packet:
+
    smtp:
  - interface: enp0s3
+
      enabled: yes
    threads: auto
+
    dns:
    cluster-id: 97
+
      enabled: yes
    cluster-type: cluster_flow
+
    modbus:
    defrag: yes
+
      enabled: yes
  - interface: enp0s8
+
    enip:
    threads: auto
+
      enabled: yes
    cluster-id: 98
+
    dnp3:
    cluster-type: cluster_flow
+
      enabled: yes
    defrag: yes
+
    nfs:
  - interface: enp0s9
+
      enabled: yes
    threads: auto
+
    ntp:
    cluster-id: 99
+
      enabled: yes
    cluster-type: cluster_flow
+
    tftp:
    defrag: yes
+
      enabled: yes
pid-file: /var/run/suricata.pid
+
    ikev2:
coredump:
+
      enabled: yes
  max-dump: unlimited
+
    krb5:
host-mode: auto
+
      enabled: yes
unix-command:
+
    dhcp:
  enabled: yes
+
      enabled: yes
  filename: /var/run/suricata-command.socket
+
    snmp:
engine-analysis:
+
      enabled: yes
  rules-fast-pattern: yes
+
    sip:
  rules: yes
+
      enabled: yes
defrag:
+
    rfb:
  memcap: 32mb
+
      enabled: yes
  hash-size: 65536
+
    mqtt:
  trackers: 65535 # number of defragmented flows to follow
+
      enabled: yes
  max-frags: 65535 # number of fragments to keep (higher than trackers)
+
    rdp:
  prealloc: yes
+
      enabled: yes
  timeout: 60
+
    http2:
default-rule-path: /etc/suricata/rules
+
      enabled: yes
rule-files:
+
    imap:
  - suricata.rules
+
      enabled: yes
  - local.rules
+
                                       
classification-file: /etc/suricata/classification.config
 
reference-config-file: /etc/suricata/reference.config
 
 
</pre>
 
</pre>
  
Zeile 93: Zeile 188:
  
 
*cat /etc/suricata/rules/local.rules
 
*cat /etc/suricata/rules/local.rules
 +
<pre>
 +
# ICMP: einfacher Ping/Traceroute (schneller Funktionstest)
 +
# Test: ping -c1 <ZIEL>
 +
alert icmp any any -> any any (msg:"ICMP Test"; classtype:misc-activity; sid:41;)
 +
 +
# HTTP: mögliches Command-Injection-Merkmal (Semikolon) in POST-Body
 +
# Test: curl -X POST http://<ZIEL>/ -d "q=test%3Bls"
 +
alert http any any -> any any (msg:"Command Injection - Semicolon in POST DATA"; classtype:web-application-attack; flow:established; content:"%3B"; nocase; http_client_body; sid:2;)
 +
 +
# HTTP: mögliches SQLi-Merkmal (einfaches Hochkomma) in POST-Body
 +
# Test: curl -X POST http://<ZIEL>/login -d "u=a&p='%20OR%201=1"
 +
alert http any any -> any any (msg:"Possible SQL Injection (singlequote in POST)"; classtype:web-application-attack; flow:established,to_server; content:"%27"; nocase; http_client_body; sid:3;)
 +
 +
# DNS: Policy – verbietet "google" in DNS-Queries
 +
# Test: dig google.com @<FW>
 +
drop dns any any -> any any (msg:"Kein Googlen"; dns.query; content:"google"; nocase; classtype:policy-violation; sid:43;)
  
drop icmp $LAN any <> $DMZ any (msg: "Ping zwischen LAN und DMZ"; sid:1;)
+
# DoS: viele identische kurze HTTP-GETs (LOIC-ähnlich)
drop dns $LAN any -> any any (msg:"Kein Googlen"; dns.query; content:"google"; nocase; sid:2;)
+
# Test: ab -n 1000 -c 500 http://<ZIEL>/
alert icmp $INTERNAL any -> !$INTERNAL any (msg:"ICMP TEST"; sid:3;)
+
drop tcp any any -> any any (msg:"ET DOS Terse HTTP GET Likely LOIC"; flow:to_server,established; dsize:18; content:"GET / HTTP/1.1|0d 0a 0d 0a|"; depth:18; threshold:type both,track by_dst,count 500,seconds 60; classtype:own-dos; sid:54; rev:2; metadata:created_at 2014_10_03, confidence Medium, signature_severity Major, updated_at 2019_07_26;)
alert tcp any any -> any any (flags: S; msg: "SYN packet"; sid:4;)
 
alert udp $LAN any <> $DMZ any (msg: "DNS abfangen"; sid:5;)
 
  
= Firewallanpassung =
+
# Scan: TCP SYN-Sweep (viele SYN in kurzer Zeit)
;Ohne Return von der IPS, Hierzu müsste die IPS der Firewall nachgeschaltet.
+
# Test: nmap -sS -p1-100 <ZIEL>
* '''vim /usr/local/sbin/firewall'''
+
drop tcp $EXTERNAL_NET any -> $HOME_NET any (msg:"OWN SCAN TCP SYN sweep"; flow:stateless,to_server; flags:S; detection_filter:track by_src,count 20,seconds 5; classtype:attempted-recon; sid:60; rev:1;)
 +
 
 +
# Scan: TCP NULL-Scan (keine Flags gesetzt)
 +
# Test: nmap -sN -p1-100 <ZIEL>
 +
drop tcp $EXTERNAL_NET any -> $HOME_NET any (msg:"OWN SCAN TCP NULL scan"; flow:stateless,to_server; flags:0; detection_filter:track by_src,count 5,seconds 10; classtype:attempted-recon; sid:61; rev:1;)
 +
 
 +
# Scan: TCP FIN-Scan (nur FIN)
 +
# Test: nmap -sF -p1-100 <ZIEL>
 +
drop tcp $EXTERNAL_NET any -> $HOME_NET any (msg:"OWN SCAN TCP FIN scan"; flow:stateless,to_server; flags:F; detection_filter:track by_src,count 5,seconds 10; classtype:attempted-recon; sid:62; rev:1;)
  
iptables -P FORWARD DROP
+
# Scan: TCP XMAS-Scan (FIN+PSH+URG)
iptables -I FORWARD -i $LANDEV -o $DMZDEV -j NFQUEUE
+
# Test: nmap -sX -p1-100 <ZIEL>
...
+
drop tcp $EXTERNAL_NET any -> $HOME_NET any (msg:"OWN SCAN TCP XMAS scan"; flow:stateless,to_server; flags:FPU; detection_filter:track by_src,count 5,seconds 10; classtype:attempted-recon; sid:63; rev:1;)
  
==Start suricata==
+
# Scan: UDP-Sweep mit leerer Payload
 +
# Test: nmap -sU --min-rate=1000 <ZIEL>
 +
drop udp $EXTERNAL_NET any -> $HOME_NET 1:65535 (msg:"OWN SCAN UDP sweep (empty probes)"; flow:to_server; dsize:0; detection_filter:track by_src,count 15,seconds 10; classtype:attempted-recon; sid:64; rev:1;)
  
*'''suricata -D -q 0 -c /etc/suricata/suricata.yaml'''
+
# Scan: ICMP Ping-Sweep (viele Echo-Requests)
 +
# Test: nmap -sn <NETZ>/24
 +
drop icmp $EXTERNAL_NET any -> $HOME_NET any (msg:"OWN SCAN ICMP ping sweep"; itype:8; detection_filter:track by_src,count 10,seconds 5; classtype:attempted-recon; sid:65; rev:1;)
  
== Problematik ==
+
</pre>
  
* Dadurch, dass Suricata alle Pakete vom LAN zur DMZ behandelt, werden alle Pakete, die nicht ausdrücklich verworfen werden akzeptiert
+
= Firewallanpassung =
* Wir müssen Suricata also so einstellen, dass es diese Pakete wieder iptables übergibt
 
  
 
= NFQUEUE Repeat =
 
= NFQUEUE Repeat =
Zeile 121: Zeile 241:
 
* Damit Suricata die nicht gedroppten Pakete automatisch akzeptiert, sondern dies der Firewall überlässt, kann es diese Pakete markieren und zurück zu iptables schicken
 
* Damit Suricata die nicht gedroppten Pakete automatisch akzeptiert, sondern dies der Firewall überlässt, kann es diese Pakete markieren und zurück zu iptables schicken
 
* Markierungen folgen der Syntax $''MARK''/$'''MASK'''
 
* Markierungen folgen der Syntax $''MARK''/$'''MASK'''
 +
 +
== iptables Version ==
 
* '''vim /usr/local/sbin/firewall'''
 
* '''vim /usr/local/sbin/firewall'''
  
 
  iptables -P FORWARD DROP
 
  iptables -P FORWARD DROP
  iptables -I FORWARD -i $LANDEV -o $DMZDEV -m mark ! --mark ''1''/'''1''' -j NFQUEUE
+
  iptables -A FORWARD -m mark ! --mark ''1''/'''1''' -j NFQUEUE
  iptables -A FORWARD -i $LANDEV -o $DMZDEV -j LOG --log-prefix "iptables nach Suricata!"
+
  iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  ...
+
iptables -A FORWARD -j LOG --log-prefix "iptables return from Suricata: "
 +
  # Hier geht es mit den normalen Regeln weiter
 +
 
 +
== nftables Version ==
 +
* '''vim /etc/nftables.conf'''
  
* '''vim /etc/suricata/suricata.yml'''
+
<syntaxhighlight lang="nftables">
 +
table inet filter {
 +
  chain forward {
 +
    type filter hook forward priority 0; policy drop;
 +
    # An Suricata übergeben, wenn Mark-Bit 0 nicht gesetzt
 +
    meta mark and 1 != 1 queue
 +
    # Logging und Akzeptanz nach Rückgabe durch Suricata (mit gesetztem Mark)
 +
    log prefix "nftables return from Suricata: "
 +
    ct state established,related accept
 +
    # Hier geht es mit den normalen Regeln weiter
 +
  }
 +
}
 +
</syntaxhighlight>
  
 +
== Suricata Anpassung ==
 
  ...
 
  ...
 
  nfq:
 
  nfq:
Zeile 140: Zeile 279:
 
*'''suricata -D -q 0'''
 
*'''suricata -D -q 0'''
 
* Den Unterschied zwischen ''repeat'' und ''accept'' kann man mit Ping und SSH testen (falls SSH in der FORWARD Kette blockiert ist)
 
* Den Unterschied zwischen ''repeat'' und ''accept'' kann man mit Ping und SSH testen (falls SSH in der FORWARD Kette blockiert ist)
 +
* Die Verstöße können folgendermaßen gesehen werden
 +
*'''tail -fn0 ''/var/log/suricata/fast.log'' '''
 +
==Suricata Fernbedienung==
 +
;Reload Rules
 +
*suricatasc -c "reload-rules"
 +
;Shutdown
 +
*suricatasc -c "shutdown"
 +
 +
= Suricata als IPS mit systemd starten =
 +
*[[Suricata als IPS mit systemd starten]]
 +
=EveBox=
 +
*[[EveBox]]
  
 
= Links =
 
= Links =
  
 
* https://docs.suricata.io/en/suricata-6.0.0/configuration/suricata-yaml.html#nfq
 
* https://docs.suricata.io/en/suricata-6.0.0/configuration/suricata-yaml.html#nfq
 +
* https://medium.com/@mshulkhan/detection-attack-using-suricata-2-d93d423a435

Aktuelle Version vom 27. August 2025, 20:24 Uhr

Grundlagen und Installation

Versuchsaufbau

IPS

  • Wir können mit nf/iptables Pakete abfangen und einer QUEUE übergeben
  • Diese QUEUE wird von suricata gelesen und ihrem REGELWERK übergeben.
  • Wenn das Paket mit einer Regel übereinstimmt, wird eine Aktion ausgelöst.
  • Alert führt zu einer Meldung
  • Bei Drop wird das Paket verworfen.

Konfiguration Suricata

  • vim /etc/suricata/suricata.yaml
%YAML 1.1
---
# Variablen für die Adressgruppen festlegen
vars:
  address-groups:
    LAN: "[172.17.213.0/24]"
    DMZ: "[10.88.213.0/24]"
    SERVER: "[172.16.213.0/24]"
    INT: "[$LAN,$DMZ,$SERVER]"
    HOME_NET: "$INT"
    EXTERNAL_NET: "!$INT"

#Suricate nimmt die Pakete von NF/IPtables wieder auf
nfq:
  mode: repeat
  repeat-mark: 1
  repeat-mask: 1


# Standard-Log-Verzeichnis
default-log-dir: /var/log/suricata/

# Statistiken aktivieren
stats:
  enabled: yes
  interval: 8

# Ausgaben konfigurieren
outputs:
  - fast:
      enabled: yes
      filename: fast.log
      append: yes
  - alert-debug:
      enabled: yes
      filename: alert-debug.log
      append: yes
  - stats:
      enabled: yes
      filename: stats.log
      append: yes
      totals: yes
      threads: no
  - eve-log:
      enabled: yes
      filetype: regular
      filename: eve.json
      types:
        - alert
        - http
        - dns
        - tls
        - flow
        - ssh
        - stats


# Logging-Einstellungen
logging:
  default-log-level: notice
  outputs:
  - console:
      enabled: yes
  - file:
      enabled: yes
      level: info
      filename: suricata.log



# PID-Datei
pid-file: /var/run/suricata.pid

# Coredump-Einstellungen
coredump:
  max-dump: unlimited

# Host-Modus
host-mode: auto

# Unix-Befehlseingabe konfigurieren
unix-command:
  enabled: yes
  filename: /var/run/suricata-command.socket

# Engine-Analyse-Einstellungen
engine-analysis:
  rules-fast-pattern: yes
  rules: yes

# Defragmentierungseinstellungen
defrag:
  memcap: 32mb
  hash-size: 65536
  trackers: 65535
  max-frags: 65535
  prealloc: yes
  timeout: 60

# Standardregelverzeichnis
default-rule-path: /etc/suricata/rules

# Regel-Dateien
rule-files:
  - local.rules

# Klassifikationsdatei
classification-file: /etc/suricata/classification.config



# Referenzkonfigurationsdatei
reference-config-file: /etc/suricata/reference.config
app-layer:
  protocols:
    http:
      enabled: yes
    tls:
      enabled: yes
    dcerpc:
      enabled: yes
    smb:
      enabled: yes
    ftp:
      enabled: yes
    ssh:
      enabled: yes
    smtp:
      enabled: yes
    dns:
      enabled: yes
    modbus:
      enabled: yes
    enip:
      enabled: yes
    dnp3:
      enabled: yes
    nfs:
      enabled: yes
    ntp:
      enabled: yes
    tftp:
      enabled: yes
    ikev2:
      enabled: yes
    krb5:
      enabled: yes
    dhcp:
      enabled: yes
    snmp:
      enabled: yes
    sip:
      enabled: yes
    rfb:
      enabled: yes
    mqtt:
      enabled: yes
    rdp:
      enabled: yes
    http2:
      enabled: yes
    imap:
      enabled: yes
                                        

Local Rules

  • cat /etc/suricata/rules/local.rules
# ICMP: einfacher Ping/Traceroute (schneller Funktionstest)
# Test: ping -c1 <ZIEL>
alert icmp any any -> any any (msg:"ICMP Test"; classtype:misc-activity; sid:41;)

# HTTP: mögliches Command-Injection-Merkmal (Semikolon) in POST-Body
# Test: curl -X POST http://<ZIEL>/ -d "q=test%3Bls"
alert http any any -> any any (msg:"Command Injection - Semicolon in POST DATA"; classtype:web-application-attack; flow:established; content:"%3B"; nocase; http_client_body; sid:2;)

# HTTP: mögliches SQLi-Merkmal (einfaches Hochkomma) in POST-Body
# Test: curl -X POST http://<ZIEL>/login -d "u=a&p='%20OR%201=1"
alert http any any -> any any (msg:"Possible SQL Injection (singlequote in POST)"; classtype:web-application-attack; flow:established,to_server; content:"%27"; nocase; http_client_body; sid:3;)

# DNS: Policy – verbietet "google" in DNS-Queries
# Test: dig google.com @<FW>
drop dns any any -> any any (msg:"Kein Googlen"; dns.query; content:"google"; nocase; classtype:policy-violation; sid:43;)

# DoS: viele identische kurze HTTP-GETs (LOIC-ähnlich)
# Test: ab -n 1000 -c 500 http://<ZIEL>/
drop tcp any any -> any any (msg:"ET DOS Terse HTTP GET Likely LOIC"; flow:to_server,established; dsize:18; content:"GET / HTTP/1.1|0d 0a 0d 0a|"; depth:18; threshold:type both,track by_dst,count 500,seconds 60; classtype:own-dos; sid:54; rev:2; metadata:created_at 2014_10_03, confidence Medium, signature_severity Major, updated_at 2019_07_26;)

# Scan: TCP SYN-Sweep (viele SYN in kurzer Zeit)
# Test: nmap -sS -p1-100 <ZIEL>
drop tcp $EXTERNAL_NET any -> $HOME_NET any (msg:"OWN SCAN TCP SYN sweep"; flow:stateless,to_server; flags:S; detection_filter:track by_src,count 20,seconds 5; classtype:attempted-recon; sid:60; rev:1;)

# Scan: TCP NULL-Scan (keine Flags gesetzt)
# Test: nmap -sN -p1-100 <ZIEL>
drop tcp $EXTERNAL_NET any -> $HOME_NET any (msg:"OWN SCAN TCP NULL scan"; flow:stateless,to_server; flags:0; detection_filter:track by_src,count 5,seconds 10; classtype:attempted-recon; sid:61; rev:1;)

# Scan: TCP FIN-Scan (nur FIN)
# Test: nmap -sF -p1-100 <ZIEL>
drop tcp $EXTERNAL_NET any -> $HOME_NET any (msg:"OWN SCAN TCP FIN scan"; flow:stateless,to_server; flags:F; detection_filter:track by_src,count 5,seconds 10; classtype:attempted-recon; sid:62; rev:1;)

# Scan: TCP XMAS-Scan (FIN+PSH+URG)
# Test: nmap -sX -p1-100 <ZIEL>
drop tcp $EXTERNAL_NET any -> $HOME_NET any (msg:"OWN SCAN TCP XMAS scan"; flow:stateless,to_server; flags:FPU; detection_filter:track by_src,count 5,seconds 10; classtype:attempted-recon; sid:63; rev:1;)

# Scan: UDP-Sweep mit leerer Payload
# Test: nmap -sU --min-rate=1000 <ZIEL>
drop udp $EXTERNAL_NET any -> $HOME_NET 1:65535 (msg:"OWN SCAN UDP sweep (empty probes)"; flow:to_server; dsize:0; detection_filter:track by_src,count 15,seconds 10; classtype:attempted-recon; sid:64; rev:1;)

# Scan: ICMP Ping-Sweep (viele Echo-Requests)
# Test: nmap -sn <NETZ>/24
drop icmp $EXTERNAL_NET any -> $HOME_NET any (msg:"OWN SCAN ICMP ping sweep"; itype:8; detection_filter:track by_src,count 10,seconds 5; classtype:attempted-recon; sid:65; rev:1;)

Firewallanpassung

NFQUEUE Repeat

  • Damit Suricata die nicht gedroppten Pakete automatisch akzeptiert, sondern dies der Firewall überlässt, kann es diese Pakete markieren und zurück zu iptables schicken
  • Markierungen folgen der Syntax $MARK/$MASK

iptables Version

  • vim /usr/local/sbin/firewall
iptables -P FORWARD DROP
iptables -A FORWARD -m mark ! --mark 1/1 -j NFQUEUE
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -j LOG --log-prefix "iptables return from Suricata: "
# Hier geht es mit den normalen Regeln weiter

nftables Version

  • vim /etc/nftables.conf
table inet filter {
  chain forward {
    type filter hook forward priority 0; policy drop;
    # An Suricata übergeben, wenn Mark-Bit 0 nicht gesetzt
    meta mark and 1 != 1 queue
    # Logging und Akzeptanz nach Rückgabe durch Suricata (mit gesetztem Mark)
    log prefix "nftables return from Suricata: "
    ct state established,related accept
    # Hier geht es mit den normalen Regeln weiter
  }
}

Suricata Anpassung

...
nfq:
  mode: repeat
  repeat-mark: 1
  repeat-mask: 1
...

Start suricata

  • suricata -D -q 0
  • Den Unterschied zwischen repeat und accept kann man mit Ping und SSH testen (falls SSH in der FORWARD Kette blockiert ist)
  • Die Verstöße können folgendermaßen gesehen werden
  • tail -fn0 /var/log/suricata/fast.log

Suricata Fernbedienung

Reload Rules
  • suricatasc -c "reload-rules"
Shutdown
  • suricatasc -c "shutdown"

Suricata als IPS mit systemd starten

EveBox

Links