通过代码内聚性分析,自动识别开源项目中的恶意代码注入。
Leveraging Code Cohesion Analysis to Identify Source Code Supply Chain Attacks
- 用命名预测法衡量函数内聚性变化,发现注入代码会破坏原有结构。
- 在369个C++项目中,注入代码导致命名更短、描述性更差,内聚性下降。
- 即使攻击极少发生,仍能以高精度定位可疑函数,适合安全审计使用。
供应链攻击严重威胁软件安全,恶意代码常混入合法项目中,虽罕见但影响巨大。现有自动化检测方法难以判断插入代码的意图及其上下文。本文提出一种无监督方法,通过量化源码内聚性变化来识别异常代码注入。基于命名预测的内聚性(NPC)度量显示,注入代码会导致函数内聚性降低,并使命名趋向简短、缺乏描述性。对54,707个函数在369个开源C++仓库中的分析表明,该现象显著存在。面对极端不平衡的数据集(1:1,000和1:10,000),监测高内聚函数的NPC值可有效发现注入代码,分别实现Precision@100为36.41%和12.47%。结果表明,尤其是基于命名预测的内聚性分析,有助于提升源码完整性与供应链安全。
原文摘要 · Abstract (English)
Supply chain attacks significantly threaten software security with malicious code injections within legitimate projects. Such attacks are very rare but may have a devastating impact. Detecting spurious code injections using automated tools is further complicated as it often requires deciphering the intention of both the inserted code and its context. In this study, we propose an unsupervised approach for highlighting spurious code injections by quantifying cohesion disruptions in the source code. Using a name-prediction-based cohesion (NPC) metric, we analyze how function cohesion changes when malicious code is introduced compared to natural cohesion fluctuations. An analysis of 54,707 functions over 369 open-source C++ repositories reveals that code injection reduces cohesion and shifts naming patterns toward shorter, less descriptive names compared to genuine function updates. Considering the sporadic nature of real supply-chain attacks, we evaluate the proposed method with extreme test-set imbalance and show that monitoring high-cohesion functions with NPC can effectively detect functions with injected code, achieving a Precision@100 of 36.41% at a 1:1,000 ratio and 12.47% at 1:10,000. These results suggest that automated cohesion measurements, in general, and name-prediction-based cohesion, in particular, may help identify supply chain attacks, improving source code integrity.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。