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

Docker installation. Give the below commands one by one. apt install docker-cli apt install docker.io After the installation is complete, if you are inside wsl then give this command to start docker, because inside wsl systemd (systemctl) does not work: service docker start WSL troubleshooting : If the above command " service docker start " does not work then use below command: dockerd (It may not work if any previous docker process is running. It will show you pid of that process. Use this command to kill that process " kill -9 pid " and run dockerd command again) If " docker ps -a " giving error like " Cannot connect to the Docker daemon at unix:///run/podman/podman.sock. Is the docker daemon running? " This is because you may installed podman-docker package. If you remove the package still you will get this error but you should remove the package. Then issue this command: env | grep -i docker DOCKER_HOST=unix:///run/podman/podman.sock   -->...

Installtion of SQLMutant tool

This tool is perfectly works on ubuntu 24 system. And I found it is not working properly in kali linux 24 version.   https://github.com/blackhatethicalhacking/SQLMutant/tree/main This tool need to use along with sqlmap tool. Showing this cheat sheet for kali or debian based system.  This tool actually analyze everything and give you the vulnerable url where sql injection is possible. You just need to use then sqlmap to exploit that.   Prerequisite: apt install pipx -y (for ubuntu) pip3 install uro or pipx install uro pipx ensurepath pipx completions  (not needed)  source ~/.bashrc   or restart system If go tool is not installed then run the below two commands first ( golang-go ) or follow this link to install go (https://mahimfiroj.blogspot.com/2024/12/installing-nuclei-in-kali.html) otherwise skip this step.   dpkg -l | grep packagename (Using this command you can check package is installed or not) apt install gccgo-go -y or apt install gol...

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