Robust Learning against Logical Adversaries

Yizhen Wang, Xiaozhu Meng, Mihai Christodorescu, Somesh Jha

Abstract

Source code attribution approaches have achieved remarkable accuracy thanks to the rapid advances in deep learning. However, recent studies shed light on their vulnerability to adversarial attacks. In particular, they can be easily deceived by adversaries who attempt to either create a forgery of another author or to mask the original author. To address these emerging issues, we formulate this security challenge into a general threat model, the relational adversary, that allows an arbitrary number of the semantics-preserving transformations to be applied to an input in any problem space. Our theoretical investigation shows the conditions for robustness and the trade-off between robustness and accuracy in depth. Motivated by these insights, we present a novel learning framework, normalize-and-predict (N&P), that in theory guarantees the robustness of any authorship-attribution approach. We conduct an extensive evaluation of N&P in defending two of the latest authorship-attribution approaches against state-of-the-art attack methods. Our evaluation demonstrates that N&P improves the accuracy on adversarial inputs by as much as 70% over the vanilla models. More importantly, N&P also increases robust accuracy to 45% higher than adversarial training while running over 40 times faster.

The Vulnerability of Code Authorship Attribution

Identifying the author of source code—authorship attribution—is a critical task in software forensics and malware analysis. However, deep learning models used for this purpose are highly susceptible to "relational" adversarial attacks. An attacker can apply a sequence of semantics-preserving transformations, such as renaming variables or altering control flow structures, to change a program's "stylistic fingerprint" without changing its logic.

Example of semantics-preserving transformations used by a relational adversary to mask authorship.

This allows an adversary to either impersonate another developer or mask their own identity. Traditional defenses like adversarial training, which involves training the model on malicious examples, are often impractical in this domain. Generating adversarial code snippets is computationally expensive, sometimes taking weeks, and these defenses are difficult to apply to non-parametric models like Random Forests.

The Normalize-and-Predict (N&P) Framework

To address these limitations, we propose the Normalize-and-Predict (N&P) framework. This approach shifts the focus from the learning algorithm itself to a robust preprocessing step.

The N&P Pipeline

Instead of training on raw, variable source code, the N&P system passes all code through a normalizer (N) during both the training and testing stages. The classifier is then trained and evaluated exclusively on these canonical "normal forms."

The Normalize-and-Predict (N&P) framework pipeline for training and testing stages.

By ensuring that an original program and its adversarial variants map to the same normal form, the model is theoretically guaranteed to produce consistent, robust predictions.

FASTNORM Algorithm

Because finding a mathematically perfect normal form is often PSPACE-hard, we developed FASTNORM, a heuristic algorithm. FASTNORM applies a set of "monotonically decreasing" rules—for instance, always converting for loops to while loops and printf to cout. This ensures the algorithm terminates at a stable, simplified version of the code, effectively stripping away stylistic obfuscation.

Experimental Evaluation

We evaluated N&P using the Google Code Jam (2017) dataset, which contains 1,632 C++ files from 204 authors. This dataset is ideal because authors solve the same problems, forcing the model to learn stylistic habits rather than task-specific patterns.

Key Results

  • Superior Accuracy: Against a "Full" attack involving 42 different transformations, a standard LSTM's accuracy plummeted to 0.9%. While adversarial training raised this to 25.1%, the N&P-LSTM achieved 71.5%.
  • Efficiency: Training a robust model via adversarial training took over 20 days. In contrast, the N&P approach completed in less than 24 hours, representing a 40x speedup.
  • Model Agnostic: N&P proved effective for both Deep Learning (LSTMs) and traditional Machine Learning (Random Forests).

Conclusion and Future Work

N&P provides a provably robust and highly efficient defense against logical adversaries in source code attribution. While FASTNORM is a heuristic and may not capture every possible program variant, it significantly reduces the "distance" between original and adversarial programs in feature space by up to 89%. Future work will focus on developing more general-purpose normalizers and expanding the scope of transformations to include complex obfuscations like function inlining.

Summary updated

BibTeX
@misc{wang2020robust,
  author = {Yizhen Wang and Xiaozhu Meng and Mihai Christodorescu and Somesh Jha},
  title = {{Robust Learning against Logical Adversaries}},
  year = {2020},
  eprint = {2007.00772},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2007.00772},
}
Figure