cybersecurity · intermediate · ~15 min · safe pentest lab
Classify a crypt(3) hash by its scheme prefix (or DES shape).
/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.
A hash string.
The scheme id above.
Prefix checks are exact; the DES rule requires length exactly 13.
#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; }
Confusing the $5$ and $6$ tags; forgetting the DES length/charset rule.
Empty string ->0; a 13-char string with a non-crypt char ->0.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.