ubuntu 16.04 + nvidia

#!/usr/bin/env bash
sudo apt purge "nvidia*"

sudo add-apt-repository -y ppa:graphics-drivers/ppa
sudo apt update && sudo apt -y full-upgrade

sudo apt install -y dkms
sudo apt install -y nvidia-378
sudo echo "blacklist nouveau" > /etc/modprobe.d/disable-nouveau.conf
sudo echo "options nouveau modeset=0" >> /etc/modprobe.d/disable-nouveau.conf

exit 0

Simple DDOS Mitigation with iptables

edit /etc/sysctl.d/60-zercle.conf
and run
sysctl --system

/etc/iptables.up.rules

# Generated by iptables-save v1.6.0 on Thu Mar 30 00:19:26 2017
*raw
:PREROUTING ACCEPT [1324:102679]
:OUTPUT ACCEPT [110:12756]
# Don't track SYN packets
-A PREROUTING -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j CT --notrack
COMMIT
# Completed on Thu Mar 30 00:19:26 2017
*mangle
:PREROUTING ACCEPT [1324:102679]
:INPUT ACCEPT [1248:94938]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [110:12756]
:POSTROUTING ACCEPT [110:12756]
# Allow loopback
-A PREROUTING -i lo -j ACCEPT
# Drop TCP packets that are new and are not SYN
-A PREROUTING -p tcp -m tcp ! --tcp-flags FIN,SYN,RST,ACK SYN -m conntrack --ctstate NEW -j DROP
# Drop SYN packets with suspicious MSS value
-A PREROUTING -p tcp -m conntrack --ctstate NEW -m tcpmss ! --mss 536:65535 -j DROP
# Block packets with bogus TCP flags
-A PREROUTING -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG NONE -j DROP
-A PREROUTING -p tcp -m tcp --tcp-flags FIN,SYN FIN,SYN -j DROP
-A PREROUTING -p tcp -m tcp --tcp-flags SYN,RST SYN,RST -j DROP
-A PREROUTING -p tcp -m tcp --tcp-flags FIN,SYN FIN,SYN -j DROP
-A PREROUTING -p tcp -m tcp --tcp-flags FIN,RST FIN,RST -j DROP
-A PREROUTING -p tcp -m tcp --tcp-flags FIN,ACK FIN -j DROP
-A PREROUTING -p tcp -m tcp --tcp-flags ACK,URG URG -j DROP
-A PREROUTING -p tcp -m tcp --tcp-flags FIN,ACK FIN -j DROP
-A PREROUTING -p tcp -m tcp --tcp-flags PSH,ACK PSH -j DROP
-A PREROUTING -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG FIN,SYN,RST,PSH,ACK,URG -j DROP
-A PREROUTING -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG NONE -j DROP
-A PREROUTING -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG FIN,PSH,URG -j DROP
-A PREROUTING -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG FIN,SYN,PSH,URG -j DROP
-A PREROUTING -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG FIN,SYN,RST,ACK,URG -j DROP
# Block spoofed packets
-A PREROUTING -s 224.0.0.0/3 -j DROP
-A PREROUTING -s 169.254.0.0/16 -j DROP
-A PREROUTING -s 172.16.0.0/12 -j DROP
-A PREROUTING -s 192.0.2.0/24 -j DROP
-A PREROUTING -s 192.168.0.0/16 -j DROP
-A PREROUTING -s 10.0.0.0/8 -j DROP
-A PREROUTING -s 0.0.0.0/8 -j DROP
-A PREROUTING -s 240.0.0.0/5 -j DROP
-A PREROUTING -s 127.0.0.0/8 ! -i lo -j DROP
# Drop fragments in all chains
-A PREROUTING -f -j DROP
COMMIT
# Completed on Thu Mar 30 00:19:26 2017
# Generated by iptables-save v1.6.0 on Tue Mar 28 11:50:15 2017
*nat
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:PREROUTING ACCEPT [0:0]
-A POSTROUTING -j MASQUERADE
COMMIT
# Completed on Thu Mar 30 00:19:26 2017
# Generated by iptables-save v1.6.0 on Tue Mar 28 11:50:15 2017
*filter
:INPUT ACCEPT [1246:94823]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [110:12756]
:port-scanning - [0:0]
# Allow loopback
-A INPUT -i lo -j ACCEPT
# Allow current connection
-A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
#Limiting the incoming icmp ping request: 
-A INPUT -p icmp -m limit --limit 1/s --limit-burst 2 -j ACCEPT
-A INPUT -p icmp -j DROP
# Simple DDOS Migation by SYNPROXY
-A INPUT -p tcp -m tcp -m conntrack --ctstate INVALID,UNTRACKED -j SYNPROXY --sack-perm --timestamp --wscale 7 --mss 1460 -m multiport --dports 22,80,443
-A INPUT -p tcp -m tcp -m conntrack --ctstate INVALID,UNTRACKED -j SYNPROXY --sack-perm --timestamp --wscale 7 --mss 1460 -m multiport --dports 8080,8443
-A INPUT -m conntrack --ctstate INVALID -j DROP
# SSH brute-force protection
-A INPUT -p tcp -m tcp --dport 22 -m conntrack --ctstate NEW -m recent --set --name SSHBF --rsource
-A INPUT -p tcp -m tcp --dport 22 -m conntrack --ctstate NEW -m recent --update --seconds 60 --hitcount 10 --name SSHBF --rsource -j DROP
# Protection against port scanning
-A port-scanning -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK RST -m limit --limit 1/sec --limit-burst 2 -j RETURN
-A port-scanning -j DROP
# Allow Apps
-A INPUT -p tcp -m tcp -m multiport -j ACCEPT --dports 22,80,443
-A INPUT -p tcp -m tcp -m multiport -j ACCEPT --dports 8080,8443
# Default DROP
-A INPUT -j DROP
COMMIT
# Completed on Thu Mar 30 00:19:26 2017

/etc/ip6tables.up.rules

# Generated by iptables-save v1.6.0 on Thu Mar 30 00:19:26 2017
*raw
:PREROUTING ACCEPT [1324:102679]
:OUTPUT ACCEPT [110:12756]
# Don't track SYN packets
-A PREROUTING -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j CT --notrack
COMMIT
# Completed on Thu Mar 30 00:19:26 2017
# Generated by iptables-save v1.6.0 on Tue Mar 28 11:50:15 2017
*filter
:INPUT ACCEPT [1246:94823]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [110:12756]
:port-scanning - [0:0]
# Allow loopback
-A INPUT -i lo -j ACCEPT
# Allow current connection
-A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
-A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
#Limiting the incoming icmp ping request: 
-A INPUT -p ipv6-icmp -m limit --limit 1/s --limit-burst 2 -j ACCEPT
-A INPUT -p ipv6-icmp -j DROP
# Simple DDOS Migation by SYNPROXY
-A INPUT -p tcp -m tcp -m conntrack --ctstate INVALID,UNTRACKED -j SYNPROXY --sack-perm --timestamp --wscale 7 --mss 1460 -m multiport --dports 22,80,443
-A INPUT -p tcp -m tcp -m conntrack --ctstate INVALID,UNTRACKED -j SYNPROXY --sack-perm --timestamp --wscale 7 --mss 1460 -m multiport --dports 8080,8443
-A INPUT -m conntrack --ctstate INVALID -j DROP
# SSH brute-force protection
-A INPUT -p tcp -m tcp --dport 22 -m conntrack --ctstate NEW -m recent --set --name SSHBF --rsource
-A INPUT -p tcp -m tcp --dport 22 -m conntrack --ctstate NEW -m recent --update --seconds 60 --hitcount 10 --name SSHBF --rsource -j DROP
# Protection against port scanning
-A port-scanning -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK RST -m limit --limit 1/sec --limit-burst 2 -j RETURN
-A port-scanning -j DROP
# Allow Apps
-A INPUT -p tcp -m tcp -m multiport -j ACCEPT --dports 22,80,443
-A INPUT -p tcp -m tcp -m multiport -j ACCEPT --dports 8080,8443
# Default DROP
-A INPUT -j DROP
COMMIT
# Completed on Thu Mar 30 00:19:26 2017
# Generated by iptables-save v1.6.0 on Tue Mar 28 11:50:15 2017
*mangle
:PREROUTING ACCEPT [1324:102679]
:INPUT ACCEPT [1248:94938]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [110:12756]
:POSTROUTING ACCEPT [110:12756]
COMMIT
# Completed on Thu Mar 30 00:19:26 2017
# Generated by iptables-save v1.6.0 on Tue Mar 28 11:50:15 2017
*nat
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:PREROUTING ACCEPT [0:0]
-A POSTROUTING -j MASQUERADE
COMMIT
# Completed on Thu Mar 30 00:19:26 2017

Debian,Ubuntu load iptables
/etc/network/if-pre-up.d/iptablesload
chmod +x /etc/network/if-pre-up.d/iptablesload

#!/usr/bin/env bash
sysctl -p/etc/sysctl.d/60-ddos.conf > /dev/null 2>&1
iptables-restore < /etc/iptables.up.rules
ip6tables-restore < /etc/ip6tables.up.rules
exit 0

RHEL,Centos load iptables

#!/usr/bin/env bash
sysctl -p/etc/sysctl.d/60-ddos.conf > /dev/null 2>&1
systemctl mask firewalld
yum -y install iptables-services
systemctl enable iptables
systemctl enable ip6tables
iptables-restore < /etc/iptables.up.rules
ip6tables-restore < /etc/ip6tables.up.rules
ln -sf /etc/iptables.up.rules /etc/sysconfig/iptables
ln -sf /etc/ip6tables.up.rules /etc/sysconfig/ip6tables
exit 0

pfSense on KVM

Create VM

CPU: pass host flag into guest
Net Interface: VirtIO

Add these script into /boot/loader.conf.local

virtio_load="YES"
virtio_pci_load="YES"
if_vtnet_load="YES"
virtio_balloon_load="YES"

 

KVM + ebtables for anti guest IP spoofing

#!/usr/bin/env bash
apt update
apt install ebtables
ebtables -A FORWARD -i <vm_interface> -p IPv4 --ip-src '!' <vm_ip> -j DROP

# eg.
# ebtables -A FORWARD -i tap100i0 -p IPv4 --ip-src '!' 192.168.0.100 -j DROP

exit 0

 

nginx config

/etc/nginx/nginx.conf

/etc/nginx/conf.d/http/letsencrypt.conf

/etc/nginx/conf.d/http/web.conf

/etc/nginx/conf.d/stream/mariadb.conf