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

Installing Codename SCNR web application scanner on ubuntu | kali

  Perform the following steps from a non-root user. We will go for manual installation.  https://github.com/scnr/installer?tab=readme-ov-file#manual-installation https://github.com/scnr/installer/releases wget https://github.com/scnr/installer/releases/download/v1.7.3/scnr-v1.7.3-linux-x86_64.tar.gz   (Download using normal user) tar -xvzf scnr-v1.7.3-linux-x86_64.tar.gz cd scnr-v1.7.3 cd bin Now go to their website ( https://ecsypno.com/products/scnr ) and subscribe for community edition license from your official email.  ./scnr_activate 6XQ97FW3LVBECD0UJ5H214 ./scnr https://www.example.net/Login.aspx --system-slots-override Now they generate .ser format report after testing the application by default which is hard to read. We need html report. So for example, to generate an HTML report: ./scnr_reporter --report=html:outfile=my_report.html.zip /home/user/.scnr/reports/report.ser Avi

API hacking lab setup

 Follow the commands to install and configure API hacking lab: 1. Install kali linux and update all the packages.  apt update -y apt upgrade -y or apt dist-upgrade -y or apt full-upgrade -y If you face any problem regarding update, install cloud flare warp in the host machine, then again start updating packages in your kali vm.  2. Install and configure burpsuite professional.  After that open burpsuite and go to Extensions tab. Click on BAppStore. Search for Autorize extension, It will help us to automate authorization testing. Click on Download Jython from the right side. From Jython website click on Jython standalone JAR and save it. Go to Extensios > Extensions settings >  under Core extension settings find out Python environment on the right pane. Select the jython jar file that you just downloaded. Now again go to BAppStore and re-search for Autorize extension. You will see Install option this time after selecting Autorize extension. Install it. You ...

Install Nessus from docker

Docker installation. Give the below commands one by one. apt install docker-cli or 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   --...