Fail2ban in a Jail to secure ownCloud-Server
Posted: 26 Oct 2014 17:59
Hello,
I have installed ownCloud 7.0.2 in a own jail as described in viewtopic.php?f=79&t=1565.
To protect the ownCloud-Server against brute-force password hacks, I've installed additionally Fail2ban in the jail.
For the installation and configuration I used following guides:
http://www.rojtberg.net/711/secure-owncloud-server/ and
https://forums.freenas.org/index.php?th ... ail.19216/
To configure Fail2ban for ownCloud I used mainly the instructions of the second link above.
At first I edited in owncloud/config/config.php and added following lines:
The correct time zone can be found at http://php.net/manual/en/timezones.php
Afterwards I added in the jail following lines (last 3 lines) to /etc/rc.conf:
and created under /usr/local/etc the file ipfw.rules with the lines
Then I've created under /usr/local/etc/fail2ban the file jail.local with
and the filter definition file owncloud.conf in /usr/local/etc/fail2ban/filter.d with following lines (works only for ownCloud v7.0.2),
In action.d I've copied then ipfw.conf to ipfw-owncloud.conf and changed there the lines for "actionban" and "actionunban" to
Finally I've restarted all relevant services
and tested the configuration by entering more than 3 times a wrong password on the ownCloud webpage.
File2ban works but I got in /var/log/fail2ban.log following error messages (red colored):
Hence, Fail2ban does not work correctly and it is still possible to guess the password infinitely often without banning the IP-address for a while.
Does somebody know how I can solve the permission problem of the socket?
Thank's in advance!
Best regards,
Ganimed.
NAS4Free 9.2.0.1 (revision 972) x86-full, VX800 AWRDACPI VIA C7-D Processor 1500MHz 1983MiB RAM
VIA VT6202 USB 2.0 controller VIA 83C572 USB controller IP1001, 10/100/1000 media interface
I have installed ownCloud 7.0.2 in a own jail as described in viewtopic.php?f=79&t=1565.
To protect the ownCloud-Server against brute-force password hacks, I've installed additionally Fail2ban in the jail.
For the installation and configuration I used following guides:
http://www.rojtberg.net/711/secure-owncloud-server/ and
https://forums.freenas.org/index.php?th ... ail.19216/
To configure Fail2ban for ownCloud I used mainly the instructions of the second link above.
At first I edited in owncloud/config/config.php and added following lines:
Code: Select all
'forcessl' => true,
'loglevel' => '2',
'logtimezone' => '<timezone>',
'log_authfailip' => true,
Afterwards I added in the jail following lines (last 3 lines) to /etc/rc.conf:
Code: Select all
sendmail_enable="NONE"
syslogd_flags="-ss"
rpc_bind="NO"
network_interfaces=""
cron_flags="$cron_flags -J 15"
mysql_enable="YES"
lighttpd_enable="YES"
firewall_enable="YES"
firewall_script="/usr/local/etc/ipfw.rules"
fail2ban_enable="YES"
Code: Select all
#!/bin/sh
# Flush out the list before we begin.
ipfw -q -f flush
# Set rules command prefix
cmd="ipfw -q add"
# Loopback Interface
$cmd 10 allow all from any to any via lo0
$cmd 20 deny all from any to 127.0.0.0/8
$cmd 30 deny all from 127.0.0.0/8 to any
$cmd 40 deny tcp from any to any frag
# Stateful connections
$cmd 50 check-state
$cmd 60 allow tcp from any to any established
$cmd 70 allow all from any to any out keep-state
$cmd 80 allow icmp from any to any
# Firewall rule used by Fail2Ban to block traffic
$cmd 90 deny all from 'table(1)' to any
# Allow access to public DNS (53),
# http (80), https (443) and port 81:
$cmd 150 allow tcp from any to any 443 in
$cmd 160 allow tcp from any to any 443 out
$cmd 170 allow udp from any to any 53 in
$cmd 175 allow tcp from any to any 53 in
$cmd 180 allow udp from any to any 53 out
$cmd 185 allow tcp from any to any 53 out
$cmd 200 allow tcp from any to any 80 in
$cmd 210 allow tcp from any to any 80 out
$cmd 220 allow tcp from any to any 81 in
$cmd 230 allow tcp from any to any 81 out
# Deny and log all other connections
$cmd 500 deny log all from any to any
Code: Select all
[owncloud]
enabled = true
filter = owncloud
action = ipfw-owncloud
port = http,https,81
protocol = tcp
logpath = /mnt/vdevs_pool/owncloud/data/owncloud.log
maxretry = 3
Code: Select all
[Definition]
failregex = {"app":"core","message":"Login failed: '.*' \(Remote IP: '<HOST>', X-Forwarded-For: '.*'\)","level":2,"time":".*"}
ignoreregex =
Code: Select all
actionban = ipfw table 1 add <ip>
actionunban = ipfw table 1 delete <ip>
Code: Select all
service lighttpd restart
service fail2ban restart
service ipfw restart
File2ban works but I got in /var/log/fail2ban.log following error messages (red colored):
When I execute the command ipfw list, then I get the same error as in the log-file: "ipfw: socket: Operation not permitted".2014-10-10 10:12:44,614 fail2ban.server.server[35189]: INFO Changed logging target to /var/log/fail2ban.log for Fail2ban v0.9.0
2014-10-10 10:12:44,622 fail2ban.server.database[35189]: INFO Connected to fail2ban persistent database '/var/db/fail2ban/fail2ban.sqlite3'
2014-10-10 10:12:44,649 fail2ban.server.jail[35189]: INFO Creating new jail 'owncloud'
2014-10-10 10:12:44,654 fail2ban.server.jail[35189]: INFO Jail 'owncloud' uses poller
2014-10-10 10:12:44,771 fail2ban.server.filter[35189]: INFO Set jail log file encoding to US-ASCII
2014-10-10 10:12:44,772 fail2ban.server.jail[35189]: INFO Initiated 'polling' backend
2014-10-10 10:12:44,929 fail2ban.server.filter[35189]: INFO Added logfile = /mnt/vdevs_pool/owncloud/data/owncloud.log
2014-10-10 10:12:44,932 fail2ban.server.filter[35189]: INFO Set maxRetry = 3
2014-10-10 10:12:44,937 fail2ban.server.filter[35189]: INFO Set jail log file encoding to US-ASCII
2014-10-10 10:12:44,940 fail2ban.server.actions[35189]: INFO Set banTime = 600
2014-10-10 10:12:44,945 fail2ban.server.filter[35189]: INFO Set findtime = 600
2014-10-10 10:12:49,328 fail2ban.server.jail[35189]: INFO Jail 'owncloud' started
2014-10-10 10:13:59,210 fail2ban.server.filter[35189]: INFO [owncloud] Found 212.xxx.xxx.xxx
2014-10-10 10:14:07,320 fail2ban.server.filter[35189]: INFO [owncloud] Found 212.xxx.xxx.xxx
2014-10-10 10:14:13,509 fail2ban.server.filter[35189]: INFO [owncloud] Found 212.xxx.xxx.xxx
2014-10-10 10:14:14,197 fail2ban.server.actions[35189]: NOTICE [owncloud] Ban 212.xxx.xxx.xxx
2014-10-10 10:14:14,248 fail2ban.server.action[35189]: ERROR ipfw table 1 add 212.xxx.xxx.xxx -- stdout: ''
2014-10-10 10:14:14,249 fail2ban.server.action[35189]: ERROR ipfw table 1 add 212.xxx.xxx.xxx -- stderr: 'ipfw: socket: Operation not permitted\n'
2014-10-10 10:14:14,250 fail2ban.server.action[35189]: ERROR ipfw table 1 add 212.xxx.xxx.xxx -- returned 69
2014-10-10 10:14:14,250 fail2ban.server.actions[35189]: ERROR Failed to execute ban jail 'owncloud' action 'ipfw-owncloud': Error banning 212.xxx.xxx.xxx
2014-10-10 10:14:20,620 fail2ban.server.filter[35189]: INFO [owncloud] Found 212.xxx.xxx.xxx
2014-10-10 10:14:32,759 fail2ban.server.filter[35189]: INFO [owncloud] Found 212.xxx.xxx.xxx
2014-10-10 10:14:39,959 fail2ban.server.filter[35189]: INFO [owncloud] Found 212.xxx.xxx.xxx
2014-10-10 10:14:40,507 fail2ban.server.actions[35189]: NOTICE [owncloud] 212.xxx.xxx.xxx already banned
Hence, Fail2ban does not work correctly and it is still possible to guess the password infinitely often without banning the IP-address for a while.
Does somebody know how I can solve the permission problem of the socket?
Thank's in advance!
Best regards,
Ganimed.
NAS4Free 9.2.0.1 (revision 972) x86-full, VX800 AWRDACPI VIA C7-D Processor 1500MHz 1983MiB RAM
VIA VT6202 USB 2.0 controller VIA 83C572 USB controller IP1001, 10/100/1000 media interface
