> For the complete documentation index, see [llms.txt](https://x7331.gitbook.io/boxes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://x7331.gitbook.io/boxes/tools/passwords/hashcat.md).

# Hashcat

## Theory

### Cracking Time

The **keyspace** is calculated as the character set raised to the power of the password length. For example, with lowercase (`26`), uppercase (`26`), and digits (`10`), the character set totals `62`. A five-character password would have `62^5` possible combinations:

```bash
# Keyspace calculation
$ echo -n "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | wc -c
62

$ python3 -c "print(62**5)"
916132832
```

The **hash rate** is a measure of how many hash calculations can be performed in a second (`1` MH/s equals `1,000,000` hashes per second):

{% code overflow="wrap" %}

```bash
# Hash rate (benchmark mode)
$ hashcat -b

# CPU example (pthread-Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz, 1545/3154 MB (512 MB allocatable), 4MCU) for MD5
Speed.#1.........:   450.8 MH/s (2.19ms) @ Accel:256 Loops:1024 Thr:1 Vec:8

# GPU example (NVIDIA GeForce RTX 3090, 23336/24575 MB, 82MCU) for MD5
Speed.#1.........: 68185.1 MH/s (39.99ms) @ Accel:256 Loops:1024 Thr:128 Vec:8
```

{% endcode %}

**Cracking time** is determined by dividing the **keyspace** by the **hash rate**:

{% code overflow="wrap" %}

```bash
# Cracking time (in seconds) for MD5

# CPU
$ python3 -c "print(916132832 / 450800000)"
20.32

# GPU
$ python3 -c "print(916132832 / 6818510000)"
0.13
```

{% endcode %}

### Length vs Complexity

Increasing **password length** increases cracking duration by **exponential time**, while increasing **password complexity** (charset) only increases cracking duration by **polynomial time**.

Exponential time grows much faster than polynomial time:

* **Polynomial time (e.g., n2n^2n2, n3n^3n3)**: As input `nnn` increases, the number of steps grows at a manageable rate.
* **Exponential time (e.g., 2n2^n2n, 3n3^n3n)**: The number of steps doubles, triples, or grows even faster with each increase in `nnn`, making it impractical for large inputs.

Increasing **password length**:

{% code overflow="wrap" %}

```bash
# Keyspace for an 8-length password
$ python3 -c "print(62**8)"
218340105584896

# Cracking time
$ python3 -c "print(218340105584896 / 9276300000)"
23537.41314801117 # ~6.5 hours

# Keyspace for a 10-length password
$ python3 -c "print(62**10)"
839299365868340224

# Cracking time
$ python3 -c "print(839299365868340224 / 9276300000)"
90477816.14095493 # ~2.8 years
```

{% endcode %}

Increasing **password complexity**:

{% code overflow="wrap" %}

```bash
# Simple charset
$ echo -n "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | wc -c
62

# Keyspace
$ python3 -c "print(62**5)"
916132832

# Cracking time
$ python3 -c "print(916132832/9276300000)"
0.09876058687192092 # ~2.7 hours


# Complex charset
$ echo -n "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$!@#$%^&*()_+=-[]{}|;:/?.><,." | wc -c
89

# New keyspace (polynomial increase)
$ python3 -c "print(89**5)"
5584059449

# Cracking time
$ python3 -c "print(5584059449/9276300000)"
0.6019705538846307 # ~16.7 hours 
```

{% endcode %}

## Usage

{% hint style="warning" %}
If using `hashcat.exe` on Windows, open the hash file with Notepad++ and go to: *Encoding* → *Convert to UTF-8 (without BOM)*.
{% endhint %}

{% code overflow="wrap" %}

```bash
# Basic usage
hashcat -a 0 -m 18200 user_hash /usr/share/wordlists/rockyou

# Auto-identify hash type
hashcat --identify <hash>

# Mode code enumeration
hashcat -hh | grep <format>

# Example formats
hashcat -m 2100 --example-hashes

# Hash with usernames
hashcat hashes.txt /usr/share/wordlists/rockyou.txt --username

# Show results
hashcat --show hashes.txt
```

{% endcode %}

### Rules

Hashcat rules can be under `/usr/share/hashcat/rules`. [Custom file rules](https://hashcat.net/wiki/doku.php?id=rule_based_attack) can also be created.

* If rule functions are on the **same line**, they are **applied consecutively to each word**.&#x20;
* If rule functions are on **separate lines**, **each line is treated as a separate rule**.

```bash
# Initial password file
$ cat mutating_example.txt
password

# Capitalize the first letter and add '1' at the end simultaneously
$ echo 'c $1' > rule1.txt && cat rule1.txt
c $1

$ hashcat -r rule1.txt --stdout mutating_example.txt
Password1

# Capitalize the first letter, add '1' at the end
$ echo -e 'c\n$1' > rule2.txt && cat rule2.txt
c
$1

$ hashcat -r rule2.txt --stdout mutating_example.txt
Password
password1
```

### Optimization

Enable a specific **workload profile** (default is 2), for example, use 3 if the PC focuses just on cracking:

{% code overflow="wrap" %}

```bash
hashcat -a 0 -m 18200 user_hash /usr/share/wordlists/rockyou -w 3
```

{% endcode %}

## Hash Types

| Type                                                                    | Mode  |
| ----------------------------------------------------------------------- | ----- |
| `$krb5asrep$23$`                                                        | 18200 |
| `$krb5tgs$23$`                                                          | 13100 |
| `NTLMv2`                                                                | 5600  |
| `NTLM`                                                                  | 1000  |
| `$krb5asrep$17$`                                                        | 32100 |
| `$krb5asrep$18$`                                                        | 32200 |
| `$krb5tgs$17$`                                                          | 19600 |
| `$krb5tgs$18$`                                                          | 19700 |
| `NTLMv2 (NT)`                                                           | 27100 |
| `$DCC2$10240`                                                           | 2100  |
| `MD5`                                                                   | 500   |
| `KeePass` ([keepass2john](/boxes/tools/passwords/john.md#kdbx-keepass)) | 13400 |
| `$sshng$6$` ([ssh2john](/boxes/tools/passwords/john.md#id_rsa-ssh))     | 22921 |

### DCC2

For the **Domain Cached Credentials 2** (`DCC2`), the domain and username must be removed. Only the value starting with `$DCC2$` is required:

{% code overflow="wrap" %}

```bash
$ cat /home/plaintext/.cme/logs/MS01_10.129.204.133_2022-11-08_093944.cached| cut -d ":" -f 2
$DCC2$10240#julio#c2139497f24725b345aa1e23352481f3
$DCC2$10240#david#a8338587a1c6ee53624372572e39b93f
$DCC2$10240#john#fbdeac2c1d121818f75796cedd0caf0a
```

{% endcode %}

### PBKDF2-HMAC-SHA256

> * <https://github.com/hashcat/hashcat/issues/1583>
> * <https://github.com/kxcode/KrackerGo?tab=readme-ov-file#hashcat>

For the `10900` mode both the salt and the hash need to be converted from string to b64 first:

{% code overflow="wrap" %}

```bash
# Original hash
$ cat admin-hash
pbkdf2:sha256:600000$AMtzteQIG7yAbZIa$0673ad90a0b4afb19d662336f0fce3a9edd0b7b19193717be28ce4d66c887133

# Salt to b64
$ echo -n "AMtzteQIG7yAbZIa" | base64 -w 0
QU10enRlUUlHN3lBYlpJYQ==

# Hash to b64
$ echo -n "0673ad90a0b4afb19d662336f0fce3a9edd0b7b19193717be28ce4d66c887133" | xxd -r -p | base64 -w 0
BnOtkKC0r7GdZiM28Pzjqe3Qt7GRk3F74ozk1myIcTM=

# Final format
> cat .\admin-hash
sha256:600000:QU10enRlUUlHN3lBYlpJYQ==:BnOtkKC0r7GdZiM28Pzjqe3Qt7GRk3F74ozk1myIcTM=

> .\hashcat.exe -m10900 admin-hash .\wordlists\rockyou.txt -O -D 2
...
sha256:600000:QU10enRlUUlHN3lBYlpJYQ==:BnOtkKC0r7GdZiM28Pzjqe3Qt7GRk3F74ozk1myIcTM=:iloveyou1
```

{% endcode %}

### Ansible

For details on how to crack Ansible password, see [here](/boxes/tl-dr/infra/apps-x-platform/ansible.md).

### VeraCrypt

{% code overflow="wrap" %}

```bash
.\hashcat.exe -m13711 'encryptedFile.hc' 'rockyou.txt' -O -D 2
```

{% endcode %}
