SpecCloak: Probing Harmful Code Generation through Engineering Specifications
作者: Wenbin Chen, Jiexin Wang, Guanting Wu, Jiaxi Liang, Yi Cai
分类: cs.SE, cs.AI
发布日期: 2026-10-13
备注: 9 pages, 7 figures
💡 一句话要点
提出SpecCloak框架以探测有害代码生成问题
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 恶意代码生成 安全性 大型语言模型 工程规范 攻击检测 防御机制 自然语言处理
📋 核心要点
- 现有方法在处理恶意代码生成时,缺乏对请求表述形式对拒绝过程影响的深入理解。
- 论文提出PseudoSpec模板,通过工程规范组织功能需求,显著降低恶意代码生成的拒绝率。
- 实验结果显示,SpecCloak框架在多个目标模型上实现了28.91%的攻击成功率,SpecReveal防御原型达到96.88%的检测率。
📝 摘要(中文)
大型语言模型(LLMs)的代码生成能力可能被滥用以实现有害功能,因此理解其在编程请求下的安全行为显得尤为重要。尽管请求措辞已知会影响拒绝响应,但编码任务要求的表述形式是否影响恶意代码生成的拒绝过程仍不明确。本文引入了PseudoSpec模板,组织功能需求为工程规范,并通过对比分析、表示分析和激活干预进行研究。结果表明,去除显式风险关键词仅部分降低拒绝率,而规范提示显著降低拒绝率,即使保留这些关键词。基于这些发现,提出了SpecCloak黑箱红队框架,结合PseudoSpec与判别器引导优化,在RedCode-Gen上实现了28.91%的攻击成功率。同时,提出SpecReveal防御原型,结合自然语言意图重构与双视角检测,达到96.88%的攻击检测率。
🔬 方法详解
问题定义:本文旨在解决大型语言模型在生成恶意代码时的拒绝响应问题。现有方法对请求表述形式的影响缺乏系统研究,导致安全性不足。
核心思路:提出PseudoSpec模板,将功能需求组织为工程规范,探索其对拒绝率的影响。通过规范提示,显著降低恶意代码生成的拒绝率。
技术框架:整体架构包括两个主要模块:SpecCloak框架用于攻击生成,SpecReveal原型用于防御检测。SpecCloak结合了PseudoSpec与判别器引导优化,SpecReveal则通过意图重构与双视角检测实现防御。
关键创新:最重要的技术创新在于引入PseudoSpec模板和SpecCloak框架,前者通过规范化表述降低拒绝率,后者实现了有效的攻击与防御机制。
关键设计:在SpecCloak中,采用判别器引导优化技术,设定特定的损失函数以提高攻击成功率;在SpecReveal中,设计了自然语言意图重构与双视角检测的结合,确保高效的攻击检测。
🖼️ 关键图片
📊 实验亮点
实验结果显示,SpecCloak框架在八个目标模型上实现了28.91%的攻击成功率,SpecReveal防御原型在单独的提示检测评估中达到了96.88%的攻击检测率,表现出显著的性能提升。
🎯 应用场景
该研究的潜在应用领域包括安全编程、代码审查和恶意软件检测等。通过理解和探测有害代码生成的机制,可以为开发更安全的编程工具和防御系统提供理论基础,进而提升软件开发的安全性和可靠性。
📄 摘要(原文)
The code generation capabilities of large language models (LLMs) can equally be misused to implement harmful functionality, underscoring the need to understand their safety behavior in response to programming requests. While request phrasing is known to influence refusal, it remains unclear whether the form in which coding task requirements are stated affects the refusal process for malicious code generation. We introduce PseudoSpec, a template that organizes functional requirements as engineering specifications, and investigate its effects through controlled comparisons, representation analysis, and activation interventions. Across five open-weight models, removing explicit risk keywords only partially reduces refusal, whereas specification prompting substantially lowers refusal even when these keywords are retained. This reduction accompanies consistent shifts toward code-output-related representations, and interventions along condition-difference directions alter refusal behavior. Output analysis further distinguishes code-related responses from generation degeneration. Building on these findings, we propose SpecCloak, a black-box red-teaming framework combining PseudoSpec with discriminator-guided optimization, achieving an average execution-verified attack success rate of 28.91\% across eight target models on RedCode-Gen. We also introduce SpecReveal, a defense prototype combining natural-language intent reconstruction with dual-view detection without target-model fine-tuning. It achieves a 96.88\% attack detection rate in a separate prompt-detection evaluation, with false positives assessed on benign programming and specification-style inputs. These results connect specification-induced response differences to practical security consequences and identify intent reconstruction as a complementary detection approach.