知识点
1、在ASCII码表中
ASCII码规则
在代码中 /ddd 任意字符 三位八进制 /160表示p 在代码中 /xhh 任意字符 二位十六进制 /x70表示p

/056 为八进制 代表 句点或小数点
/160 为八进制 代表 小写字母 p
/150 为八进制 代表 小写字母 h
/x70 为十六进制 代表 小写字母 p
实况
1、打开靶机,发现直接就将源码展现出来了

2、对代码进行审计
1 <?php
2 error_reporting(0);
3 $zero=$_REQUEST['zero'];
4 $first=$_REQUEST['first']; //传两个变量,zero和first变量
5 $second=$zero.$first;
6 if(preg_match_all("/Yeedo|wants|a|girl|friend|or|a|flag/i",$second)){
7 $key=$second;
8 if(preg_match("//./.|flag/",$key)){
9 die("Noooood hacker!");
10 }else{
11 $third=$first;
12 if(preg_match("///|/056/160/150/x70/i",$third)){
13 $end=substr($third,5);
14 highlight_file(base64_decode($zero).$end);//maybe flag in flag.php
15 }
16 }
17 }
18 else{
19 highlight_file(__FILE__);
20 }
1)
1 <?php
2 preg_match("///|/056/160/150/x70/i",$string)
3 //1.执行ASC码转为可打印字符 /056/160/150/x70 => .php
4 //2.执行php语法转义 // => /,剩下 /|.php
5 //3.执行正则语法转义 /| => |,剩下 |.php
6 ?>
2)
1 $zero=$_REQUEST['zero'];
2 $first=$_REQUEST['first']; //传两个变量,zero和first变量
3 $second=$zero.$first;
4 if(preg_match_all("/Yeedo|wants|a|girl|friend|or|a|flag/i",$second)){
5 $key=$second;
echo $second 发现是把zero和first变量连起来
3)
1 if(preg_match("//./.|flag/",$key)){
2 die("Noooood hacker!");
3 }else{
4 $third=$first;
5 if(preg_match("///|/056/160/150/x70/i",$third)){
6 $end=substr($third,5);
7 highlight_file(base64_decode($zero).$end);//maybe flag in flag.php
8 }
9 }
10 }
11 else{
12 highlight_file(__FILE__);
在$second里必须匹配到/Yeedo|wants|a|girl|friend|or|a|flag/i这里面的字符,$key=$second,接着在$key里不能匹配到/..|flag/,然后$third=first,并且在$里要匹配有//|/056/160/150/x70/i,$end从third里第五位字符开始截取
3、解题思路
1)
seconde里要存在"/Yeedo|wants|a|girl|friend|or|a|flag/i",而second=zero.first,所以zero=flag
2)
key=second=zero.first,并且不能存在"//./.|flag/",也就是说zero不能=flag或=.
3)
highlight_file(base64_decode($zero).$end),会对$zero进行base64解密,所以我们直接将它进行base64加密$zero=ZmxhZw==
4)
之后third=first,并且要匹配”///|/056/160/150/x70/i”,这是16进制与进制的东西,转换成10进制,再转成ascii码后即为|.php,但$end=substr($third,5);,故需要在|.php前面加上4个字符,来绕过substr,不过这4个字符得都是”/Yeedo|wants|a|girl|friend|or|a|flag/i”,这里面的列出一些组合(aaaa oror Flag girl )只能使用aaaa或girl
4、构造传参
?zero=ZmxhZw==&&first=girl|.php 或 ?zero=ZmxhZw==&&first=aaaa|.php
得到flag

原创文章,作者:kepupublish,如若转载,请注明出处:https://blog.ytso.com/tech/php/272269.html