• Stars
    star
    614
  • Rank 72,781 (Top 2 %)
  • Language
  • Created over 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Magic hashes – PHP hash "collisions"

Magic hashes – PHP hash "collisions"

Register with password 1 and then sign in with password 2. If you're in then the storage uses specified algorithm to hash the password and PHP uses == to compare them (for MD5, SHA-1, and plaintext).

MD5, SHA-1, SHA-224, SHA-256 and others

For MD5, SHA-1 and SHA-2 family, it uses the long-known trick (it actually is a documented feature, see PHP type comparison tables & Floating point numbers) that for PHP '0e1' == '00e2' == '0', it just uses it for practical purposes. Any password matches any other password from the list. This is a different trick than integral strings overflowing into floating point numbers, just spot the difference between these two lines.

These are all the algorithms with magic hashes:

To quote @0xb0bb, "there are other applications for magic hashes other than password comparisons (such as caching layers or data derived from the output of a hash function) where these known insecure, lesser known and pseudo-hash algorithms can be found more readily."

Plaintext

For plaintext, it uses various conversion tricks. First password will match just the second one. Tricks are grouped by PHP versions allowing them.

bcrypt

bcrypt truncates passwords to a maximum length of 72 characters. The passwords match if the first 72 characters of both passwords match.

descrypt

descrypt (traditional UNIX DES crypt) truncates passwords to a maximum length of 8 characters. The passwords also match if the first 8 characters of both passwords match, see the "General cross-check" section.

PBKDF2-HMAC-SHA1, PBKDF2-HMAC-SHA224, PBKDF2-HMAC-SHA256

If you use a password longer than 64 bytes and hash it with PBKDF2-HMAC-SHA1, it is first pre-hashed with SHA1, so PBKDF2-HMAC-SHA1(password1) === PBKDF2-HMAC-SHA1(password2) because sha1(password1) === bin2hex(password2). The similar pre-hashing is applied in case of PBKDF2-HMAC-SHA224 and PBKDF2-HMAC-SHA256.

Tiger/192,3

Right now there's just one magic hash in each thanks to Norbert Tihanyi, more will be hopefully added in the future.

Conclusion

Use === when comparing anything* in PHP, not ==. And use password_hash() and password_verify() for password hashing in PHP, don't use MD5 or SHA-1. *Use hash_equals() when comparing hashes.

History

It all started with this tweet, I've generated QNKCDZO and 240610708 in February 2014 and it has since spread all over the intertubes. Just google it.

How to calculate your own

I've used my laptop, few for (or foreach?) loops, many CPU cycles and an external fan back in 2014 but today you can/should use a GPU and a modified hashcat for that. See this write-up by Carl Löndahl and 0xb0bb.

Chick3nman & co. is also working on their version of hashcat, stay tuned.

More Repositories

1

oprah-proxy

Generate credentials for Opera's "browser VPN"
Python
255
star
2

phpstan-disallowed-calls

PHPStan rules to detect disallowed method & function calls, constant, namespace, attribute & superglobal usages
PHP
146
star
3

domains

Unofficial and incomplete lists of various domain names
69
star
4

jakobejitblokaci.cz

www.jakobejitblokaci.cz
HTML
42
star
5

letsgetacert

Let's get cert – a Certbot wrapper
Shell
23
star
6

encrypt-hash-password-php

Example of an encrypted password hash storage in PHP
PHP
21
star
7

upc_keys-lambda

Peter "blasty" Geissler's upc_keys.c with custom prefix support and Lambda sauce
C
15
star
8

webtop100

Dokumenty k hodnocení soutěže WebTop100
15
star
9

csp-config

Build Content Security Policy from a config file
PHP
11
star
10

exploited.cz

https://exploited.cz
HTML
8
star
11

michalspacek.cz

michalspacek.cz + michalspacek.com + subdomains source code because why not
PHP
8
star
12

nonce-generator

Content Security Policy Nonce Generator
PHP
6
star
13

ebabis.cz

A v březnu někdo přišel s tím matematickým modelem A v srpnu někdo, sice byl to ten stejný člověk, ale už přišel v nějakém čase A ty, který měli přijít, nepřišli
HTML
6
star
14

canhas.report

Reporting API demos, learn all about CSP & other reports (Network Error Logging/NEL, Crash, Deprecation, Intervention, Mixed Content & more) in this interactive app.
PHP
6
star
15

phpstan-stripe

Stripe SDK extension for PHPStan
PHP
5
star
16

emulated-prepared-statements

SQL Injection using Emulated Prepared Statements (the default) in PHP PDO_MYSQL in GBK
PHP
5
star
17

cotel

Company Intel, data and proof-of-concept quick-and-dirty code for an bookmarking app. Abandoned.
CSS
5
star
18

phpinfo

Extract phpinfo() into a variable and move CSS to external file
CSS
4
star
19

sri-macros

Subresource Integrity macros for Latte template engine
PHP
4
star
20

bez-komentare

Filtry odstraňující komentáře, jejich počet, notifikace z českých stránek
3
star
21

fa-extract

A tool to extract only used icons from Font Awesome JS/SVG icons sets (PRE-ALPHA, I use it but YMMV)
PHP
3
star
22

feed-exports

Atom feed Response and related objects for Nette framework
PHP
3
star
23

svg-icons-latte

SVG Icons Custom Tag for Latte Templating System
PHP
2
star
24

coding-standard

PHP Code Sniffer rules
PHP
2
star
25

security-txt

PHP
2
star
26

stupid-git-deploy

Shell
2
star
27

nepovolenainternetovahazardnihra.cz

nepovolenainternetovahazardnihra.cz + jakobejitblokaci.cz = BFF ❤
HTML
2
star
28

libini-djgpp

LibINI is a C library for DJGPP and Linux for reading, updating and writing Windows-like INI files. I wrote this back in 1999.
C
2
star
29

reveal-input-details

Chrome JS snippet to reveal hidden inputs and input details
JavaScript
1
star
30

webleed

We Bleed scanner tools
Python
1
star
31

svnwcdump

Dumps Subversion working copy located at a website and accessible using HTTP
Python
1
star
32

phpstan-disallowed-calls-nette

1
star
33

common-config

Configuration wants to be shared
1
star