Learning from Few Samples: A Novel Approach for High-Quality Malcode Generation
Haijian Ma, Daizong Liu, Xiaowen Cai, Pan Zhou, Yulai Xie · 2025
Read Learning from Few Samples: A Novel Approach for High-Quality Malcode Generation by Haijian Ma, Daizong Liu, Xiaowen Cai, Pan Zhou, Yulai Xie (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2508-18148.txt.
Introduction
Haijian Ma and four co-authors tackle a lack of training samples for spotting malicious code, in a 2025 computer security study. Guards that watch networks learn from labeled samples, but good labels for attack code are scarce. The team builds a two-part system for SQL injection attacks, where bad input tricks a database. One part invents new attack samples, and the other part learns to spot them.
The inventor is a large language model, and the spotter grows sharper by sparring with the invented samples. Scores from the spotter feed back as rewards, so the invented code gets more real over time. Tests show the loop improves both the quality of the fake attacks and the skill of the spotter. The authors offer the loop as a path to guards that adapt as threats change.
Catalog record
| CREATOR | Haijian Ma, Daizong Liu, Xiaowen Cai, Pan Zhou, Yulai Xie |
|---|---|
| YEAR | 2025 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 53 KB |
| VERSION | 1.0 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2508-18148
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
Learning from Few Samples: A Novel Approach for High-Quality Malcode Generation Haijian Ma, Daizong Liu, Xiaowen Cai, Pan Zhou, Yulai Xie Abstract Intrusion Detection Systems (IDS) play a crucial role in network security defense. However, a significant challenge for IDS in training detection models is the shortage of adequately labeled malicious samples. To address these issues, this paper introduces a novel semi-supervised framework GANGRL-LLM , which integrates Generative Adversarial Networks (GANs) with Large Language Models (LLMs) to enhance malicious code generation and SQL Injection (SQLi) detection capabilities in few-sample learning scenarios. Specifically, our framework adopts a collaborative training paradigm where: (1) the GAN-based discriminator improves malicious pattern recognition through adversarial learning with generated samples and limited real samples; and (2) the LLM-based generator refines the quality of malicious code synthesis using reward signals from the discriminator. The experimental results demonstrate that even with a limited number of labeled samples, our training framework is highly effective in enhancing both malicious code generation and detection capabilities. This dual enhancement capability offers a promising solution for developing adaptive defense systems capable of countering evolving cyber threats. † † * Equal contributions. \dagger Corresponding authors. 1 Introduction The rapid evolution of cyber threats has exposed the limitations of traditional intrusion detection systems (IDS) in defending against modern attacks. A key challenge lies in the scarcity and lack of diversity in malicious samples—often referred to as black samples—which are essential for training robust detection models ( Kavitha and Ramalakshmi 2024 ) and designing effective honeypots ( BP and Sunitha 2024 ) . Most IDSs today rely on three types of black sample sources: real-world attack data, open-source malcode generators, and threat intelligence-based Indicators of Compromise (IOC). However, each has notable drawbacks. Real-world attack cases are often limited due to privacy issues, legal constraints, and organizations’ reluctance to disclose breaches ( Lu et al. 2022 ) , which reduces their usefulness for training generalized models. IOC data, while informative, is inherently reactive and typically lags behind emerging threats ( Asiri et al. 2023 ) , especially when facing increasingly diverse attack patterns ( Izuazu et al. 2025 ) . Furthermore, attackers often use obfuscation techniques to evade detection, undermining the reliability of IOC-based approaches. Therefore, a good malcode generator like the one in Figure 1 is what we desperately need to improve the defenses of IDS. Figure 1: Illustration of our motivation. Large language models (LLMs) have demonstrated strong code generation capabilities ( Jiang et al. 2024 ) . However, research has shown that their performance can degrade when trained on low-quality or insufficient datasets ( Gu et al. 2024 ) . While existing open-source attack generation tools provide synthetic samples, they often lack the complexity and variability required to simulate realistic attack scenarios. The limitations stem from both the generative capacity of the underlying models ( Xu et al. 2023 ) and the quality and quantity of the training data ( Setiyaji et al. 2024 ) . Therefore, this motivates us to propose an LLM-driven approach that can generate high-quality malicious samples using only a small number of labeled instances, thereby enhancing the overall detection capability of intrusion detection systems (IDS). To address these limitations, we introduce GANGRL-LLM, a novel semi-supervised framework that synergistically integrates the complementary strengths of Generative Adversarial Networks (GANs) and Large Language Models (LLMs). Unlike conventional approaches, our framework leverages the powerful code-generation capabilities of large language models (LLMs), while incorporating a two-tiered GAN-based structure augmented with reinforcement learning reward signals to effectively guide the iterative training process. A key innovation lies in the use of the discriminator’s output as a dynamic reward signal in the GAN, which actively guides the generator toward producing increasingly sophisticated and attack-like code structures. To further enhance training stability and prevent mode collapse, we incorporate contrastive constraints that preserve semantic consistency with real-world samples. The resulting two-tiered GAN-based structure enables collaborative, bidirectional learning between the generator and discriminator, significantly boosting malcode generation performance even under extreme data-scarcity conditions. Our main contributions are summarized as follows: • We introduce a novel multi-model collaborative learning framework for malcode generation which is different from text generation (more details in B ), enabling joint training of generator and discriminator components to improve the robustness and generalization of detection models. • Our framework combines a two-tiered GAN-like architecture with LLMs, where the generator is trained with guidance from the discriminator’s output used as a reward signal. This strategy effectively enhances training stability and sample generation quality, especially when labeled data is limited. • Experimental results demonstrate that our framework not only effectively improves the generation quality of malicious samples and the detection accuracy of IDS models in few-shot learning settings but also exhibits transferability. Figure 2: Framework overview of our proposed GANGRL-LLM. 2 Related Work 2.1 Text/Code Generation Recent advancements in code generation have leveraged pre-trained language models, such as GPT-3 and Codex, to generate high-quality code from natural language descriptions. Studies ( Chen et al. 2021 ) have shown that large-scale pre-training on diverse datasets can lead to impressive performance on a range of code generation tasks. Further research has emphasized the importance of fine-tuning on high-quality and diverse datasets to improve the model’s performance. A small or non-diverse dataset is prone to overfitting, where the model performs well on the training data but poorly on unseen data ( Yin and Neubig 2017 ) . Experimental results show that when the fine-tuning dataset is insufficient, the performance of LLMs in domain-specific code generation significantly declines. For instance, ChatGPT’s average CodeBLEU score drops by 51.48% in domain-specific tasks ( Gu et al. 2024 ) . This decline is primarily attributed to the model’s unfamiliarity with using specific domain libraries. Due to the performance degradation of fine-tuned models in code generation under few-shot labeling conditions, we employ token-level adversarial rewards to guide the model’s learning and optimization. By leveraging the discriminator’s judgments during the collaborative training of multiple models, we effectively direct the code generation process of the generative model. 2.2 GAN for Text Generation Generative Adversarial Networks (GANs) ( Goodfellow et al. 2020 ) were originally designed to generate realistic data samples and are particularly effective in scenarios with limited labeled data. However, one of the major challenges in applying GANs to text generation is their difficulty in handling discrete data. Unlike continuous outputs typical of GAN generators, textual data consists of discrete symbols such as words or characters, making gradient-based optimization through backpropagation problematic ( De Rosa and Papa 2021 ) . Generative Adversarial Networks (GANs) were initially used for image generation.While SeqGAN Yu et al. 2017 LeakGAN Guo et al. 2018 and MaliGAN Che et al. 2017 have made significant strides in sequence generation tasks, they still have notable limitations. The reward signals in existing methods are often sparse, which leads to slow convergence of the generator and unstable output quality. During training, particularly when generating diverse content, it is difficult to ensure convergence, leading to lower quality in the generated text or code. So we propose a novel design based on a discriminator reward mechanism. Unlike traditional cross-entropy loss, our model adjusts the generator’s loss by using real-time rewards derived from the discriminator’s output probability which is