[WIP] Rework the linked server usage#1271
Draft
Dfte wants to merge 3 commits into
Draft
Conversation
Dfte
requested review from
Marshall-Hallenbeck,
NeffIsBack,
mpgn and
zblurx
as code owners
June 5, 2026 15:34
Contributor
Author
|
Will have to merge that as well, wrapping both linked-server and impersonation will be absolutely powerful #1271 |
Dfte
marked this pull request as draft
June 8, 2026 09:29
13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
So far NXC MSSQL can list linked servers via the enum_links module which output is the following:
The module is great because it allows listing both the local login, the remote login and the target server.
From there a user could use modules *_links to execute code on the linked server. Let's say the user wants to get the version of the SQL database via the following request:
SELECT @@VERSION;If using the *_links module, the module will wrap it that way:
EXEC('SELECT @@VERSION;') AT [TARGET_LINKED_SERVER];Whil it works, I believe we shouldn't have a module to use this feature as it clearly limitates what we can do with it. For example, it is not yet possible to do a simple SQL query via a linked server. Why ? Because modules only allow running xpcmdshell via a linked server. It's not a proper way of handling this amazing feature so here is my proposal.
First, note this is a crash test PR (hence WIP). The idea is to provide a working solution and estimate whether or not we should deploy it globally. To handle this issue, I added the following function:
It does a few things:
For testing purpose I have added the following --list-linked-servers option:
Whose output is the following:
From the output we understand that, being connected on SRV22 as WHITEFLAG/administrator, I can run queries as SA on DC25. Using the --on-linked-server, I can now select where to run the query:
nxc mssql 192.168.56.72 -u Administrator -p Defte@WF -q "SELECT @@VERSION;" --on-linked-server DC25And here without the option, we have a different output:
Because:
Now about the wrapping, we simply have the following modification to replicate everywher we use self.conn.sql_query:
Doing so we will be able to eliminate 4 modules that were great at the time but not necessary anymore. This will also allow using linked servers on SQLEXEC methods which is why I believe we should rework that part.
Type of change
Insert an "x" inside the brackets for relevant items (do not delete options)
Setup guide for the review
More on that later.
Screenshots (if appropriate):
Checklist:
Insert an "x" inside the brackets for completed and relevant items (do not delete options)
poetry run ruff check ., use--fixto automatically fix what it can)tests/e2e_commands.txtfile if necessary (new modules or features are required to be added to the e2e tests)