2024-02-29 03:45:58 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# poor mans firewall - developed by acidvegas (https://git.acid.vegas/void)
|
|
|
|
|
|
|
|
set -xev
|
|
|
|
|
|
|
|
# Configuration
|
2024-07-10 00:50:57 +00:00
|
|
|
PORT_SSH='22'
|
2024-02-29 03:45:58 +00:00
|
|
|
|
|
|
|
# Kernel hardening settings
|
|
|
|
mkdir -p /etc/sysctl.d
|
|
|
|
{
|
|
|
|
printf "net.ipv4.conf.all.accept_source_route = 0\n"
|
|
|
|
printf "net.ipv6.conf.all.accept_source_route = 0\n"
|
|
|
|
printf "net.ipv4.conf.all.rp_filter = 1\n"
|
|
|
|
printf "net.ipv4.conf.default.rp_filter = 1\n"
|
|
|
|
printf "net.ipv4.conf.all.accept_redirects = 0\n"
|
|
|
|
printf "net.ipv6.conf.all.accept_redirects = 0\n"
|
|
|
|
printf "net.ipv4.conf.default.accept_redirects = 0\n"
|
|
|
|
printf "net.ipv6.conf.default.accept_redirects = 0\n"
|
|
|
|
printf "net.ipv4.conf.all.log_martians = 1\n"
|
|
|
|
printf "kernel.randomize_va_space = 2\n"
|
|
|
|
printf "fs.suid_dumpable = 0\n"
|
|
|
|
} > /etc/sysctl.d/99-custom-hardening.conf
|
|
|
|
|
|
|
|
# Apply hardening settings
|
|
|
|
sysctl -p /etc/sysctl.d/99-custom-hardening.conf
|
|
|
|
|
|
|
|
# Flush existing rules
|
|
|
|
iptables -F
|
|
|
|
iptables -X
|
|
|
|
iptables -t nat -F
|
|
|
|
iptables -t nat -X
|
|
|
|
iptables -t mangle -F
|
|
|
|
iptables -t mangle -X
|
|
|
|
|
|
|
|
# Default chain policies
|
|
|
|
iptables -P INPUT DROP
|
|
|
|
iptables -P FORWARD DROP
|
|
|
|
iptables -P OUTPUT ACCEPT
|
|
|
|
|
|
|
|
# Common Firewall rules
|
|
|
|
iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
|
|
|
|
iptables -A INPUT -p icmp --icmp-type echo-request -j DROP # Disable response to ping requests
|
|
|
|
iptables -A INPUT -p icmp --icmp-type port-unreachable -j DROP
|
|
|
|
iptables -A INPUT -i lo -j ACCEPT
|
|
|
|
|
|
|
|
# Allow SSH access from the Pi server
|
2024-07-10 00:50:57 +00:00
|
|
|
iptables -A INPUT -p tcp --dport $PORT_SSH -j ACCEPT
|
2024-02-29 03:45:58 +00:00
|
|
|
|
|
|
|
# Save rules
|
|
|
|
iptables-save > /etc/iptables/iptables.rules
|
|
|
|
|
|
|
|
# Create and configure the iptables service
|
|
|
|
printf '#!/bin/sh\nexec 2>&1\niptables-restore < /etc/iptables/iptables.rules\nexec chpst -b iptables pause\n' > /etc/sv/iptables/run
|
|
|
|
chmod +x /etc/sv/iptables/run
|
|
|
|
ln -sf /etc/sv/iptables /var/service/ && sv restart iptables
|
|
|
|
|
|
|
|
# Show rules
|
|
|
|
iptables -L -v -n
|