PySQLRecon
PySQLRecon is a Python port of the awesome SQLRecon project by @sanjivkawa. See the commands section for a list of capabilities.
Post demonstrating SCCM TAKEOVER-1 with PySQLRecon.
Install
PySQLRecon can be installed with pip3 install pysqlrecon or by cloning this repository and running pip3 install .
Commands
All of the main modules from SQLRecon have equivalent commands. Commands noted with [PRIV] require elevated privileges or sysadmin rights to run. Alternatively, commands marked with [NORM] can likely be run by normal users and do not require elevated privileges.
Support for impersonation ([I]) or execution on linked servers ([L]) are denoted at the end of the command description.
adsi [PRIV] Obtain ADSI creds from ADSI linked server [I,L]
agentcmd [PRIV] Execute a system command using agent jobs [I,L]
agentstatus [PRIV] Enumerate SQL agent status and jobs [I,L]
checkrpc [NORM] Enumerate RPC status of linked servers [I,L]
clr [PRIV] Load and execute .NET assembly in a stored procedure [I,L]
columns [NORM] Enumerate columns within a table [I,L]
databases [NORM] Enumerate databases on a server [I,L]
disableclr [PRIV] Disable CLR integration [I,L]
disableole [PRIV] Disable OLE automation procedures [I,L]
disablerpc [PRIV] Disable RPC and RPC Out on linked server [I]
disablexp [PRIV] Disable xp_cmdshell [I,L]
enableclr [PRIV] Enable CLR integration [I,L]
enableole [PRIV] Enable OLE automation procedures [I,L]
enablerpc [PRIV] Enable RPC and RPC Out on linked server [I]
enablexp [PRIV] Enable xp_cmdshell [I,L]
impersonate [NORM] Enumerate users that can be impersonated
info [NORM] Gather information about the SQL server
links [NORM] Enumerate linked servers [I,L]
olecmd [PRIV] Execute a system command using OLE automation procedures [I,L]
query [NORM] Execute a custom SQL query [I,L]
rows [NORM] Get the count of rows in a table [I,L]
sample [NORM] Query a sample of table data [I,L]
sccm [SUBM] Submodule for SCCM specific commands
search [NORM] Search a table for a column name [I,L]
smb [NORM] Coerce NetNTLM auth via xp_dirtree [I,L]
tables [NORM] Enumerate tables within a database [I,L]
users [NORM] Enumerate users with database access [I,L]
whoami [NORM] Gather logged in user, mapped user and roles [I,L]
xpcmd [PRIV] Execute a system command using xp_cmdshell [I,L]
SCCM Commands
SCCM commands can be found by running pysqlrecon [OPTIONS] sccm -h (required global flags will need to be specified for this to work - see usage)
addadmin [PRIV] Elevate an account to Full Administrator [I]
credentials [NORM] Display encrypted credentials [I]
logons [NORM] Display SCCM clients and last logged on user [I]
removeadmin [PRIV] Remove elevated account or elevated privileges [I]
sites [NORM] Gather SCCM site info [I]
taskdata [NORM] Decrypt task sequences [I]
tasklist [NORM] Display task sequences [I]
users [NORM] Enumerate SCCM users [I]
Usage
PySQLRecon has global options (available to any command), with some commands introducing additional flags. All global options must be specified before the command name:
pysqlrecon [GLOBAL_OPTS] COMMAND [COMMAND_OPTS]
View global options:
pysqlrecon --help
View command specific options:
pysqlrecon [GLOBAL_OPTS] COMMAND --help
Change the database authenticated to, or used in certain PySQLRecon commands (query, tables, columns rows), with the --database flag.
Target execution of a PySQLRecon command on a linked server (instead of the SQL server being authenticated to) using the --link flag.
Impersonate a user account while running a PySQLRecon command with the --impersonate flag.
--link and --impersonate are incompatible.
Usage with ntlmrelayx
PySQLRecon can be used with proxychains to take advantage of relayed authentication targeting a mssql:// service. Due to the way ntlmrelayx sessions work, the --database parameter will not be respected when running PySQLRecon (the relay session will always be connected to the master database). This can come into play especially when using SCCM modules, which require the site database to be sepecified. To fix this, first change the database context using the query module (this will persist across any subsequent PySQLRecon usage, with the same relay session). Example:
proxychains4 pysqlrecon -t <target> -d <DOMAIN> -u <username> -p FAKE query --query 'use new_db_name'
You can now run modules/queries that target resources within that specifc database, even without specifying --database, from the same ntlmrelayx session.
Development
pysqlrecon uses uv to manage dependencies. Install from source and setup for development with:
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install pysqlrecon
git clone https://github.com/tw1sm/pysqlrecon
cd pysqlrecon
uv sync
uv run pysqlrecon --help
Adding a Command
PySQLRecon is easily extensible - see the template and instructions in resources
TODO
- Add SQLRecon SCCM commands
- Add Azure SQL DB support?
References and Credits
- Impacket
- @sanjivkawa for the SQLRecon project
- https://securityintelligence.com/x-force/databases-beware-abusing-microsoft-sql-server-with-sqlrecon/
- https://gist.github.com/skahwah/a585e176e4a5cf319b0c759637f5c410
- Also checkout MSSqlPwner for other offensive MSSQL capabilities written in Python
- PXEThief
Metadata
Release files for pysqlrecon 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pysqlrecon-0.3.1.tar.gz | 30.8 kB | Without provenance | Details for pysqlrecon-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pysqlrecon-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for pysqlrecon-0.3.1-py3-none-any.whl |
Total release size: 87.6 kB
Release files / pysqlrecon-0.3.1.tar.gz
| Download URL | pysqlrecon-0.3.1.tar.gz |
|---|---|
| Size | 30.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eee7748415ec1a44ca3b7ab76920e072512ec704769d8f347afc067849bde729
|
|
BLAKE2b-256 checksum How to use checksums |
7144fcdb19ec2c0824a47850f21f9aed7450b49533dc0973e6f5a908eb70fc51
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / pysqlrecon-0.3.1-py3-none-any.whl
| Download URL | pysqlrecon-0.3.1-py3-none-any.whl |
|---|---|
| Size | 56.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8cd24638000bcf5ded56bc185c3595d0e00e4ef184862d4788a944a36e2212d8
|
|
BLAKE2b-256 checksum How to use checksums |
8b05130ac2b4d3567841f7067fc9a22356f9b32f9b2c9434b273406f3bf46c7e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for pysqlrecon 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.