• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

减少xp_sendmail安全漏洞_sqlserver

sqlserver 搞代码 7年前 (2018-06-17) 112次浏览 已收录 0个评论

的用户有权限通过SQL Mail使用SQL Server的文件吗?SQL Mail和 SQL代理帐号一样运行在相同安全条件下。默认情况下,SQL代理运行在本地系统帐号下。如果用户能存取SQL Server数据库里的系统扩展存储过程xp_sendmail,那么就会有安全漏洞了。

 
通过给系统扩展存储过程xp_sendmail附加参数,用户就可以获得存取服务器上的文件的权限。通过一个方法你就可以保护xp_sendmail:把它封装倒一个存储过程中去,使附加参数非public。许可受这个存储过程的保护,把许可从xp_sendmail中取消。

下面基本的工作模板,你用它就可以保护xp_sendmail:

use master
go
— =============================================
— Create procedure basic template
— =============================================

http://www.gaodaima.com/?p=36363减少xp_sendmail安全漏洞_sqlserver

— creating the store procedure
IF EXISTS (SELECT name
         FROM     sysobjects
         WHERE    name = N’sp_sendmail’
         AND      type = ‘P’)
    DROP PROCEDURE sp_sendmail
GO

CREATE PROCEDURE sp_sendmail
     @in_recipients VARCHAR(8000) = ‘<default email address>’
    ,@in_message VARCHAR(8000)= ‘test’
    ,@in_query VARCHAR(8000)= ”
    ,@in_copy_recipients VARCHAR(8000)= NULL
    ,@in_blind_copy_recipients VARCHAR(8000)= NULL
    ,@in_subject VARCHAR(80)= ‘test’
    ,@in_type VARCHAR(80)= NULL
    ,@in_attach_results VARCHAR(80)= NULL
    ,@in_no_output VARCHAR(8)= NULL
    ,@in_no_header VARCHAR(8)= NULL
    ,@in_width INT = 10
    ,@in_separator VARCHAR(8)= NULL
    ,@in_echo_error VARCHAR(8000)= NULL
    ,@in_set_user VARCHAR(256) = NULL
    ,@in_dbuse VARCHAR(256) = NULL
AS

DECLARE @attachments VARCHAR(8000)

SET @in_recipients = ‘<default dba email address>;’ + @in_recipients
exec master..xp_sendmail
     @recipients = @in_recipients
    ,@message = @in_message
    ,@query = @in_query
    ,@attachments =  ‘ ‘
    ,@copy_recipients = @in_copy_recipients
    ,@blind_copy_recipients = @in_blind_copy_recipients
    ,@subject = @in_subject
    ,@type = @in_type
    ,@attach_results = @in_attach_results
    ,@no_output = @in_no_output
    ,@no_header = @in_no_header
    ,@width = @in_width
    ,@separator = @in_separator
    ,@echo_error = @in_echo_error
    ,@set_user = @in_set_user
    ,@dbuse = @in_dbuse
GO

— example to execute the store procedure

EXECUTE sp_sendmail
GO

— example to grant permissions to the store procedure

GRANT EXECUTE ON sp_sendmail TO public
GO
REVOKE EXECUTE ON xp_sendmail TO public
GO

欢迎大家阅读《减少xp_sendmail安全漏洞_sqlserver,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:减少xp_sendmail安全漏洞_sqlserver

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址