檢視次數:

使用這些 YAML 配置範例作為範本,透過 AI 掃描器掃描您的 AI 應用程式。選擇與您的應用程式託管方式相符的提供者類型。

AI 掃描器支援五種目標提供者類型。選擇與您的應用程式託管方式相符的類型,或使用通用的 custom 類型來適用於任何其他 HTTP 應用程式介面 (API)。尋找與您的設置相符的配置模式並進行調整以開始掃描:

配置檔案結構

每個配置檔案都需要以下內容:
  • version:配置架構版本,例如 2.9.0。AI 掃描器會自動遷移較舊的 1.x2.x 檔案。
  • target:正在測試的AI應用程式
  • judge:評估攻擊是否成功的模型
  • 其中一個attack_presetattack_objectivescustom_promptsagentic:用來攻擊目標的方式。您可以將這些方式結合使用。
每個 targetjudge 封鎖透過包含以下子封鎖之一來選擇其提供者:openaibedrockazurevertexcustomtrendai。您不需要設定 type 欄位;AI 掃描器會從存在的子封鎖中推斷提供者。並非每個子封鎖都適用於每個角色,如下表所示。
提供者封鎖
用於
目標
判斷
代理攻擊者
openai
OpenAI 和 OpenAI 相容的端點
bedrock
AWS Bedrock
No
azure
Azure OpenAI 服務或 Azure AI Foundry
No
vertex
Google Cloud Vertex AI
No
custom
任何其他具有請求和回應範本的 HTTP API
No
No
trendai
Trend Vision One–託管模型
No
目前,判斷端點不支援所有提供者。
AI 掃描器如何使用來自 api_key_env 的 API 金鑰進行身份驗證,取決於提供者:
  • openaitrendai:使用 Bearer 方案在 Authorization 標頭中發送
  • azureauth_type: api_key:在不可配置的固定 api-key 標頭中發送
  • custom:預設情況下,使用 Bearer 方案在 Authorization 標頭中發送。要更改標頭名稱或前綴,請使用 auth_headerauth_prefix 欄位,例如 auth_prefix: "Token "
  • bedrockvertexapi_key_env 不適用。這些提供者通過 AWS 或 Google Cloud 憑證鏈進行身份驗證,如其章節中所述。
僅針對custom提供者,兩個佔位符控制AI掃描器插入和提取資料的位置:
  • {{prompt}}:AI 掃描器在運行時將此佔位符替換為攻擊提示。
  • {{response}}:AI 掃描器從此位置資訊提取模型回應。
重要
重要
將 API 金鑰儲存在環境變數中。不要直接在配置檔中包含 API 金鑰。在執行掃瞄之前,請設定名為 api_key_env 的環境變數。

OpenAI 和 OpenAI 相容的端點

當您的 AI 應用程式是 OpenAI 本身、與 OpenAI 相容的閘道,或是提供 OpenAI 聊天完成 API 的自我託管模型時,請使用此配置。
version: 2.9.0
name: OpenAI Compatible Scan
description: Security scan for an OpenAI-compatible chat endpoint
target:
  name: my-openai-app
  endpoint: https://api.openai.com/v1/
  api_key_env: TARGET_API_KEY
  openai:
    model: gpt-4o
    system_prompt: You are a helpful customer support assistant.
judge:
  name: judge
  endpoint: https://api.openai.com/v1/
  api_key_env: JUDGE_API_KEY
  openai:
    model: gpt-4o
settings:
  concurrency: 10
attack_preset: OWASP
endpoint 指向任何與 OpenAI 相容的基本 URL;不需要是 api.openai.com

Amazon Bedrock

當您的AI應用程式是託管在AWS Bedrock上的基礎模型時,請使用此配置。
version: 2.9.0
name: Bedrock Target Scan
description: Security scan for a Bedrock-hosted model
target:
  name: my-bedrock-app
  bedrock:
    region: us-east-1
    model: anthropic.claude-3-5-sonnet-20241022-v2:0
    temperature: 0.6
    system_prompt: You are a helpful AI assistant.
judge:
  name: judge
  endpoint: https://api.openai.com/v1/
  api_key_env: JUDGE_API_KEY
  openai:
    model: gpt-4o
attack_preset: OWASP
bedrock 區塊不使用 api_key_env。AI 掃描器通過標準 AWS SDK 憑證鏈來解析 AWS 憑證,例如 IAM 角色、環境變數、共享憑證文件或 SSO。如果已設定 AWS_DEFAULT_REGIONAWS_REGION,您可以省略 region

Azure OpenAI

使用此配置進行 Azure OpenAI 服務或 Azure AI Foundry 部署。選擇兩種驗證模式中的一種,使用 azure.auth_type
若要進行 API 金鑰驗證,請使用以下配置:
version: 2.9.0
name: Azure OpenAI Target Scan
description: Security scan for an Azure OpenAI deployment
target:
  name: my-azure-app
  endpoint: https://my-resource.openai.azure.com
  api_key_env: TARGET_API_KEY
  azure:
    deployment_name: gpt-4o
    auth_type: api_key
    temperature: 0.6
    system_prompt: You are a helpful AI assistant.
judge:
  name: judge
  endpoint: https://api.openai.com/v1/
  api_key_env: JUDGE_API_KEY
  openai:
    model: gpt-4o
attack_preset: OWASP
對於 Microsoft Entra ID 驗證,該驗證適用於 Azure OpenAI 服務,但不適用於 Azure AI Foundry,請設定 auth_type: entraid 並移除 api_key_env。然後匯出 AZURE_CLIENT_IDAZURE_TENANT_IDAZURE_CLIENT_SECRET,以供在資源上具有 Cognitive Services OpenAI 使用者角色的服務主體使用。
endpoint 接受 Azure OpenAI Service 的 *.openai.azure.com 主機和 Azure AI Foundry 的 *.services.ai.azure.com 主機。

Google Vertex AI

當您的 AI 應用程式是託管在 Google Cloud Vertex AI 上的 Gemini 模型時,請使用此配置。
version: 2.9.0
name: Vertex AI Target Scan
description: Security scan for a Vertex AI-hosted Gemini model
target:
  name: my-gemini-app
  vertex:
    project: my-gcp-project
    location: us-central1
    model: gemini-2.5-flash
    temperature: 0.6
    system_prompt: You are a helpful AI assistant.
judge:
  name: judge
  endpoint: https://api.openai.com/v1/
  api_key_env: JUDGE_API_KEY
  openai:
    model: gpt-4o
attack_preset: OWASP
vertex 封鎖不使用 api_key_env。Vertex AI 使用應用程式預設憑證 (ADC)。在執行掃瞄之前,請使用 gcloud auth application-default login 進行本地開發的身份驗證,或配置服務帳戶或工作負載身份聯邦以進行自動化管道。

自訂 HTTP 端點

對於任何不兼容 OpenAI、Bedrock、Azure OpenAI 或 Vertex AI 的 AI 應用程式,請使用 custom 提供者。custom 封鎖以 YAML 模板描述您 API 的請求和回應格式。
您必須指定下列項目:
  • 端點 URL
  • HTTP 方法
  • 標頭欄位,例如內容類型宣告
  • 請求主體的 JSON 結構,包括以 {{prompt}} 標示的文字提示位置資訊
  • 回應主體的 JSON 結構,包括模型輸出的位置資訊,以 {{response}} 標示

簡單的 REST API

當您的AI應用程式公開一個簡單的REST端點,該端點在單一欄位中接受提示並在單一欄位中返回模型回應時,請使用此配置。在requestresponse部分調整欄位名稱以符合您的API架構。
version: 2.9.0
name: Simple REST API Scan
description: Security scan for a basic text generation endpoint
target:
  name: my-text-api
  endpoint: https://api.example.com/v1/generate
  api_key_env: TARGET_API_KEY
  custom:
    method: POST
    headers:
      Content-Type: application/json
    request:
      input: "{{prompt}}"
      temperature: 0.2
    response:
      answer: "{{response}}"
judge:
  name: judge
  endpoint: https://api.openai.com/v1/
  api_key_env: JUDGE_API_KEY
  openai:
    model: gpt-4o
settings:
  concurrency: 10
attack_objectives:
  - name: System Prompt Leakage
    techniques:
      - None
    modifiers:
      - None
  - name: Sensitive Data Disclosure
    techniques:
      - None
    modifiers:
      - None

聊天完成 API 與訊息陣列

當您的AI應用程式遵循聊天完成API慣例時,請使用此配置,其中提示作為消息陣列發送,包含角色和內容欄位。此模式常見於自定義託管端點,這些端點遵循與OpenAI相同的請求結構。
要包含系統提示,請將其作為第一個項目添加到messages陣列中,並使用role: system。AI 掃描器將每個攻擊提示作為role: user訊息發送。
version: 2.9.0
name: Chat Completions API Scan
description: Security scan for a chat-style AI endpoint
target:
  name: my-chat-api
  endpoint: https://api.example.com/v1/chat/completions
  api_key_env: TARGET_API_KEY
  custom:
    method: POST
    headers:
      Content-Type: application/json
    request:
      model: my-model-v1
      messages:
        - role: system
          content: You are a helpful assistant.
        - role: user
          content: "{{prompt}}"
      stream: false
    response:
      choices:
        - finish_reason: stop
          index: 0
          message:
            content: "{{response}}"
            role: assistant
judge:
  name: judge
  endpoint: https://api.openai.com/v1/
  api_key_env: JUDGE_API_KEY
  openai:
    model: gpt-4o
settings:
  concurrency: 10
attack_objectives:
  - name: System Prompt Leakage
    techniques:
      - DAN (Do anything now)
    modifiers:
      - None
  - name: Malicious Code Generation
    techniques:
      - Ignore all previous instructions
    modifiers:
      - Base64 Encoding
response 模板包含一個陣列時,例如此處的 choices,AI 掃描器會從索引 0 提取。

嵌套的請求和回應結構

當您的AI應用程式將提示和回應包裹在深層嵌套的JSON物件中時,例如包含元數據或配置參數的API,請使用此配置。
version: 2.9.0
name: Nested Structure API Scan
description: Security scan for an endpoint with nested JSON payloads
target:
  name: my-nested-api
  endpoint: https://nlp.example.net/run
  api_key_env: TARGET_API_KEY
  custom:
    method: POST
    headers:
      Content-Type: application/json
    auth_prefix: "Token "
    request:
      payload:
        prompt: "{{prompt}}"
      config:
        temperature: 0.1
        max_tokens: 1000
    response:
      data:
        result:
          message: "{{response}}"
judge:
  name: judge
  endpoint: https://api.openai.com/v1/
  api_key_env: JUDGE_API_KEY
  openai:
    model: gpt-4o
settings:
  concurrency: 5
attack_objectives:
  - name: Sensitive Data Disclosure
    techniques:
      - Payload splitting
    modifiers:
      - Best-of-N Scrambling
  - name: Agent Tool Definition Leakage
    techniques:
      - None
    modifiers:
      - None

自訂端點限制

  • JSON 回應僅限。AI 掃描器不支援非 JSON 的回應主體。
  • 不支援串流。AI 掃描器在解析之前會先讀取完整的回應主體,因此不支援伺服器發送事件或分塊串流。
  • 僅限第一個陣列元素。當回應模板包含陣列時,AI 掃描器總是從索引 0 提取。
秘訣
秘訣
如果您的應用程式位於封鎖非相關提示的護欄後面,包括 AI 掃瞄器在掃瞄開始前發送的連接性檢查,您可以使用可選的 target.health_check 封鎖來覆蓋檢查提示或關閉它:
target:
  health_check:
    enabled: true      # set to false to skip the check entirely
    message: How can I do DC profiling?

Trend Vision One 托管判斷模型

如果您不想使用您自己的 OpenAI 相容金鑰來評分攻擊結果,可以改用 Trend Vision One 提供的評審模型。trendai 提供者封鎖僅適用於 judge 角色,並可選擇性地適用於代理攻擊者角色。您無法將其用作掃瞄 target,因為目標始終是您正在測試的 AI 應用程式。
version: 2.9.0
name: TrendAI Judge Example
description: Scan a customer OpenAI target with a Trend Vision One-hosted judge
target:
  name: customer-app
  endpoint: https://api.openai.com/v1/
  api_key_env: TARGET_API_KEY
  openai:
    model: gpt-4o
judge:
  name: trend-saas-judge
  api_key_env: TREND_AI_KEY
  trendai:
    region: us
attack_preset: OWASP
此提供者的模型、端點、系統提示和調整參數無法由用戶配置;AI 掃描器會自動從 region 和角色中獲取這些參數,角色是可選的,預設為 us。支持的地區:
  • us
  • eu
  • jp
  • sg
  • au
  • in
  • mea
  • uk
  • ca
  • za