Skip to content

Robustness evaluation of Gmail's malware detection system to transferable adversarial attacksEvaluating the Robustness of a Production Malware Detection System to Transferable Adversarial Attacks

arXiv· arXiv:2510.01676· ACM CCS 2025· Milad Nasr, Yanick Fratantonio, Luca Invernizzi, Ange Albertini, Loua Farah, Alex Petit-Bianco, Andreas Terzis, Kurt Thomas, Elie Bursztein, Nicholas CarliniGoogle DeepMind; GoogleIndexed by this site · 27 days ago· Originally publishedSelected AttacksSelectedAttention41

Quick read

Attacks

Based on the paper PDF (AI-generated); refer to the original

The authors mount a transfer adversarial attack on the Magika file-type router in the Gmail malware detection pipeline, achieving 90% success rate by modifying 13 bytes, and propose an AES preprocessing defense that has been deployed.

Threat modelThe attacker's goal is to send malware via Gmail attachments: first bypass signature detection, then make the Magika router misroute the sample to a mismatched specialized scanner. Two settings are considered: full whitebox (knowing the deployed model parameters, which holds because the open-source and production versions have the same parameters) and black-box transfer attacks (the defender keeps a small amount of secret, while the attacker can access the open-source architecture and training code, collect same-distribution data, and train substitute models).

Questions
The Gmail malware detection pipeline uses the open-source Magika model for file-type routing; the authors study whether attackers can bypass the entire detection pipeline by deceiving this routing component, and the risks brought by open-source production models.
Methods
The authors adapted the GCG discrete adversarial attack to make in-place modifications to file bytes, combining blind spots to preserve file format and malicious functionality; for defense, after evaluating multiple schemes, they proposed adding a single-round AES transform in preprocessing, and it has been deployed to the Gmail production classifier.
Experiments and results
Under white-box conditions, modifying 13 bytes achieved 90% ASR, and format-preserving attacks across seven formats all reached 100%; in an end-to-end proof of concept, a malicious PDF was successfully delivered via Gmail. Under a single-round AES defense, a high-resource attacker modifying 50 bytes achieved only 20% ASR.
Limitations and future work
The authors note: the evaluation focuses on transfer attacks, and white-box attackers can still succeed; the number of modified bytes does not fully reflect the real attack cost; malicious functionality is verified only on the subset of files used in the proof of concept; the defense can still be bypassed by large-budget black-box search or direct white-box attacks.
Experimental setupMagika · Magika 作者提供的 1,130 个文件(113 种文件类型各 10 个测试样本)、VirusTotal 与 GitHub 收集的 20M 文件(训练替代模型) · attack success rate、修改字节数 et al.
Evaluated models
Magika
Benchmarks
Magika 作者提供的 1,130 个文件(113 种文件类型各 10 个测试样本)VirusTotal 与 GitHub 收集的 20M 文件(训练替代模型)
Metrics
attack success rate修改字节数benign accuracy延迟
AI summaryand selection rationaleResearchers from Google and Google DeepMind evaluated in a paper the robustness of Gmail's malware detection system to transferable adversarial attacks, with the attack targeting its Magika file-type classifier. At the time of disclosure, the open-source and production versions had identical parameters, and based on this the researchers adapted the GCG attack to modify bytes in files that do not affect functionality; changing 13 bytes was enough to bypass Magika in 90% of cases, keeping files valid across seven formats including PDF, ZIP and Docx and achieving a 100% success rate; in an end-to-end experiment permitted by Gmail, a malicious PDF with its extension removed and undetected by mainstream antivirus engines was successfully delivered to an account controlled by the researchers. On defenses, after evaluating approaches such as randomization, architecture changes and adversarial training, the paper proposed a defense based on AES preprocessing; under the defended production model, a high-resource attacker would need to change 50 bytes to reach a 20% attack success rate, and the defense has been deployed to Gmail's production environment in collaboration with Google engineers.

Researchers from Google and Google DeepMind evaluated in a paper the robustness of Gmail's malware detection system to transferable adversarial attacks, with the attack targeting its Magika file-type classifier. At the time of disclosure, the open-source and production versions had identical parameters, and based on this the researchers adapted the GCG attack to modify bytes in files that do not affect functionality; changing 13 bytes was enough to bypass Magika in 90% of cases, keeping files valid across seven formats including PDF, ZIP and Docx and achieving a 100% success rate; in an end-to-end experiment permitted by Gmail, a malicious PDF with its extension removed and undetected by mainstream antivirus engines was successfully delivered to an account controlled by the researchers. On defenses, after evaluating approaches such as randomization, architecture changes and adversarial training, the paper proposed a defense based on AES preprocessing; under the defended production model, a high-resource attacker would need to change 50 bytes to reach a 20% attack success rate, and the defense has been deployed to Gmail's production environment in collaboration with Google engineers.

Why it was selectedThe paper shows how machine learning components in production security systems can become the weakest link exploitable by adversarial attacks, and its defense approach aimed at raising attack costs can be transferred to similar systems.

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    The authors study whether an attacker can bypass the entire malware detection pipeline by deceiving the open-source Magika file type router in the Gmail pipeline.

    Core question: when an ML model is embedded as a component in a production security system, can adversarial attacks targeting that component cause real harm at the system level—using the Magika file-type router in the Gmail malware detection pipeline as a case study.

    • Scenario and importance: Gmail's detection has three steps—a fast signature classifier, a routing classifier (including Magika), and specialized malware classifiers. The authors point out that the security of the entire pipeline depends on the robustness of the routing component, and that Magika is open source.
    • Shortcomings of the existing situation: The authors state that although adversarial example research has existed for over a decade, real attackers rarely use gradient-based attacks (citing "real attackers don't compute gradients"); a common explanation is that adversarial attacks are rarely the easiest way to achieve a goal; this paper presents a real scenario in which an adversarial attack is instead an appropriate means.
    • Core observation: Tricking Magika into misrouting a sample to a mismatched specialized scanner may be easier than directly tricking the specialized scanner; Magika is a standard neural network not designed for adversarial examples, and its code is open source.
    • Paper contributions: Design an adversarial attack against Magika (changing 13 bytes achieves a 90% success rate) and conduct an end-to-end Gmail proof of concept; propose and deploy a defense such that a high-resource attacker changing 50 bytes achieves only a 20% success rate.
    • Threat model:
      • Goal: Send malware via Gmail attachments, bypassing the entire detection pipeline.
      • Knowledge: Two settings—full whitebox (possessing the exact parameters of the deployed model); black-box (the defender can keep a small number of secrets; the attacker knows the training algorithm but not the specific randomness or private secrets).
      • Capability: Modify the bytes of their own malicious files; under black-box, can access the open-source architecture and training code, collect same-distribution data, and train substitute models for transfer attacks.
      • Victim system: The Gmail malware detection pipeline (signature matching + file-type router + specialized scanners).
  2. What related research exists?

    Related work covers three categories: adversarial examples and NLP discrete attacks, transfer attacks and defenses, and malware and file type detection.

    Adversarial examples and NLP discrete attacks

    • Goodfellow et al. [17], Szegedy et al. [33], etc.—classic adversarial example work in image and other domains; Apruzzese et al. [4] point out that real attackers rarely compute gradients, and Gilmer et al. [16] give a common explanation.
    • Early NLP attacks (HotFlip [14], Jia and Liang [20], Liang et al. [22])—deceive sentiment analysis and reading comprehension systems by adding or removing whitespace or characters; the authors state that modern language models are relatively robust to such simple attacks.
    • Zou et al. [38]—propose the Greedy Coordinate Gradient (GCG) attack, which generates adversarial examples with a limited number of modifications in the discrete input domain; the attack in this paper builds on GCG, changed to in-place modification of file bytes.

    Transfer attacks and defenses

    • Papernot et al. [27], Liu et al. [23]—study the transferability of adversarial examples across unrelated models.
    • Tramèr et al. [35]—use ensemble methods to mitigate transferable adversarial examples; Madry [25]—adversarial training; Shumailov et al. [32]—use cryptography-based methods to prevent transfer, which the authors note is similar to this paper's approach.
    • Hong et al. [19]—propose Similarity Unpairing, arguing that the similarity of input gradient landscapes between the released model and the private model is key to transfer attacks; this paper reproduces it as one of the defense baselines.

    Malware and file type detection

    • Pierazzi et al. [28]—propose problem space constraints; the format-preserving attack in this paper follows this framework; Albertini [1]—studies bypassing simple file type detection through file format inconsistencies.
    • Fratantonio et al. [15]—propose Magika, which uses a convolutional architecture to classify the first, middle, and last 512 bytes of a file; the authors note that Magika was explicitly not designed against adversarial attacks, and its authors also stated this limitation.
    • Brodin et al. [6]—the concept of blind spots (bytes that can be modified without breaking file structure); this paper uses the Mitra tool to identify blind spots in 40 formats.

    Baselines and benchmarks: Defense comparison baselines include retraining with a different seed, changing architecture, changing preprocessing offset, adversarial training, and Similarity Unpairing; the attack baseline is GCG. The evaluation dataset is the 1,130 files provided by the Magika authors.

    Positioning: The authors state that this paper's distinction is analyzing a real production system rather than an isolated model, and actually deploying the defense; Shumailov et al. [32] is closest to this paper's approach (cryptographic methods to prevent transfer).

  3. How does the paper address this problem?

    The authors adapt GCG into an in-place modification attack on file bytes and propose a defense that embeds a single-round AES transform in preprocessing.

    Overall approach: on the attack side, the GCG discrete adversarial attack is adapted to the file byte domain to make Magika misclassify while preserving file format and malicious functionality; on the defense side, a keyed AES transform is added to the preprocessing pipeline to decouple the input spaces of the open-source model and the private model. The method has no separate name; the defense is called AES-based preprocessing.

    Problem setting and formalization

    • The attack objective follows the adversarial example definition: x∗ = x + argmin{z : O(x+z) ≠ O(x)}, i.e., making the minimal modification to the input so that the model prediction changes.
    • The authors focus on l0 attacks: the key metric is the number of modified bytes rather than the specific values they are changed to, because what is modified are blind spots (bytes that can be freely changed without breaking file structure and functionality).
    • The authors consider byte count not an ideal metric (a malicious file remains malicious no matter how many bytes are changed), but it can be used to quantify attack difficulty and compare defenses.

    Attacks: white-box and format-preserving

    • White-box attack (Algorithm 1/2): GCG is modified—instead of searching for an appended suffix, it searches for bytes that can be modified in place; it first finds the k positions with the largest gradients, then enumerates candidate values for each position and selects the modification that minimizes the classification loss.
    • Format-preserving attack: Must satisfy operating system constraints (e.g., magic bytes) and file format constraints; the Mitra tool is used to identify blind spots, divided into three categories by degree of controllability—Full Control (ZIP, ISO, etc., where essentially all of the first 2048 bytes are controllable), Parasite (comments or metadata can be inserted, usually at least 2000 controllable bytes), Scattered Blind Spots (only deprecated fields or descriptive text are available).
    • End-to-end process: Select a malicious sample not detected by common antivirus software, remove or modify the file extension to evade Gmail's extension rules, then apply adversarial modifications so that Magika misroutes it.

    Defense: AES preprocessing

    • Threat model: Standard transfer attack setting—the defender deploys a private fθtarget, and the attacker can access the open-source architecture and training code, collect same-distribution data, train substitute models, and knows the training algorithm (except for explicit randomness and private secrets).
    • Design: The input is split into 16-byte blocks, encrypted with key K using R rounds of AES (ECB mode), and then fed to the model; the diffusion and confusion properties of AES are used to expand the space of preprocessing functions. The authors state that full AES would make the model overly sensitive to single-bit perturbations, so only a limited number of rounds are used, with 1 round for deployment.
    • Objective function (Similarity Unpairing baseline): L = Lxe(fθ′(x), y) + λ · Cs(x, y, fθ, fθ′), i.e., minimizing the input gradient similarity (using cosine similarity) between the public model and the private model while maintaining accuracy.

    Evaluation method

    • Success criterion: whether Magika misclassifies the file (most experiments); the end-to-end proof of concept is judged by successful delivery of a malicious PDF through Gmail to a controlled account.
    • Dataset: 1,130 files (10 test samples each for 113 types), provided by the Magika authors; additionally, 20M files were collected from VirusTotal and GitHub following the Magika paper's method to train substitute models.
    • Implementation: Magika was reimplemented in JAX and Keras weights were loaded, verifying equivalence with the original implementation.
  4. What experiments did the paper conduct?

    Under white-box, modifying 13 bytes reaches 90% ASR, and format-preserving attacks reach 100% on all seven formats; under the AES defense, a high-resource attacker modifying 50 bytes achieves only 20%.

    Experimental setup

    • Model under test: Magika file type classifier (open-source version; the authors state that at disclosure time its parameters were the same as the Gmail production version); defense experiments use private variants trained with different seeds, architectures, preprocessing offsets, or keys.
    • Dataset: 1,130 files (10 test samples each for 113 file types), provided by the Magika authors and shared across all experiments; the substitute model training set is 20M files collected from VirusTotal and GitHub following the Magika paper's method.
    • Attack methods: modified GCG (Algorithm 1/2), white-box direct attack, transfer attack (single substitute model and ensemble), adaptive attack (retraining after probing the offset).
    • Metrics: curves of attack success rate (ASR) versus number of modified bytes; defense experiments additionally report clean accuracy and latency.
    • Evaluation method: Magika misclassification counts as attack success; the end-to-end proof of concept is judged by successful delivery through Gmail, and the paper does not report an automated evaluation model.
    • Number of repetitions: the paper does not report the number of repetitions for each experiment (Figure 17 notes an average of 5 runs).

    Main results

    The paper's main results are presented mainly as figures; key numbers are as follows (per the main text and figure captions):

    Swipe horizontally to read the table

    SettingNumber of modified bytesASRSource
    White-box warmup (without format constraints)590%Figure 3 caption
    White-box warmup<3More than half of binary files can be misclassifiedSection 4.2
    Format-preserving attack (7 formats)Unrestricted100%Section 4.3
    Format-preserving attack (7 formats)1390%Section 4.3
    Transfer to a different-seed model (single substitute model)1035%Section 5.1
    AES defense (1 round, attacker trains 512 models)5020%Abstract
    • The authors state that a few bytes of modification are extremely small relative to multi-MB files (3 bytes is about 0.00001%), but relative to the 1,536-byte input the classifier actually reads, the perturbation ratio is 0.1–1%, comparable to other adversarial attacks.
    • In the format-preserving experiments, Office files (Docx, Xlsx) require the most modifications, but all formats reach 100% ASR; Figure 4 gives the cumulative modification count curves for each of the seven formats.
    • The authors state that the defense goal is not to completely solve the adversarial example problem, but to make the ML component no longer the weakest link.

    End-to-end Gmail proof of concept

    • What was tested: A malicious PDF not detected by common antivirus software was selected from VirusTotal, the .pdf extension was removed to evade Gmail's extension rules, and bytes were modified so that Magika no longer classifies it as PDF.
    • Result: The modified malicious PDF was successfully delivered through Gmail to a second account controlled by the authors (Figure 5); on Ubuntu 22 the file can still be opened normally by a PDF reader.
    • Authors' interpretation: The authors state that this shows that bypassing Magika and other file type detection is sufficient to route a malicious file to a mismatched scanner; they also acknowledge that the missing extension may affect whether the victim opens the file, and the attacker must rely on system differences or social engineering.

    Defense comparison experiments

    • Changing seed/architecture/preprocessing offset: Single substitute model transfer success rate drops from 90% under white-box to 35% (10 bytes, Figure 6); but after the attacker trains multiple substitute models as an ensemble, the transfer rate recovers (Figures 7, 8), and the same holds for changing architecture (Figure 9) and changing preprocessing offset (Figures 10, 11); the authors state that a well-resourced attacker can break all of them.
    • Adversarial training: Adversarial training with perturbation budgets of k ∈ {5, 10, 15} bytes improves robustness under low-byte attacks, but once the perturbation exceeds the training budget the attack success rate approaches 100% (Figure 12); clean accuracy drops from 99% (k=0) to 97% (k=10) and below 90% (k=15) (Figure 13), so the authors did not adopt it further.
    • Similarity Unpairing: Fine-tuning for 10 rounds has little effect on clean accuracy; it can reduce transfer effectiveness when no additional substitute models are added, but after the attacker trains more substitute models with the same unpairing loss, the attack effectiveness recovers (Figure 14).

    AES defense and adaptive attacks

    • Effectiveness: The defender uses 1 round of AES; the attacker trains 512 models with different keys/seeds for ensemble transfer, and the transfer rate is greatly reduced (Figure 15); the authors state that the remaining misclassifications may come from classification errors rather than transfer.
    • Cost: Increasing the number of AES rounds noticeably reduces clean accuracy (Figure 16), and the impact is acceptable at 1 round; single-round AES adds less than 1 microsecond of latency per file, and 3 rounds remain below 1 millisecond.
    • Negative results: The defense still fails when the attacker can randomly modify a large number of bytes (Figure 17, average of 5 runs); Appendix A states that directly attacking the target model (not transfer) can achieve a higher success rate; Appendix A also discusses a gradient-free (fuzzing-like) attacker.

    Other ablations and analyses

    • Increasing the number of GCG search points improves attack effectiveness, with diminishing returns after 2^13 neighbors (Figure 18).
    • Adaptive attacks (first probing the target model's preprocessing offset, then training substitute models) can reduce the computational cost of finding transferable samples, but it remains higher than ordinary transfer (dashed line in Figure 11).
    • Substitute model architecture diversity is obtained by randomly sampling convolution depth (1–4), convolution kernel size (8–16), and number of fully connected layers (1–4); each substitute model is required to have at least 95% average test accuracy (Appendix B).
    • CBC mode has a large impact on model utility, and the paper reports only ECB mode results (Section 5.6).
  5. What are some points that can be further explored?

    The authors list limitations such as white-box threats beyond transfer attacks and the shortcomings of the byte-count metric, and propose directions such as defenses customized by file type.

    Limitations and future directions noted by the authors

    • White-box threats remain (Section 6): The evaluation focuses on transfer attacks; AES preprocessing greatly reduces the transfer success rate under this setting, but a white-box attacker with full system access can still succeed.
    • Conditions of the proof of concept (Section 6): The Gmail proof of concept requires simultaneously modifying or removing the file extension and bypassing Magika and other rule-based classifiers; file handling behavior varies by operating system, and some users may be unwilling to open files without a familiar extension.
    • Insufficient measurement (Section 6): Measuring attack cost by the number of modified bytes does not fully reflect real workload; a motivated attacker can modify more bytes.
    • Scope of functional validation (Section 6): Malicious functionality was validated only on the subset of files used in the proof of concept and in an isolated environment, not exhaustively across all formats.
    • Defenses can be bypassed (Section 6): The defense may still be bypassed by large-budget black-box search or direct white-box attacks.
    • Future directions (Section 7): Use domain knowledge of each file type to improve and simplify the defense (e.g., specialized adversarial training for PDFs or images); systematically evaluate the defense's effectiveness and trade-offs on other tasks and datasets—the authors say it may lead to decreased model utility on tasks with more complex data patterns.

    Scope of experiments

    • The models tested are Magika and its private variants (different seeds, architectures, preprocessing offsets, AES keys), a total of 1 model family.
    • The evaluation dataset is 1,130 files (10 each of 113 types), shared by all experiments; the format-preserving experiments cover seven formats: PDF, ZIP, Docx, Xlsx, ELF, PNG, and JavaScript.
    • The defense evaluation includes six: retraining with a different seed, changing architecture, changing preprocessing offset, adversarial training, Similarity Unpairing, and AES preprocessing.
    • End-to-end validation was only a proof of concept on one malicious PDF on Gmail.
    • The paper does not report the number of repetitions for each experiment (except Figure 17, which is the average of 5 runs), nor the specific values of the number of queries and iteration budget for the attacks.
  6. Summarize the main content of the paper

    Transfer adversarial attacks against the open-source Magika router in the Gmail pipeline and a deployed AES preprocessing defense.

    An adversarial attack case study targeting a production system: the authors analyze the Gmail malware detection pipeline, in which the open-source Magika model is responsible for routing files to specialized scanners.

    • Problem: The security of the entire pipeline depends on the routing component; deceiving Magika so that malicious files are misrouted may be easier than directly deceiving the specialized scanners.
    • Method: The GCG discrete adversarial attack is adapted into in-place modifications of file bytes, using blind spots to preserve file format and malicious functionality; on the defense side, a keyed single-round AES transform is added to preprocessing, decoupling the input spaces of the open-source model and the private model.
    • Attack results: Under white-box, modifying 5 bytes reaches 90% ASR (Figure 3); format-preserving attacks reach 100% ASR on all seven common formats, and 90% when limited to 13 bytes; a malicious PDF is successfully delivered end-to-end through Gmail (Figure 5).
    • Defense results: Changing the seed, changing the architecture, changing preprocessing, adversarial training, and Similarity Unpairing can all be broken by an ensemble of multiple substitute models or by adaptive attacks; under the single-round AES defense, a high-resource attacker who trains 512 substitute models achieves only 20% ASR when modifying 50 bytes, with additional latency below 1 microsecond per file and an acceptable impact on clean accuracy.
    • Authors' conclusion: The authors state that the goal is not to completely solve the adversarial example problem, but to make the ML component no longer the weakest link in the operating environment; the defense has been deployed to the Gmail production classifier in collaboration with Google engineers, and the attacks in the paper are unlikely to remain effective after publication.
    • Implications: The authors argue that adversarial ML research should analyze real end-to-end systems more, and evaluate defenses in terms of "raising the attacker's cost in practice"; they also discuss the pros and cons of open-source production models—open source facilitates attacks, but also facilitates security research and defense development.
Read originalACM CCS 2025