Suricata IPS: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
 
(26 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt)
Zeile 2: Zeile 2:
 
*[[Suricata Grundlagen]]
 
*[[Suricata Grundlagen]]
 
*[[Suricata Installation]]
 
*[[Suricata Installation]]
 +
*[[Chrome Dev Tools]]
  
 
=Versuchsaufbau=
 
=Versuchsaufbau=
Zeile 7: Zeile 8:
  
 
=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 23: Zeile 24:
 
vars:
 
vars:
 
   address-groups:
 
   address-groups:
     LAN: "[192.168.10.0/24]"
+
     LAN: "[172.17.213.0/24]"
     DMZ: "[172.18.10.0/24]"
+
    DMZ: "[10.88.213.0/24]"
     INT: "[$LAN,$DMZ]"
+
     SERVER: "[172.16.213.0/24]"
 +
     INT: "[$LAN,$DMZ,$SERVER]"
 +
    HOME_NET: "$INT"
 
     EXTERNAL_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
 
# Standard-Log-Verzeichnis
Zeile 52: Zeile 62:
 
       totals: yes
 
       totals: yes
 
       threads: no
 
       threads: no
 +
  - eve-log:
 +
      enabled: yes
 +
      filetype: regular
 +
      filename: eve.json
 +
      types:
 +
        - alert
 +
        - http
 +
        - dns
 +
        - tls
 +
        - flow
 +
        - ssh
 +
        - stats
 +
  
 
# Logging-Einstellungen
 
# Logging-Einstellungen
Zeile 64: Zeile 87:
 
       filename: suricata.log
 
       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-Datei
Zeile 120: Zeile 127:
 
# Klassifikationsdatei
 
# Klassifikationsdatei
 
classification-file: /etc/suricata/classification.config
 
classification-file: /etc/suricata/classification.config
 +
 +
  
 
# Referenzkonfigurationsdatei
 
# Referenzkonfigurationsdatei
reference-config-file: /etc/suricata/reference.config                                                                                                                                  
+
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
 +
                                       
 
</pre>
 
</pre>
  
Zeile 128: 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;)
 +
 +
# 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;)
  
drop http any any <> any any (msg: "SQL Injection Attempt!"; http.request_body; content: "OR 1=1"; sid:2;)
+
# Scan: TCP NULL-Scan (keine Flags gesetzt)
drop dns any any -> any any (msg:"Kein Googlen"; dns.query; content:"google"; nocase; sid:3;)
+
# Test: nmap -sN -p1-100 <ZIEL>
drop http any any -> any any (msg: "Possible SQL Injection attack (Contains singlequote POST DATA)"; flow:established,to_server; content:"%27"; nocase; http_client_body; sid:4;)
+
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;)
drop http any any -> any any (msg: "Possible Command Injection attack (Contains semicolon POST DATA)"; flow:established,to_server; content:"%3B"; nocase; http_client_body; sid:5;)
 
  
= Firewallanpassung =
+
# Scan: TCP FIN-Scan (nur FIN)
;Ohne Return von der IPS, Hierzu müsste die IPS der Firewall nachgeschaltet.
+
# Test: nmap -sF -p1-100 <ZIEL>
* '''vim /usr/local/sbin/firewall'''
+
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 -A FORWARD -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
+
# 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 155: 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 -A FORWARD -m mark ! --mark ''1''/'''1''' -j NFQUEUE
 
  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: "
 
  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 174: 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 =

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