萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網路程式設計 >> ASP 程式設計

解決防毒軟體誤判刪除 ASP 檔案:關鍵字拆分與編碼混淆技巧

問題成因

防毒軟體掃描 ASP 原始碼時,若發現特定「敏感關鍵字」 (如 adodb.stream, CreateObject, Execute, Shell, WScript.Shell 等),常誤判為 Webshell / 木馬而隔離或刪除檔案。

核心對策:字串拆分與動態組合

將敏感字串拆解為多段,執行時用 & 串接,繞過靜態特徵碼掃描。

案例 1:ADODB.Stream 物件建立

' 原始 (易被掃描)
Set stm = Server.CreateObject("adodb.stream")

' 拆分混淆
Set stm = Server.CreateObject("ado" & "db.stre" & "am")
' 或更進一步
Set stm = Server.CreateObject("ad" & "od" & "b." & "str" & "eam")

案例 2:物件方法呼叫 (如 CopyTo)

' 原始
stm1.CopyTo stm2, 200

' 使用 Execute 執行動態字串
Execute("stm1.Cop" & "yTo stm2, 200")

案例 3:完整建立與呼叫鏈混淆

' 原始
Dim stm
Set stm = Server.CreateObject("adodb.stream")

' 全混淆版
Dim stm
Execute("Set stm = Ser" & "ver.Crea" & "teObject(""ad" & "od" & "b.stre" & "am"")")

進階技巧:編碼/加密載入

Base64 編碼儲存核心邏輯

<%
' 核心邏輯另存為 encoded_logic.txt (Base64 編碼)
' 執行時解碼並 Execute
Dim encoded, decoder, decoded
encoded = "RGltIHN0bQ0KU2V0IHN0bSA9IFNlcnZlci5DcmVhdGVPYmplY3QoImFkb2Iuc3RyZWFtIikNCg==" ' 範例

Set decoder = CreateObject("Microsoft.XMLDOM")
Set decoder = decoder.CreateElement("tmp")
decoder.DataType = "bin.base64"
decoder.Text = encoded
decoded = decoder.NodeTypedValue ' 取得二進位
' 需轉為字串再 Execute,略...

' 更簡單:使用自訂解碼函式
Function Base64Decode(b64)
    Dim xml, node
    Set xml = CreateObject("Microsoft.XMLDOM")
    Set node = xml.CreateElement("tmp")
    node.DataType = "bin.base64"
    node.Text = b64
    Base64Decode = BytesToString(node.NodeTypedValue)
End Function

Function BytesToString(bytes)
    Dim stm
    Set stm = CreateObject("ADODB.Stream")
    stm.Type = 1: stm.Open
    stm.Write bytes
    stm.Position = 0
    stm.Type = 2: stm.Charset = "utf-8"
    BytesToString = stm.ReadText
    stm.Close
End Function

Execute(Base64Decode(encoded))
%>

微軟官方工具:Script Encoder (screnc.exe)

  • 將 .asp 編碼為 .asa / .vbe / .jse,原始碼加密。
  • 指令:screnc.exe input.asp output.asp
  • IIS 5.0+ 內建支援執行編碼後腳本。
  • 缺點:非加密,只是編碼,工具即可解碼;且除錯極度困難 (行號錯亂)。

防禦深度:結合多層策略

  1. 白名單排除:在防毒軟體設定「排除掃描」目錄 (網站根目錄),風險自負。
  2. 程式碼簽名:對生產環境 ASP 檔案簽名,建立信任基準。
  3. 檔案完整性監控 (FIM):Tripwire / OSSEC / Windows 稽核原則,偵測未授權修改。
  4. WAF / IIS Request Filtering:攔截惡意請求,降低被植入 Webshell 風險。
  5. 定期離線掃描:離線掃描備份檔案,不影響線上服務。

現代視角:棄用 Classic ASP

Classic ASP (VBScript) 已停止主流支援,強烈建議遷移至 ASP.NET Core / Node.js / Python 等現代框架:

  • 原生編譯/解譯,無原始碼暴露風險。
  • 成熟的依賴管理、型別系統、測試框架。
  • 主動安全更新與社群支援。

總結

字串拆分 "ad" & "odb.stream"、Execute 動態執行、Base64 編碼載入、Script Encoder 加密,可有效繞過防毒靜態掃描。但這只是「治標」,根本之道在於架構現代化、最小權限部署、多層防禦體系。

copyright © 萬盛學電腦網 all rights reserved