> For the complete documentation index, see [llms.txt](https://0xb0b.gitbook.io/writeups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://0xb0b.gitbook.io/writeups/tryhackme/2025/directory.md).

# Directory

Do you have what it takes to crack this case? - by hadrian3689

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

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)

***

For this challenge, we are provided with a PCAP file. We first analyze it using Wireshark. Based on the SYN requests and the RST-ACK responses from 10.0.2.74, we can quickly tell that a port scan has taken place.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FVT0nVhiJJ5Vq29uU9h0T%2Fimage.png?alt=media&amp;token=a1a6db65-c023-4bf6-b1f8-9b67175ab874" alt=""><figcaption></figcaption></figure>

The first `3610` pakets are related to the port scan, after that we can discover some HTTP traffic.&#x20;

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FHqtkdaoHVOAKPhVXcaM5%2Fimage.png?alt=media&amp;token=0bf2c8c1-a130-42f9-9078-0f11c434fa43" alt=""><figcaption></figcaption></figure>

## What ports did the threat actor initially find open? Format: from lowest to highest, separated by a comma.

To answer the following questions, we try to use TShark. TShark is the command‑line network protocol analyzer companion to Wireshark, capable of capturing, decoding, and filtering packet data directly in a terminal.

The question now is about the open ports that the attacker has found. Means, that we get an answer via `SYN ACK` response indicating an open port.

We use the knowledge from our first insight via Wireshark that the scan extends to packet `3610` and limit the analysis to this.

The `-c` option in TShark specifies the number of packets to capture or read from a file. With `-c 3610` tshark will process only the first `3610` packets from the `traffic-1725627206938.pcap` file. Once it reaches the limit of `3610` packets, it will stop processing. We filter TCP packets where both the SYN and ACK flags are set `-Y "tcp.flags.syn == 1 && tcp.flags.ack == 1"`, and print only each packet’s TCP source‑port field `-T fields -e tcp.srcport`.  We then sort the ports numerically, removes duplicates, and outputs the unique list as a single comma‑separated line `| sort -n | uniq | paste -sd ','`.

{% code overflow="wrap" %}

```
tshark -r traffic-1725627206938.pcap -c 3610 -T fields -e tcp.srcport -Y "tcp.flags.syn == 1 && tcp.flags.ack == 1" | sort -n | uniq | paste -sd ','
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F8XvEr3YtrS63D6zzzcqJ%2Fimage.png?alt=media&amp;token=50234f59-73b3-4480-96b3-9e9a2104fb53" alt=""><figcaption></figcaption></figure>

## The threat actor found four valid usernames, but only one username allowed the attacker to achieve a foothold on the server. What was the username?&#x20;

We skip the Nmap traffic and scroll down the traffic shown in Wireshark, until we reach packet no. `4667`, there the KRB5 traffic starts. From this traffic we can potentially extract the username that allowed the attacker to achieve foothold.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FBubhKFSx6HHlrIEanzoR%2Fgrafik.png?alt=media&amp;token=3e593472-3bef-4a92-9511-f0b0fb8e6fa7" alt=""><figcaption></figcaption></figure>

Scrolling down to `4679` we see an error for `PREAUTH_REQUIRED.`

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Fobk8RPmHFA1VDLlljSPa%2Fimage.png?alt=media&amp;token=44111532-9b4b-4cf2-a04e-9f99513cc39b" alt=""><figcaption></figcaption></figure>

We see some authentication attempts resulting in unknown principals errors. The errors stop occuring after packet no. `4785`.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FsHatF2duNIUeE49hqA7a%2Fimage.png?alt=media&amp;token=c9b33dbe-d7c6-4d6d-bf6f-880176daeeda" alt=""><figcaption></figcaption></figure>

On packet no. `4817` we don't see any error after an AS-REQ and could extract the username here.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FW4lRhLtEVrjaJ3Bu4WQj%2Fimage.png?alt=media&amp;token=7d87e130-96a6-4827-8087-51907cf7c51c" alt=""><figcaption></figcaption></figure>

Solving this task with TShark we check the fields available to extract related to kerberos.

```
tshark -G fields | grep -i kerberos
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Fbe43SkzY4iUlJMtQDXAF%2Fimage.png?alt=media&amp;token=7c464995-67e6-4d77-8450-aee6bf58eebc" alt=""><figcaption></figcaption></figure>

With the following command we extract every matching packet containing the Kerberos client principal name string `kerberos.CNameString` and its realm `kerberos.crealm`. We assume the last entries are the ones, that made a successful login.

{% code overflow="wrap" %}

```
tshark -r traffic-1725627206938.pcap -Y "kerberos" -T fields -e kerberos.CNameString -e kerberos.crealm
```

{% endcode %}

{% code overflow="wrap" %}

```
tshark -r traffic-1725627206938.pcap -Y "kerberos" -T fields -e kerberos.CNameString -e kerberos.crealm | awk 'NF==2 {print $2 "\\" $1}'
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Frk2ieYk3z1lW8DASEb0L%2Fimage.png?alt=media&amp;token=f04ed844-7485-46d6-973d-5bd79080a259" alt=""><figcaption></figcaption></figure>

## The threat actor captured a hash from the user in question 2. What are the last 30 characters of that hash?

{% hint style="info" %}
What we are looking for is an encrypted message or blob of information, not a hash, that is used by Kerberos for authentication. The AS-REP is an encrypted packet, not a hash. It is encrypted using AES, RC4, or even public-key cryptography (PKINIT).

[Marjan Sterjev](https://www.linkedin.com/in/marjansterjev) had pointed out my post on LinkedIn regarding this topic, and I agree with him that we should use precise terminology. Thank you, for your clarification!
{% endhint %}

The requested information is contained in the packets that transmit the kerberos.cipher. Filtering these packets will allow us to extract the last 30 characters.

{% code overflow="wrap" %}

```
tshark -r traffic-1725627206938.pcap -Y 'kerberos and kerberos.CNameString == "larry.doe"' -T fields -e kerberos.checksum -e kerberos.cipher -e kerberos.CNameString -e frame.number
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FEgelieXhWWAcEoRaduXo%2Fimage.png?alt=media&amp;token=08072a58-3a83-49ad-acf3-bddf0665038a" alt=""><figcaption></figcaption></figure>

We extract the frame number too, and see that the blob was transferred in the packet before `4817`.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FuXiDmGwbwEz70lvxPpYC%2Fimage.png?alt=media&amp;token=8bbe9ad3-5996-4291-b5a9-040464777c2b" alt=""><figcaption></figcaption></figure>

Next, we just extract `kerberos.cipher` field from the last request...

{% code overflow="wrap" %}

```
tshark -r traffic-1725627206938.pcap -Y 'kerberos and kerberos.CNameString == "larry.doe"' -T fields -e kerberos.cipher | tail -n 1
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FD26U5hVo9l2GxhIeoJu5%2Fimage.png?alt=media&amp;token=da6ecded-3307-4831-a349-9d435e8686be" alt=""><figcaption></figcaption></figure>

... and use AWK to print the last 30 characters of the blob.

{% code overflow="wrap" %}

```
tshark -r traffic-1725627206938.pcap -Y 'kerberos and kerberos.CNameString == "larry.doe"' -T fields -e kerberos.cipher | tail -n 1 | awk '{print substr($0, length($0)-29)}'
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FusyKCmo2EALnJIneALcc%2Fimage.png?alt=media&amp;token=06d1a1e5-0598-4463-9b5b-0f7b5c85358d" alt=""><figcaption></figcaption></figure>

## What is the user's password?

While researching about KRB traffic, we came across the following resource:

{% embed url="<https://blog.xpnsec.com/kerberos-attacks-part-2/>" %}

It is depicted there how to use the following script to extract any AS-REP ciphers transferred in a PCAP file. Unfortunately, this is no longer available.

{% embed url="<https://github.com/openwall/john/blob/bleeding-jumbo/run/krbpa2john.py>" %}

But we get an alternative here:

{% embed url="<https://github.com/truongkma/ctf-tools/blob/master/John/run/krbpa2john.py>" %}

After we have converted the `pcap` file as described and used the `pdml` file with the script `krbpa2john.py` , we have not received any output. We were only able to partially reconstruct the Kerberos cipher using the `krb2john.py` script provided by John, the `user@domain.com` was missing. We already got that information - see question 2. We can already see that it is a `Kerberos 5, etype 23, AS-REP` blob.&#x20;

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FvbvuCAXOwS1REe6Mzybi%2Fimage.png?alt=media&amp;token=05444a58-53fa-4267-9048-ae9b0d6643cb" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FNOroNPLE9SPMperqx95S%2Fimage.png?alt=media&amp;token=5b89bfa9-175e-4127-aa47-4a0504284c79" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FFGQUHWBfC0iKwK6vj8HK%2Fgrafik.png?alt=media&amp;token=9a9cb06c-f926-40a1-9394-05af511ab610" alt=""><figcaption></figcaption></figure>

The following TShark attempt shows how to reconstruct it manually. We can extract all the required information with the command below.

{% code overflow="wrap" %}

```
tshark -r traffic-1725627206938.pcap -Y 'kerberos and kerberos.CNameString == "larry.doe"' -T fields -e kerberos.CNameString -e kerberos.crealm -e kerberos.sname_string -e kerberos.checksum -e kerberos.cipher -e kerberos.info_salt | tail -n 1
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FNikUF0v3arMDozQfzGvv%2Fimage.png?alt=media&amp;token=5d8eae89-5330-48c2-91c3-20cfff64e77b" alt=""><figcaption></figcaption></figure>

To reconstruct the required format by hashcat to crack it, the second part of the `kerberos.cipher` field is relevant.

{% code overflow="wrap" %}

```
tshark -r traffic-1725627206938.pcap -Y "frame.number==4817" -T fields -e kerberos.cipher
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FH5cmHL7LNCB4hOrRzfnV%2Fimage.png?alt=media&amp;token=05d5bceb-bf78-44e7-9ff6-b57e800aaafb" alt=""><figcaption></figcaption></figure>

We use AWK to combine everything into the format required by hashcat.

{% code overflow="wrap" %}

```
tshark -r traffic-1725627206938.pcap -Y "frame.number==4817" -T fields -e kerberos.cipher -e kerberos.CNameString -e kerberos.crealm | \
awk -F'\t' '{split($1,a,","); print "$krb5asrep$23$"$2"@"$3":"a[2]}' | \
awk -F':' '{prefix_len=length($1) + 33; print substr($0, 1, prefix_len) "$" substr($0, prefix_len+1)}'

```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FIuM68SljTcTKnPU8doHD%2Fimage.png?alt=media&amp;token=25700b92-4b49-4269-91c7-21c8dc4bcbc5" alt=""><figcaption></figcaption></figure>

Next, we crack it using `rockyou.txt`.

```
hashcat -a0 -m18200 directory.hash /usr/share/wordlists/rockyou.txt
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FeTxgXuws4v4aNohmjzwk%2Fimage.png?alt=media&amp;token=1025d4c7-b13a-4696-b9ad-4df9a192fe84" alt=""><figcaption></figcaption></figure>

## What were the second and third commands that the threat actor executed on the system? Format: command1,command2

After the authentication of larry.doe we see traffic on 5985. Port 5985 is used for **Windows Remote Management - WinRM**, indicating remote command execution or administrative access after authentication.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FlCtxhnSU60zyKz901dKl%2Fimage.png?alt=media&amp;token=05846166-5c59-4bee-b9b7-33cee5cb2452" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FKI3VIBbfg77J9AKzmp6n%2Fimage.png?alt=media&amp;token=121d72e4-836a-44b8-9745-4cd0d90be815" alt=""><figcaption></figcaption></figure>

However, the traffic is encrypted.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FrzT4b3ZjSTSupWfPH8Zv%2Fimage.png?alt=media&amp;token=173eaf6f-0dbd-4995-89eb-fb97156abdb5" alt=""><figcaption></figcaption></figure>

After a short research we come across the following tool for decrypting winrm traffic. This is possible for us, as we have the user's password.

{% embed url="<https://github.com/h4sh5/decrypt-winrm?tab=readme-ov-file>" %}

Unfortunately, it throws errors.

```
python3 winrm_decrypt.py -p 'REDACTED' ../traffic-1725627206938.pcap
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FlDOyauYmPD7MPEqyLqqA%2Fimage.png?alt=media&amp;token=ac863b4c-964e-4aef-9489-a149345a48cc" alt=""><figcaption></figcaption></figure>

In the description of the repo we see a reference to a fork. We try to use that instead.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FvkhScVDazSIFd0yMUstU%2Fgrafik.png?alt=media&amp;token=2e685110-b696-4d61-834c-a74a13a14f3a" alt=""><figcaption></figcaption></figure>

We run the script from the fork and are able to decrypt the traffic. We directly write it to a file.

[https://gist.github.com/jborean93/d6ff5e87f8a9f5cb215cd49826523045/ ](<https://gist.github.com/jborean93/d6ff5e87f8a9f5cb215cd49826523045/ >)&#x20;

{% code overflow="wrap" %}

```
python3 winrm_decrypt.py -p 'REDACTED' ./traffic-1725627206938.pcap > decrypted_traffic.txt
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FLnkiLOS2jHkQo2A1SVv1%2Fimage.png?alt=media&amp;token=6cd69d4a-40e8-4b16-a72d-0d431215f640" alt=""><figcaption></figcaption></figure>

When scrolling through the decrypted traffic, we recognize a schema. The commands are base64 encoded in arguments  tags.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Fhe0NJufBqFxAjy45G1gx%2Fimage.png?alt=media&amp;token=3c22e85c-a758-481c-9515-74331b85a130" alt=""><figcaption></figcaption></figure>

We extract them and write them to a file.

```
grep -oP '(?<=<rsp:Arguments>).*?(?=</rsp:Arguments>)' decrypted_traffic.txt
```

{% code overflow="wrap" %}

```
grep -oP '(?<=<rsp:Arguments>).*?(?=</rsp:Arguments>)' decrypted_traffic.txt > encoded_arguments.txt
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FzyPD4V1pgvVyA0IniBSH%2Fimage.png?alt=media&amp;token=d1e4cdca-e099-4adc-ba1f-30b46ef89fc3" alt=""><figcaption></figcaption></figure>

Next, we decode each argument.

```
while read line; do                                                     
  echo "$line" | base64 --decode >> arguments.txt
  echo "" >> arguments.txt
done < encoded_arguments.txt
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Fo50BCu03nwcLjSwGhWTa%2Fimage.png?alt=media&amp;token=39280991-7ef6-4b3c-b229-36e5f1a03946" alt=""><figcaption></figcaption></figure>

We find the first command: `whoami`

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FLl6O7Wf6Qq0c2qQi2HcG%2Fimage.png?alt=media&amp;token=1a1171e7-ed45-4b81-b809-a6ad496a4b27" alt=""><figcaption></figcaption></figure>

To make it more readable we use grep. And now find all commands made including the flag.

```
grep -a '<S N="V">' arguments.txt | awk -F'[<>]' '{print $3}'
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FjNqEPDxmFcqKcm0ZydRY%2Fimage.png?alt=media&amp;token=a8cc4c63-f3e6-4ffe-bbe0-cb21f40cbbd8" alt=""><figcaption></figcaption></figure>

## What is the flag?

```
grep -a '<S N="V">' arguments.txt | awk -F'[<>]' '{print $3}'
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FI6FpWKnbaR0oKZx0zCBB%2Fimage.png?alt=media&amp;token=cd0035e5-2cf2-47ec-b014-2ba1231beb0b" alt=""><figcaption></figcaption></figure>

## Recommendation

Marjan Sterjevs version of the script does not need password or nt\_hash:

<https://pastebin.com/u2jCceRX>

> If -e is specified on the input, the script will try to:
>
> * process the WWW-Authenticate and Authorization NTLMSSP Negotiation messages
> * crack the password with John The Riper and finally
> * decode, process and output the string content of the WinRM messages; it looks for RSP CommandLine content and the associated response streams.

<https://www.linkedin.com/posts/marjansterjev_directory-activity-7353043871032827904-3vc1?utm_source=share&utm_medium=member_desktop&rcm=ACoAAEQHbzcBmjOtd0QWGGhWpdy2mzZ2j-geKp8>
