Skip to main content

Impacket GetUserSPNs.py | Service account | smb share | active directory | kerberoasting | TGS-REP | Service ticket | sql | ntlm pass hash of service account

SPN - service principle name. Services (mysql or http) that supports kerberos authentication are require to have a SPN associated with it in order to point users to the appropriate resource for connection. Its a unique identifier of a service instance. 

SPN tells that which service is mapped with which account. Further meaning, what are the service account are there that are mapped with corresponding service account. i.e. http service is mapped with SAccount. MSSQLSvc service is mapped with Sqlsvc account. When we issue the below command then we are seeing an encrypted data. 

GetUserSPNs.py -request -dc-ip 10.6.0.2 htb.local/JSmith:passw0rd

For example our service account are SAccount or sqlsvc. They are the user account remember. The data has been encrypted with corresponding service account ntlm hash password. If we decrypt the data then we shall get the password of that corresponding service account. This is the TGS that is encrypted with NTLM hash of the service account (which is SAccount or sqlsvc) by the KDC. In normal request, user cannot decrypt this except the KDC and target service account (SAccount). Here we are doing this manually by using GetUserSPNs.py tool.  

Now lets discuss why this attack get success? Where the vulnerability lies? 

Sqlsvc is a user account. If you navigate to user account properties in AD, attribute editor> there you will find service principle name along with some values. This values makes the python script work. If you remove that value then python script will return you nothing. But if you want this service account sqlsvc perform kerberos authentication to take sql service then it has to has service principle name associate with this account (sqlsvc). 

Note: The machine from where we launching GetUserSPNs.py tool (can be called our attacking machine), is completely separated from the domain. 

From our attacking machine, set DC server ip address as dns settings in the ip address settings. This will also help for silver ticket attack. If you dont set this then you need to use -dc-ip switch to provide DC ip address. Actually while working with GetUserSPNs.py tool then you can either use -dc-ip switch or set DC server ip in the ip address dns settings. This will allow you to use ip address still in kerberos. As we know, Kerberos by default will not support to use ip address. It support FQDN. If you use ip address instead of FQDN then it will fall back to NTLM.  

In order to perform this attack, we need one domain user credential. The user is normal user. Does not have any admin rights. Just we need one AD user username and password. 

This script is used for cracking service account password. 

e type is encryption type which is 23 is hashcat example page. This is TGS REP attack. This will work for any user account that are set to run services that authenticated with kerberos. '

So what is inside of TGS-REQ?

After getting the TGS from the KDC, user initiate TGS-REQ packet. In this packet, what service we want to access in which server is told.  

In the above ss, the user saying we want to access MSSQLSvc in dc1.htb.local server.

So the question is, why we are not attacking computer account? computer account also have spn associate with it. 

Because computer account password are too long may be 150 character. And the system itself set the password and change the password frequently within a interval of 1 month. 

 

Powershell commands also help to get the SPNs:

import-module activedirectory 

get-aduser -ldapfilter "(serviceprincipalname=*)" -properties "serviceprincipalname" 


 

 

https://pentestlab.blog/2018/06/04/spn-discovery/

https://www.youtube.com/watch?v=HHJWfG9b0-E

https://www.youtube.com/watch?v=xH5T9-m9QXw 

https://www.scip.ch/en/?labs.20181011

 

CTF problem: Can you find the flag hidden in the shared directory for the SAccount user? 




locate GetUserSPNs.py

python /usr/share/doc/python3-impacket/examples/GetUserSPNs.py -request -dc-ip 10.6.0.2 insecureAD.local/NAccount -outputfile hashes.kerberoast

It will ask for a password of the NAccount which we already cracked and provide. 

 

john --format=krb5tgs --wordlist=/usr/share/wordlists/rockyou.txt hashes.kerberoast 


Avi

 

Comments

Popular posts from this blog

Install Nessus from docker

The below two commands you need to run first one by one:  docker run -itd --name=ramisec_nessus -p 8834:8834 ramisec/nessus docker exec -it ramisec_nessus /bin/bash /nessus/update.sh Username: admin And you need to change the password: #Enter the command line of the docker container docker exec -it ramisec_nessus bash #Execute the following commands in sequence # Enter this directory cd /opt/nessus/sbin # List logged in users ./nessuscli lsuser # Modify the password of the specified user (take admin as an example) ./nessuscli chpasswd admin After access to the nessus, make sure you turn off the automatic updates otherwise crack will not work after some time. Before any scan you need to run the update.sh command (shown above) to have the latest plugins. Now everytime your system reboots, your docker instance will be shutdown. You need to up it again manually. Here are the commands.  1. docker ps -a    Now note down the container id. 2. docker start <container id> C

net command cheat sheet

  To see what users present in the system: net user To see local groups in the system: net localgroup To see domain groups. This should be run on a domain controller: net group To see the details of a user along with his/her group membership: net user mahim To see who are the members of a particular group (local machine): net localgroup "administrators"    (These are not case sensitive. You can use administrators or Administrators. Both will give you same result. To see who are the members of a particular group (domain machine): net group "domain admins" Create a local user: net user localuser1 MyP@ssw0rd /add Create a domain user: net user domainuser1 MyP@ssw0rd /add /domain Add the local user to local admin group: net localgroup Administrators localuser1 /add Add the user to domain admin group: net group "Domain Admins" domainuser1 /add /domain Avi