Leveraging Large Language Models to Detect npm Malicious Packages

📄 arXiv: 2403.12196v4 📥 PDF

作者: Nusrat Zahan, Philipp Burckhardt, Mikola Lysenko, Feross Aboukhadijeh, Laurie Williams

分类: cs.CR, cs.AI

发布日期: 2024-03-18 (更新: 2025-01-06)

备注: 13 pages, 2 Figure, 6 tables


💡 一句话要点

提出SocketAI以提高npm恶意包检测的准确性

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 恶意代码检测 大型语言模型 SocketAI 静态分析 网络安全 npm包 机器学习

📋 核心要点

  1. 现有的恶意代码检测方法依赖多种工具,导致误分类率高且效率低下。
  2. 本研究提出SocketAI工作流程,利用大型语言模型提升恶意代码检测的准确性与效率。
  3. 实验结果显示,GPT-4在精度和F1分数上分别达到99%和97%,显著优于传统静态分析方法。

📝 摘要(中文)

现有的恶意代码检测技术需要整合多种工具以识别不同的恶意软件模式,且常常面临高误分类率的问题。因此,采用更先进的自动化方法来提升检测准确性和降低误分类率显得尤为重要。本研究旨在通过实证研究大型语言模型(LLMs)在恶意代码检测中的有效性,帮助安全分析师识别恶意包。我们提出了SocketAI,一个用于检测恶意代码的审查工作流程,并利用包含5,115个npm包的基准数据集进行评估,其中2,180个包含有恶意代码。通过与最先进的CodeQL静态分析工具进行基线比较,结果显示GPT-4在精度和F1分数上分别比静态分析提高了16%和9%。

🔬 方法详解

问题定义:本论文旨在解决现有恶意代码检测技术整合多种工具导致的高误分类率和低效率问题。现有方法在检测不同恶意软件模式时,常常需要多次分析,增加了工作负担。

核心思路:论文提出SocketAI工作流程,利用大型语言模型(LLMs)来自动化恶意代码检测,从而提高检测的准确性和效率。通过将静态分析与LLMs结合,减少了需要分析的文件数量。

技术框架:整体架构包括数据集准备、静态分析预筛选、LLM分析和结果评估四个主要模块。首先,利用静态分析工具筛选出可疑文件,然后使用LLMs进行深入分析。

关键创新:最重要的创新在于将大型语言模型应用于恶意代码检测,显著提高了检测的精度和效率。与传统方法相比,SocketAI能够更快速地识别恶意代码,且误分类率更低。

关键设计:在实验中,使用了39个自定义的CodeQL规则进行静态分析,并对比了GPT-3和GPT-4的性能。参数设置上,GPT-4在精度和F1分数上表现优异,而GPT-3则在成本效益上更具优势。

🖼️ 关键图片

fig_0
fig_1

📊 实验亮点

实验结果显示,GPT-4在精度和F1分数上分别达到99%和97%,相比于静态分析工具提高了16%和9%。同时,静态分析作为预筛选工具,减少了77.9%的文件分析需求,显著降低了分析成本,GPT-3和GPT-4的成本分别降低了60.9%和76.1%。

🎯 应用场景

该研究的潜在应用领域包括软件包管理、网络安全和恶意软件检测等。通过提高恶意代码检测的准确性,SocketAI可以帮助安全分析师更有效地识别和应对潜在威胁,降低企业的安全风险。未来,该方法还可以扩展到其他编程语言和软件生态系统中,进一步提升安全性。

📄 摘要(原文)

Existing malicious code detection techniques demand the integration of multiple tools to detect different malware patterns, often suffering from high misclassification rates. Therefore, malicious code detection techniques could be enhanced by adopting advanced, more automated approaches to achieve high accuracy and a low misclassification rate. The goal of this study is to aid security analysts in detecting malicious packages by empirically studying the effectiveness of Large Language Models (LLMs) in detecting malicious code. We present SocketAI, a malicious code review workflow to detect malicious code. To evaluate the effectiveness of SocketAI, we leverage a benchmark dataset of 5,115 npm packages, of which 2,180 packages have malicious code. We conducted a baseline comparison of GPT-3 and GPT-4 models with the state-of-the-art CodeQL static analysis tool, using 39 custom CodeQL rules developed in prior research to detect malicious Javascript code. We also compare the effectiveness of static analysis as a pre-screener with SocketAI workflow, measuring the number of files that need to be analyzed. and the associated costs. Additionally, we performed a qualitative study to understand the types of malicious activities detected or missed by our workflow. Our baseline comparison demonstrates a 16% and 9% improvement over static analysis in precision and F1 scores, respectively. GPT-4 achieves higher accuracy with 99% precision and 97% F1 scores, while GPT-3 offers a more cost-effective balance at 91% precision and 94% F1 scores. Pre-screening files with a static analyzer reduces the number of files requiring LLM analysis by 77.9% and decreases costs by 60.9% for GPT-3 and 76.1% for GPT-4. Our qualitative analysis identified data theft, execution of arbitrary code, and suspicious domain categories as the top detected malicious packages.