Adversarial Source Code Generation via Vulnerable Position Selection
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Conventional adversarial attack methods for artificial intelligence models processing programming languages are inefficient due to low attack success rates and failure to completely preserve compilability.
Innovation Solution
A black box adversarial attack method and apparatus that selects vulnerable positions in source code, acquires dissimilar open source codes, extracts snippets based on attention scores, and generates adversarial source code by inserting dead code into these positions.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Reliability
If sampling-based variable name changes are used for adversarial attacks, then the attack process can be implemented, but the attack success rate is low and the number of attempts required is large
Solution Approach 1:
The patent performs preliminary actions by selecting vulnerable positions in the source code before generating adversarial examples. The vulnerable position selection unit identifies specific locations in the code where adversarial insertions are most likely to succeed, allowing the attack to focus efforts on high-probability targets rather than randomly attempting various modifications.
Solution Approach 2:
The patent segments the source code into distinct vulnerable positions and processes each position independently. The vulnerable position selection unit divides the code into manageable segments (vulnerable positions), and the adversarial example generation unit processes each segment separately, inserting adversarial code at specific locations rather than applying uniform changes throughout the entire codebase.
2Object-affected harmful factors
If conventional adversarial attack methods are applied to source code processing models, then attacks can be performed, but compilability is not completely preserved
Solution Approach 1:
The patent applies local quality by making targeted changes only at vulnerable positions rather than applying uniform modifications throughout the code. The adversarial example generation unit inserts adversarial code snippets specifically at identified vulnerable positions, leaving the rest of the code structure intact and compilable. This localized approach ensures that compilability is preserved while still exploiting model vulnerabilities.
Solution Approach 2:
The patent uses copying by extracting code snippets from existing source code and reusing them as adversarial examples. The snippet extraction unit identifies and extracts relevant code patterns that can be copied and inserted at vulnerable positions, ensuring that the inserted code maintains syntactic correctness and compilability while still serving as an effective adversarial example.
3Reliability
If more attempts are made in adversarial attacks, then potentially higher success rates may be achieved, but the time and computational resources required increase
Solution Approach 1:
The patent performs preliminary analysis to identify vulnerable positions before generating adversarial examples. By pre-processing the source code to locate vulnerable positions and extract relevant snippets, the system eliminates the need for numerous trial-and-error attempts, significantly reducing the time required to achieve successful attacks.
Solution Approach 2:
The patent replaces brute-force mechanical trial-and-error approaches with an intelligent system that uses vulnerable position selection and snippet extraction. Instead of mechanically attempting random modifications, the system intelligently identifies target positions and inserts pre-extracted code snippets, substituting computational brute force with structured analysis and significantly reducing execution time.
Data Source
AI summary
The present disclosure relates to an adversarial attack method and apparatus. The adversarial attack method according to an embodiment of the present disclosure may include: selecting vulnerable positions of an original source code; acquiring open source codes based on an open source code set; selecting dissimilar codes among the open source codes based on dissimilarity of the open source codes; acquiring an attention score for each of the dissimilar codes; extracting a snippet from at least one of the dissimilar codes based on the attention scores; and generating an adversarial source code based on the at least one snippet.


