cybersecurity · intermediate · ~15 min · safe pentest lab

Flag a weak shadow hash

Decide whether a shadow hash uses a weak (fast-to-crack) scheme.

Challenge

Turn scheme knowledge into a verdict:

int is_weak_shadow_hash(const char *h);

Return 1 if the hash is weak — plaintext/unknown, traditional DES (13 chars), or md5crypt ($1$). sha256crypt/sha512crypt/yescrypt/bcrypt are strong (0).

Input format

A hash string.

Output format

1 if weak, else 0.

Constraints

Unknown/empty is treated as weak (conservative).

Starter code

#include <stddef.h>
/* 1 if the crypt(3) hash is WEAK: plaintext/unknown, traditional DES (13 chars),
   or md5crypt ($1$). sha256/sha512/yescrypt/bcrypt are strong (0). */
int is_weak_shadow_hash(const char *h){ (void)h; return 0; }

Common mistakes

Treating an unrecognized scheme as strong; missing that md5crypt is weak despite the $ prefix.

Edge cases to handle

$y$ and $2b$ are strong; a 13-char DES hash is weak.

Background lessons

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.