Tags: hacking #hacking security-tools toolkit hash-cracking Learning cyber-security
Links:
How to Use John the Ripper - A Quick and Easy Guide
John Basic Syntax
The basic syntax of John the Ripper commands is as follows. We will cover the specific options and modifiers used as we use them.
john [options] [file path]
john
: Invokes the John the Ripper program[options]
: Specifies the options you want to use[file path]
: The file containing the hash you’re trying to crack; if it’s in the same directory, you won’t need to name a path, just the file.
Automatic Cracking
John has built-in features to detect what type of hash it’s being given and to select appropriate rules and formats to crack it for you; this isn’t always the best idea as it can be unreliable, but if you can’t identify what hash type you’re working with and want to try cracking it, it can be a good option! To do this, we use the following syntax:
john --wordlist=[path to wordlist] [path to file]
--wordlist=
: Specifies using wordlist mode, reading from the file that you supply in the provided path[path to wordlist]
: The path to the wordlist you’re using, as described in the previous task
Example Usage:
john --wordlist=/usr/share/wordlists/rockyou.txt hash_to_crack.txt
Identifying Hashes
Sometimes, John won’t play nicely with automatically recognising and loading hashes, but that’s okay! We can use other tools to identify the hash and then set John to a specific format. There are multiple ways to do this, such as using an online hash identifier like this site. I like to use a tool called hash-identifier, a Python tool that is super easy to use and will tell you what different types of hashes the one you enter is likely to be, giving you more options if the first one fails.
To use hash-identifier, you can use wget
or curl
to download the Python file hash-id.py
from its GitLab page. Then, launch it with python3 hash-id.py
and enter the hash you’re trying to identify. It will give you a list of the most probable formats. These two steps are shown in the terminal below.
wget https://gitlab.com/kalilinux/packages/hash-identifier/-/raw/kali/master/hash-id.py
A Note on Formats:
When you tell John to use formats, if you’re dealing with a standard hash type, e.g. md5 as in the example above, you have to prefix it with raw-
to tell John you’re just dealing with a standard hash type, though this doesn’t always apply. To check if you need to add the prefix or not, you can list all of John’s formats using john --list=formats
and either check manually or grep for your hash type using something like john --list=formats | grep -iF "md5"
.
Zip2John
Similarly to the unshadow
tool we used previously, we will use the zip2john
tool to convert the Zip file into a hash format that John can understand and hopefully crack. The primary usage is like this:
zip2john [options] [zip file] > [output file]
[options]
: Allows you to pass specific checksum options tozip2john
; this shouldn’t often be necessary[zip file]
: The path to the Zip file you wish to get the hash of>
: This redirects the output from this command to another file[output file]
: This is the file that will store the output
Example Usage
zip2john zipfile.zip > zip_hash.txt
Cracking
We’re then able to take the file we output from zip2john
in our example use case, zip_hash.txt
, and, as we did with unshadow
, feed it directly into John as we have made the input specifically for it.
john --wordlist=/usr/share/wordlists/rockyou.txt zip_hash.txt
Cracking a Password-Protected RAR Archive
We can use a similar process to the one we used in the last task to obtain the password for RAR archives. If you aren’t familiar, RAR archives are compressed files created by the WinRAR archive manager. Like Zip files, they compress folders and files.
Rar2John
Almost identical to the zip2john
tool, we will use the rar2john
tool to convert the RAR file into a hash format that John can understand. The basic syntax is as follows:
rar2john [rar file] > [output file]
rar2john
: Invokes therar2john
tool[rar file]
: The path to the RAR file you wish to get the hash of>
: This redirects the output of this command to another file[output file]
: This is the file that will store the output from the command
Example Usage
/opt/john/rar2john rarfile.rar > rar_hash.txt
Cracking
Once again, we can take the file we output from rar2john
in our example use case, rar_hash.txt
, and feed it directly into John as we did with zip2john
.
john --wordlist=/usr/share/wordlists/rockyou.txt rar_hash.txt