Skip to content
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

Mssql xp_cmdshell added "is enabled" check #405

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

0xQRx
Copy link

@0xQRx 0xQRx commented Aug 24, 2024


name: Pull request
about: Update code to add an enhancement
title: Add functionality to check if xp_cmdshell is enabled before execution
labels: enhancement

Description

This update adds functionality to check if xp_cmdshell is enabled before attempting to enable it. This enhancement prevents unnecessary changes to the state of xp_cmdshell. The updated code now:

  • Checks if xp_cmdshell is enabled using sp_configure.
  • Executes the command if xp_cmdshell is already enabled, without altering its state.
  • Enables xp_cmdshell only if it is disabled, executes the command, and then restores the original state by disabling it again.

Motivation: This change ensures that xp_cmdshell is not disabled after the execution if it was enabled initially, maintaining the target system's configuration integrity.

Dependencies: No new dependencies were introduced in this change.

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Target with xp_cmdshell already enabled: Verified that the command executes without disabling xp_cmdshell.
  • Target with xp_cmdshell disabled: Verified that the command enables xp_cmdshell, executes successfully, and restores the disabled state afterward.

Test Configuration:

  • Python version: Python 3.11.9
  • OS: Linux kali 6.6.9-amd64
  • Target MSSQL version: Microsoft SQL Server 2022 (RTM) - 16.0.1000.6 (X64) Oct 8 2022
  • Locally tested with a Windows 10 target running Microsoft SQL Server 2022

Screenshots:

xp_cmdshell disabled flow:

cmdshell_disabled
cmdshell_disabled_2

xp_cmdshell enabled flow:

cmdshell_enabled

0xQRx and others added 2 commits August 24, 2024 18:09
… is already enabled, to avoid altering its state
@NeffIsBack
Copy link
Contributor

Oh very nice! That was really needed, encountered the problem on a pentest myself. Thanks for the PR!

@NeffIsBack NeffIsBack added bug-fix This Pull Request fixes a bug enhancement New feature or request labels Aug 24, 2024
@mpgn mpgn added this to the v1.3.0 milestone Aug 25, 2024
@NeffIsBack NeffIsBack modified the milestones: v1.3.0, v1.4.0 Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-fix This Pull Request fixes a bug enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants