Some Assembly Required

Some Assembly Required 1

Author: Sears Schulz

Description

http://mercury.picoctf.net:36152/index.htmlarrow-up-right

Solution

We are given a page, without description. Page is simple submit form.

<html>
<head>
	<meta charset="UTF-8">
	<script src="G82XCw5CX3.js"></script>
</head>
<body>
	<h4>Enter flag:</h4>
	<input type="text" id="input"/>
	<button onclick="onButtonPress()">Submit</button>
	<p id="result"></p>
</body>
</html>

Let's view what javascript is doing. The Javascript is obfuscated... after some analysis in VSCode this is what I ended up with.

Note: You can view this values from console tab in Developer Tools without running script, but you'll have to use original names.

So script gets some file, collects imports (some functions), calls copy_char a lot and finally checks if flag is correct. The file it gets is WebAssembly.

Without diving too much into assembly we can view flag with strings.

circle-check

Some Assembly Required 2

Description

http://mercury.picoctf.net:7319/index.htmlarrow-up-right

Analysis

We are given almost same code (I converted it for more readability). Reorder array -> Get Wasm (Web Assembly) -> Use assembly functions -> Compare to flag -> Profit.

Downloading wasmarrow-up-right from server and running strings shows:

Looking at the last line it seems like flag, but encrypted, 110% bet it's an XOR.

Opening wasm into wasm2watarrow-up-right gives us somewhat readable code. Searching for XOR (local.set $l8 (i32.xor(local.get $l6) (local.get $l7))), now it's clear that XOR is involved, but which one is the key and which one is the flag.

Instructions before XOR are following. In XOR key is constant so the KEY must be 8.

Solution

some-assembly-required-2-1

Clean up encryption a bit.

some-assembly-required-2-2
circle-check

Some Assembly Required 3

Description

http://mercury.picoctf.net:47240/index.htmlarrow-up-right

Analysis

Viewing JavaScript the file looks the same as previous ones, but URI is provided to us without obfuscating. let _0x487b31 = await fetch("./qCCYI0ajpD")

In wasm2wat we can see some odd values, probably flag and key (XOR operation can be found in code):

Using WATBarrow-up-right to decompile the code:

While it's not 100% clear what the code is doing, it's understandable that input gets XOR-ed with key and this key get cycled through, as commonly seen in XOR ciphers.

Solution

circle-check

Last updated