feat(captures): inspect recorded packets with bounded TShark delivery (#2318)

Inspect selected fields in existing captures through shared CLI/MCP Evidence.
Page matching frames without changing dissection or two-pass read coverage;
retain failed descriptor/process cleanup ownership and reject excess admission.

Verified with real TShark 4.0.17 and 4.2.2, public Wireshark recordings,
owned HTTP application traffic, real CLI/MCP workflows and schema checks.

Co-authored-by: Olorinm <59321404+Olorinm@users.noreply.github.com>
Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
This commit is contained in:
Ysopwnable
2026-10-12 19:35:35 +00:00
committed by GitHub
co-authored by Olorinm
parent 570c40cde5
commit f611d8ce72
50 changed files with 2850 additions and 0 deletions
+17
View File
@@ -1,3 +1,6 @@
import type { PacketCaptureService } from "../application/captures/PacketCaptureService.js";
import { createPacketCaptureService } from "../composition/captures.js";
import { registerCaptureTools } from "./registerCaptureTools.js";
import type { WasmArtifactService } from "../application/wasm/WasmArtifactService.js";
import { wasmArtifactModule } from "../composition/wasm.js";
import { registerWasmTools } from "./registerWasmTools.js";
@@ -119,6 +122,7 @@ const ACTIVE_TARGET_INSTRUCTIONS =
export interface CreateServerOptions {
readonly environment?: Readonly<NodeJS.ProcessEnv>;
readonly delivery?: ToolResultDelivery;
readonly packetCapture?: PacketCaptureService;
readonly wasmArtifact?: WasmArtifactService;
readonly evmInterface?: EvmInterfaceService;
readonly sqliteDatabase?: SqliteDatabaseService;
@@ -161,6 +165,9 @@ const installSessionToolAvailability = (
const basePolicy = sessionAvailabilityPolicy(options.availabilityPolicy, {
optionalProviderLoadFailures: options.optionalProviderLoadFailures,
optionalFeatures: {
packetCaptureEnabled:
options.packetCapture !== undefined ||
(linux && isAbsolute(environment.REA_TSHARK_COMMAND ?? "")),
wasmArtifactEnabled:
options.wasmArtifact !== undefined ||
isAbsolute(environment.REA_WABT_BIN_DIRECTORY ?? ""),
@@ -292,6 +299,8 @@ export const createServer = (
environment,
options.wasmArtifact,
);
const packetCapture =
options.packetCapture ?? createPacketCaptureService(environment);
const apktool =
options.apktoolAnalysis ??
createApktoolResourceAnalysisProvider(environment);
@@ -304,6 +313,7 @@ export const createServer = (
android.close(),
fridaInstrumentation.closeAll(),
wasmArtifact.close(),
packetCapture.close(),
apktool.close(),
jeb.close(),
adbDevice.close(),
@@ -384,6 +394,13 @@ export const createServer = (
for (const result of results)
if (result.status === "rejected") throw result.reason;
};
registerCaptureTools(
server,
packetCapture,
toolLogger,
recordEvidence,
analysisAdmission,
);
registerConfiguredAnalysisTools(
toolContext,
android,
+31
View File
@@ -0,0 +1,31 @@
import type { EvidenceMcpServer } from "./EvidenceMcpServer.js";
import type { PacketCaptureService } from "../application/captures/PacketCaptureService.js";
import type { EvidenceWriter } from "../application/investigation/InvestigationRecordPort.js";
import { toolContract } from "../contracts/toolContracts.js";
import type { Logger } from "pino";
import type { WithAdmittedAnalysis } from "./analysisAdmission.js";
import { createEvidenceToolHandler } from "./contractToolHandler.js";
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
/** Bind the named capture contract through shared admission and retained Evidence delivery. */
export const registerCaptureTools = (
server: EvidenceMcpServer,
service: PacketCaptureService,
logger: Logger,
recordEvidence?: EvidenceWriter["recordEvidence"],
withAdmittedAnalysis?: WithAdmittedAnalysis,
): void => {
const contract = toolContract("inspect_packet_capture");
const handler = createEvidenceToolHandler(
server,
(input, options) => service.inspect(input, options),
logger,
recordEvidence,
withAdmittedAnalysis,
);
server.registerTool(
contract.name,
toolRegistrationOptions(contract),
handler(contract),
);
};
+3
View File
@@ -8,6 +8,7 @@ export interface SessionAvailabilityDefaults {
| undefined;
readonly optionalFeatures?: Pick<
AvailabilityPolicy,
| "packetCaptureEnabled"
| "wasmArtifactEnabled"
| "evmInterfaceEnabled"
| "browserObservationEnabled"
@@ -32,6 +33,8 @@ export const sessionAvailabilityPolicy = (
const policy =
configured ??
(() => ({
packetCaptureEnabled:
defaults.optionalFeatures?.packetCaptureEnabled ?? false,
wasmArtifactEnabled:
defaults.optionalFeatures?.wasmArtifactEnabled ?? false,
evmInterfaceEnabled: