用行为感知框架提升大模型检测网页后门的能力。
Can LLMs Handle WebShell Detection? Overcoming Detection Challenges with Behavioral Function-Aware Framework
- 基于关键函数过滤与上下文代码提取,构建针对网页后门的行为感知检测框架。
- 大模型在高精度下易漏检,小模型则相反,现有提示方法性能不如传统检测器。
- 新框架使大模型平均F1提升13.82%,部分模型超越现有最佳水平。
网页后门攻击——攻击者在网站服务器上植入恶意脚本——仍是持续威胁。以往机器学习与深度学习检测器依赖特定任务监督,在数据稀缺、概念漂移和分布外部署下表现脆弱。大语言模型(LLMs)虽展现强大代码理解能力,但其在网页后门检测中的可靠性尚不明确。本文系统评估了七种LLMs(包括GPT-4、LLaMA-3.1-70B、Qwen-2.5系列)在26,590个PHP脚本上的表现,并提出行为功能感知检测(BFAD)框架,通过关键函数过滤锚定分析,结合上下文代码提取生成紧凑输入,利用加权行为函数分析选择上下文示例,按函数级相似性加权排序。实证发现:大模型通常精度高但召回率低,小模型则相反;通用提示策略表现不及已有检测器。BFAD显著提升所有评估的LLMs,平均F1提升13.82%;其中GPT-4、LLaMA-3.1-70B和Qwen-2.5-Coder-14B超越当前最优基准,而Qwen-2.5-Coder-3B达到传统方法竞争力。结果揭示了LLM在网页后门检测中的适用边界,提供可落地方案,并指明未来改进方向。
原文摘要 · Abstract (English)
WebShell attacks - where adversaries implant malicious scripts on web servers - remain a persistent threat. Prior machine-learning and deep-learning detectors typically depend on task-specific supervision and can be brittle under data scarcity, rapid concept drift, and out-of-distribution (OOD) deployment. Large language models (LLMs) have recently shown strong code understanding capabilities, but their reliability for WebShell detection remains unclear. We address this gap by (i) systematically evaluating seven LLMs (including GPT-4, LLaMA-3.1-70B, and Qwen-2.5 variants) against representative sequence- and graph-based baselines on 26.59K PHP scripts, and (ii) proposing Behavioral Function-Aware Detection (BFAD), a behavior-centric framework that adapts LLM inference to WebShell-specific execution patterns. BFAD anchors analysis on security-sensitive PHP functions via a Critical Function Filter, constructs compact LLM inputs with Context-Aware Code Extraction, and selects in-context demonstrations using Weighted Behavioral Function Profiling, which ranks examples by a behavior-weighted, function-level similarity. Empirically, we observe a consistent precision-recall asymmetry: larger LLMs often achieve high precision but miss attacks (lower recall), while smaller models exhibit the opposite tendency; moreover, off-the-shelf LLM prompting underperforms established detectors. BFAD substantially improves all evaluated LLMs, boosting F1 by 13.82% on average; notably, GPT-4, LLaMA-3.1-70B, and Qwen-2.5-Coder-14B exceed prior SOTA benchmarks, while Qwen-2.5-Coder-3B becomes competitive with traditional methods. Overall, our results clarify when LLMs succeed or fail on WebShell detection, provide a practical recipe, and highlight future directions for making LLM-based detection more reliable.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。