A C# MS SQL toolkit designed for offensive reconnaissance and post-exploitation

渗透技巧 2年前 (2022) admin
632 0 0

SQLRecon

Description

A C# MS-SQL toolkit designed for offensive reconnaissance and post-exploitation. For detailed usage information on each technique, refer to the wiki.

Usage

You can grab a copy of SQLRecon from the releases page. Alternatively, feel free to compile the solution yourself This should be as straight forward as cloning the repo, double clicking the solution file and building.

Mandatory Arguments

The mandatory arguments consist of an authentication type (either Windows, Local or Azure), connection parameters and a module.

  • -a – Authentication Type
    • -a Windows – Use Windows authentication. This uses the current users token.
    • -a Local – Use local authentication. This requires the credentials for a local database user.
    • -a Azure – Use Azure AD domain username and password authentication. This requires the credentials for a domain user.

If the authentication type is Windows, then you will need to supply the following parameters.

  • -s SERVERNAME – SQL server hostname
  • -d DATABASE – SQL server database name
  • -m MODULE – The module you want to use

If the authentication type is Local, then you will need to supply the following parameters.

  • -d DATABASE – SQL server database name
  • -u USERNAME – Username of local SQL user
  • -p PASSWORD – Password of local SQL user
  • -m MODULE – The module you want to use

If the authentication type is Azure, then you will need to supply the following parameters.

  • -d DATABASE – SQL server database name
  • -r DOMAIN.COM – FQDN of Domain
  • -u USERNAME – Username of domain user
  • -p PASSWORD – Password of domain user
  • -m MODULE – The module you want to use

There are cases where a MS SQL Server might not be listening on a standard TCP port. A good example is MS SQL failover clustering. If the authentication type is Windows or Local, you can optionally set a non-standard connection port by supplying the -r PORT flag. By default, SQLRecon will connect to a databases via TCP Port 1433.

Standard Modules

Standard modules are used to interact against a single MS SQL server.

  • query -o QUERY – Execute an arbitrary SQL query
  • whoami – See what user you are logged in as, mapped as and what roles exist
  • databases – Show all databases present on the SQL server
  • tables -o DATABASE – Show all tables in the database you specify
  • search -o KEYWORD – Search column names within tables of the database you are connected to
  • smb -o SHARE – Capture NetNTLMv2 hash
    ↓ Command Execution (requires sysadmin role or similar)
  • enablexp – Enable xp_cmdshell
  • disablexp – Disable xp_cmdshell
  • xpcmd -o COMMAND – Execute an arbitrary system command using xp_cmdshell
  • enableole – Enable OLE Automation Procedures
  • disableole – Disable OLE Automation Procedures
  • olecmd -o COMMAND – Execute an arbitrary system command using OLE Automation Procedures
  • enableclr – Enable Custom CLR Assemblies
  • disableclr – Disable Custom CLR Assemblies
  • clr -o DLLPATH -f FUNCTION – Load and execute a .NET assembly within a custom stored procedure
  • agentstatus – Check to see if SQL agent is running and obtain jobs
  • agentcmd -o COMMAND – Execute an arbitary system command

Impersonation Modules

Impersonation modules are used to interact against a single MS SQL server, under the context of an impersonated SQL user.

  • impersonate – Enumerate any user accounts that can be impersonated
  • iwhoami – See what user you are logged in as, mapped as and what roles exist
  • iquery -i IMPERSONATEUSER -o QUERY – Execute an arbitrary SQL query as an impersonated user
    ↓ Command Execution (requires sysadmin role or similar)
  • ienablexp -i IMPERSONATEUSER – Enable xp_cmdshell
  • idisablexp -i IMPERSONATEUSER– Disable xp_cmdshell
  • ixpcmd -i IMPERSONATEUSER -o COMMAND – Execute an arbitrary system command using xp_cmdshell
  • ienableole -i IMPERSONATEUSER – Enable OLE Automation Procedures
  • idisableole -i IMPERSONATEUSER – Disable OLE Automation Procedures
  • iolecmd -i IMPERSONATEUSER -o COMMAND – Execute an arbitrary system command using OLE Automation Procedures
  • ienableclr – Enable Custom CLR Assemblies
  • idisableclr – Disable Custom CLR Assemblies
  • iclr -o DLLPATH -f FUNCTION – Load and execute a .NET assembly within a custom stored procedure
  • iagentstatus -i IMPERSONATEUSER – Check to see if SQL agent is running and obtain jobs
  • iagentcmd -i IMPERSONATEUSER -o COMMAND – Execute an arbitary system command

Linked SQL Server Modules

Linked SQL Server modules are effective when you are able to interact with a linked SQL server via an established connection.

  • links – Enumerate any linked SQL servers
  • lquery -l LINKEDSERVERNAME -o QUERY – Execute an arbitrary SQL query on the linked SQL server
  • lwhoami – See what user you are logged in as on the linked SQL server
  • ldatabases -l LINKEDSERVERNAME – Show all databases present on the linked SQL server
  • ltables -l LINKEDSERVERNAME -o DATABASE – Show all tables in the supplied database on the linked SQL server
  • lsmb -l LINKEDSERVERNAME -o SHARE – Capture NetNTLMv2 hash from linked SQL server
    ↓ Command Execution (requires sysadmin role or similar)
  • lenablerpc -l LINKEDSERVERNAME – Enable RPC and RPC out on a linked SQL server
  • ldisablerpc -l LINKEDSERVERNAME – Disable RPC and RPC out on a linked SQL server
  • lenablexp -l LINKEDSERVERNAME – Enable xp_cmdshell on the linked SQL server
  • ldisablexp -l LINKEDSERVERNAME – Disable xp_cmdshell on the linked SQL server
  • lxpcmd -l LINKEDSERVERNAME -o COMMAND – Execute an arbitrary system command using xp_cmdshell on the linked SQL server
  • lenableole -l LINKEDSERVERNAME – Enable OLE Automation Procedures on the linked SQL server
  • ldisableole -l LINKEDSERVERNAME – Disable OLE Automation Procedures on the linked SQL server
  • lolecmd -l LINKEDSERVERNAME -o COMMAND – Execute an arbitrary system command using OLE Automation Procedures on the linked SQL server
  • lenableclr -l LINKEDSERVERNAME – Enable Custom CLR Assemblies on the linked SQL server
  • ldisableclr -l LINKEDSERVERNAME – Disable Custom CLR Assemblies on the linked SQL server
  • lagentstatus -l LINKEDSERVERNAME – Check to see if SQL agent is running and obtain jobs on the linked SQL server

Examples

See the wiki. for detailed examples.

Roadmap

The below techniques are on the roadmap for future releases

  • Look into creating lclr
  • Look into creating lagentcmd

 

 

版权声明:admin 发表于 2022年10月13日 上午10:34。
转载请注明:A C# MS SQL toolkit designed for offensive reconnaissance and post-exploitation | CTF导航

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...