Browse Source

iptables: forward & masquerade docker net -> hackthebox vpn

Fabian Peter Hammerle 5 years ago
parent
commit
ad760a0a71
2 changed files with 13 additions and 2 deletions
  1. 2 2
      Dockerfile
  2. 11 0
      vpn.sh

+ 2 - 2
Dockerfile

@@ -5,5 +5,5 @@ RUN apk add --no-cache openvpn
 VOLUME /hackthebox
 WORKDIR /hackthebox
 
-CMD ["openvpn", "--config", "/hackthebox/vpn-config.ovpn", \
-     "--user", "openvpn", "--group", "openvpn"]
+COPY ./vpn.sh /vpn.sh
+CMD ["/vpn.sh"]

+ 11 - 0
vpn.sh

@@ -0,0 +1,11 @@
+#!/bin/sh
+
+set -ex
+
+iptables -P FORWARD DROP
+iptables -A FORWARD -i eth0 -o tun0 -d 10.10.10.0/24 -j ACCEPT
+iptables -A FORWARD -i tun0 -o eth0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
+iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
+
+openvpn --config /hackthebox/vpn-config.ovpn \
+    --user openvpn --group openvpn