THC Hydra: Auditing passwords

As we have said previously, the Cyber Security world is full of useful tools to perform different task. At the end of the day, pentesters are usually very proficient with some of them, the ones they use in daily day basis but, at least, they know or they have tried some of the others. Even similar tools or tools that apparently do the same task, sometimes have slightly different behaviors that can be the difference between success or fail in a pentest.

The tool we are going to see today is called THC Hydra. THC Hydra is a tool that will help us to test the strength of our passwords auditing remote authentication services.

As an example, I am going to use the same set up I used in the Ncrack article before. If you do not know what I am talking about, you can follow this link to my previous article.

After we have our service running in our virtual machine, and we have checked the machine and the service are available, we can execute the “hydra” command.

Just a few notes before test our service.

You can execute the command to obtain information about how to execute the tool:

hydra

You will see that multiple flags are listed, and the most interesting part is the list of services that are supported by the tool. As an important note, I must say that the number of services supported by the tool depends on the kind of compilation and installation we have done. There are a few libraries or dependencies we need to install before THC Hydra to have support for all types of services.

To follow this example, it is enough if you have install the tool with the “libssh” support.

Now, let’s continue. As you have seen in the help description for the tool, there are multiple flags we can use, but for this test, we are going to focus in the next flags:

  • -l LOGIN or -L FILE: It allows us to give to the tool a user or a list of users.
  • -p PASS or -P FILE: It allows us to give to the tool a password or a list of passwords.
  • service: The service we want to test. In our case “ssh”

Now, following the appropriate syntax, we can execute the next command:

hydra -l fjavierm -P password.txt ssh://192.168.0.38

This is going to show us the result:

Hydra v8.4 (c) 2017 by van Hauser/THC - Please do not use in military or secret service organizations, or for illegal purposes.

Hydra (http://www.thc.org/thc-hydra) starting at 2017-04-02 08:26:38
[WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4
[DATA] max 3 tasks per 1 server, overall 3 tasks, 3 login tries (l:1/p:3), ~1 try per task
[DATA] attacking service ssh on port 22
[22][ssh] host: 192.168.0.38 login: fjavierm password: pa$$w0rd
1 of 1 target successfully completed, 1 valid password found
Hydra (http://www.thc.org/thc-hydra) finished at 2017-04-02 08:26:41

As we can see, we have been able to find the weak password.

Advertisements
THC Hydra: Auditing passwords

SSH access with Ncrack

The cybersecurity field has thousands of tools we can use to check the security of our systems. One category of tools we can find is the password crackers. In this group, we can find Ncrack. Ncrack defines itself as a high-speed network authentication cracker.

Ncrack is a high-speed network authentication cracking tool. It was built to help companies secure their networks by proactively testing all their hosts and networking devices for poor passwords. Security professionals also rely on Ncrack when auditing their clients. Ncrack was designed using a modular approach, a command-line syntax similar to Nmap and a dynamic engine that can adapt its behaviour based on network feedback. It allows for rapid, yet reliable large-scale auditing of multiple hosts.

Ncrack’s features include a very flexible interface granting the user full control of network operations, allowing for very sophisticated bruteforcing attacks, timing templates for ease of use, runtime interaction similar to Nmap’s and many more. Protocols supported include RDP, SSH, HTTP(S), SMB, POP3(S), VNC, FTP, SIP, Redis, PostgreSQL, MySQL, and Telnet.

Let´s try to do a little demo. Previously, we need a few things:

  • A remote system to audit. It can be a real system or a virtual machine. In my case, I am going to use a Debian VM with a SSH server installed.
  • Ncrack installed in our machine. There are versions available for different systems like Windows, Linux and Mac OS.
  • We need two dictionaries. One with a list of users we want to use and, the second one with a list of passwords to use to audit the system.

Firsts thing, let´s try the connectivity with the system we want to audit:

~# ping -c 1 192.168.0.38
PING 192.168.0.38 (192.168.0.38): 56 data bytes
64 bytes from 192.168.0.38: icmp_seq=0 ttl=64 time=0.382 ms

--- 192.168.0.38 ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.382/0.382/0.382/0.000 ms

The next step should be to check if the SSH port is available in the remote system. For this purpose, we can use a tool like Nmap.

~# nmap -sV 192.168.0.38

Starting Nmap 7.40 ( https://nmap.org ) at 2017-03-25 10:09 GMT
Nmap scan report for 192.168.0.38
Host is up (0.00094s latency).
Not shown: 992 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 6.7p1 Debian 5+deb8u3 (protocol 2.0)
80/tcp open tcpwrapped
110/tcp open tcpwrapped
111/tcp open rpcbind 2-4 (RPC #100000)
143/tcp open tcpwrapped
443/tcp open tcpwrapped
993/tcp open imaps?
995/tcp open pop3s?
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 6.45 seconds

And, finally, let´s audit our external system using Ncrack. We are going to use a few flags to execute the Ncrack tool:

  • -p: Allows us to specify the port we want to audit.
  • -U: Allows us to specify a file with the list of users.
  • -P: Allows us to specify a file with the list of passwords.
~# ncrack -p 22 -U users.txt -P passwords.txt 192.168.0.38

Starting Ncrack 0.5 ( http://ncrack.org ) at 2017-03-25 10:11 GMT

Discovered credentials for ssh on 192.168.0.38 22/tcp:
192.168.0.38 22/tcp ssh: 'fjavierm' 'pa$$w0rd'

Ncrack done: 1 service scanned in 18.02 seconds.

Ncrack finished.

And, let´s double check the credentials are working properly:

~# ssh 192.168.0.38
fjavierm@192.168.0.38's password: 

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sat Mar 25 10:07:52 2017 from 192.168.0.15
fjavierm@debian:~$

As we can see, now, we have access to the remote system exploiting a weak password.

There are some countermeasures that we can implement to fix this problem, one of them is to establish a strong password policy.

SSH access with Ncrack