> 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/35.-hybrid-attack.md).

# Hybrid Attack

## What is a Hybrid Attack?

A **hybrid attack** combines a dictionary attack with brute force — it takes wordlist entries and appends/prepends brute-forced characters. It targets the common pattern of `word + numbers/symbols`.

```
"password" + "123"  → "password123"
"summer"   + "2024" → "summer2024"
"dragon"   + "!"    → "dragon!"
```

***

## How It Works

```
Wordlist word → apply brute force mask → try hash

"password" + ?d?d?d → password000 ... password999
"letmein"  + ?d?d   → letmein00  ... letmein99
```

***

## Hashcat Hybrid Modes

```bash
# Mode 6: Wordlist + Mask (append)
hashcat -m 0 -a 6 hashes.txt rockyou.txt ?d?d?d?d

# Mode 7: Mask + Wordlist (prepend)
hashcat -m 0 -a 7 hashes.txt ?d?d?d?d rockyou.txt

# Examples:
hashcat -m 0 -a 6 hashes.txt words.txt ?d?d         # word + 2 digits
hashcat -m 0 -a 6 hashes.txt words.txt ?d?d?d?d     # word + 4 digits (year)
hashcat -m 0 -a 6 hashes.txt words.txt ?s           # word + symbol
hashcat -m 0 -a 6 hashes.txt words.txt ?u?l?l?d     # word + upper+lower+lower+digit

# Masks:
# ?l = lowercase a-z
# ?u = uppercase A-Z
# ?d = digit 0-9
# ?s = special !@#$...
# ?a = all printable
```

***

## Python Example

```python
import hashlib, itertools, string

def hybrid_attack(target: str, wordlist: list, suffix_len: int = 3):
    charset = string.digits
    for word in wordlist:
        for suffix in itertools.product(charset, repeat=suffix_len):
            candidate = word + ''.join(suffix)
            if hashlib.sha256(candidate.encode()).hexdigest() == target:
                return candidate
    return None

target = hashlib.sha256(b"summer123").hexdigest()
result = hybrid_attack(target, ["summer", "winter", "password"])
print(result)  # "summer123"
```

***

## Defense

* Use **bcrypt/Argon2** — makes each attempt slow
* Block passwords matching `word + digits` patterns
* Enforce **minimum length of 12+** characters
* Use **passphrases** instead of word+number combos


---

# 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/35.-hybrid-attack.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.
