cybersecurity · intermediate · ~15 min · safe pentest lab

Identify a shadow hash scheme

Classify a crypt(3) hash by its scheme prefix (or DES shape).

Challenge

/etc/shadow hashes carry a scheme tag. Implement:

int shadow_hash_scheme(const char *h);

Return: $1$->2 (md5crypt), $5$->5 (sha256crypt), $6$->6 (sha512crypt), $y$->7 (yescrypt), $2a$/$2b$/$2y$->8 (bcrypt), a 13-char string of [./0-9A-Za-z]->1 (traditional DES), everything else->0.

Input format

A hash string.

Output format

The scheme id above.

Constraints

Prefix checks are exact; the DES rule requires length exactly 13.

Starter code

#include <stddef.h>
/* Identify a crypt(3) hash scheme:
   $1$=2 md5crypt, $5$=5 sha256crypt, $6$=6 sha512crypt, $y$=7 yescrypt,
   $2a/$2b/$2y$=8 bcrypt, 13-char [./0-9A-Za-z]=1 DES, else 0. */
int shadow_hash_scheme(const char *h){ (void)h; return 0; }

Common mistakes

Confusing the $5$ and $6$ tags; forgetting the DES length/charset rule.

Edge cases to handle

Empty string ->0; a 13-char string with a non-crypt char ->0.

Background lessons

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