Docs / 자동화와 확장
Script 완성 예제
앱의 실무 예제 3개와 빈 스크립트 외에, 직접 확장할 때 참고하는 13개 SDK 예제를 제공합니다. 각 예제는 코드만 복사하지 말고 표시된 Inspector 설정과 입력 조건도 함께 적용하세요.
Pro BetaWireSnare 1.0.0 · 출시 예정이 기능을 사용하려면 Pro Beta가 필요합니다.
이 문서의 목차
예제를 사용하는 순서
아래 코드는 Script SDK 참조 예제입니다. 앱에서 선택해 설치하는 예제 네 가지는 입력 반사 검토·입력 지점 분류·응답 정책 검토·JavaScript 경로 추출입니다. README·코드·트리거·권한을 확인하고 실제 History 근거로 테스트한 뒤 필요한 것만 활성화하세요. Script Studio 사용법 →
가장 작은 스크립트
- Trigger
manual- Capabilities
- 없음
- 입력 조건
- 어떤 Test 입력이든 사용합니다.
- 예상 결과
- summary가 Script completed이며 Action은 없습니다.
import type { WireSnareContext, ScriptResult } from "@wiresnare/sdk";
export function run(context: WireSnareContext): ScriptResult {
return { summary: "Script completed", notes: [] };
}
HTTP 응답 헤더를 확인하고 메모 제안
- Trigger
http-response- Capabilities
traffic.read+history.annotate- 입력 조건
- HTTP 응답이 필요합니다. Test에서는 메모 초안만 확인합니다.
- 예상 결과
- content-type 값을 포함한 메모 1개. 응답이 없으면 안내 summary만 반환합니다.
import type { WireSnareContext, ScriptResult } from "@wiresnare/sdk";
export function run(context: WireSnareContext): ScriptResult {
const response = context.http?.response;
if (!response) return { summary: "HTTP response required" };
const type = (response.headers.get("content-type") ?? "unknown").slice(0, 512);
return { summary: "Header note prepared",
annotations: [{ target: context.selection,
text: "Observed content-type: " + type, color: "blue" }] };
}
누락된 헤더를 Finding 후보로 기록
- Trigger
http-response- Capabilities
traffic.read+findings.create- 입력 조건
- CSP 헤더가 없는 HTTP 응답. 헤더 부재만으로 취약점을 확정하지 않습니다.
- 예상 결과
- 미확정 Finding 초안 1개. CSP가 있으면 초안을 만들지 않습니다.
import type { WireSnareContext, ScriptResult } from "@wiresnare/sdk";
export function run(context: WireSnareContext): ScriptResult {
const response = context.http?.response;
if (!response) return { summary: "HTTP response required" };
if (response.headers.has("content-security-policy")) {
return { summary: "CSP header observed" };
}
return { summary: "Header review candidate prepared",
findings: [{ title: "Review missing CSP header", severity: "info",
confidence: "candidate", evidence: context.selection,
summary: "The response has no CSP header. Review content type and application context before concluding a vulnerability." }] };
}
완전한 JSON 응답을 실패 없이 검사
- Trigger
context-action- Capabilities
traffic.read- 입력 조건
- 선택한 HTTP 응답의 text를 읽습니다. 잘림·바이너리·문법 오류·배열을 별도로 처리합니다.
- 예상 결과
- {"ok":true}는 notes: ["ok"]. 파싱 실패를 실행 예외로 남기지 않습니다.
import type { WireSnareContext, ScriptResult } from "@wiresnare/sdk";
export function run(context: WireSnareContext): ScriptResult {
const response = context.http?.response;
if (!response) return { summary: "HTTP response required" };
if (response.partial === true || typeof response.base64 === "string" || typeof response.text !== "string") {
return { summary: "Complete UTF-8 response required" };
}
let value: unknown;
try { value = JSON.parse(response.text); }
catch { return { summary: "Response is not valid JSON" }; }
if (!value || typeof value !== "object" || Array.isArray(value)) {
return { summary: "JSON object required" };
}
const keys = Object.keys(value).slice(0, 20).map(key => key.slice(0, 100));
return { summary: "JSON object inspected", notes: [keys.join(", ")] };
}
TCP·UDP 바이트를 원래 경계로 요약
- Trigger
tcp-chunk/udp-datagram- Capabilities
traffic.read+ui.panels- 입력 조건
- tcp-chunk 또는 udp-datagram. 일반 TCP의 read-chunk를 애플리케이션 메시지로 해석하지 않습니다.
- 예상 결과
- 동일한 바이트라도 TCP는 read-chunk, UDP는 datagram으로 표시됩니다.
import type { WireSnareContext, ScriptResult } from "@wiresnare/sdk";
export function run(context: WireSnareContext): ScriptResult {
const raw = context.raw;
if (!raw) return { summary: "Raw input required" };
const hex = raw.bytes.slice(0, 16).map(byte => byte.toString(16).padStart(2, "0")).join(" ");
return { summary: "Raw prefix inspected", panels: [{ id: "raw-prefix",
title: "Retained byte prefix", kind: "table", columns: ["Field", "Value"],
rows: [["Boundary", raw.boundary ?? "unknown"],
["Partial", String(raw.partial ?? "unknown")], ["First bytes", hex]] }] };
}
완전한 DNS 메시지의 고정 헤더 읽기
- Trigger
dns-message- Capabilities
traffic.read- 입력 조건
- DNS 보존 메시지의 첫 12바이트. DNS-over-TCP 길이 접두부를 다시 제거하지 않습니다.
- 예상 결과
- 예제 메시지는 id=4660, questions=1, answers=0. 짧거나 잘린 메시지는 파싱하지 않습니다.
import type { WireSnareContext, ScriptResult } from "@wiresnare/sdk";
export function run(context: WireSnareContext): ScriptResult {
const raw = context.raw;
if (!raw || raw.protocol !== "dns" || raw.messageBoundary !== true || raw.partial !== false || raw.bytes.length < 12) {
return { summary: "Complete DNS message required" };
}
const u16 = (offset: number) => raw.bytes[offset] * 256 + raw.bytes[offset + 1];
return { summary: "DNS header inspected",
notes: ["id=" + u16(0), "questions=" + u16(4), "answers=" + u16(6)] };
}
완전한 텍스트 WebSocket 프레임 읽기
- Trigger
websocket-frame- Capabilities
traffic.read+ui.panels- 입력 조건
- websocket.frame의 opcode·final·partial을 확인합니다. text가 원본 wire임을 가정하지 않습니다.
- 예상 결과
- WELCOME은 텍스트 패널 1개. continuation·잘린 프레임은 안내만 반환합니다.
import type { WireSnareContext, ScriptResult } from "@wiresnare/sdk";
export function run(context: WireSnareContext): ScriptResult {
const frame = context.websocket?.frame;
if (!frame || frame.opcode !== 1 || !frame.final || frame.partial || typeof frame.text !== "string") {
return { summary: "Complete text frame required" };
}
return { summary: "Text frame inspected", panels: [{ id: "ws-text",
title: "Retained frame prefix", kind: "text", text: frame.text.slice(0, 2000) }],
notes: ["Representation: " + frame.payloadRepresentation] };
}
HTTP 요청을 전송 전 Request Lab 초안으로 복사
- Trigger
context-action- Capabilities
traffic.read+requestlab.write- 입력 조건
- 완전한 HTTP 텍스트 요청. rawText를 trim하지 않고 본문 공백·CRLF를 유지합니다. 이 초안은 원본 wire 재현을 보장하지 않습니다. 이 예제는 rawText 4,000자를 넘으면 자르지 않고 건너뜁니다.
- 예상 결과
- Request Lab 초안 1개, 전송 0회. 부분 본문이면 초안을 만들지 않습니다.
import type { WireSnareContext, ScriptResult } from "@wiresnare/sdk";
function httpLocation(url: string) {
const match = /^(https?):\/\/([^/?#]+)(\/.*)?$/i.exec(url);
if (!match) return null;
const tls = match[1].toLowerCase() === "https";
const authority = match[2];
if (authority.length > 255 || /[\s@\\]/.test(authority)) return null;
const explicitPort = /^\[[^\]]+\]:\d+$/.test(authority) || /^[^:]+:\d+$/.test(authority);
return { authority, path: match[3] || "/", tls,
target: explicitPort ? authority : authority + (tls ? ":443" : ":80") };
}
export function run(context: WireSnareContext): ScriptResult {
const request = context.http?.request;
if (!request) return { summary: "HTTP request required" };
if (request.partial === true || typeof request.base64 === "string" || typeof request.text !== "string") {
return { summary: "Complete UTF-8 request required" };
}
const location = httpLocation(request.url);
if (!location) return { summary: "Supported HTTP URL required" };
const headers = request.headers.entries().map(([name, value]) => name + ": " + value);
if (!request.headers.has("host")) headers.unshift("Host: " + location.authority);
const rawText = request.method + " " + location.path + " HTTP/1.1\r\n" + headers.join("\r\n") + "\r\n\r\n" + request.text;
if (rawText.length > 4000) return { summary: "Draft exceeds this example budget" };
return { summary: "Unsent draft prepared", requestLab: [{ title: "Review copied request",
rawText, target: location.target, useTls: location.tls, groupName: "Script examples" }] };
}
보류 HTTP에 ASCII 헤더 수정안 제안
- Trigger
intercept-action/intercept-hook- Capabilities
traffic.read+traffic.proposePatch- 입력 조건
- Intercept의 보류 HTTP 입력만 사용합니다. 같은 코드는 intercept-hook에도 등록 가능하며, 자동 적용은 별도 traffic.applyPatch 권한을 검토한 뒤 선택합니다.
- 예상 결과
- X-Docs 헤더 수정안 1개. 원본 본문은 그대로이며 적용과 Forward는 별도입니다.
import type { WireSnareContext, ScriptResult } from "@wiresnare/sdk";
export function run(context: WireSnareContext): ScriptResult {
const held = context.intercept;
if (!held || (held.kind !== "req" && held.kind !== "res")) return { summary: "Held HTTP required" };
const bytes = held.bytes;
const at = bytes.findIndex((byte, i) => byte === 13 && bytes[i + 1] === 10 && bytes[i + 2] === 13 && bytes[i + 3] === 10);
if (at < 0 || bytes.length > 65000) return { summary: "Complete bounded CRLF headers required" };
const header = "X-Docs: reviewed\r\n";
return { summary: "Header patch proposed", patches: [{ sourceId: held.id,
sourceRevision: held.revision, offset: at + 2, deleteLength: 0,
insertBytes: Array.from(header, ch => ch.charCodeAt(0)) }] };
}
버튼으로 갱신하는 헤더 검색 패널
- Trigger
context-action- Capabilities
traffic.read+ui.panels- 입력 조건
- 컨텍스트 명령으로 패널을 게시한 뒤 버튼을 누릅니다. Test의 버튼은 비활성입니다. 콜백에서는 패널·summary·notes만 반환합니다.
- 예상 결과
- 초기 헤더 표, query=accept로 필터, reset으로 초기화. 헤더는 최대 20개·이름 80자·값 512자 접두부를 표시합니다. 새 History 조회나 전송은 없습니다.
import type { WireSnareContext, ScriptResult } from "@wiresnare/sdk";
export function run(context: WireSnareContext): ScriptResult {
const action = context.panelAction;
const query = action?.actionId === "reset" ? "" : action?.values.query ?? "";
const rows = (context.http?.request.headers.entries() ?? [])
.filter(([name, value]) => (name + ": " + value).toLowerCase().includes(query.toLowerCase()))
.slice(0, 20).map(([name, value]) => [name.slice(0, 80), value.slice(0, 512)]);
return { summary: "Header panel updated", panels: [{ id: "headers", title: "Retained request headers",
kind: "table", columns: ["Header", "Value"], rows,
controls: { inputs: [{ id: "query", label: "Search", kind: "text", value: query }],
actions: [{ id: "apply", label: "Apply" }, { id: "reset", label: "Reset" }] } }] };
}
프로젝트 저장소 읽기·저장·목록·삭제
- Trigger
context-action- Capabilities
traffic.read+storage.project+ui.panels- 입력 조건
- 활성 context-action + storage.project가 필요합니다. Test에서는 첫 분기로 종료합니다. scratch는 이 예제가 소유하는 임시 키입니다.
- 예상 결과
- 미리보기는 저장 작업 0회. 활성 실행은 이전 선택 표시·현재 선택 저장·키 목록·scratch 삭제 결과를 반환합니다.
import type { WireSnareContext, WireSnareSDK, ScriptResult } from "@wiresnare/sdk";
export async function run(context: WireSnareContext, ws: WireSnareSDK): Promise<ScriptResult> {
if (!ws.storage.available) return { summary: "Preview: storage unavailable" };
const previous = await ws.storage.get("last-selection");
await ws.storage.set("last-selection", { id: context.selection.id, kind: context.selection.kind });
const keys = await ws.storage.keys();
const removed = await ws.storage.delete("scratch");
return { summary: "Project selection saved", notes: ["keys=" + keys.join(","), "scratch removed=" + removed],
panels: [{ id: "previous", title: "Previous selection", kind: "text",
text: JSON.stringify(previous).slice(0, 8192) }] };
}
확인 후 body 없는 GET·HEAD 한 번 전송
- Trigger
context-action- Capabilities
traffic.read+network.send- 입력 조건
- 본문이 없고 완전한 GET/HEAD 요청. Test는 전송 미리보기이며 활성 컨텍스트 명령은 별도 확인창·프로젝트 Scope 검증이 필요합니다. 인증·Cookie를 복사하지 않습니다. 이 예제는 요청 문자열 4,000자를 넘으면 건너뜁니다.
- 예상 결과
- 요청 후보 1개. 예제의 Host 실행만으로는 네트워크 전송이 없습니다. POST·본문 있는 요청은 건너뜁니다.
import type { WireSnareContext, ScriptResult } from "@wiresnare/sdk";
function httpLocation(url: string) {
const match = /^(https?):\/\/([^/?#]+)(\/.*)?$/i.exec(url);
if (!match) return null;
const tls = match[1].toLowerCase() === "https";
const authority = match[2];
if (authority.length > 255 || /[\s@\\]/.test(authority)) return null;
const explicitPort = /^\[[^\]]+\]:\d+$/.test(authority) || /^[^:]+:\d+$/.test(authority);
return { authority, path: match[3] || "/", tls,
target: explicitPort ? authority : authority + (tls ? ":443" : ":80") };
}
export function run(context: WireSnareContext): ScriptResult {
const request = context.http?.request;
if (!request || !["GET", "HEAD"].includes(request.method) || request.partial === true ||
typeof request.base64 === "string" || request.text !== "") {
return { summary: "Complete body-free GET or HEAD required" };
}
const location = httpLocation(request.url);
if (!location) return { summary: "Supported HTTP URL required" };
const rawText = request.method + " " + location.path + " HTTP/1.1\r\nHost: " + location.authority + "\r\n\r\n";
if (rawText.length > 4000) return { summary: "Request exceeds this example budget" };
return { summary: "HTTP confirmation candidate prepared", requests: [{ title: request.method + " " + location.path,
rawText,
target: location.target, useTls: location.tls }] };
}
이전 Flow 예제 안내
이전 context.flow 예제는 현재 스크립트에서 사용할 수 없습니다. 현재 예제 보기 →