Page 218 - 《软件学报》2026年第3期
P. 218

田朝 等: CoDefense: 面向对抗性攻击的多粒度代码归一化防御方法                                           1181


                 型具有不同的结构, 不同的任务侧重于不同的代码特征, 因此这些针对特定模型和任务而设计的白盒攻击方法难
                 以推广到其他模型和任务. 此外, Nguyen        等人  [71] 提出了恶意  API 插入  (malicious APIs insertion) 攻击, 将其定义为
                 在正常代码中插入包含恶意代码的             API 或错误  API, 其中这些   API 可能是虚构的, 或是错误的        (来自伪造的第三
                 方库). 在恶意   API 插入后, 含有这些    API 的代码在特定上下文或使用场景中执行时, 可能会触发中断或引发严重
                 错误. 鉴于本文的研究重点在于保持代码语义一致的对抗性攻击方法, 因此假设任何破坏代码语义的攻击均会被
                 识别. 本文所研究的对抗性攻击技术           (如重命名、死代码插入、等价结构转换等) 皆不改变代码的功能语义, 也不
                 会在原始代码中引入缺陷或漏洞, 从而难以被漏洞扫描工具或测试用例检测到. 与之对比, 恶意                            API 插入直接影响
                 代码的语义一致性, 并可能引入新的漏洞, 因此不符合本文在对抗性攻击及其防御策略中的假设前提. 基于以上考
                 虑, 并与现有对抗性攻击和防御研究           [16,19,21] 的常见假设一致, 本文未将恶意    API 插入攻击纳入实验考量. 未来工作
                 中, 计划将恶意    API 插入攻击的防御视为潜在的扩展方向, 以进一步提升                CoDefense 的适用性和防御广度.

                           表 4 现有的针对代码输入的预训练模型对抗性攻击方法总结                    (按出版物年份升序排列)

                   ID     对抗性攻击方法           出版物          白盒/黑盒             任务              对抗性攻击策略
                                 [30]                               Functionality classification  变量名替换
                    1       DAMP          OOPSLA 2020     白盒
                                                                        Code completion     死代码插入
                                 [18]
                    2        MHM           AAAI 2020      黑盒        Functionality classification  变量名替换
                                                                                            变量名替换
                                  [39]
                    3      Srikant等人       ICLR 2021      白盒        Functionality classification
                                                                                            死代码插入
                                                                                            变量名替换
                                  [72]
                    4      Rabin等人          IST 2021      白盒         Method name prediction
                                                                                           代码结构转换
                                                                     Method name prediction
                    5      Pour等人 [73]     ICST 2021      黑盒            Code captioning     变量名替换
                                                                         Code search       代码结构转换
                                                                      Code Summarization
                                                                                            变量名替换
                    6      AVERLOC [45]   SANER 2022      黑盒          Code summarization
                                                                                           代码结构转换
                    7      ACCENT [74]    TOSEM 2022      黑盒          Code summarization    变量名替换
                    8     WIR-Random [21]  ISSTA 2022     黑盒          Vulnerability detection  变量名替换
                                                                      Code summarization
                                                                                            变量名替换
                                 [50]
                    9       RoPGen         ICSE 2022      黑盒          Authorship attribution
                                                                                           代码结构转换
                                                                    Functionality classification  变量名替换
                   10      CARROT [20]    TOSEM 2022      白盒            Clone detection     死代码插入
                                                                      Vulnerability detection
                                                                      Authorship attribution
                   11       ALERT [19]     ICSE 2022      黑盒            Clone detection     变量名替换
                                                                      Vulnerability detection
                   12       MixCode [75]  SANER 2023      白盒        Functionality classification  变量名替换
                                                                         Bug detection      死代码插入
                                                                      Vulnerability detection
                                                                        Clone detection     变量名替换
                   13       CODA [15]       ASE 2023      白盒          Authorship attribution  代码结构转换
                                                                    Functionality classification
                                                                       Defect Prediction
                                                                      Vulnerability detection  死代码插入
                   14     StyleTransfer [16]  FSE 2023    黑盒            Clone detection    代码结构转换
                                                                      Code Summarization

                    具体而言, 在表     4  展示的  8  种黑盒攻击中, 我们选择了      WIR-Random [21] 、ALERT [19] 和  StyleTransfer  [16] 这  3  种
                 方法. 这是因为    MHM  [18] 、ACCENT [74] 、WIR-Random [21] 和  ALERT [19] 均是利用变量名替换作为攻击策略, 其中
                 WIR-Random 和  ALERT  作为其中最先进、最有效的方法, 被选为我们的研究对象. 其他                  4  种方法, Pour 等人  [73] 、
   213   214   215   216   217   218   219   220   221   222   223