标签:CTF | isset() | sha1() | 代码审计 | 改后缀
提示:这里涉及一个很好用的特殊传参方式
传送门:http://59.63.200.79:1880/Web-Security/CTF/3/web14/index.php
Your password can not be your name./你的密码不能是你的名字。
查看网页源代码(Ctrl+U),发现隐藏内容:<!--index.phps-->
访问的inde.phps然后就能下载inde.phps源代码文件了,
phps文件就是php的源代码文件,通常用于提供给用户(访问者)查看php代码。
因为用户无法直接通过Web浏览器看到php文件的内容,所以需要用phps文件代替。其实,只要不用php等已经在服务器中注册过的MIME类型为文件即可,但为了国际通用,所以才用了phps文件类型。
<?php
error_reporting(0);
$flag = '********';
if (isset($_GET['name']) and isset($_GET['password'])){
if ($_GET['name'] == $_GET['password'])
print 'name and password must be diffirent';
else if (sha1($_GET['name']) === sha1($_GET['password']))
die($flag);
else print 'invalid password';
}
?>
代码解释
error_reporting — 设置应该报告何种 PHP 错误
error_reporting(0); // 关闭所有PHP错误报告
if (isset($_GET['name']) and isset($_GET['password'])){}
如果 传参的值存在并且值不是 NULL 则返回 TRUE,否则返回 FALSE。
如果一次传入多个参数,那么 isset() 只有在全部参数都以被设置时返回 TRUE 计算过程从左至右,中途遇到没有设置的变量时就会立即停止。
也就是说GET传参的参数name和password必须存在且值不能为NULL,只要满足条件就能执行if里边的语句了。
if ($_GET['name'] == $_GET['password'])
print 'name and password must be diffirent';
这句话的意思是如果传参的name和password的值相等就输出 name and password must be diffirent。
else if (sha1($_GET['name']) === sha1($_GET['password'])) die($flag);
意思是GET传参的参数name和password经过sha1()函数处理之后,进行完全匹配。
md5 和 sha1 无法处理数组,所以false===false返回true。
如果把这两个字段构造为数组,如:?name[]=a&password[]=b ,这样在第一处判断时两数组确实是不同的,但在第二处判断时由于sha1()函数无法处理数组类型,将报错并返回false,然后false===false,if 条件成立,获得flag。
经验证md5()函数同样存在此漏洞,只要两个传参都是数组就能绕过。
Payload:?name[]=1&password[]=2
Flag:flag{think_I_just_brok1_sha1}
打赏我,让我更有动力~
© 2016 - 2023 掌控者 All Rights Reserved.
chongxiao01
发表于 2021-6-25
新知识点,SHA1无法处理数组,那么问题来了,SHA256能处理吗,查资料去
评论列表
加载数据中...
zinc
发表于 2021-8-18
这里也可以用sha1强碰撞
评论列表
加载数据中...