Skip to content

Bruteforce protection [WIP] - #1603

Closed
LukasReschke wants to merge 5 commits into
masterfrom
bruteforce-protection
Closed

LukasReschke wants to merge 5 commits into
masterfrom
bruteforce-protection

Conversation

@LukasReschke

Copy link
Copy Markdown
Contributor

Don't merge this! - This is scheduled for 6.0 7.0

This is a simple (but configurable) brute force protection for logins, it will block all IP addresses for 15 minutes who tried to login 10 times with invalid credentials within 15 minutes. Additionally, it will add an entry to the ownCloud log with the username + IP address.

I think this is enough, since I don't know anyone who enters his password wrong 10 times in 15 minutes ;-) - nevertheless, if one does this he will get a warning instead of the login screen saying that he should wait 15 minutes and then try it again.

Currently, it does not work with reverse proxies in place. This should get fixed before merging.

I'm not sure about the index in db_structure.xml, could anyone check if this is correct? THX.

Btw. every improvement is appreciated - just commit it to the bruteforce-protection branch!

Todos:

  • Make compatible with reverse proxies
  • Protect the login with a CSRF token
  • Check if this is compatible with other user backends
  • Ask @danimo or @dragotin if this block has bad impacts on WebDAV clients and mirall, maybe a specific statuscode should be sent?
  • Block IPs after X logins for 24h
    • Currently an IP is able to try (at maximum) 960 logins per day, we should implement a block lasting at least 24h after a massive abuse from a single IP address.

Ref #1580

\cc @jancborchardt @karlitschek

This will block IP addresses for 15 minutes which tried to login more
than 10 times in the last 15 minutes.

@karlitschek Check it out.
@karlitschek

Copy link
Copy Markdown
Contributor

Hi Lukas, This is awesome! Thanks a lot for your work.
I'm not sure currently if we should merge this now because this can potentially break stuff and we are over a week after feature freeze.
@LukasReschke What is you opinion? How dangerous are the changes in your opinion?

@LukasReschke

Copy link
Copy Markdown
Contributor Author

To be honest, I'd really like to have this in ownCloud 5.0 since this is - from a security point of view - a real important feature and rules are there to be broken ;-)

But it needs some polishing before I'd say that it can be merged with being 100% sure that it won't break something. (e.g. the CSRF check should be included and the timeframe/allowed logins need some more fine-tuning and I'd like to check if the request has been done using a proxy etc... - I'll take care of all that later this week)

For a future release (read: ownCloud 6.0) I have also some additional ideas to make it even cooler! (e.g. white- and blacklisting IP addresses via the GUI for persons with enhanced security requirements e.g. governments or companies) :-)

The code itself is pretty straight forward and shouldn't break anything, but I need some feedback on the index in db_structure.xml since I'm really not that into the DB stuff :-) @bartv2 Maybe you could judge on this?

Ok for you, @karlitschek?

@karlitschek

Copy link
Copy Markdown
Contributor

Hmmm. O.K. with me if:

  1. This code is ready really soon. (next few hours)
  2. You pay me a beer for every problem this triggers ;-)

@icewind1991 What do you think about the code?

@LukasReschke

Copy link
Copy Markdown
Contributor Author
  1. This code is ready really soon. (next few hours)

That won't probably happen since I have other things to do just now. - But well, I won't blame you for delaying it until oC 6.0 ;-)

@DeepDiver1975

Copy link
Copy Markdown
Contributor

What about adding this to 5.1 then?
Gives us more time to test and review the code and nobody has to wait until OC6

@karlitschek

Copy link
Copy Markdown
Contributor

There is no 5.1 planed at the moment. There will be an ownCloud 6 from master with new features 3 month after the 5 release and 5.0.1, 5.0.2, ... with only bugfixes from a stable branch.

Comment thread lib/user.php

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be executed on every login attempt, maybe move this to 'logInvalidAttempt'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Also in 'logInvalidAttempt' it should be inside the OC_Config::getValue( "bruteforce", true) condition, otherwise it would be a performance hit even if the bruteforce option is disabled.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, after second thought a performance hit on a failed login request is not an issue (and even desirable in some cases).

@laryllian

Copy link
Copy Markdown

@jancborchardt

Copy link
Copy Markdown
Contributor

@LukasReschke any update on this btw?

@kaworu

kaworu commented Apr 30, 2013

Copy link
Copy Markdown

Hi !
I've landed here in my attempt to make owncloud play nice with fail2ban.

I believe the patch has two issues in its current form:

  1. neither checkBlock() nor logInvalidAttempt() treat localhost as a special case. IMHO 127.0.0.1 and ::1 should never be blocked (this could be hardcoded or implemented by a configurable whitelist system).
  2. the localhost issue is common when owncloud is accessed through a localhost proxy. In that case, the "real" client's IP can be (usually) be found in the X-Forwarded-For header while $_SERVER['REMOTE_ADDR'] will contains the proxy's IP. The roundcube's IP logging function might be a good start: https://github.com/roundcube/roundcubemail/blob/master/program/lib/Roundcube/rcube_utils.php#L644

@bantu

bantu commented May 16, 2013

Copy link
Copy Markdown

A properly configured reverse proxy setup makes sure that owncloud gets the correct via REMOTE_ADDR.

If X-Forwarded-For is to be supported it might make sense to have a whitelist of IPs from which the X-Forwarded-For headers are trusted (for all other sources, X-Forwarded-For headers are thrown away).

@bantu

bantu commented May 16, 2013

Copy link
Copy Markdown

I am not sure this patch is a good idea. It might create more problems than it solves:

NATs are used almost everywhere for mobile internet and some DSL providers are using it too because of IPv4 address exhaustion. Universities are another good example.

This patch can be easily abused when behind a NAT for a Denial of Service attack against all the other users behind the same NAT. As long as you send login attempts fast enough, nobody else behind the same NAT will be able to log in.

Also, this patch does not work against brute force attacks via IPv6 because an attacker is likely able to freely pick a few bits of his IP address (usually ca. 64 bits).

Consider the following instead:

  • After a certain number of tries, show a CAPTCHA to further slow down automated attacks. This likely won't do much because they usually can be cracked in seconds (or less) by non-PHP code.
  • Increasing required password complexity to increase the search space an attacker has to search.

and finally as a strategy consider

  • Preferring user accounts with weak passwords being hacked instead of blocking users with good passwords from accessing their accounts.

cc @karlitschek

@LukasReschke

Copy link
Copy Markdown
Contributor Author

Guys, this is a 3 month old PR which was written in about 10 - 20 minutes and is more of a proof of concept instead of a working solution. - I'm absolutely aware of the potential problems and am currently working on a proper two-factor authentication.

(Actually I have in mind to send the server response a little bit slower after every invalid login attempt to make bruteforcing more inefficient. - e.g. after 3 invalid logins there is a timeout of 10 seconds, after 5 a timeout of 20 seconds etc...)

NATs are used almost everywhere for mobile internet and some DSL providers are using it too because of IPv4 address exhaustion.

I'd blame the shitty provider here ;-)

As long as you send login attempts fast enough, nobody else behind the same NAT will be able to log in.

Dude - you can easily DoS a oC instance with an authenticated user account in two minutes. Believe me, there are bigger issues an admin should care for at the moment ;-)

This patch can be easily abused when behind a NAT for a Denial of Service attack against all the other users behind the same NAT. As long as you send login attempts fast enough, nobody else behind the same NAT will be able to log in.

That's why it will be configurable. - But the current login procedure is really more than insufficient.

Also, this patch does not work against brute force attacks via IPv6 because an attacker is likely able to freely pick a few bits of his IP address (usually ca. 64 bits).

ACK - but I hadn't had the time to implement this yet.

@LukasReschke

Copy link
Copy Markdown
Contributor Author

Don't understand me wrong - I'm really grateful for every comment here! I really believe that discussing security related code is the only way to ensure that it is adequate.

@bantu

bantu commented May 16, 2013

Copy link
Copy Markdown

I'd blame the shitty provider here ;-)

Sounds like you perfectly understood the problem of IPv4 exhaustion there. ;-)

Dude - you can easily DoS a oC instance with an authenticated user account in two minutes. Believe me, there are bigger issues an admin should care for at the moment ;-)

Well, owncloud has to start somewhere with stopping making mistakes. :-P

Don't understand me wrong - I'm really grateful for every comment here! I really believe that discussing security related code is the only way to ensure that it is adequate.

You're welcome. :)

@ext-caucesystem

Copy link
Copy Markdown

There is another problem that could be solved with this patch: currently we are detecting blocked users in our LDAP, due to ownCloud desktop login retries whenever a user changes his password.

This is becoming a big problem for our users. Every password change ends in a blocked account. The only thing that we can do now, is to configure the oC desktop client not to store the password, and close the oC desktop before a password change.

@kaworu

kaworu commented Jun 4, 2013

Copy link
Copy Markdown

A properly configured reverse proxy setup makes sure that owncloud gets the correct via REMOTE_ADDR.

Could you backup this claim with some documentation please ? I fail to see how a reverse proxy, by definition, can change a PHP variable.

@bantu

bantu commented Jun 4, 2013

Copy link
Copy Markdown

@kaworu I said "reverse proxy setup", not just "reverse proxy".

The proxy adds a header, e.g. "X-Real-IP" containing the remote IP connecting to the proxy before forwarding the request to the webserver. The webserver checks whether the connecting remote IP is a valid proxy. If it is, it uses X-Real-IP as the remote IP instead, which will be available to PHP.

See
http://wiki.nginx.org/HttpProxyModule
http://wiki.nginx.org/HttpRealipModule
http://stderr.net/apache/rpaf/

@kaworu

kaworu commented Jun 4, 2013

Copy link
Copy Markdown

@bantu thank you for the clarification.

@Niduroki

Copy link
Copy Markdown

Admins should be able to manually remove blocks.
For the case someone does try ten times to log in in 15 mins. (There will be people, believe me …)

@DeepDiver1975

Copy link
Copy Markdown
Contributor

There is another problem that could be solved with this patch: currently we are detecting blocked users in our LDAP, due to ownCloud desktop login retries whenever a user changes his password.

This is becoming a big problem for our users. Every password change ends in a blocked account. The only thing that we can do now, is to configure the oC desktop client not to store the password, and close the oC desktop before a password change.

@ext-caucesystem have you reported this issue already on the mirall repo? THX

@DeepDiver1975

Copy link
Copy Markdown
Contributor

@LukasReschke I know you are pretty busy at the moment. But what's the status of this? THX

@MorrisJobke

Copy link
Copy Markdown
Contributor

Maybe someone should take this. @Kondou-ger @Raydiation @georgehrke @ringmaster ?

@danimo

danimo commented Aug 26, 2013

Copy link
Copy Markdown
Contributor

On the client side, there is no special status code required if existing sessions are unaffected. For new log ins, simply use 403.

Conflicts:
	config/config.sample.php
	core/templates/login.php
	lib/base.php
	lib/user.php
	lib/util.php
@Niduroki

Copy link
Copy Markdown

Did my best to do a merge here. I'll take this over, when I'm done with my avatars.

@karlitschek

Copy link
Copy Markdown
Contributor

@Kondou-ger This would be great :-)

@jancborchardt

Copy link
Copy Markdown
Contributor

@Kondou-ger are you still working on this? Or has this already been solved elsewhere? :)

@Niduroki

Niduroki commented Feb 6, 2014

Copy link
Copy Markdown

Status update (just saying the obvious) I'm not working on this anymore – anybody feel free to take this over.

@LukasReschke

Copy link
Copy Markdown
Contributor Author

As this is actually outdated and wouldn't work properly with the current core. I'm therefore closing this pull request.

Let's look whether we have time to implement this in the near future.

@LukasReschke
LukasReschke deleted the bruteforce-protection branch February 20, 2014 13:16
@lock lock Bot locked as resolved and limited conversation to collaborators Aug 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.