Git Product home page Git Product logo

hashes's Introduction

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."

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

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

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.

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.

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.

Real collisions

If you need a real alphanumerical collision, here's a 72-byte alphanum MD5 collision with 1-byte difference, 1-bit even, by Marc Stevens:

md5("TEXTCOLLBYfGiJUETHQ4hAcKSMd5zYpgqf1YRDhkmxHkhPWptrkoyz28wnI9V0aHeAuaKnak")
=
md5("TEXTCOLLBYfGiJUETHQ4hEcKSMd5zYpgqf1YRDhkmxHkhPWptrkoyz28wnI9V0aHeAuaKnak")

Note that if you register with the first password, and log in with the second, it may still mean that the site uses bcrypt(md5($password)), not just md5($password). Such hash wrapping is sometimes used when upgrading password hashing but it should be used only temporarily.

See Marc's Project HashClash if you're interested in these real collisions or if you'd like to create your own.

hashes's People

Contributors

0xb0bb avatar chick3nman avatar ethernetlord avatar hops avatar matlink avatar maxim-masiutin-isa-utm-md avatar maximmasiutin avatar morsisko avatar myst404 avatar roycewilliams avatar spaze avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hashes's Issues

Hashes with numbers and digits only

Hi everyone who read this,

While doing a security CTF challenge, I found some other strange hashes on a Stackoverflow discussion

  • Only Numbers

    • ximaz : 61529519452809720693702583126814
    • aalbke : 55203129974456751211900188750366
    • afnnsd : 49716523209578759475317816476053
    • aooalg : 68619150135523129199070648991237
    • bzbkme : 69805916917525281143075153085385
    • Ioktak : 54948232518148653519995784773259
    • '99x`b0x'b : 24034969117462298298932307218853
    • uttuJ## : 74616072929762262275291990931711
  • Only letters

    • cbaabcdljdac : cadbfdfecdcdcdacdbbbfadbcccefabd

Maybe it could be useful to someone..maybe not!

Originally posted by @r3g31rk in #20 (comment)

the `==` trick only works with php 5.4.3 and earlier

The == trick is used only for MD5, SHA-1, and plaintext

It should be noted that the == trick doesn't work with php 5.4.4+ since as of php 5.4.4 "Integral strings that overflow into floating point numbers will no longer be considered equal"

Since that overflow issue is what the == trick is actually using, it's important to note the version dependency.

Although I do understand there are some exceptions with md5 that still work with the == trick even in php 7.1 https://3v4l.org/krCff

corrections to the plaintext items this list shows various PHP versions that may or may not allow the == trick to work https://3v4l.org/sHmuG

pbkdf hashes

I was trying to add these hashes to seclists when I ran into a issue verifying the pbkdf hashes. The problem is that I can’t seem to get a magic hashes out of any entries for pbkdf2-* files. If anyone knows how to correctly hash the entries using cyberchef or php please leave the code here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.