hacking-tutorial

# Lesson 07 — Password Attacks & Hash Cracking (Hashcat & John)

## Overview

This lesson introduces password-based attacks and demonstrates local, safe labs for cracking password hashes using two common tools: Hashcat and John the Ripper. It focuses on practical techniques, defensive measures, and legal/ethical constraints.

Important: Only perform these exercises on machines and data you own or where you have explicit permission. Never attempt password cracking on third-party systems without written authorization.

## Learning objectives

## Prerequisites

If you don’t want to install tools locally, use the official Docker images for Hashcat or John.

## Lab setup — safe sample hashes

We’ll create a minimal, local sample file with a few hashed passwords using common algorithms. Save the following small Python helper as make_hashes.py and run it locally to produce sample_hashes.txt.

 # make_hashes.py — generate sample password hashes (for local lab only)
 import hashlib
 import bcrypt

 passwords = [
     'password123',
     'hunter2',
     'S3cur3P@ss!',
     'letmein',
 ]

 # SHA1 (insecure, demonstrative)
 with open('sample_hashes.txt', 'w') as f:
     for p in passwords:
         h = hashlib.sha1(p.encode()).hexdigest()
         f.write(f'sha1:{h}:{p}\n')

 # bcrypt (slow, recommended for real systems)
 with open('sample_hashes_bcrypt.txt', 'w') as f:
     for p in passwords:
         bh = bcrypt.hashpw(p.encode(), bcrypt.gensalt()).decode()
         f.write(f'bcrypt:{bh}:{p}\n')

Run it to create sample_hashes.txt and sample_hashes_bcrypt.txt.

## Lab 1 — Cracking simple SHA1 hashes with Hashcat (demo)

  1. Prepare your wordlist. If you have rockyou.txt, use it; otherwise create a tiny wordlist.txt with candidate passwords.

  2. Hashcat requires a hash file with one hash per line. Extract the SHA1 column from sample_hashes.txt into sha1-only.txt (one hash per line).

  3. Run Hashcat in a minimal mode (example uses hash type 100 for raw SHA1):

 # Example (Linux/WSL/PowerShell-friendly):
 hashcat -m 100 -a 0 sha1-only.txt wordlist.txt --show

Notes:

## Lab 2 — John the Ripper (single mode and wordlist)

John is simpler to start with for beginners. Prepare a john_hashes.txt in a format John expects (one hash per line). Then run:

 john --wordlist=wordlist.txt john_hashes.txt
 john --show john_hashes.txt

Use --rules to apply mangling rules (prepend/append digits, case changes).

## Lab 3 — Hashcat rules and hybrid attacks (brief)

Hashcat supports powerful rule sets. Example: use the best64.rule with a dictionary:

 hashcat -m 100 -a 0 sha1-only.txt wordlist.txt -r rules/best64.rule --show

Hybrid attack (mask + wordlist):

 hashcat -m 100 -a 6 sha1-only.txt wordlist.txt ?d?d

This appends two digits to each word from the list.

## Lab 4 — Cracking bcrypt (why it’s harder)

Bcrypt is intentionally slow and resists GPU acceleration. Use John or Hashcat with the right mode, but expect longer runtimes. Example with John:

 john --wordlist=wordlist.txt sample_hashes_bcrypt.txt

Expect bcrypt cracking to be much slower — that’s by design.

## Defensive measures — how to stop this happening

## Safe practice and legal notes

## Optional exercises

## References


Updated: 2025-10-07