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
Post a Comment