Skip to content

extend js smb for #4707 - #7565

Merged
Mzack9999 merged 13 commits into
devfrom
4707-smb-enhance
Jul 26, 2026
Merged

extend js smb for #4707#7565
Mzack9999 merged 13 commits into
devfrom
4707-smb-enhance

Conversation

@Mzack9999

@Mzack9999 Mzack9999 commented Jul 22, 2026

Copy link
Copy Markdown
Member

Closes #4707
Related #6142

Grow nuclei SMB support on the JS stack with a shared goimpacket session, RPC enums, and an optional file-protocol UNC/smb:// bridge.

  • nuclei/smb: ListDir, ReadFile, ListTree, ListProtocols (share path sandbox + size/depth caps)
  • nuclei/dcerpc: EnumServices, EnumSessions, EnumProcesses, EnumLoggedOnUsers (users/psexec already existed)
  • smbsession + gptransport: one dial/policy path for smb + dcerpc file helpers
  • file: optional smb-user/password/domain/hash/port for UNC and smb:// targets
  • docs: capability map; flood / mbenum / print-text left out of scope on purpose

Summary by CodeRabbit

  • New Features
    • Added SMB remote support for the file protocol, including SMB URLs and UNC paths for listing directories, reading files, and recursive tree traversal.
    • Exposed SMB capability/dialect reporting and added new SMB list/read/tree operations returning share entries.
    • Expanded Windows DCERPC enumeration coverage (services, sessions, processes, logged-on users) with SMB template routing guidance.
  • Bug Fixes
    • Enforced execution-bound dialing and host allowlisting before any connection for both SMB and DCERPC.
    • Strengthened SMB share/path parsing and validation (including traversal protection) and improved remote file handling.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 76f7d10d-dc02-4c0d-95e7-ec19d48f0ebe

📥 Commits

Reviewing files that changed from the base of the PR and between caaaff5 and 3631d7b.

📒 Files selected for processing (2)
  • pkg/js/libs/smbsession/session.go
  • pkg/js/libs/smbsession/session_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/js/libs/smbsession/session.go
  • pkg/js/libs/smbsession/session_test.go

Walkthrough

Changes

SMB and DCERPC expansion

Layer / File(s) Summary
SMB session and path foundations
pkg/js/libs/smbsession/*
Adds shared SMB credentials, path validation, session operations, bounded tree traversal, and fake-backend tests.
SMB JavaScript API integration
pkg/js/libs/smb/*, pkg/js/libs/dcerpc/dcerpc.go, go.mod
Adds memoized SMB directory/file APIs, protocol metadata conversion, and routes DCERPC SMB helpers through smbsession.
Execution-bound transport
pkg/js/libs/gptransport/*, pkg/js/libs/dcerpc/transport_init.go, pkg/js/libs/dcerpc/wmiexec.go
Centralizes execution ID extraction, host policy checks, fastdialer routing, and global goimpacket dial enforcement.
DCERPC enumeration APIs
pkg/js/libs/dcerpc/enum.go, pkg/js/libs/dcerpc/*_test.go
Adds service, session, process, and logged-on-user enumeration methods with mapped JS-facing records and policy tests.
SMB file protocol bridge
pkg/protocols/file/*
Adds SMB/UNC parsing, credential and port resolution, remote enumeration and reading, execution integration, configuration fields, and tests.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

Suggested reviewers: dogancanbakir, ehsandeep

Poem

I’m a rabbit with packets tucked under my ear,
SMB paths now hop through the forest clear.
Shares bloom, files dance, RPC services gleam,
Safe little dialers guard every stream.
I nibble the tests—what a wonderful byte!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR adds SMB sessions, listing, protocols, and enumeration, but it does not implement smb-flood, smb-mbenum, or smb-print-text from #4707. Either implement the remaining SMB feature scripts listed in #4707 or update the linked issue scope to exclude them.
Docstring Coverage ⚠️ Warning Docstring coverage is 19.75% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and clearly points to the JS SMB expansion tied to issue #4707.
Out of Scope Changes check ✅ Passed The changes stay focused on SMB session, enumeration, and UNC file-bridge support with no clear unrelated additions.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 4707-smb-enhance

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 9

🧹 Nitpick comments (1)
pkg/js/libs/dcerpc/transport_init.go (1)

16-17: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Redundant "ensure init runs" reference.

Go executes every imported package's init() regardless of symbol usage, and gptransport is already imported and used by the wrapper above (line 13). This var _ = gptransport.NewExecDialer line adds nothing.

♻️ Proposed cleanup
-
-// Ensure gptransport init() runs whenever dcerpc is imported.
-var _ = gptransport.NewExecDialer
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/js/libs/dcerpc/transport_init.go` around lines 16 - 17, Remove the
redundant blank assignment referencing gptransport.NewExecDialer in the dcerpc
transport initialization code. Keep the existing gptransport import and wrapper
usage unchanged so package initialization continues through the normal import
mechanism.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/js/libs/dcerpc/enum.go`:
- Line 32: Add TSTS and tsts to the repository’s typos allow-list configuration,
preserving the legitimate technical abbreviation and the gptsts package
references in the surrounding code and comments.

In `@pkg/js/libs/smb/memo.smb.go`:
- Around line 45-90: Update memoizedlistDir, memoizedreadFile, and
memoizedlistTree so their memoization keys no longer use colon-concatenated raw
inputs or expose passwords. Encode the complete structured input fields
unambiguously, hash the encoded payload, and use the resulting digest (with an
operation discriminator) as the key passed to protocolstate.Memoizer.Do,
preserving distinct keys for each operation and input combination.

In `@pkg/js/libs/smb/smb_share.go`:
- Around line 12-59: The `@memo` annotations on listShares, listDir, readFile, and
listTree cause password values to enter generated memoization keys. Remove
memoization from these credential-bearing functions, or configure the generated
wrappers to exclude user/password while preserving correct cache isolation for
authenticated calls; do not allow plaintext passwords in memoizer keys.

In `@pkg/js/libs/smbsession/session.go`:
- Around line 59-87: The Dial function currently ignores its ctx argument and
can block indefinitely in client.Connect. Add a context-aware cancellation and
timeout wrapper around gpsmb.Client.Connect, ensuring Dial returns promptly when
ctx is canceled or its deadline expires while preserving the existing connection
and error behavior otherwise.
- Around line 185-210: The readFile function currently calls shareBackend.Cat,
buffering the entire remote file before enforcing maxBytes. Extend shareBackend
with Open and Read support, then update readFile to open the normalized path and
stream it through io.LimitReader with a maxBytes+1 limit, preserving the
existing oversized-file error and returning only content within the limit.

In `@pkg/protocols/file/find.go`:
- Around line 23-36: Update getInputPaths to accept a context parameter and use
it for enumerateSMBInputs instead of context.Background(). In
ExecuteWithResults, pass input.Context() into getInputPaths, and remove the
no-op request.options branch while preserving the existing SMB path handling and
callback deduplication.

In `@pkg/protocols/file/smb_bridge.go`:
- Around line 65-135: Eliminate redundant SMB authentication by reusing a single
smbsession.Session across enumeration and file reads for one scan, keyed by
execution and connection credentials (execID, host, port, and resolved creds).
Update enumerateSMBInputs and readSMBFile, plus their request-processing
callers, to obtain and reuse the shared session for both directory entries and
single-file targets, closing it only after the scan completes; avoid dialing
independently per expanded file.
- Around line 116-135: Update readSMBFile after obtaining execID from
request.executionID() to return the same “smb file target requires an
initialized execution id” error when it is empty, before calling
smbsession.Dial. Keep the existing session dialing and file-reading flow
unchanged for initialized execution IDs.
- Around line 65-114: Update enumerateSMBInputs to use
isDirectorySMBTarget(input), or an equivalent trailing-slash directory check,
instead of relying on target.Path != ".". Ensure SMB targets with subdirectory
paths ending in a slash are enumerated through the existing directory-listing
flow rather than returned as files.

---

Nitpick comments:
In `@pkg/js/libs/dcerpc/transport_init.go`:
- Around line 16-17: Remove the redundant blank assignment referencing
gptransport.NewExecDialer in the dcerpc transport initialization code. Keep the
existing gptransport import and wrapper usage unchanged so package
initialization continues through the normal import mechanism.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 53867c2f-d217-4983-bd07-62cbe46334ea

📥 Commits

Reviewing files that changed from the base of the PR and between 1709267 and 767e064.

⛔ Files ignored due to path filters (3)
  • go.sum is excluded by !**/*.sum
  • pkg/js/generated/ts/dcerpc.ts is excluded by !**/generated/**
  • pkg/js/generated/ts/smb.ts is excluded by !**/generated/**
📒 Files selected for processing (26)
  • go.mod
  • pkg/js/libs/dcerpc/dcerpc.go
  • pkg/js/libs/dcerpc/enum.go
  • pkg/js/libs/dcerpc/enum_policy_test.go
  • pkg/js/libs/dcerpc/enum_test.go
  • pkg/js/libs/dcerpc/transport_init.go
  • pkg/js/libs/dcerpc/wmiexec.go
  • pkg/js/libs/gptransport/dialer.go
  • pkg/js/libs/gptransport/dialer_test.go
  • pkg/js/libs/smb/memo.smb.go
  • pkg/js/libs/smb/smb.go
  • pkg/js/libs/smb/smb_path.go
  • pkg/js/libs/smb/smb_policy_test.go
  • pkg/js/libs/smb/smb_share.go
  • pkg/js/libs/smb/smb_share_test.go
  • pkg/js/libs/smbsession/path.go
  • pkg/js/libs/smbsession/path_test.go
  • pkg/js/libs/smbsession/session.go
  • pkg/js/libs/smbsession/session_test.go
  • pkg/protocols/file/file.go
  • pkg/protocols/file/find.go
  • pkg/protocols/file/request.go
  • pkg/protocols/file/smb_bridge.go
  • pkg/protocols/file/smb_bridge_test.go
  • pkg/protocols/file/smb_path.go
  • pkg/protocols/file/smb_path_test.go
💤 Files with no reviewable changes (1)
  • go.mod

Comment thread pkg/js/libs/dcerpc/enum.go Outdated
Comment thread pkg/js/libs/smb/memo.smb.go
Comment thread pkg/js/libs/smb/smb_share.go
Comment thread pkg/js/libs/smbsession/session.go
Comment thread pkg/js/libs/smbsession/session.go
Comment thread pkg/protocols/file/find.go
Comment thread pkg/protocols/file/smb_bridge.go
Comment thread pkg/protocols/file/smb_bridge.go
Comment thread pkg/protocols/file/smb_bridge.go
@coderabbitai coderabbitai Bot mentioned this pull request Jul 24, 2026

@dwisiswant0 dwisiswant0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

banger

but conflicting.

Comment thread pkg/js/libs/smb/memo_key.go Dismissed
@Mzack9999
Mzack9999 merged commit 1f39f73 into dev Jul 26, 2026
19 checks passed
@Mzack9999
Mzack9999 deleted the 4707-smb-enhance branch July 26, 2026 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SMB Enhancement

3 participants