Skip to content

Improve MSSQL JS fingerprint via TDS prelogin - #7577

Merged
Mzack9999 merged 6 commits into
devfrom
4864-mssql-fingerprint
Jul 27, 2026
Merged

Improve MSSQL JS fingerprint via TDS prelogin#7577
Mzack9999 merged 6 commits into
devfrom
4864-mssql-fingerprint

Conversation

@Mzack9999

@Mzack9999 Mzack9999 commented Jul 24, 2026

Copy link
Copy Markdown
Member

Summary

Summary by CodeRabbit

  • New Features
    • Added MSSQL pre-login fingerprinting to capture protocol version/build, encryption settings, and server capability indicators.
    • Added a new integration test case for the MSSQL fingerprint template.
  • Bug Fixes
    • Updated MSSQL detection to rely on the fingerprint probe for more consistent identification, including correct handling of non-MSSQL replies as a negative match.
  • Tests
    • Added unit tests for pre-login parsing/validation and detection behavior.
    • Added integration-style tests using an in-process TCP mock server and template execution.

@coderabbitai

coderabbitai Bot commented Jul 24, 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: d114cd0d-76e6-4667-a609-d997bc9560c3

📥 Commits

Reviewing files that changed from the base of the PR and between ba31a68 and af049c2.

📒 Files selected for processing (1)
  • internal/tests/integration/javascript_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/tests/integration/javascript_test.go

Walkthrough

Adds MSSQL TDS pre-login fingerprinting with parsed server metadata, memoized execution, MSSQL detection reuse, and JavaScript integration tests backed by a localhost mock listener.

Changes

MSSQL fingerprinting

Layer / File(s) Summary
TDS pre-login parsing and validation
pkg/js/libs/mssql/fingerprint.go, pkg/js/libs/mssql/fingerprint_test.go
Defines MSSQLInfo, validates and parses TDS pre-login responses, maps encryption modes, and tests parsed fields and invalid packet types.
Fingerprint execution and detection reuse
pkg/js/libs/mssql/fingerprint.go, pkg/js/libs/mssql/memo.fingerprint.go, pkg/js/libs/mssql/mssql.go, pkg/js/libs/mssql/fingerprint_test.go
Performs allowlisted TCP fingerprinting, memoizes results, and uses fingerprint outcomes in IsMssql.
JavaScript template integration test
internal/tests/integration/javascript_mssql_test.go, internal/tests/integration/javascript_test.go
Registers the MSSQL JavaScript testcase and validates one result against a mock pre-login listener.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant JavaScriptTemplate
  participant MSSQLClient
  participant MockMSSQLServer
  JavaScriptTemplate->>MSSQLClient: Request MSSQL fingerprint
  MSSQLClient->>MockMSSQLServer: Send TDS pre-login request
  MockMSSQLServer-->>MSSQLClient: Return crafted pre-login response
  MSSQLClient-->>JavaScriptTemplate: Return parsed MSSQLInfo
Loading

Poem

I’m a rabbit with packets to parse,
Through tunnel and carrot-lit wire I race.
TDS crumbs reveal version and mode,
Cached hops lighten the network road.
One mock server answers—what a fine trace!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 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 accurately reflects the main change: improving MSSQL fingerprinting via TDS prelogin.
Linked Issues check ✅ Passed The PR adds MSSQL prelogin fingerprinting with version/config parsing and updates IsMssql to use the new probe as requested.
Out of Scope Changes check ✅ Passed The new tests, memoized wrapper, and integration template all support the MSSQL fingerprinting work and appear in scope.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ 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 4864-mssql-fingerprint

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: 1

🤖 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/mssql/fingerprint.go`:
- Around line 100-159: Update fingerprintMssql and its IsMssql caller to
distinguish parsePreloginResponse failures or missing MSSQL version tokens from
transport and permission errors: return a non-MSSQL result as (false, nil) for
unparseable/non-MSSQL TDS responses, while continuing to propagate dial,
allowlist, initialization, read, write, and other probe failures as errors.
🪄 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 Plus

Run ID: fdba497a-e6a5-4a67-9e84-768b1ed03ceb

📥 Commits

Reviewing files that changed from the base of the PR and between bcf2089 and 6787cdb.

⛔ Files ignored due to path filters (3)
  • internal/tests/integration/testdata/protocols/javascript/mssql-fingerprint.yaml is excluded by !**/*.yaml
  • pkg/js/generated/go/libmssql/mssql.go is excluded by !**/generated/**
  • pkg/js/generated/ts/mssql.ts is excluded by !**/generated/**
📒 Files selected for processing (6)
  • internal/tests/integration/javascript_mssql_test.go
  • internal/tests/integration/javascript_test.go
  • pkg/js/libs/mssql/fingerprint.go
  • pkg/js/libs/mssql/fingerprint_test.go
  • pkg/js/libs/mssql/memo.fingerprint.go
  • pkg/js/libs/mssql/mssql.go

Comment thread pkg/js/libs/mssql/fingerprint.go

@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: 1

🤖 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/mssql/fingerprint_test.go`:
- Around line 68-73: Update TestFingerprintMarksInvalidPacketAsNotMssql to
exercise fingerprintMssql with the invalid packet and assert it returns a
non-MSSQL result while preserving the expected error behavior. Do not manually
wrap the parser error with errNotMssql, since that only tests the test’s own
fmt.Errorf call; if testing isMssqlResult directly instead, pass the wrapped
value into it and assert (false, nil).
🪄 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 Plus

Run ID: 7a5f1d7b-24d3-4806-8afd-8d35fb46a6b7

📥 Commits

Reviewing files that changed from the base of the PR and between 6787cdb and 604cffc.

📒 Files selected for processing (3)
  • pkg/js/libs/mssql/fingerprint.go
  • pkg/js/libs/mssql/fingerprint_test.go
  • pkg/js/libs/mssql/mssql.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/js/libs/mssql/mssql.go
  • pkg/js/libs/mssql/fingerprint.go

Comment thread pkg/js/libs/mssql/fingerprint_test.go
@Mzack9999
Mzack9999 merged commit e6e558d into dev Jul 27, 2026
19 checks passed
@Mzack9999
Mzack9999 deleted the 4864-mssql-fingerprint branch July 27, 2026 09:07
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.

Add/Improve Fingerprint data in Mssql Module

1 participant