Skip to content

Cracking database password hashes: MySQL, PostgreSQL, and MSSQL

Identify and crack MySQL, PostgreSQL, and MSSQL password hashes with the correct hashcat mode and John the Ripper format for each legacy and current variant.

Published on 4 min read

Database password hashes rarely make it into a cracking session as cleanly as a /etc/shadow dump — they come out of a privileged query, a mysqldump, or a backup file, each engine with its own column name and its own hash format, and usually more than one format depending on how old the server is. Getting the mode number wrong here does not just waste time; dumping the wrong column or querying the wrong system table can mean you never get the hash at all. This post covers all three major engines end to end: where the hash lives, how to pull it out, and the exact hashcat mode and John the Ripper format for each.

MySQL

Old format: MySQL 3.23 (pre-4.1)

Before MySQL 4.1, PASSWORD() produced a 16-character hex string with no salt, computed from a now-undocumented weak hashing scheme:

5d2e19393cc5ef67

You still find it on ancient, un-upgraded installations or in old dumps. MySQL 3.23 cracks with hashcat mode 200 or John's mysql format:

echo '5d2e19393cc5ef67' > hash.txt && hashcat -m 200 hash.txt /usr/share/wordlists/rockyou.txt
echo '5d2e19393cc5ef67' > hash.txt && john --format=mysql --wordlist=/usr/share/wordlists/rockyou.txt hash.txt

It is unsalted and cheap to compute, so it falls just as fast as unsalted MD5 — see why fast hashes are dangerous for why that matters.

Current format: MySQL 4.1+ (SHA1(SHA1(password)))

Since 4.1, PASSWORD() double-hashes with SHA-1 and prefixes the 40-character hex digest with an asterisk:

*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19

This is the format you will find in any MySQL 5.x/8.x mysql.user table that still uses the legacy auth plugin (mysql_native_password). It is MySQL 4.1+ / SHA1(SHA1()), hashcat mode 300, John format mysql-sha1:

echo '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' > hash.txt && hashcat -m 300 hash.txt /usr/share/wordlists/rockyou.txt -r /usr/share/hashcat/rules/best64.rule
echo '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' > hash.txt && john --format=mysql-sha1 --wordlist=/usr/share/wordlists/rockyou.txt hash.txt

Still unsalted, still fast — double-SHA-1 adds essentially no cost per guess, so it cracks at GPU speed. Pull the column directly if you have access:

SELECT user, authentication_string FROM mysql.user;

(Older servers call the column Password instead of authentication_string.) Check plugin in the same table before you assume the format: MySQL 8's default caching_sha2_password authentication stores a different, SHA-256-based hash that is outside the scope of the two legacy formats above, so a dump from a default MySQL 8 install may contain a mix of both depending on when each account was created.

PostgreSQL

MD5 (pg_authid.rolpassword)

The classic format stores "md5" + md5(password || username):

md599e5ea7a6f7c3269995cba3927fd0093

The username is baked in as a pseudo-salt, but since the username is known and reused, it does not meaningfully slow a targeted crack. This is PostgreSQL MD5, hashcat mode 12, John format postgres:

echo 'md599e5ea7a6f7c3269995cba3927fd0093' > hash.txt && hashcat -m 12 hash.txt /usr/share/wordlists/rockyou.txt
echo 'md599e5ea7a6f7c3269995cba3927fd0093' > hash.txt && john --format=postgres --wordlist=/usr/share/wordlists/rockyou.txt hash.txt

Note that hashcat's -m 12 input needs the username supplied alongside the hash (hash:username) since the username is part of what gets hashed — check hashcat --example-hashes -m 12 on your build for the exact line format expected.

Fetch it with:

SELECT rolname, rolpassword FROM pg_authid WHERE rolpassword LIKE 'md5%';

This requires superuser privileges (or membership in pg_read_all_settings/equivalent on managed services) — pg_authid is locked down specifically because it holds these hashes.

Current format: SCRAM-SHA-256

PostgreSQL 10+ defaults to password_encryption = scram-sha-256, which stores iteration count, salt, and both a stored key and a server key:

SCRAM-SHA-256$4096:tQ4dDxqg5cXh2pVn...$3sH0pZ9k...

This is PostgreSQL SCRAM-SHA-256, hashcat mode 28600 (no John the Ripper format ships for it at the time of writing):

echo 'SCRAM-SHA-256$4096:tQ4dDxqg5cXh2pVn...$3sH0pZ9k...' > hash.txt && hashcat -m 28600 hash.txt /usr/share/wordlists/rockyou.txt

SCRAM is a real improvement: a genuine random salt plus a PBKDF2-style iteration count (4096 by default, raisable via scram_iterations on PostgreSQL 16+) make it meaningfully slower per guess than the MD5 format, in the same spirit covered in Argon2 vs bcrypt vs scrypt. It is still nowhere near bcrypt-slow, so weak passwords remain crackable — just not at raw-MD5 speed.

MSSQL

All three generations live in sys.sql_logins.password_hash, queryable with sysadmin rights:

SELECT name, password_hash FROM sys.sql_logins WHERE type_desc = 'SQL_LOGIN';

A backup of the master database (or a copy of the raw MDF/LDF) also carries this table if you cannot query live.

MSSQL (2000)

0x01002702560500000000000000000000000000000000000000008db43dd9b1972a636ad0c7d4b8c515cb8ce46578

A 4-byte salt followed by two SHA-1 digests: one of the password as typed, one of the password upper-cased. That second, case-insensitive digest is the weak point — it is routinely cracked first, then the case-sensitive variant is brute-forced from it. MSSQL (2000) is hashcat mode 131, John format mssql:

echo '0x01002702560500000000000000000000000000000000000000008db43dd9b1972a636ad0c7d4b8c515cb8ce46578' > hash.txt && hashcat -m 131 hash.txt /usr/share/wordlists/rockyou.txt
echo '0x01002702560500000000000000000000000000000000000000008db43dd9b1972a636ad0c7d4b8c515cb8ce46578' > hash.txt && john --format=mssql --wordlist=/usr/share/wordlists/rockyou.txt hash.txt

MSSQL (2005)

Same idea, shorter — SQL Server 2005 dropped the case-insensitive secondary hash that 2000 carried:

0x010040866ceb6bf8cc2e6f6d6c4f5fabe6cae0a45f6f5e8a

MSSQL (2005) is hashcat mode 132, John format mssql05:

echo '0x010040866ceb6bf8cc2e6f6d6c4f5fabe6cae0a45f6f5e8a' > hash.txt && hashcat -m 132 hash.txt /usr/share/wordlists/rockyou.txt
echo '0x010040866ceb6bf8cc2e6f6d6c4f5fabe6cae0a45f6f5e8a' > hash.txt && john --format=mssql05 --wordlist=/usr/share/wordlists/rockyou.txt hash.txt

MSSQL (2012/2014/2016/2019)

Current SQL Server versions switched to salted SHA-512:

0x0200F733058A07892C5CACE899768F89965F6BD1DED7955FE89E1C9A10E27849B0B213B5CE92CC9347ECCB34C3EFADAF2FD99BFFECD8D9150DD6AACB5D409A9D2652A4E0AF16

MSSQL (2012/2014) is hashcat mode 1731, John format mssql12. The same mode and format also cover 2016 and 2019, since the scheme has not changed since 2012:

echo '0x0200F733058A07892C5CACE899768F89965F6BD1DED7955FE89E1C9A10E27849B0B213B5CE92CC9347ECCB34C3EFADAF2FD99BFFECD8D9150DD6AACB5D409A9D2652A4E0AF16' > hash.txt && hashcat -m 1731 hash.txt /usr/share/wordlists/rockyou.txt
echo '0x0200F733058A07892C5CACE899768F89965F6BD1DED7955FE89E1C9A10E27849B0B213B5CE92CC9347ECCB34C3EFADAF2FD99BFFECD8D9150DD6AACB5D409A9D2652A4E0AF16' > hash.txt && john --format=mssql12 --wordlist=/usr/share/wordlists/rockyou.txt hash.txt

All three MSSQL generations are single-round and GPU-friendly — the salt stops rainbow tables but none of them slow down a per-guess attack the way a proper KDF would.

Picking the attack once you have the mode

Every format above is fast enough that a plain rockyou-plus-rules pass is worth running first before anything more targeted; see wordlists and rules that work for building that rule set, and mask attacks and keyspace if you know the organization enforces a specific password shape. If you are not certain which of these formats a given string is, paste it into the identifier — it distinguishes them locally, in your browser, without the hash ever leaving your machine.

Related articles

WordPress just changed how it hashes passwords. Identify legacy $P$ phpass and the new $wp$2y$ bcrypt format, and crack each with the right hashcat mode.
Identify Cisco IOS type 5, 7, 8 and 9 passwords, decode type 7 instantly, and crack type 5/8/9 with the right hashcat mode and John the Ripper format.
Extract a crackable hash from a LUKS header or a BitLocker volume, pick the right hashcat mode for LUKS1 vs LUKS2 and user-password vs recovery-password BitLocker, and run the attack.