LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-12-2021, 05:10 PM   #1
poolk-nu.b
LQ Newbie
 
Registered: Feb 2021
Posts: 1

Rep: Reputation: Disabled
Fail2Ban Owncloud Issues - Regex works | Not Banning


Hey folks, newbie here.
I've set up as RPi4 (Dietpi) with a 4TB HDD for Owncloud.

Owncloud is working fine and surprisingly fast.

In noticed in the Access.log and via tcpdump that i was pinged quiet often, so i thought it would be a good idea to set up fail2ban for ssh, owncloud and apache2.
Soo, SSH (Dropbear) gets banned perfectly (Backend = systemd). But i have some problems with owncloud.
Setup
Rpi4 + 4TB HDD USB3
Dietpi (Repo)
Owncloud 10.6.0.5 (Repo)
Fail2Ban v0.10.2
Dietpi_userdata on the 4TB Harddrive.

Problem
1. Fail2Ban dosn't block failed Owncloud login attempts. But Fail2Ban-regex works.
2. I had to change the Permission of the /var/log/owncloud.log to 644. Otherwise Owncloud wouldnt be able to write to it. Seem like the the change of the data to HDD messed up something.
All other Logs in /var/log/ are also empty, exept for the Apache logs in the separate apache dir.

Thanks for considering helping!

Logs & Outputs

#Fail2Ban-Status
Code:
root@DietPi:# sudo fail2ban-client status
Status
|- Number of jail:      3
`- Jail list:   dropbear, owncloud, sshd

#Fail2Ban-Status owncloud
Code:
root@DietPi:/# fail2ban-client status owncloud
Status for the jail: owncloud
|- Filter
|  |- Currently failed: 0
|  |- Total failed:     0
|  `- Journal matches:
`- Actions
   |- Currently banned: 0
   |- Total banned:     0
   `- Banned IP list:

#Permissions check
Code:
root@DietPi:/# ls -al /var/log/fail2ban.log
-rwxr-xr-x 1 root adm 0 Feb 12 01:18 /var/log/fail2ban.log
Code:
root@DietPi:/# ls -al /var/log/owncloud.log
-rw-rw-r-- 1 root www-data 2981 Feb 13 00:01 /var/log/owncloud.log

#REGEX
Code:
root@DietPi:/# sudo fail2ban-regex /var/log/owncloud.log /etc/fail2ban/filter.d/owncloud.conf

Running tests
=============

Use   failregex filter file : owncloud, basedir: /etc/fail2ban
Use         log file : /var/log/owncloud.log
Use         encoding : UTF-8


Results
=======

Failregex: 2 total
|-  #) [# of hits] regular expression
|   1) [2] {.*,"message":"Login failed: '.*' \(Remote IP: '<HOST>'\)"}
`-

Ignoreregex: 0 total

Date template hits:
|- [# of hits] date format
|  [2] ExYear(?P<_sep>[-/.])Month(?P=_sep)Day(?:T|  ?)24hour:Minute:Second(?:[.,]Microseconds)?(?:\s*Zone offset)?
`-

Lines: 2 lines, 0 ignored, 2 matched, 0 missed
[processed in 0.08 sec]

#Fail2Ban Owncloud.conf
Code:
 [Definition]
  failregex={.*,"message":"Login failed: '.*' \(Remote IP: '<HOST>'\)"}
  ignoreregex =

#Owncloud.log
Code:
{"reqId":"GPlHNyd6N47EzIbXrB0t","level":2,"time":"2021-02-12T23:47:37+01:00","remoteAddr":"144.2.99.155","user":"--","app":"core","method":"POST","url":"\/o$
{"reqId":"lWEr77uO431yB558AxcN","level":2,"time":"2021-02-12T23:47:39+01:00","remoteAddr":"144.2.99.155","user":"--","app":"core","method":"POST","url":"\/o$

#jail.local
Code:
[INCLUDES]
before = paths-debian.conf

[DEFAULT]
ignorself = true
ignoreip = 127.0.0.1/8 ::1
ignorecommand =
bantime  = 10m
findtime  = 10m
maxretry = 5
backend = systemd
usedns = warn
logencoding = auto
enabled = false
mode = normal
filter = %(__name__)s[mode=%(mode)s]
destemail = root@localhost
sender = root@<fq-hostname>
mta = sendmail
protocol = tcp
chain = <known/chain>
port = 0:65535
fail2ban_agent = Fail2Ban/%(fail2ban_version)s
banaction = iptables-multiport
banaction_allports = iptables-allports
action_ = %(banaction)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
action_mw = %(banaction)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
            %(mta)s-whois[name=%(__name__)s, sender="%(sender)s", dest="%(destemail)s", protocol="%(protocol)s", chain="%(chain)s"]
action_mwl = %(banaction)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
             %(mta)s-whois-lines[name=%(__name__)s, sender="%(sender)s", dest="%(destemail)s", logpath=%(logpath)s, chain="%(chain)s"]
action_xarf = %(banaction)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
             xarf-login-attack[service=%(__name__)s, sender="%(sender)s", logpath=%(logpath)s, port="%(port)s"]
action_cf_mwl = cloudflare[cfuser="%(cfemail)s", cftoken="%(cfapikey)s"]
                %(mta)s-whois-lines[name=%(__name__)s, sender="%(sender)s", dest="%(destemail)s", logpath=%(logpath)s, chain="%(chain)s"]

#
# JAILS
#

#
# SSH servers
#

#[sshd]
#enabled = true
# To use more aggressive sshd modes set filter parameter "mode" in jail.local:
# normal (default), ddos, extra or aggressive (combines all).
# See "tests/files/logs/sshd" or "filter.d/sshd.conf" for usage example and details.
#mode   = normal
#port    = ssh


[dropbear]
enabled = true
port     = ssh
filter = dropbear
bantime = 7200
findtime = 3600
maxretry = 3
banaction = iptables-allports

[owncloud]
enabled = true
filter = owncloud
bantime = 7200
findtime = 3600
maxretry = 3
banaction = iptables-multiport[name=owncloud, port="http,https"]
logpath = /var/log/owncloud.log
###################

Thanks for any help to find what i'm missing!
 
Old 02-13-2021, 10:10 AM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,678

Rep: Reputation: Disabled
Quote:
Originally Posted by poolk-nu.b View Post
I had to change the Permission of the /var/log/owncloud.log to 644.
Code:
root@DietPi:/# ls -al /var/log/owncloud.log
-rw-rw-r-- 1 root www-data 2981 Feb 13 00:01 /var/log/owncloud.log
Probably a typo. You mean 664, right?

Quote:
Originally Posted by poolk-nu.b View Post
#Owncloud.log
Code:
{"reqId":"GPlHNyd6N47EzIbXrB0t","level":2,"time":"2021-02-12T23:47:37+01:00","remoteAddr":"144.2.99.155","user":"--","app":"core","method":"POST","url":"\/o$
{"reqId":"lWEr77uO431yB558AxcN","level":2,"time":"2021-02-12T23:47:39+01:00","remoteAddr":"144.2.99.155","user":"--","app":"core","method":"POST","url":"\/o$
The log lines are truncated, cannot see whether the regex matches. It seems to be JSON, pipe it through jq perhaps, then post the output here?
Code:
jq </var/log/owncloud.log

Last edited by shruggy; 02-13-2021 at 10:21 AM.
 
Old 02-13-2021, 02:10 PM   #3
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Why in the world would you ever have /var/log/fail2ban.log executable.
You posted it was -rwxr-xr-x. (755)
Should that not be either
-rw-r--r-- or -rw-rw-r-- (644 or 664)

Last edited by computersavvy; 02-13-2021 at 02:12 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
fail2ban-regex not filtering, banning IP addresses dthims Linux - Newbie 2 02-13-2016 04:49 PM
fail2ban inconsistent in banning hackers compused Linux - Security 3 05-30-2014 01:56 PM
is IP banning more difficult than banning user accounts? newbiesforever General 15 04-26-2013 01:28 AM
Fail2ban noscript jail is banning googlebot...should I make an exception? sneakyimp Linux - Security 4 12-08-2012 01:01 PM
[SOLVED] fail2ban - not banning apache scanners djsmiley2k Linux - Server 1 08-26-2010 04:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration