> For the complete documentation index, see [llms.txt](https://kos0ng.gitbook.io/ctfs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kos0ng.gitbook.io/ctfs/write-up/2024/swampctf/misc.md).

# Misc

<table><thead><tr><th width="347">Challenge</th><th>Link</th></tr></thead><tbody><tr><td>Lost Some Magic (92 pts)</td><td><a href="#lost-some-magic-92-pts">Here</a></td></tr></tbody></table>

## Lost Some Magic (92 pts)

### Description

Our SOC analysts saw some strange DNS traffic. Wanted you to figure out what was exfiltated , can you check it and sum it up ?

### Solution

Given file with unknown type, lets check the contents.

<figure><img src="/files/BmGdufKjd32rVsxNMpZy" alt=""><figcaption></figcaption></figure>

There is no extension with header signature 4200. Based on the description it should be kind of compression so lets try to check another compressed file.

<figure><img src="/files/XtOjIg8kXWo5WRDVp1Jn" alt=""><figcaption></figcaption></figure>

bz2 header looks similar with 2 bytes value nulled. So rewrite those null bytes to 5a68 and do bz2 decompress.

<figure><img src="/files/xk2Fodf7VfxGfMJEsgCE" alt=""><figcaption></figcaption></figure>

Okay, lets check the next part.&#x20;

<figure><img src="/files/BExyroDUSi2aFTNY90YP" alt=""><figcaption></figcaption></figure>

Looks like it similar with tar archive, tar doesn't compress the value. So just take directly the value from xxd.

<figure><img src="/files/D7PkQhraDZ6D85Djs8Uw" alt=""><figcaption></figcaption></figure>

```python
f = open("data2.tar", "rb").read()
data = bytes.fromhex("8b08086e37c4650003666c6167")
index = f.index(data)
val = f[index:index+73]

g = open("data3", "wb")
g.write(val)
```

<figure><img src="/files/6Eg3Le0TXqYgFbnm2uOZ" alt=""><figcaption></figcaption></figure>

Looks like data3 is gz archive with removed header and trailer. Lets add header and trailer and try to decompress it.

```python
f = open("data2.tar", "rb").read()
data = bytes.fromhex("8b08086e37c4650003666c6167")
index = f.index(data)
val = f[index:index+73]
new_val = b"\x1f" + val + b"\x00" * 3

g = open("data3.gz", "wb")
g.write(new_val)
```

<figure><img src="/files/kcDWhuwmRlePSgLZVZHJ" alt=""><figcaption></figcaption></figure>

Flag: swampCTF{C0113ct1ng\_th3\_mag1c\_number5}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://kos0ng.gitbook.io/ctfs/write-up/2024/swampctf/misc.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
