# Hashcat

### --| Posted: 05-06-25

#### Table of Contents

#### 1. Background Information

hashcat is a tool which is able to utilize either the CPU or GPU to recover passwords from hashes by guessing the password, hashing it, and comparing it to the hash the is attempting to be "cracked" or reversed.

For this section of the course, I will discuss how to use hashcat to perform different types of attacks on a GPG secret key password. If you do not know what GPG is or have not used it before, it's easy to pick up. I have documented the important parts of using GPG for both asymmetric and symmetric encryption.

#### 1.1 Links Used on this Page

    ▶[https://xkcd.com/538/]

    ◉───╡ Average Day at ABC Headquarters.

    ▶[https://git.qwik.space/left4code/L4C_Forensics_CTF/src/branch/master/Filesystem Imaging & hashing/hashing/learning]

    ◉───╡ Gitea learning files

    ▶[https://www.howtogeek.com/658904/how-to-add-a-directory-to-your-path-in-linux/]

    ◉───╡ Adding hashcat to your PATH variable.

    ▶[https://github.com/dboyd42/cheatsheets/blob/c2611772a5874d1a387d70baccaa01ab577cddc8/hashcat-blackHills_2018.pdf]

    ◉───╡ BlackHills Hashcat Cheat Sheet.

    ▶[https://hashcat.net/wiki/doku.php?id=example_hashes]

    ◉───╡ Hashcat Example Hashes Page.

    ▶[https://github.com/hashstation/zip2hashcat/releases/tag/1.0]

    ◉───╡ zip2hashcat download.

    ▶[https://left4code.neocities.org/blogs/apr-19-2025]

    ◉───╡ My GPG Guide

    ▶[https://reusablesec.blogspot.com/2014/12/tool-deep-dive-prince.html]

    ◉───╡ Old princeprocessor Blog Explaining Tool Use.

    ▶[https://github.com/vpmv/princeprocessor]

    ◉───╡ vpmv's Re-write of princeprocessor in Go (Supports Separator)

    ▶[https://vikaskumar.org/2024/01/14/hashcat-gpu-cluster-linux-setup.html]

    ◉───╡ Entire Blog Installing and Using GPU drivers in Hashcat.

#### 2. What you need to know

1. basic understanding of the linux command line, specifically flags and output redirection just like the sha*sum section.

2. understanding of how to read manpages, you can type "man man" in your terminal to get an understanding.

3. a small bit of dedication to learn and follow along!

#### 3. Our Scenario for Using Hashcat.

Let's say you're doing a forensic investigation on someone who's using encryption to store data that is required to be known for the purposes of an investigation, the suspect isn't disclosing the password, so what can be done other than the obvious?

this is where hashcat comes in. Hashcat allows a forensic investigator to crack the password used for encryption on a file or disk. It does this by first guessing a password through either a wordlist, brute-force, or other type of attack and hashing it. This generated hash is compared to the target hash and if they match, the password for the encryption is now known to the investigator.

as discussed earlier in the hashing section, any hash generated should be unique to that input that is used to create it, the word "Hi" should have it's own hash, and "Hello" should have it's own hash.

for the demonstration of using hashcat, my gitea will contain a gpg private key, and a file encrypted with it's public key. If you want to follow along with that I'm doing, then download them!

    git clone https://git.qwik.space/left4code/L4C_Forensics_CTF

then go to the "Filesystem Imaging & hashing" directory for the files, they're in the "learning" directory.

#### 4. Installing Hashcat and John the Ripper

Before I go into installing these, if you want to skip this section, all you need to do is install Kali Linux into a VM, all the tools are pre-built and the modules may work better in general.

To install hashcat, open a terminal and run the following command:

    sudo apt install hashcat

This will work if you are using apt as your package manager, if you are using another system change to your package manager accordingly.

We will be installing John the Ripper purely for the gpg2john.c program which will look through the GPG private key and pull out the password hash for the file which we can break with hashcat.

clone John the Ripper from the official git repo:

    git clone https://github.com/openwall/john

from there you can cd into the src directory and run

    ./configure && make

if you get an error saying you don't have the necessary OpenSSL headers, you can specify --without-openssl after ./configure like this:

    ./configure --without-openssl && make

if there is further errors, you may not have the gcc, build-essential or make packages installed and will need to install those.

you should now be able to move into the run directory which will now have the gpg2john program in it. To run it and test if it's working, you can run:

    ./gpg2john

if you get output saying how to use gpg2john, then it's ready to go!

If you would like to run any of the programs in the /john/run directory from any other directory in the shell, you can add the directory to your path.

Assuming you cloned john to your Downloads directory, you can add it to your path like this:

    export PATH=/home/<your_user_name>/Downloads/john/run:$PATH

you should now be able to run:

    echo $PATH

and see that the entry for the john/run directory is in the path now. Remember that this directory's availability is only for this terminal session and will not work once you close your terminal or open another one. You will need to add the above command to the bottom of your .bashrc. this guide outlines the process clearly and should be easy to follow.

#### 5. Help with Hashcat

Before I get into how to use Hashcat, I will link to a very nice cheatsheet from BlackHills infosec which shows all of the important commands that you will be using for password recovery. It is linked here!

if you want to get help from the official source, you can run:

    hashcat -h

or

    man hashcat

to get official documentation information for using the program, the better you get at reading manpages, the more information you'll pick up that I don't talk about here.

#### 6. GPG Private key hash cracking Hashcat and gpg2john

This section will show how to use gpg2john and hashcat to crack a GPG private key's password and take over the identity of that user.

#### 6.1 Extracting the Hash.

First, you should extract the hash from the .asc file.

For this specific section, we will use "billy_sec.asc", it is meant to be easy to brute-force and is not a strong password at all. This is just to get the understanding of how to convert the hashes and everything.

for the purposes of this demonstration, the secret key file is provided, in a real-world scenario, this secret key file would not be easily accessible and would probably be behind another layer of encryption like LUKS.

after you have the .asc file, run gpg2john on it by using the following command:

    gpg2john bill_sec.asc > <hashfile_name>

this extracts the hash and puts the results in a file.

now since we're using hashcat, we need to do some modifications on the hash file before hashcat will accept it, so you need to open the hash file in your favorite text editor and change some things around.

before we do that, I would like to point you to the example hash page for hashcat. You should reference this for the gpg hashes specifically, I had a lot of trouble actually getting hashcat to accept the hash, so don't get discouraged if it doesn't work immediately.

you will want to remove the parts of the hash that gpg2john generated which include the name of the key ("billy:" at the beginning) and remove the three ":" symbols at the end of the file and everything after that (:::billy (break this with hashcat------))

I will include the hashfile that worked for me so you can check the file differences.

A small note, on the hashcat examples page, anything marked with an "*" as an example means it's a feature in the beta build of hashcat only and is not available in normal hashcat.

#### 6.2 Brute-Force Attack.

To brute force the new hash we just generated and changed you need to run this command in this very specific order:

    hashcat -m 17010 -a 3 new_bill.hash ?a?a?a

To break this command down:

1. the -m 17010 is the gpg sha-1 hashcat module

2. the -a 3 specifies the brute-force method

3. ?a?a?a means try all possible characters within 3 key positions, an example of this would be "abc" or "C2E" as the password, I will show how to have more control over this functionality, especially when you don't know the potential length of characters in a hash that are being used.

after hashcat has turned through all of the possible combinations and finished, you can run the following command to see the hashes and decrypted password resulting from it:

    hashcat -m 17010 -a 3 new_bill.hash ?a?a?a --show

you should be able to deduce from the end of the output that the password is "123" as seen from "<hash>:123" inside hashcat.

if you didn't know the length of the password, you can use the "-i" flag and "--incrment-min" and "--increment-max" flags to specify what range of character length should be brute-forced.

    hashcat -m 17010 -a 3 new_bill.hash -i --increment-min=1 --increment-max=4 ?a?a?a

#### 6.3 Dictionary Attack.

Well.. Billy's private key password is leaked to literally everyone and is therefore able to be controlled by anyone! If you import this key into your GPG keyring as shown in my GPG guide and export the public key, you can now hold Billy's identity hostage! If he doesn't have a revoke certificate for that key, he's done for.

Hey, wait.. Billy had some file encrypted with his public key didn't he? Let's decrypt it and see what it is!

Using GPG to decrypt the file and supplying the password

    gpg <file>

it gives a zip file, unzipping it presents a password-protected zip file and a text file with some chat logs in it. So we're not done yet. We will use zip2hashcat to get the hash for this zip file later.

Just clone the repository, and run the zip2hashcat binary on the zip file.

Billy seems to have bumped up security when it comes to this zip file, he could have made a phrase the password based using some of the words in the log. Standard brute forcing methods aren't going to cut it here.

In a case like this, what could be done is we could take the words from this text file, pick out the important ones and joiner words, then make a dictionary file with them.

For some background, in KeePassXC, there's a passphrase generator that will make a large password based on different words and supports separator characters too, like this for example:

    Savor Spiny Shove Maroon Algebra Kindred Breezy

From what I've seen, hashcat and John the Ripper are not equipped to handle passwords like this natively, and they do not seem to be able to generate a combination of words at a large scale.

Looking around, I found princeprocessor, which is an old hashcat module written in C which seemed to do what I wanted, you can look at this blog post about it all the way back in 2014 sadly, princeprocessor does not support character spacing, there's a 2 year old pull request for it that hasn't been satisfied yet. Not good.

But the day has been saved by vpmv! They re-wrote princeprocessor in Go and gave it separator functionality!

So that's the ticket, make the initial wordlist, then run it through princeprocessor with the amount of words you think could range in the chain, and generate the wordlist!

Word of warning though, it takes so much disk space for the password I created, so I'll just tell you the password, it's:

    Jesse from Breaking Bad in Alaska flying Delta

The wordlist could probably be cut down a lot if you were to run it through something else which checked each chain to see if it made grammatical sense and remove failing entries, but I don't know if that actually exists or not. But it would cut the wordlist down to probably megabytes in size compared to like 5 gigs.

For the record, this program is totally able to generate the password and with enough resources you would be able to crack this zip within a day with a couple GPUs

I was able to run this command and using grep, I checked and the password was there.

If you want to install this program for yourself, install the golang package and run:

    go install github.com/vpmv/princeprocessor

you'll find it in /home/<user>/go/bin/ then run ./princeprocessor to use it.

the command I used to generate the wordlist was this:

    ./princeprocessor -i <initial_dictionary> -n 8 -m 8 -o prince_dict.txt

after you have your generated wordlist, you would run the following command using it:

    hashcat -m 13600 -a 0 -w 3 <princeprocessor_wordlist.txt> <zip_hash.txt>

#### 7. Using GPUs

I talked earlier about using GPUs for hash cracking. This is true, you should be using GPUs for hash cracking as it is much faster than user the CPU by default. However you need to do some things first before you can use the GPU, you can even combine the CPU and GPU together for cracking. This guide shows the process for getting drivers nicely.

To summarize this article for the drivers, if you're using Kali, drivers should work out of the box and all you will need to do is run:

    hashcat -I

to see the different devices hashcat has detected.

you would then run the command:

    hashcat -D <device_number>

before your command, this would use the device. If you want to use multiple devices, you just have to separate them by commas (,) to add them. An example of this would be:

    hashcat -D 1,2 <other_flags>

#### 8. Conclusion

Hashcat is a very advanced program for cracking hashes, I don't think I did it justice given what I've covered compared to the sheer scale of this program's abilities. I highly recommend you dive as far as you can into hashcat forum posts and the hashcat manual if you want more specific options or your individual situation was not covered in this course section.