No one knows regex better than me
翻译一下是正则
点进环境发现如下代码
<?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__);
}
一行行分析
$zero=$_REQUEST['zero'];
$first=$_REQUEST['first'];
获取zero和first的值
-----------------------------------------
$second=$zero.$first;
合并zero和first的值?
-----------------------------------------
if(preg_match_all("/Yeedo|wants|a|girl|friend|or|a|flag/i",$second)){
$key=$second;
正则匹配成功后将second的值赋给key
-----------------------------------------
if(preg_match("/\.\.|flag/",$key)){
die("Noooood hacker!");
key值中如果有..或者flag返回nod hacker,所以second不能出现这些字符
-----------------------------------------
}else{
$third=$first;
如果没出现如下字符则将first的值赋给third
-----------------------------------------
if(preg_match("/\\|\056\160\150\x70/i",$third)){
$end=substr($third,5);
highlight_file(base64_decode($zero).$end);//maybe flag in flag.php
如果在third中匹配到了这些字符 则将third前五个字符去掉后赋值给end
然后高亮zero的base64解码+end的拼接字符
最后还给了个提示 获取flag在flag.php里
/\\|\056\160\150\x70/i
这个是混合的 第一个第四个为16进制 第二第三个为8进制(前面还有个|),所以匹配为|.php
找了半天对照这篇文章就知晓了
https://blog.csdn.net/yelangjueqi/article/details/52210290
-----------------------------------------substr用法
substr(a,b)
echo substr("Hello world",6);//从字符串中返回 "world":
echo substr('abcdef', 1); // bcdef
很容易可以看出最后就是拼接flag.php
那么zero可以赋值为flag的base64编码形式,就是ZmxhZw==
但是first要通过第一第三个if不能匹配第二个if 所以里面要有|.php,而且前面五个字符会被消除 所以前面可以加上a或者girl或者or来通过第一个if
所以first可以构造为
111a|.php
girl|.php
11or|.php
所以最终构造为
zero=ZmxhZw==&first=girl|.php