Skip to content

feat(captures): inspect recorded packet fields with TShark - #2130

Closed
Olorinm wants to merge 5 commits into
morluto:mainfrom
Olorinm:feat/packet-captures
Closed

Olorinm wants to merge 5 commits into
morluto:mainfrom
Olorinm:feat/packet-captures

Conversation

@Olorinm

@Olorinm Olorinm commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add inspect_packet_capture / inspect-packet-capture to inspect explicitly selected fields in an existing capture through caller-supplied TShark. An analyst can correlate a device/app investigation with recorded network or Bluetooth traffic and keep the result in REA Evidence without opening a binary target.

Problem and expected behavior

Existing web HAR/mitmproxy workflows do not expose packet-capture dissection. This tool accepts a local capture, field names, display filter, decode-as rules, pass mode and optional input-packet limit. Repeated field values remain ordered string arrays and every returned packet retains its original frame number. Missing fields and empty filtered results are not treated as proof of absent device traffic.

No linked issue: this is a focused enhancement proposal. It is independent of the signal-recording proposal #2126 and can be reviewed or merged separately.

Change and scope

One file-analysis contract, optional TShark adapter, shared application validation/Evidence, CLI/MCP registration, capability/catalog entries, guide, canonical README rows in every translation, authored skill guidance and real-provider CI lane. No live capture, interfaces, device commands, installer, arbitrary process flags, automatic protocol guessing or changes to HAR/mitmproxy behavior.

Contract and boundary impact

  • Semantic owner and earliest changed stage: strict packet-capture schemas; TShark adapter owns producer arguments and selected-field parsing. Output validates frame ordering and field selection before shared Evidence construction.
  • CLI and MCP/tool-catalog contract: additive named contract with required path/fields. frame.number is always included; optional packet_limit counts input packets before filtering, and two_pass defaults to true (--no-two_pass in CLI requests false).
  • Provider, bridge, target-format, or platform compatibility: absolute REA_TSHARK_COMMAND, TShark 4.x version gate; Linux with util-linux prlimit is required; unsupported hosts fail before workspace allocation. REA_TSHARK_PRLIMIT_COMMAND can override /usr/bin/prlimit. Known producer JSON is validated; no claim that every 4.x version/format/dissector has been exercised.
  • Evidence, artifact, provenance, or reconstruction contract: source digest/size/path, configured and resolved executable/limiter paths, digests and arguments, full tool version, exact selections, selected fields, inspection stderr and separate version-probe diagnostics. Export-only _index/_score are omitted. Read scope is explicit; no total packet count is inferred from filtered output. Selectors are bounded before argv expansion: up to 1,024 fields/rules per array, 8,192 UTF-16 units per string and 32 KiB total UTF-8 text/terminator/flag/pointer budget, shared by CLI and MCP.
  • Process execution, authorization, cleanup, or containment impact: owned process supervision, cancellation, private read-only input, empty personal configuration, disabled name resolution, 30-second command deadline, 32-MiB input and 4-MiB output bounds. Failed cleanup retains ownership and observations for retry; late cancellation preserves a completed observation. The one-shot CLI awaits a close retry without masking the original failure; MCP records completed partial Evidence before error delivery, and bounded post-run identity checks complete before honoring a late abort. Before launch, prlimit enforces soft and hard limits of at most 1 GiB address space, 64 MiB per file, 30 CPU seconds and no core dumps. Stricter inherited soft/hard limits are preserved and effective values are reported. These are per-process/per-file limits, not aggregate quotas or an OS sandbox; the selected limiter, installed libraries/global configuration/plugins are trusted. Workspace failures are distinguished from invalid input. Post-run identity errors identify the private copy/tool/limiter involved and retain captured output. Resource-signal failures retain the signal and effective limits without claiming the signal proves its cause.
  • Generated metadata, package, or installation impact: source catalog registration; no generated output, dependency or installation changes.

Evidence and regression coverage

Executed real TShark verification synthesizes its own Ethernet/IPv4/UDP/DNS and Bluetooth HCI PCAPs. It checks compiled CLI/MCP parity, advertised schemas, persisted Evidence, source digests, repeated and missing fields, both pass modes, filters, decode-as, a prefix limit before matching packets, invalid requests and cleanup.

Representative output for selected network frames is {"frame.number":["2"],"ip.addr":["192.0.2.1","192.0.2.2"],"udp.port":["40000","5555"]}. Explicit DNS decode-as yields example.test; the HCI fixture yields opcode 0x0c03. Setting input limit 1 before the matching frames correctly returns an empty result with up-to-input-packet-limit scope.

Command-boundary tests additionally cover invalid producer JSON, changed private copies, nonzero exit, overflow, cancellation, cleanup retry and completed observations on late cancellation. Parser cases cover repeated, unordered, missing and malformed frame identities and unexpected fields. Additional regressions distinguish workspace failures, refuse unsupported hosts, and use a synthetic producer to verify real Linux kernel limits and a refused allocation. A second Linux process test confirms lower inherited file/CPU limits are preserved during the actual launch.

Remaining proof gaps: PCAPNG, USB, BLE ATT, other dissectors/formats and physical acquisition. macOS and Windows are explicitly unsupported. The real provider and Linux kernel-limit checks run in the linked fork workflow below; upstream CI remains visible under Checks; the links below are independently executed fork verification.

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run check — passed; existing repository lint warnings remain.
  • npm run docs:check — passed.
  • npm run verify:test-discovery — all 921 test files discovered exactly once.
  • Focused provider/parser/MCP, capability and product-catalog tests — 62 passed on macOS, three Linux-only kernel tests skipped.
  • Linux workflow on 0781d8dfb — passed: 39 provider/parser/CLI/MCP/resource-limit tests, plus 12 real TShark CLI/MCP cases on Ubuntu 24.04 with TShark 4.2.2. Kernel tests verify refused oversized allocation, lower inherited file/CPU limits, and a real SIGXFSZ termination retaining its effective file ceiling.
  • git diff --check and staged-diff Gitleaks scan — passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: no changes to those providers. This new adapter supports Linux only; earlier macOS verification does not establish the current bounded integration.
  • Package/release metadata impact: none.
  • Security/privacy/containment: selected capture content and diagnostics are preserved, including potentially sensitive fields. Ambient environment is not serialized. Only a private copy is passed to TShark; tool/library/plugin/limiter trust remains explicit. Address-space limits bound per-process expansion before allocation, without claiming an aggregate sandbox.

Review checklist

  • Concrete enhancement; one focused outcome and Conventional Commit title.
  • Reason for no linked issue stated above.
  • Public behavior and meaningful failure paths covered.
  • Owning docs, contracts and source catalog updated.
  • Representative CLI/MCP output and executed validation included.
  • Final diff checked for secrets, unrelated changes and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T11:47:52.244588Z 0781d8d New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a74f0337c2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/cli/captureCommands.ts Outdated
Comment on lines +22 to +24
// The provider cleans each call before returning, including failed calls.
// A second close here could replace a cleanup error carrying partial Evidence.
run: ({ args, options }) =>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Retry retained cleanup from the one-shot CLI

When an owned command or private-root cleanup remains incomplete, service.inspect() returns a ProviderCleanupError while TsharkCaptureProvider deliberately keeps the supervisor/root in #pending; the official one-shot CLI path performs no subsequent provider shutdown, and these lines explicitly skip service.close(), so there is no retry and an owned process or the capture copy can survive the command. Preserve the projected original error/partial Evidence, but still join or retry service.close() before the adapter exits.

AGENTS.md reference: AGENTS.md:L17-L17

Useful? React with 👍 / 👎.

const configured = this.environment.REA_TSHARK_COMMAND ?? "";
if (!isAbsolute(configured))
throw new Error("Supply absolute REA_TSHARK_COMMAND for TShark 4.x.");
const command = await realpath(configured);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve the configured TShark path before resolving it

When REA_TSHARK_COMMAND points through a symlink, as package-manager shims commonly do, realpath() overwrites the caller-selected path and the report later serializes only tool.path: command; the Evidence therefore cannot say which configured path was chosen even though it records the resolved target and digest. Keep the configured path alongside the resolved executable identity rather than discarding it.

AGENTS.md reference: AGENTS.md:L25-L25

Useful? React with 👍 / 👎.

Comment thread docs/packet-captures.md Outdated
Comment on lines +9 to +12
Supply an existing TShark 4.x installation:

```sh
export REA_TSHARK_COMMAND=/absolute/path/to/tshark

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Expose TShark support in the canonical README

When users rely on README as the provider inventory, this setup remains invisible: README.md:163 still maps saved captures only to HAR/mitmdump, and README contains neither REA_TSHARK_COMMAND nor a link to this new guide. Add a TShark packet-capture entry and link to README rather than publishing setup only in the VitePress navigation and skill.

AGENTS.md reference: AGENTS.md:L5-L5

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 34878b4f2c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/captures/TsharkCaptureProvider.ts Outdated
Comment on lines +143 to +145
`--as=${LIMITS.address_space_bytes}:${LIMITS.address_space_bytes}`,
`--fsize=${LIMITS.file_bytes}:${LIMITS.file_bytes}`,
`--cpu=${LIMITS.cpu_seconds}:${LIMITS.cpu_seconds}`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Respect inherited ceilings when applying prlimit

On a Linux process started with stricter inherited limits, these fixed pairs either raise the child's soft resource policy (for example, AS 256 MiB soft/2 GiB hard becomes 1 GiB/1 GiB) or make prlimit exit with EPERM when the inherited hard limit is below the requested value, so an otherwise safe capture cannot run. I checked util-linux prlimit --help: <limit> is a soft:hard range (or one value defining both), and HARD is the ceiling. Clamp to and report the inherited effective limits rather than unconditionally replacing both.

AGENTS.md reference: AGENTS.md:L46-L46

Useful? React with 👍 / 👎.

Comment thread src/server/registerCaptureTools.ts Outdated
withAdmittedAnalysis?: WithAdmittedAnalysis,
): void => {
const contract = toolContract("inspect_packet_capture");
const handler = createEvidenceToolHandler(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Record completed partial Evidence in the MCP session

When TShark completes but #release() fails (or cancellation lands after completion), the service returns an error containing a complete Evidence-valued partialObservation. createEvidenceToolHandler exits on !result.ok before invoking recordEvidence (src/server/contractToolHandler.ts:64-66), so this registration exposes the partial result in the response but omits it from get_evidence_bundle; use the recorded-partial path already used by the Electron handler rather than the generic failure path.

AGENTS.md reference: AGENTS.md:L5-L5

Useful? React with 👍 / 👎.

this.environment.REA_TSHARK_PRLIMIT_COMMAND ?? "/usr/bin/prlimit";
if (!isAbsolute(configuredLimiter))
throw new Error("REA_TSHARK_PRLIMIT_COMMAND must be absolute.");
const limiter = await realpath(configuredLimiter);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the configured limiter path before resolving it

The newly added limiter configuration loses provenance when REA_TSHARK_PRLIMIT_COMMAND names a symlink: realpath() replaces the caller-selected lookup path, and the report later serializes only this resolved value as resource_limiter.path. Evidence therefore cannot reconstruct which configured limiter path was chosen; retain the configured value separately from the resolved executable identity and digest.

AGENTS.md reference: AGENTS.md:L25-L25

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 43d9641591

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +10 to +12
fields: z
.array(argument)
.min(1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Bound selector arrays before building argv

On MCP requests with a generated field list whose expanded argv exceeds the host exec limit (getconf ARG_MAX is 2,097,152 in the inspected Linux environment), this schema accepts the list without any count or aggregate-size ceiling; TsharkCaptureProvider.ts:251-254 then adds two argv entries per unique field and spawn fails with E2BIG, which is returned as an output error rather than rejected input. Add bounded selector sizes or an aggregate argv budget before expansion.

AGENTS.md reference: AGENTS.md:L46-L46

Useful? React with 👍 / 👎.

read_scope:
input.packet_limit === null ? "to-eof" : "up-to-input-packet-limit",
configuration: "private-empty-personal-profile",
diagnostics: output.stderr.text,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Retain stderr from the version probe

When TShark's successful --version probe emits a loader, plugin, or configuration warning on stderr, execute captures it in version.stderr, but the report keeps only the later inspection snapshot's output.stderr. The resulting Evidence silently loses configuration diagnostics that can explain dissection behavior even though its limitations claim all stderr is retained; record diagnostics for both invocations.

AGENTS.md reference: AGENTS.md:L11-L11

Useful? React with 👍 / 👎.

{ output_bytes: LIMITS.output_bytes },
detail,
);
return new AnalysisOutputError(OPERATION, reason, detail);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Classify enforced file-limit exits as resource failures

When a capture hits the enforced file ceiling—for example, a stricter inherited RLIMIT_FSIZE while TShark writes temporary or reassembly data—runOwnedCommand returns a process failure with snapshot.signal === "SIGXFSZ", but this fallback turns it into AnalysisOutputError and the captured object above omits the signal. I checked /usr/bin/prlimit --help, which defines --fsize as “maximum size of files written by the process”; src/evm/EvmoleFailures.ts:80-105 already maps the same signal to AnalysisResourceConstraintError. Preserve the signal and report the effective file limit so CLI/MCP callers receive the actionable resource failure.

AGENTS.md reference: AGENTS.md:L25-L25

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0781d8dfb7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +520 to +523
{
cause,
userMessage: `${reason} On Linux, configure TShark 4.x through REA_TSHARK_COMMAND and util-linux prlimit through REA_TSHARK_PRLIMIT_COMMAND (default /usr/bin/prlimit).`,
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve output from rejected version probes

When --version exits zero with a TShark 3.x or otherwise nonmatching banner, execute() has already populated observedOutput, but this options object omits it, so CLI/MCP error projections expose only the generic expectation and lose the actual banner and stderr. Fresh evidence in the final tree is that successful reports now retain version_diagnostics, while this rejected-version path still discards the probe output; pass it through as capturedOutput.

AGENTS.md reference: AGENTS.md:L11-L11

Useful? React with 👍 / 👎.

return new AnalysisInputError(OPERATION, { cause }, [
{ path: ["path"], reason: "invalid_value", message: reason },
]);
return new AnalysisOutputError(OPERATION, reason, { cause });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Attach captured output to parse failures

When TShark exits zero but stdout is invalid JSON or fails the producer schema parse, execute() has already filled observedOutput, yet this fallback constructs AnalysisOutputError with only the cause. The resulting CLI/MCP error loses the exact stdout and warning stderr needed to diagnose the producer; attach observedOutput as capturedOutput here.

AGENTS.md reference: AGENTS.md:L11-L11

Useful? React with 👍 / 👎.

.digest("hex"),
);
assert.equal(report.hardware_acquisition, "not-performed");
assert.equal(report.limits.address_space_bytes, 1073741824);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor inherited limits in the real verifier

When the real verifier is launched with an inherited RLIMIT_AS below 1 GiB but still sufficient for this capture, the provider correctly clamps and reports that lower ceiling, so this assertion (and the fixed --as=1073741824:1073741824 assertion below it) falsely fails a valid run. Fresh evidence after the ceiling fix is that the provider now reports effective inherited limits, while this verifier still hard-codes the configured maximum; derive the expected value from the inherited limit and construct the expected limiter argument from the report.

AGENTS.md reference: AGENTS.md:L46-L46

Useful? React with 👍 / 👎.

@N0zoM1z0 N0zoM1z0 self-assigned this Oct 12, 2026
@N0zoM1z0 N0zoM1z0 closed this Oct 12, 2026
@morluto morluto added enhancement New feature or request area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thanks @Olorinm for proposing a focused way to inspect recorded packet fields with caller-supplied TShark. Main now exposes that selected-field workflow through the CLI and MCP and documents its limits (main).

@morluto morluto added area: runtime Process capture and runtime observation provider: tshark Analysis provider / engine: tshark labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior area: runtime Process capture and runtime observation enhancement New feature or request provider: tshark Analysis provider / engine: tshark

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants