Sem 7

Password Attacks

Decks 10 (Part 1 and full). Types of brute-force attacks, offline cracking with John the Ripper, wordlist generation with Crunch, the Linux /etc/shadow format, and online cracking with Hydra.

A password attack is any method used to obtain or guess passwords to gain unauthorised access to a system.

Brute-force attacksSearch on YouTube

A brute-force attack uses trial and error to crack passwords, login credentials and encryption keys. The attacker tests many username/password combinations, usually with a computer, until the correct login is found. It is simple but reliable.

Types of brute-force attackSearch on YouTube

TypeHow it works
Simple brute forceTry every possible combination systematically.
Dictionary attackTry passwords from a wordlist of likely candidates.
Hybrid brute forceCombine a dictionary word with appended numbers/symbols (e.g. password123).
Reverse brute forceFix one common password and try it against many usernames.
Credential stuffingReuse stolen valid username/password pairs from one service against others, exploiting password reuse.

Password spraying uses a short list of common passwords tried against a large number of accounts, aiming to find one weak password without locking accounts out.

Know the difference: credential stuffing uses known valid pairs (it exploits reuse). Password spraying uses a few common passwords across many accounts (it avoids lockouts).

Cracking toolsSearch on YouTube

ToolTypeNotes
John the RipperOfflineOpen-source password recovery; supports hundreds of cipher and hash types — macOS/Unix/Windows user passwords, database servers, web apps, network traffic, encrypted private keys, document files.
HydraOnlineWorks on live services; parallelised login cracker for many protocols.

John the Ripper (offline)Search on YouTube

John is an offline tool: it works on a captured hash, not a live service.

How John worksSearch on YouTube

John takes each candidate from a wordlist, hashes it with the same algorithm, and compares the result to the target hash. A match reveals the password.

  1. Input: the hash of the password to be cracked, and a wordlist of candidate passwords.
  2. For each word, apply the hashing algorithm to produce an output hash.
  3. Compare the output hash with the target hash; a match reveals the plaintext.

InstallSearch on YouTube

sudo apt update
sudo apt install john

The Linux /etc/shadow fileSearch on YouTube

/etc/shadow stores encrypted user passwords and account information. It is readable only by privileged users (root) for security.

sudo cat /etc/shadow

A hash field such as $y$j9T$gs93511UPLhR74auj16Dv0$3Xg/QI4I0j... breaks down as:

PartMeaning
$y$Algorithm identifier (here, yescrypt)
j9TEncoded parameters (work factor, cost, memory usage)
gs93511UPLhR74auj16Dv0Random salt (unique per user/password)
3Xg/QI4I0j...Final hash of (password + salt + parameters)

The salt is random and unique per password, so identical passwords produce different hashes and precomputed (rainbow) tables are defeated.

Cracking a password-protected ZIPSearch on YouTube

Step 1. Extract the hash from the protected ZIP with zip2john.

zip2john protected.zip > hash.txt

Step 2. Run John against the hash.

john hash.txt

Step 3. John prints the recovered password; unzip the file with it.

Cracking a password-protected PDFSearch on YouTube

/usr/share/john/pdf2john.pl myfile_protected.pdf > hash.txt   # extract the hash
john hash.txt                                                  # crack it

Using your own wordlistSearch on YouTube

john --wordlist=/root/Desktop/rockyou.txt hash.txt

Crunch (wordlist generation)Search on YouTube

Crunch is a wordlist generator built into Kali, used to create focused dictionaries for brute-force and dictionary attacks. It is best when you know details about the target (username, date of birth, hobbies) and want a focused list instead of a large generic one like rockyou.txt.

crunch <min> <max> [charset] [options]

<min>/<max> set the minimum and maximum password length; [charset] is the character set; [options] adds flags like output file and pattern.

Pattern placeholders in -t:

SymbolMeans
%a number
@a lowercase letter
,an uppercase letter
^a symbol

Examples:

crunch 4 4 0123456789 -o pinlist.txt            # all 4-digit PINs
crunch 3 5 abcdefghijklmnopqrstuvwxyz -o words.txt  # lowercase, length 3 to 5
crunch 6 6 -t neha%%                             # neha00, neha01, ... neha99
crunch 8 8 abc123!@# -o passlist.txt             # all 8-char combos of a,b,c,1,2,3,!,@,#

Crunch output can reach gigabytes, so limit it:

crunch 6 6 -t user@@ -c 1000 -o START   # split into 1000 lines per file: START1, START2, ...

-c 1000 splits output into 1000-line files; -o START names them START1, START2, etc.

Hydra (online)Search on YouTube

Hydra is a fast, flexible, parallelised login cracker that attacks many protocols on live services. It shows how easy unauthorised remote access can be against weak credentials.

hydra [OPTIONS] [PROTOCOL]://[TARGET]
OptionMeaning
-l <login>single username
-L <file>file of usernames
-p <password>single password
-P <file>file of passwords
-t <number>parallel tasks (threads)
-fexit after the first valid login
-T <seconds>timeout per attempt
-w <seconds>wait time between attempts
-s <port>target port if non-default

Use -l when you already know the username (for example Administrator) and only need the password.

Services to targetSearch on YouTube

First scan the target to find open services:

nmap -p 21 192.168.56.102     # confirm FTP is open: expect 21/tcp open ftp
PortServiceTool
21FTPHydra / Medusa
22SSHHydra
80 / 8080 / 8383Web loginsHydra / Burp Suite
445SMBHydra / smbclient
3306MySQLHydra
3389RDPHydra / xfreerdp

Example: FTP brute forceSearch on YouTube

If anonymous FTP login fails, the server needs valid credentials. Build wordlists, then run Hydra.

# usernames
cat > users.txt <<EOF
admin
administrator
user
test
guest
EOF

# passwords (first 50 lines of rockyou)
head -n 50 /usr/share/wordlists/rockyou.txt > passwords.txt

# attack FTP
hydra -l Administrator -P passwords.txt ftp://192.168.56.102

There is also a GUI version, xhydra:

xhydra
  • Enforce long, unique passwords and a password manager (defeats reuse-based credential stuffing).
  • Account lockout / rate limiting and increasing delays after failed logins.
  • Multi-factor authentication, so a cracked password alone is not enough.
  • Strong, salted, slow hashes (yescrypt, bcrypt) in /etc/shadow; keep it root-only.
  • Disable anonymous and default accounts; monitor for brute-force patterns.

Lab 8 (Password Cracking). A password-protected ZIP contains two password-protected PDFs. Task 1: from recon intel (Username: Yash, DOB: 14 Feb 1998) generate a Crunch wordlist of candidate passwords (yash21998, yash140298, Yash141998, ...), extract the PDF hash with pdf2john.pl, and crack it with John. Task 2: generate a Crunch wordlist for the second PDF (length 15, containing a name, one special character, a place, one digit and one alphabet) and crack it with John.

Quick self-testSearch on YouTube

What is the difference between credential stuffing and password spraying?

Credential stuffing reuses known valid username/password pairs stolen elsewhere, exploiting password reuse. Password spraying tries a few common passwords against many accounts to avoid lockouts.

Is John the Ripper an online or offline tool? What about Hydra?

John is offline (it cracks a captured hash). Hydra is online (it attacks live services).

How does John the Ripper recover a password from a hash?

It hashes each wordlist candidate with the same algorithm and compares the result to the target hash; a match reveals the plaintext.

In an /etc/shadow entry $y$j9T$...$..., what do $y$ and the salt do?

$y$ is the algorithm identifier (yescrypt). The salt is random and unique per password, so identical passwords hash differently and rainbow tables are defeated.

Which commands extract hashes from a ZIP and a PDF for John?

zip2john protected.zip > hash.txt and /usr/share/john/pdf2john.pl file.pdf > hash.txt.

In Crunch, what do %, @, , and ^ mean in a -t pattern?

% = number, @ = lowercase letter, , = uppercase letter, ^ = symbol.

Write a Crunch command that generates all 4-digit PINs to a file.

crunch 4 4 0123456789 -o pinlist.txt

What do the Hydra flags -l, -P and -f do?

-l a single username, -P a file of passwords, -f exit after the first valid login found.

Which ports/services does the deck list for Hydra attacks?

21 FTP, 22 SSH, 80/8080/8383 web logins, 445 SMB, 3306 MySQL, 3389 RDP.

Name two defences against brute-force password attacks.

Account lockout / rate limiting and multi-factor authentication. Also strong salted slow hashes and unique passwords.

  • Brute-force types: simple, dictionary, hybrid, reverse, credential stuffing; plus password spraying.
  • John the Ripper is offline: it hashes wordlist candidates and compares to the target hash.
  • /etc/shadow stores salted hashes (root-only); format $id$params$salt$hash.
  • Extract hashes with zip2john and pdf2john.pl; crack with john or john --wordlist=....
  • Crunch builds focused wordlists; pattern symbols % @ , ^; -o output, -c split.
  • Hydra is online: -l/-L users, -p/-P passwords, -t threads, -f stop on first hit, -s port.
  • Target ports: 21 FTP, 22 SSH, 80 web, 445 SMB, 3306 MySQL, 3389 RDP; xhydra is the GUI.
  • Defend with lockout, MFA, unique passwords and strong salted hashes.