知识点
ASCII码规则
在代码中 \ddd 任意字符 三位八进制 \160表示p 在代码中 \xhh 任意字符 二位十六进制 \x70表示p
<?php
preg_match("/\\|\056\160\150\x70/i",$string)
//1.执行ASC码转为可打印字符 \056\160\150\x70 => .php
//2.执行php语法转义 \\ => \,剩下 \|.php
//3.执行正则语法转义 \| => |,剩下 |.php
?>
题目
页面显示一段源码
<?php
error_reporting(0);
$zero=$_REQUEST['zero'];
$first=$_REQUEST['first'];
$second=$zero.$first;
if(preg_match_all("/Yeedo|wants|a|girl|friend|or|a|flag/i",$second)){
$key=$second;
if(preg_match("/\.\.|flag/",$key)){
die("Noooood hacker!");
}else{
$third=$first;
if(preg_match("/\\|\056\160\150\x70/i",$third)){
$end=substr($third,5);
highlight_file(base64_decode($zero).$end);//maybe flag in flag.php
}
}
}
else{
highlight_file(__FILE__);
}
关键匹配
preg_match("/\\|\056\160\150\x70/i",$third)表示匹配 |.php.
1.执行ASC码转为可打印字符 \056\160\150\x70 => .php
2.执行php语法转义 \\ => \,剩下 \|.php
3.执行正则语法转义 \| => |,剩下 |.php
关键点
根据提示maybe flag in flag.php
highlight_file(base64_decode($zero).$end)
应该是
highlight_file(flag.php)
$zero=base64_encode("flag") = ZmxhZw==
以此往上推理
判断first=xxxx|.php,其中xxxx可以是任意匹配Yeedo|wants|a|girl|friend|or|a的字符串