Suricata IPS: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
Zeile 11: Zeile 11:
 
* '''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: "[192.168.10.0/24]"
 +
    DMZ: "[172.18.10.0/24]"
 +
    INT: "[$LAN,$DMZ]"
 +
    EXTERNAL_NET: "!$INT"
  
%YAML 1.1
+
# Standard-Log-Verzeichnis
---
+
default-log-dir: /var/log/suricata/
vars:
+
 
  address-groups:
+
# Statistiken aktivieren
    LAN: "[172.16.1''xx''.0/24]"
+
stats:
    DMZ: "[10.0.1''xx''.0/24]"
+
  enabled: yes
    INTERNAL: "[$LAN,$DMZ]"
+
  interval: 8
    EXTERNAL_NET: "!$INTERNAL"
+
 
default-log-dir: /var/log/suricata/
+
# Ausgaben konfigurieren
stats:
+
outputs:
  enabled: yes
+
  - fast:
  interval: 8
+
      enabled: yes
outputs:
+
      filename: fast.log
  - fast:
+
      append: yes
      enabled: yes
+
  - alert-debug:
      filename: fast.log
+
      enabled: yes
      append: yes
+
      filename: alert-debug.log
  - alert-debug:
+
      append: yes
      enabled: yes
+
  - stats:
      filename: alert-debug.log
+
      enabled: yes
      append: yes
+
      filename: stats.log
  - stats:
+
      append: yes
      enabled: yes
+
       totals: yes
      filename: stats.log
+
       threads: no
      append: yes      # append to file (yes) or overwrite it (no)
+
 
      totals: yes      # stats for all threads merged together
+
# Logging-Einstellungen
      threads: no       # per thread stats
+
logging:
logging:
+
  default-log-level: notice
  default-log-level: notice
+
  outputs:
  outputs:
+
  - console:
  - console:
+
      enabled: yes
      enabled: yes
+
  - file:
  - file:
+
      enabled: yes
      enabled: yes
+
      level: info
      level: info
+
      filename: suricata.log
      filename: suricata.log
+
 
      # type: json
+
# Netzwerkschnittstellen konfigurieren
af-packet:
+
af-packet:
  - interface: enp0s3
+
  - interface: enp0s3
    threads: auto
+
    threads: auto
    cluster-id: 97
+
    cluster-id: 97
    cluster-type: cluster_flow
+
    cluster-type: cluster_flow
    defrag: yes
+
    defrag: yes
  - interface: enp0s8
+
  - interface: enp0s8
    threads: auto
+
    threads: auto
    cluster-id: 98
+
    cluster-id: 98
    cluster-type: cluster_flow
+
    cluster-type: cluster_flow
    defrag: yes
+
    defrag: yes
  - interface: enp0s9
+
  - interface: enp0s9
    threads: auto
+
    threads: auto
    cluster-id: 99
+
    cluster-id: 99
    cluster-type: cluster_flow
+
    cluster-type: cluster_flow
    defrag: yes
+
    defrag: yes
pid-file: /var/run/suricata.pid
+
 
coredump:
+
# PID-Datei
  max-dump: unlimited
+
pid-file: /var/run/suricata.pid
host-mode: auto
+
 
unix-command:
+
# Coredump-Einstellungen
  enabled: yes
+
coredump:
  filename: /var/run/suricata-command.socket
+
  max-dump: unlimited
engine-analysis:
+
 
  rules-fast-pattern: yes
+
# Host-Modus
  rules: yes
+
host-mode: auto
defrag:
+
 
  memcap: 32mb
+
# Unix-Befehlseingabe konfigurieren
  hash-size: 65536
+
unix-command:
  trackers: 65535 # number of defragmented flows to follow
+
  enabled: yes
  max-frags: 65535 # number of fragments to keep (higher than trackers)
+
  filename: /var/run/suricata-command.socket
  prealloc: yes
+
 
  timeout: 60
+
# Engine-Analyse-Einstellungen
default-rule-path: /etc/suricata/rules
+
engine-analysis:
rule-files:
+
  rules-fast-pattern: yes
  - suricata.rules
+
  rules: yes
  - local.rules
+
 
classification-file: /etc/suricata/classification.config
+
# Defragmentierungseinstellungen
reference-config-file: /etc/suricata/reference.config
+
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
 +
 
 +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
 +
~                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
 +
~                                                                                                                                         
 
</pre>
 
</pre>
  

Version vom 11. September 2023, 12:26 Uhr

IPS

  • Wir können mit 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: "[192.168.10.0/24]"
    DMZ: "[172.18.10.0/24]"
    INT: "[$LAN,$DMZ]"
    EXTERNAL_NET: "!$INT"

# 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

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

# Netzwerkschnittstellen konfigurieren
af-packet:
  - interface: enp0s3
    threads: auto
    cluster-id: 97
    cluster-type: cluster_flow
    defrag: yes
  - interface: enp0s8
    threads: auto
    cluster-id: 98
    cluster-type: cluster_flow
    defrag: yes
  - interface: enp0s9
    threads: auto
    cluster-id: 99
    cluster-type: cluster_flow
    defrag: yes

# 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

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
~                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
~                                                                                                                                          

Local Rules

  • cat /etc/suricata/rules/local.rules
drop icmp $LAN any <> $DMZ any (msg: "Ping zwischen LAN und DMZ"; sid:1;)
drop dns $LAN any -> any any (msg:"Kein Googlen"; dns.query; content:"google"; nocase; sid:2;)
alert icmp $INTERNAL any -> !$INTERNAL any (msg:"ICMP TEST"; sid:3;)
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

Ohne Return von der IPS, Hierzu müsste die IPS der Firewall nachgeschaltet.
  • vim /usr/local/sbin/firewall
iptables -P FORWARD DROP
iptables -I FORWARD -i $LANDEV -o $DMZDEV -j NFQUEUE
...

Start suricata

  • suricata -D -q 0 -c /etc/suricata/suricata.yaml

Problematik

  • Dadurch, dass Suricata alle Pakete vom LAN zur DMZ behandelt, werden alle Pakete, die nicht ausdrücklich verworfen werden akzeptiert
  • Wir müssen Suricata also so einstellen, dass es diese Pakete wieder iptables übergibt

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
  • vim /usr/local/sbin/firewall
iptables -P FORWARD DROP
iptables -I FORWARD -i $LANDEV -o $DMZDEV -m mark ! --mark 1/1 -j NFQUEUE
iptables -A FORWARD -i $LANDEV -o $DMZDEV -j LOG --log-prefix "iptables nach Suricata!"
...
  • vim /etc/suricata/suricata.yml
...
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)

Links