Most of my recent posts have been centered around red team security, but this article will be more from a blue team perspective of network security. I’ll cover setting up an offsite server to be an encrypted network internet gateway for local endpoints secured with an active Intrusion Prevention System (Suricata IPS) coupled Oinkmaster rule pulling software for automatic updates. Everything will be encrypted over the air and wire via an OpenVPN configuration. All data also goes through iptables, which does the packet forwarding.
First you’ll need to install OpenVPN and it’s dependancies. I suggest using your distribution’s package manager. Since my gateway is running Debian, we’ll be using apt.
You should also create a vpn group in case OpenVPN gets owned.
Next you’ll need to generate some keys. We’ll be using easy-rsa.
Make sure your permission are correct so no unauthorized users can read the ca and server key or you’ll open yourself up to a man in the middle attack. Now you’ll need to configure the OpenVPN server. You can tweak this to your liking, but our lab server config looks something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
cipher AES-256-CBC # network's encryption
auth SHA256 # authentication encryption
dh /etc/openvpn/server/dh.pem # diffie pem
user nobody # unpriviledged user
group vpn # group to run in
proto udp # i'm using the UDP protocol because of low overhead
dev tun # we want to use a tun device for udp
cert /etc/openvpn/server/server.crt # server's cert generated by easy-rsa
key /etc/openvpn/server/server.key # server's key generated by easy-rsa
ca /etc/openvpn/server/ca.crt # certificate authority gen'd by easy-rsa
tls-server # tells clients this is a tls server
server 10.0.0.0 255.255.255.0 # client's dhcp pool
push "redirect-gateway def1" # this pushes the gateway to the client (needed if exit)
push "dhcp-option DNS 8.8.8.8" # dns server to go to clients (needed if an exit)
To get the OpenVPN server to actually be a gateway we need to do a couple more steps, such as turning IP forwarding on, as well as configuration of iptables for masquerade.
# Generated by iptables-save v1.8.4 on Tue May 18 16:35:45 2021
*nat
:PREROUTING ACCEPT [8965:625941]
:INPUT ACCEPT [343:19575]
:OUTPUT ACCEPT [10:757]
:POSTROUTING ACCEPT [343:22904]
-A POSTROUTING -s 10.0.0.0/8 -o eth0 -j MASQUERADE
COMMIT
# Completed on Tue May 18 16:35:45 2021
# Generated by iptables-save v1.8.4 on Tue May 18 16:35:45 2021
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:LOGGING - [0:0]
-A INPUT -i lo -j ACCEPT
-I INPUT -j NFQUEUE --queue-num 0
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -p udp -m udp --dport 1194 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 8 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -j LOGGING
-I FORWARD -j NFQUEUE --queue-num 0
-A FORWARD -s 10.0.0.0/8 -p tcp -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -d 10.0.0.0/8 -p tcp -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -j LOGGING
-A OUTPUT -o lo -j ACCEPT
-I OUTPUT -j NFQUEUE --queue-num 0
-A OUTPUT -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
-A OUTPUT -p icmp -m icmp --icmp-type 0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A OUTPUT -p icmp -m icmp --icmp-type 8 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
-A OUTPUT -j LOGGING
-A LOGGING -m limit --limit 2/min -j LOG --log-prefix "iptables_drop: "
-A LOGGING -j DROP
COMMIT
# Completed on Tue May 18 16:35:45 2021
Then pull in the rules with:
I also suggest installing iptables-persistent if available.
Also finally we need to turn on IP forwarding:
Then spin up OpenVPN with:
You’ll also need to generate .ovpn files for your clients connecting. You can use this script to genearte the files, then securely transfer them to your clients.
Lastly, install the client .ovpn files on each machine you want to connect. (repeat the above steps for generating a client key for each client!)
OpenVPN should now work. If you have any trouble, check
1
/var/log/openvpn/openvpn.log
, and that should point you in the general direction of your problem.
Suricata IPS
To secure the network from the internet, we should install an IPS. In this case we’re using Suricata coupled with Oinkmaster and iptables.
First we need to install Suricata and Oinkmaster:
We also need to install the rules (all the .rules files from suricata.yaml). Let’s do this with Oinkmaster.
Then edit
1
/etc/suricata/suricata.yaml
to your liking. Mine looks like:
We also need to install the rules (all the .rules files from suricata.yaml). Lets do this with Oinkmaster.
I also recommend putting the last two commands in serial in the root user’s crontab so that the IPS will automatically update its rules.
Then a systemd script: