# Härtung Firewall

[![image.png](https://docs.maximilianberthold.de/uploads/images/gallery/2024-08/scaled-1680-/image.png)](https://docs.maximilianberthold.de/uploads/images/gallery/2024-08/image.png)

### Firewall-Commands (auf Webserver und Firewall)

```bash
# Akzeptiert Verbindung von Adminserver
iptables -A INPUT -p tcp -s 10.10.10.4 --dport 22 -j ACCEPT

# Lässt keine erstmal keine Verbindung auf Port 22 zu
iptables -A INPUT -p tcp -s 0.0.0.0/0 --dport 22 -j DROP

# Für jeden weiteren Eintrag - Input auf 2 damit die 0.0.0.0/0 Regel an Pos 1 bleibt
iptables -I INPUT 2 -p tcp -s hier neue ip --dport 22 -j ACCEPT 
```

## Intrusion Detection System

[![image.png](https://docs.maximilianberthold.de/uploads/images/gallery/2024-08/scaled-1680-/G8Yimage.png)](https://docs.maximilianberthold.de/uploads/images/gallery/2024-08/G8Yimage.png)

[![image.png](https://docs.maximilianberthold.de/uploads/images/gallery/2024-08/scaled-1680-/BAmimage.png)](https://docs.maximilianberthold.de/uploads/images/gallery/2024-08/BAmimage.png)

[![image.png](https://docs.maximilianberthold.de/uploads/images/gallery/2024-08/scaled-1680-/jLiimage.png)](https://docs.maximilianberthold.de/uploads/images/gallery/2024-08/jLiimage.png)

[![image.png](https://docs.maximilianberthold.de/uploads/images/gallery/2024-08/scaled-1680-/Ctmimage.png)](https://docs.maximilianberthold.de/uploads/images/gallery/2024-08/Ctmimage.png)

### Suricata

[![image.png](https://docs.maximilianberthold.de/uploads/images/gallery/2024-08/scaled-1680-/Xc6image.png)](https://docs.maximilianberthold.de/uploads/images/gallery/2024-08/Xc6image.png)

#### ICMP-Alerts

[![image.png](https://docs.maximilianberthold.de/uploads/images/gallery/2024-08/scaled-1680-/3dsimage.png)](https://docs.maximilianberthold.de/uploads/images/gallery/2024-08/3dsimage.png)

```bash
# Start von Suricata
# -D = Detatched

# suricata -i [INTERFACE1] -i [INTERFACE2] -D

suricata -i ens160 -i ens256 -D
```

#### Commands zum Beenden eines Prozesses

```bash
# Prozess anzeigen
ps aux | grep suricata

# Prozess killen
kill -9 [PID]
# oder
kill [PID]
```

#### DNS-Alerts

[![image.png](https://docs.maximilianberthold.de/uploads/images/gallery/2024-08/scaled-1680-/zLGimage.png)](https://docs.maximilianberthold.de/uploads/images/gallery/2024-08/zLGimage.png)

Diese Regel in Suricata überwacht den DNS-Verkehr (Domain Name System) und löst eine Warnung aus, wenn eine DNS-Anfrage den Begriff "google" enthält.

- **alert dns:** Dies gibt an, dass die Regel auf DNS-Verkehr angewendet wird.
- **dns any any -&gt; any any:** Dies bedeutet, dass die Regel für jede DNS-Anfrage von jeder Quelle zu jedem Ziel gilt.
- **(msg: "DNS LOOKUP for Google";:** Dies ist die Nachricht, die in der Warnung angezeigt wird.
- **dns\_query;:** Dies gibt an, dass die Regel nur auf DNS-Anfragen angewendet werden soll (keine Antworten).
- **content: "google";:** Dies ist die Bedingung, die erfüllt sein muss, damit die Warnung ausgelöst wird. Die DNS-Anfrage muss das Wort "google" enthalten.
- **sid:1000001;)** Dies ist eine eindeutige ID für die Regel.

Mit folgenden Befehlen kann man testen:

```bash
# Google pingen
ping google.com

# DNS-Auflösung
nslookup google.com
```

[![image.png](https://docs.maximilianberthold.de/uploads/images/gallery/2024-08/scaled-1680-/GCOimage.png)](https://docs.maximilianberthold.de/uploads/images/gallery/2024-08/GCOimage.png)

#### Ausgehende SSH-Verbindungen erkennen und alterten

```bash
alert tcp 10.10.10.0/24 any -> any 22 (msg:"Ausgehende SSH-Verbindung erkannt"; flow:established,to_client; sid:1000002; rev:1;) 
```

#### Suricata als Service in Debian machen

create user for **suricata**

```
useradd -r -s /usr/sbin/nologin suricata
```

change the **IFACE** at `/etc/default/suricata` and make it listen to our **infterface**

[![image.png](https://docs.maximilianberthold.de/uploads/images/gallery/2024-09/scaled-1680-/image.png)](https://docs.maximilianberthold.de/uploads/images/gallery/2024-09/image.png)

change the owner of **/var/log/suricata** using command below

```
chown -R suricata:suricata /var/log/suricata
```

edit **interfaces** at **/etc/suricata/suricata.yaml** and make it listen to our **infterface**

[![image.png](https://docs.maximilianberthold.de/uploads/images/gallery/2024-09/scaled-1680-/V9Iimage.png)](https://docs.maximilianberthold.de/uploads/images/gallery/2024-09/V9Iimage.png)

start the S**uricata** and make sure it has been running well

```
systemctl start suricata<br></br>systemctl status suricata
```