跳到正文
Skillpedia
机器学习6.5k · #13948

adversarial-ml-evasion

它能做什么

这项技能介绍对抗样本,即对输入做微小改动,使模型给出错误答案。适合想测试自己的图像、恶意软件或垃圾邮件分类器的团队。

适用场景

  • ✓当团队要求智能体测试自有图像或垃圾邮件分类器,是否会被微小输入改动欺骗时。
  • ✓当智能体在设计任何测试之前,需要了解目标模型接受什么输入时。
  • ✓当报告需要说明模型稳健性是如何测试的以及发现了什么时。

技能链接

https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/analyst/adversarial-ml-evasion/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/analyst/adversarial-ml-evasion/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请帮我测试一下,我们自己的垃圾邮件分类器在输入内容做了微小改动后,是否会给出错误的判断?”

每周 5 个新技能,1 分钟读完。

工作原理

智能体先了解模型的输入和输出,然后进行小幅、可控的改动,并记录答案改变的频率。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Adversarial ML Evasion

Adversarial examples are inputs modified with small, deliberate perturbations that reliably cause a trained classifier to produce incorrect predictions. The perturbation is typically imperceptible to humans or functionally irrelevant, while the model's decision boundary is crossed. This is distinct from LLM jailbreaks: the target is a trained discriminative model (CNN, gradient-boosted tree, SVM, LSTM) served via an API or embedded in a product.

Authorized use only. All testing must be conducted against systems you own or have explicit written permission to assess. Generating adversarial inputs against production ML APIs without authorization may violate the CFAA and equivalent statutes.


ATT&CK Mapping

Technique Use
T1562.001 — Impair Defenses: Disable or Modify Tools Evade ML-based AV/EDR/IDS
T1036 — Masquerading Make malicious content look benign to a classifier
T1027 — Obfuscated Files or Information Perturb a file/image to fool static ML analysis

1. Reconnaissance — understand the target model

Before crafting perturbations, determine the attack surface:

# 1a. Identify the ML stack from job postings, open-source repos, error messages
# Common deployment stacks: TensorFlow Serving, TorchServe, ONNX Runtime, SageMaker, AzureML

# 1b. Probe input shape and output format
curl -s -X POST "$TARGET/predict" \
  -H "Content-Type: application/json" \
  -d '{"data": [[0.0]*784]}' | jq .
# Note: number of output classes, confidence scores vs hard labels
# Confidence scores = white-box-equivalent gradient signal via finite differences

# 1c. Check if the API returns confidence values (score-based black-box) or label only (hard-label)
# Score-based: enables gradient estimation, ZOO, NES attacks
# Label-only: requires hard-label attacks (HopSkipJump, QEBA)

2. White-box evasion (full model access)

Use when you have the model weights (pentest scope, internal system, open-source model).

2a. FGSM — Fast Gradient Sign Method (single step)

import torch, torchvision.transforms as T
from PIL import Image
import requests, json

def fgsm(model, x, y_true, epsilon=0.03):
    """Single-step gradient attack. Fast, low distortion for strong models."""
    x.requires_grad_(True)
    loss = torch.nn.CrossEntropyLoss()(model(x), y_true)
    loss.backward()
    return (x + epsilon * x.grad.sign()).clamp(0, 1).detach()

2b. PGD — Projected Gradient Descent (iterative, stronger)

def pgd(model, x, y_true, epsilon=0.03, alpha=0.007, steps=40):
    """Madry's PGD — iterative FGSM with projection back into epsilon-ball."""
    x_adv = x.clone().detach().requires_grad_(True)
    for _ in range(steps):
        loss = torch.nn.CrossEntropyLoss()(model(x_adv), y_true)
        loss.backward()
        with torch.no_grad():
            x_adv = x_adv + alpha * x_adv.grad.sign()
            delta = torch.clamp(x_adv - x, -epsilon, epsilon)
            x_adv = torch.clamp(x + delta, 0, 1).detach().requires_grad_(True)
    return x_adv

2c. C&W — Carlini & Wagner (optimization-based, minimal distortion)

pip install adversarial-robustness-toolbox  # IBM ART
python - <<'EOF'
from art.attacks.evasion import CarliniL2Method
from art.estimators.classification import PyTorchClassifier
# wrap your model in PyTorchClassifier, then:
attack = CarliniL2Method(classifier=clf, confidence=0.5, max_iter=100)
x_adv = attack.generate(x=x_test[:10])
EOF

3. Black-box evasion (API access only)

3a. Score-based: NES / ZOO (gradient-free estimation)

When confidence scores are returned, estimate gradient via finite differences:

import numpy as np

def nes_gradient_estimate(query_fn, x, sigma=0.01, n=50):
    """Natural Evolution Strategy gradient estimate from prediction scores."""
    grads = np.zeros_like(x)
    for _ in range(n):
        noise = np.random.randn(*x.shape)
        pos = query_fn(x + sigma * noise)
        neg = query_fn(x - sigma * noise)
        grads += (pos - neg) * noise
    return grads / (2 * n * sigma)

# query_fn: callable that sends x to the API and returns target-class score
# Use grads to step: x_adv = x - alpha * np.sign(grads)

3b. Transfer attack (surrogate model)

The reference approach from 13o-bbr-bbq/machine_learning_security's CNN_test:

# 1. Collect input samples via normal API usage
# 2. Train a local surrogate on (input, label) pairs
# 3.
常见问题

什么是对抗样本?

它是一种输入,经过细微的、往往难以察觉的改动后,会使模型给出错误的结果。

这和越狱聊天机器人是一回事吗?

不是。该技能针对的是已训练的分类器,而不是大语言模型的提示词。

能否未经许可用在公司的生产 API 上?

不能。该技能指出,测试必须限于测试人员拥有或获得书面授权评估的系统。

详情

作者的原始描述

Craft adversarial examples that cause trained ML classifiers to misclassify at inference time — image recognition, malware detectors, IDS, spam filters.

repo: BitterSecurity/Decepticon

热度

GitHub 星标
6.5k
排名
#13948
许可证
Apache-2.0
更新时间
2026/11/1

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能