C:\Seyi\Portfolio\writeups\pw_crack_5_ Y:0000PX
...\writeups\pw_crack_5 Y:0000PX

< back to write-ups

CTF // MEDIUM pw_crack_5.md

// PW Crack 5

General Skills · Medium · CyLab Security Academy (picoCTF)

// Summary

Four files are given: a locked flag, a program that unlocks it with the right password, a list of possible passwords, and a scrambled code made from the correct password. That code (a ) cannot be turned back into the password, but any guess can be scrambled the same way and compared. Scrambling every word on the list finds the one that matches, and that same word unlocks the flag. Comparable to holding a fingerprint and a list of suspects, and fingerprinting each suspect until one matches. Where the analogy stops: two different inputs can in theory share a hash, but for this purpose a match is treated as proof.

// Objective

Given: a password-check script, an flag, a file of candidate passwords, and level5.hash.bin (the hash of the correct password).
Asked: the flag, format academy{...}.
Type: stated.

// Recon

Read the script — It hashes the entered password with hash_pw() and compares it to level5.hash.bin. On a match it decrypts the flag with str_xor(flag_enc, password).
Read the dictionary — A list of candidate passwords (pos_pw_list once loaded).

// Deduction

  1. Hashes are one-way → level5.hash.bin cannot be reversed → hash each candidate and compare.
  2. The script already has hash_pw() and the comparison → loop the dictionary through them.
  3. The password is also the key → the matching word decrypts the flag directly.

// Solve

  1. Add a loop to the script, after the dictionary and hash are loaded:
    for x in pos_pw_list:
                if hash_pw(x) == correct_pw_hash:
                    print("Found the correct password: " + x)
                    print(str_xor(flag_enc.decode(), x))
  2. Run the script.
    Result: the matching password, then the flag.

The exact filenames of the script, encrypted flag, and dictionary are not recorded.

// Answer

Plain: the flag is the message that was locked with the correct password. Finding the password by trial unlocked it.
Technical: the dictionary entry x with hash_pw(x) == correct_pw_hash is the password. The flag is str_xor(flag_enc, x): the encrypted bytes XORed with the repeating password.

// Root cause

Flaw: an unsalted, fast password hash. Any wordlist can be hashed offline and matched without touching a login or triggering a lockout.
CWE: CWE-759, one-way hash without a ; CWE-916, password hash with insufficient computational effort.
Fix: hash passwords with a per-user salt and a slow algorithm (, scrypt, Argon2).
Real-world impact: when a site's password database leaks, attackers recover common passwords on their own computers within minutes, then try them on the victims' other accounts.

// Transfer

  • Given a hash and a wordlist → hash every word, compare. Never try to reverse the hash.
  • Large wordlists or known hash types → hashcat / john instead of a hand-written loop.

// Index

  1. 1HashA function that turns input into a fixed-length scrambled code. Same input, same code; cannot be reversed.
  2. 2Encrypt / decryptLock data so it is unreadable without a key / unlock it with the key.
  3. 3Wordlist / dictionaryA file of candidate passwords.
  4. 4XORA simple way of combining data with a key. Applying the same key again undoes it.
  5. 5SaltRandom data added to each password before hashing, so the same password gives different hashes and precomputed lists stop working.
  6. 6bcrypt, scrypt, Argon2Password-hashing methods designed to be slow, which makes mass guessing impractical.