> For the complete documentation index, see [llms.txt](https://alham-rizvi.gitbook.io/alhamrizvi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alham-rizvi.gitbook.io/alhamrizvi/cryptography/hashing/46.-common-tricks.md).

# 46. Common CTF Hash Tricks

## 1. Magic Hashes (PHP Type Juggling)

PHP uses loose comparison (`==`). If a hash starts with `0e` followed by digits, PHP treats it as `0` in scientific notation.

```php
"0e1234" == "0e5678"  // true! Both == 0
```

### Known Magic Hash Inputs

| Input       | Hash (MD5)                         |
| ----------- | ---------------------------------- |
| `240610708` | `0e462097431906509019562988736854` |
| `QNKCDZO`   | `0e830400451993494058024219903391` |
| `aabg74560` | `0e00090022888024612349082480906`  |

### SHA-1 Magic Hashes

| Input      | SHA-1                                      |
| ---------- | ------------------------------------------ |
| `aaroZmOk` | `0e66507019969427134894567494305185566735` |

**CTF Use:** Bypass login where `md5($password) == md5($stored)` uses `==`.

## 2. Length Extension Attack

Applies to: `MD5`, `SHA-1`, `SHA-256`, `SHA-512`\
Does NOT apply to: `HMAC`, `SHA-3`, `bcrypt`

When server computes `H(secret || message)`, you can append data and compute a valid hash without knowing the secret.

```bash
# Using hashpump
hashpump -s <original_hash> -d <original_data> -a <data_to_append> -k <key_length>
```

## 3. Hash Collision (MD5)

Two different inputs with the same MD5 hash exist and are publicly known.

```
File A MD5 == File B MD5 (but File A ≠ File B)
```

**CTF Use:** If challenge checks `md5(file1) == md5(file2)` but `file1 != file2`.

Known collision pairs: <https://www.mscs.dal.ca/\\~selinger/md5collision/>

## 4. Double Hashing

Some apps hash twice: `MD5(MD5(password))`. The output is still 32 hex chars. Crack by:

```bash
hashcat -m 2600 hash.txt rockyou.txt   # MD5(MD5(pass))
```

## 5. Hash as Password

In some CTF challenges, the hash itself is used as the password or flag. Always try submitting:

* The raw hash
* Uppercase version
* Wrapped: `CTF{<hash>}`

## 6. Salted Hash Formats

```
hash:salt       → provide as "hash:salt" to hashcat with --username
$id$salt$hash   → Unix shadow file format
```

## 7. Rainbow Table Lookup

Precomputed hash→plaintext tables. Defeated by salting.

* Try <https://crackstation.net> for unsalted MD5/SHA1/SHA256


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://alham-rizvi.gitbook.io/alhamrizvi/cryptography/hashing/46.-common-tricks.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
