Created
April 6, 2016 09:19
-
-
Save ggiamarchi/a955aaa5b3898c4c63842ec84be04f22 to your computer and use it in GitHub Desktop.
Example of fail2ban util with apache HTTP server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
$script = <<SCRIPT | |
set -ex | |
apt-get update | |
apt-get install -y apache2 fail2ban | |
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.conf.bak | |
cat > /etc/fail2ban/jail.conf <<EOF | |
[DEFAULT] | |
#ignoreip = 127.0.0.1/8 | |
backend = auto | |
usedns = warn | |
EOF | |
cat > /etc/fail2ban/filter.d/apache-notfound.conf <<EOF | |
[Definition] | |
failregex = ^<HOST> .*GET .* 404 .* | |
ignoreregex = | |
EOF | |
cat > /etc/fail2ban/jail.d/apache-notfound.conf <<EOF | |
[apache-notfound] | |
enabled = true | |
filter = apache-notfound | |
logpath = /var/log/apache2/access.log | |
bantime = 15 | |
findtime = 10 | |
maxretry = 8 | |
action = iptables-multiport[name=%(__name__)s, port="http,https", protocol="tcp", chain="INPUT"] | |
EOF | |
fail2ban-client reload | |
fail2ban-client status | |
SCRIPT | |
Vagrant.configure('2') do |config| | |
config.vm.box = 'ubuntu/trusty64' | |
config.vm.provider 'virtualbox' do |vb| | |
vb.customize ['modifyvm', :id, '--memory', '1024'] | |
end | |
config.vm.network "forwarded_port", guest: 80, host: 8008 | |
config.vm.provision 'shell', inline: $script, privileged: true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment