`
kkllmey
  • 浏览: 101533 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论
阅读更多
一、简介
        xp_cmdshell 扩展存储过程将命令字符串作为操作系统命令 shell 执行,并以文本行的形式返回所有输出。

二、安全隐患
        由于xp_cmdshell 可以执行任何操作系统命令,所以一旦SQL Server管理员帐号(如sa)被攻破,那么攻击者就可以利用xp_cmdshell 在SQL Server中执行操作系统命令,如:创建系统管理员,也就意味着系统的最高权限已在别人的掌控之中。

三、SQL Server 2005中的xp_cmdshell
        由于存在安全隐患,所以在SQL Server 2005中, xp_cmdshell 默认是关闭的。
        此时,如果执行 xp_cmdshell 将会提示服务未开启:

        exec xp_cmdshell 'dir c:\'

消息 15281,级别 16,状态 1,过程 xp_cmdshell,第 1 行
SQL Server 阻止了对组件 'xp_cmdshell' 的 过程'sys.xp_cmdshell' 的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用 'xp_cmdshell'。有关启用 'xp_cmdshell' 的详细信息,请参阅 SQL Server 联机丛书中的 "外围应用配置器"。

四、开启xp_cmdshell
        打开外围应用配置器—>
        功能的外围应用配置器—>
        实例名\Database Engine\xp_cmdshell—>
        启用


五、使用xp_cmdshell
        显示C盘根目录下的所有目录和文件:

        exec xp_cmdshell 'dir c:\'

output
------------------------------------------------------------------------
驱动器 C 中的卷没有标签。
卷的序列号是 F8C5-1B8C
NULL
c:\ 的目录
NULL
2007-01-29  14:08                 0 AUTOEXEC.BAT
2007-01-29  14:08                 0 CONFIG.SYS
2007-01-29  14:20    <DIR>          dell
2007-01-29  14:13    <DIR>          Documents and Settings
2007-07-11  09:57    <DIR>          Inetpub
2007-07-11  14:31    <DIR>          Program Files
2007-06-07  07:35    <DIR>          TEMP
2007-07-05  15:08             1,506 testout.txt
2007-07-05  15:10             1,506 testout01.txt
2007-07-11  13:32    <DIR>          WINDOWS
2007-01-29  14:09    <DIR>          wmpub
2007-06-25  15:00    <DIR>          ~CUL2
               4 个文件          3,012 字节
               8 个目录    420,556,800 可用字节
NULL
(20 行受影响)

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics