Can LLMs Handle WebShell Detection? Overcoming Detection Challenges with Behavioral Function-Aware Framework
作者: Feijiang Han, Jiaming Zhang, Chuyi Deng, Jianheng Tang, Yunhuai Liu
分类: cs.CR, cs.LG
发布日期: 2025-04-14 (更新: 2025-10-13)
备注: Published as a conference paper at COLM 2025
💡 一句话要点
提出BFAD框架,提升LLM在WebShell检测中的性能,超越传统方法。
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: WebShell检测 大型语言模型 行为分析 恶意代码 网络安全
📋 核心要点
- 传统WebShell检测方法依赖大量数据,存在泛化性差和灾难性遗忘问题,难以有效应对新型攻击。
- BFAD框架通过关键函数过滤、上下文感知代码提取和加权行为函数分析,提升LLM在WebShell检测中的性能。
- 实验表明,BFAD框架显著提升了LLM的F1得分,使大型模型超越SOTA,小型模型达到传统方法水平。
📝 摘要(中文)
WebShell攻击是一种严重的网络安全威胁,它通过将恶意脚本注入Web服务器来实现。传统的机器学习和深度学习方法常常受限于大量训练数据的需求、灾难性遗忘和泛化能力差等问题。近年来,大型语言模型(LLM)在代码相关任务中表现出强大的潜力,但其在WebShell检测中的应用尚未得到充分探索。本文贡献在于:(1) 对包括GPT-4、LLaMA 3.1 70B和Qwen 2.5系列在内的七个LLM进行了全面评估,并使用包含26.59K个PHP脚本的数据集,将其与传统的序列和图方法进行了基准测试;(2) 提出了行为功能感知检测(BFAD)框架,旨在解决将LLM应用于该领域的特定挑战。该框架集成了三个组件:关键函数过滤器,用于隔离恶意PHP函数调用;上下文感知代码提取策略,用于捕获最具行为指示性的代码段;加权行为函数分析,通过优先考虑基于判别函数级别配置文件的最相关演示来增强上下文学习。结果表明,由于其独特的分析策略,较大的LLM实现了接近完美的精度,但召回率较低,而较小的模型则表现出相反的权衡。然而,所有基线模型的性能都落后于先前的SOTA方法。通过应用BFAD,所有LLM的性能都得到了显著提高,平均F1得分提高了13.82%。值得注意的是,较大的模型现在优于SOTA基准,而较小的模型(如Qwen-2.5-Coder-3B)实现了与传统方法相当的性能。这项工作首次探索了LLM在WebShell检测中的可行性和局限性,并提供了解决该任务中挑战的方案。
🔬 方法详解
问题定义:WebShell检测旨在识别注入到Web服务器中的恶意脚本。现有方法,如传统的机器学习和深度学习模型,需要大量的训练数据,并且容易出现灾难性遗忘,导致泛化能力较差,难以有效检测新型或变种WebShell攻击。
核心思路:论文的核心思路是利用大型语言模型(LLM)强大的代码理解和生成能力,结合行为分析,克服传统方法的局限性。通过提取WebShell脚本中的关键行为特征,并利用LLM进行恶意代码的识别和分类,从而提高检测的准确性和泛化性。
技术框架:BFAD框架包含三个主要模块:1) 关键函数过滤器:用于识别并提取PHP脚本中可能具有恶意行为的关键函数调用,减少LLM需要处理的代码量,提高效率。2) 上下文感知代码提取:根据关键函数调用,提取相关的代码片段,形成包含上下文信息的代码块,为LLM提供更全面的行为特征。3) 加权行为函数分析:通过分析不同函数在恶意脚本中的重要性,为LLM提供加权的函数特征,引导LLM关注最具判别性的行为模式。
关键创新:BFAD框架的关键创新在于将LLM与行为分析相结合,提出了一个行为功能感知的检测方法。与直接使用LLM进行代码分类不同,BFAD框架通过预处理和特征提取,突出了WebShell脚本中的关键行为特征,从而提高了LLM的检测性能和效率。此外,加权行为函数分析能够让LLM更好地学习恶意代码的行为模式,提高泛化能力。
关键设计:关键函数过滤器依赖于预定义的恶意函数列表,需要定期更新以应对新的攻击手段。上下文感知代码提取策略需要平衡提取的代码量和上下文信息的完整性,避免引入过多噪声。加权行为函数分析中的权重可以通过统计分析或专家知识来确定,需要根据实际情况进行调整。框架使用F1 score作为评估指标,以平衡precision和recall。
🖼️ 关键图片
📊 实验亮点
实验结果表明,BFAD框架能够显著提升LLM在WebShell检测中的性能。应用BFAD后,所有LLM的平均F1得分提高了13.82%。更大的模型(如GPT-4)在应用BFAD后,性能超越了SOTA基准。即使是较小的模型(如Qwen-2.5-Coder-3B),在BFAD的加持下,也能达到与传统方法相当的性能。
🎯 应用场景
该研究成果可应用于Web服务器安全防护、入侵检测系统、恶意代码分析等领域。通过提升WebShell检测的准确性和效率,可以有效降低Web服务器被攻击的风险,保护用户数据安全,维护网络安全环境。未来可扩展到其他类型的恶意代码检测。
📄 摘要(原文)
WebShell attacks, where malicious scripts are injected into web servers, pose a significant cybersecurity threat. Traditional ML and DL methods are often hampered by challenges such as the need for extensive training data, catastrophic forgetting, and poor generalization. Recently, Large Language Models have emerged as powerful alternatives for code-related tasks, but their potential in WebShell detection remains underexplored. In this paper, we make two contributions: (1) a comprehensive evaluation of seven LLMs, including GPT-4, LLaMA 3.1 70B, and Qwen 2.5 variants, benchmarked against traditional sequence- and graph-based methods using a dataset of 26.59K PHP scripts, and (2) the Behavioral Function-Aware Detection (BFAD) framework, designed to address the specific challenges of applying LLMs to this domain. Our framework integrates three components: a Critical Function Filter that isolates malicious PHP function calls, a Context-Aware Code Extraction strategy that captures the most behaviorally indicative code segments, and Weighted Behavioral Function Profiling that enhances in-context learning by prioritizing the most relevant demonstrations based on discriminative function-level profiles. Our results show that, stemming from their distinct analytical strategies, larger LLMs achieve near-perfect precision but lower recall, while smaller models exhibit the opposite trade-off. However, all baseline models lag behind previous SOTA methods. With the application of BFAD, the performance of all LLMs improves significantly, yielding an average F1 score increase of 13.82%. Notably, larger models now outperform SOTA benchmarks, while smaller models such as Qwen-2.5-Coder-3B achieve performance competitive with traditional methods. This work is the first to explore the feasibility and limitations of LLMs for WebShell detection and provides solutions to address the challenges in this task.