基於詞法分析與集成學習之跨語言 Webshell 偵測框架
Cross-Language Webshell Detection Framework Based on Lexical Analysis and Ensemble Learning
摘要
Webshell為攻擊者常用來建立網頁伺服器後門的惡意腳本,伴隨著原始碼混淆技術的出現,基於傳統正規表示式或特徵碼比對的偵測方法已難以應對混淆後的Webshell。為此,現有研究多透過提取抽象語法樹(Abstract Syntax Tree, AST)或操作碼(Opcode)作為特徵,並結合機器學習技術來解決此類問題。然而,這些方法易受攻擊者植入畸形原始碼導致解析失敗,亦多侷限於單一程式語言偵測,難以應對現今不同程式語言之網頁環境。為突破上述瓶頸,本研究提出一種基於詞法分析(Lexical Analysis)的Webshell偵測框架,能以輕量化分析方式,將不同程式語言之原始碼轉換為Token序列,並提取邏輯結構特徵。在實現跨語言偵測的同時,能有效降低混淆、畸形原始碼的干擾。為最大化偵測表現,本研究採用堆疊集成學習(Stacking Ensemble Learning)作為模型訓練的主要框架。實驗結果顯示,透過詞法分析及堆疊集成學習能有效辨別出Webshell與良性原始碼,並達到99.75%的準確率(Accuracy)、98.96%的精確率(Precision)與98.57%的召回率(Recall)。此結果突顯框架能在兼顧輕量化分析、支援跨語言,以及抗混淆與畸形原始碼之前提下,展現卓越的偵測能力。
Webshells are malicious scripts commonly used to establish backdoors on web servers. With the emergence of source code obfuscation, traditional detection methods based on regular expressions or signature matching struggle to remain effective. To address this, existing studies predominantly combine machine learning with extracted features like Abstract Syntax Tree (AST) or Opcodes. However, these methods are highly susceptible to parsing failures caused by injected malformed code, and are often limited to single-language detection, failing to address today's diverse web environments. To overcome these bottlenecks, this study proposes a lexical analysis-based Webshell detection framework. This lightweight approach uniformly converts multi-language source code into Token sequences to extract logical structure features, achieving cross-language detection while effectively mitigating interference from obfuscated and malformed code. To maximize performance, Stacking Ensemble Learning is adopted as the primary model training framework. Experimental results demonstrate that the proposed approach effectively distinguishes Webshells from benign source code, achieving 99.75% accuracy, 98.96% precision, and 98.57% recall. This highlights the framework's exceptional detection capabilities while ensuring lightweight analysis, cross-language support, and robustness against obfuscation and malformed code.