-
Notifications
You must be signed in to change notification settings - Fork 603
Fix/mssql xpcmdshell permission check #960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix/mssql xpcmdshell permission check #960
Conversation
|
Thanks for the PR! |
I don’t have any specific external resource apart from the official Microsoft documentation, but here are some useful references: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@azoxlpf please check the coding conventions with ruff. VSCode plugin highly recommended if you don't want to use the cli
|
A few other things:
|
Oh my bad, i’m already using the Ruff VS Code extension thought I’d fixed everything |
Got it, so you’d prefer to move the permission check into the check_if_admin function in mssql.py, right? |
As this allows command execution i think that would be the best way, yes (but in a different PR). Can you provide a proof or configuration guide that i can configure it myself to check if it indeed does? Just took a look at our wiki and saw that the explanation for MSSQL is missing: https://www.netexec.wiki/getting-started/using-credentials |
You can reproduce it easily by creating a login with the following SQL commands (run as sysadmin): This grants the minimum permission ( |
|
Hey i am not sure if this is the right approach. I don't think adding a bunch of try&except will solve the problem. I think the better solution is to:
See also: #997 Regarding the check on alter settings:
|
Hi, that sounds like the best approach. Then we handle the permission checks and the is_admin() update separately in another PR. |
|
And yes, an account with ALTER SETTINGS can enable xp_cmdshell but still be unable to actually execute commands through it unless it’s sysadmin (or explicitly configured via proxy). |
Description
This PR fixes issue #959, where the
enable_cmdshellMSSQL module displayedxp_cmdshell successfully enabledeven when the user lackedRECONFIGUREpermissions.Now, before attempting to enable
xp_cmdshell, the module performs:A silent permission check using
HAS_PERMS_BY_NAME(NULL, 'SERVER', 'ALTER SETTINGS')andIS_SRVROLEMEMBER('sysadmin').A verification of
sys.configurations.value_in_useto confirm the actual runtime state.If the user lacks the required permissions, NetExec will now correctly display:
Type of change
Insert an "x" inside the brackets for relevant items (do not delete options)
Screenshots (if appropriate):
Before :

After :

Checklist:
Insert an "x" inside the brackets for completed and relevant items (do not delete options)
poetry run python -m ruff check . --preview, 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)