> For the complete documentation index, see [llms.txt](https://alham-rizvi.gitbook.io/alhamrizvi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alham-rizvi.gitbook.io/alhamrizvi/picoctf-writeups/picoctf/web-exploitation/some-assembly-required-3.md).

# Some Assembly Required 3

Detailed walkthrough will be available after 24 hours on medium!

<https://medium.com/@alhamrizvi.in/list/web-exploitation-picoctf-hard-f1416428808a>

this challenge demonstrates how client-side JavaScript can act as a thin wrapper while hiding the real logic inside a WebAssembly binary. initial analysis of the JS revealed that user input was being passed into a WASM module, making it clear that reversing the binary was necessary.

upon decompiling the WASM, we identified an encoded byte array (the flag) and a 5-byte key. each input character was XORed with this key before comparison. the tricky part was that the key indexing was reversed (`key[4 - (i % 5)]`), which caused incorrect results during the first decoding attempt.

after correcting the logic and applying the proper XOR operation, we successfully recovered the flag.

#### Exploitation Code

```python
# encoded bytes from WASM (offset 1024)
enc = [
0x9d,0x6e,0x93,0xc8,0xb2,0xb9,0x41,0x8b,0x94,0x90,
0xdd,0x3e,0x94,0x97,0x90,0xdd,0x3f,0xc4,0xc2,0xc9,
0xdd,0x34,0xc2,0xc5,0x97,0xdb,0x31,0x93,0x92,0xc0,
0xda,0x36,0x93,0x93,0xc1,0xd9,0x3e,0x91,0xc1,0x97,
0x90
]

# key from WASM (offset 1067)
key = [0xf1, 0xa7, 0xf0, 0x07, 0xed]

flag = ""

for i in range(len(enc)):
    flag += chr(enc[i] ^ key[4 - (i % 5)])

print(flag)
```

***

#### Output

```
picoCTF{3a09d0a084e8032bf66c5171c4049aff}
```


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://alham-rizvi.gitbook.io/alhamrizvi/picoctf-writeups/picoctf/web-exploitation/some-assembly-required-3.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
