Beyond V8: SpiderMonkey, LibJS, MuJS and mJS


Browser Exploitation: A CTF Study Path.

Not every browser is Chrome. SpiderMonkey NaN-boxes its values and has its own JIT; SerenityOS's LibJS and the small MuJS and mJS interpreters are C/C++ programs where a JavaScript bug quickly becomes a glibc heap or GOT exploit. These engines run through a bundled Ubuntu 22.04 glibc, so their heap behaves like the original servers'. Take this module any time after 01.

Where to start

Start from the engine, not the bug. For Outfoxed, read how SpiderMonkey boxes values and lays out arrays and typed arrays, and redo module 01's chain with NaN-boxed values. For LibJS, MuJS and mJS, read the engine's source for the value representation and the object the patch touches. These are ordinary C/C++ programs: once you have a primitive, the ending is usually glibc heap or GOT work, so checksec the binary and use the bundled glibc version when you plan it.

Reading



Challenges

KalmarCTF 2023 · difficulty ★★☆☆☆ · module: Beyond V8: SpiderMonkey, LibJS, MuJS and mJS

Cesanta's mJS, hardened by the organizers. Function pointers are just numbers.

Engine: Cesanta mJS (hardened), master + diff.patch

Running it

Put your exploit at /home/hacker/exploit.js and run /challenge/run. It passes it to the engine as a file, with the original challenge's flags: glibc/ld-linux-x86-64.so.2 --library-path glibc mjs exploit.js. The engine runs as an unprivileged user (uid 1001) that cannot read /flag.

Once your code runs inside the engine (shellcode, or a shell it spawns), execute /readflag to print the flag, as in the original challenge.

This engine needs a newer glibc than the container has, so it runs through the bundled loader in /challenge/glibc (the binary itself is unchanged; libc addresses differ from the original server).

The original joined your lines without newlines and ran mjs -e; here the file is passed as is. The original's flag file is replaced by /readflag: run it from the shell or shellcode your exploit gets.

Debugging it

Debug your own copy (no root needed):

mkdir -p ~/dbg && cd ~/dbg && cp -r /challenge/. . && gunzip -fr . && chmod +x mjs glibc/ld-linux-x86-64.so.2
./glibc/ld-linux-x86-64.so.2 --library-path ./glibc ./mjs ~/exploit.js
gdb -q --args ./glibc/ld-linux-x86-64.so.2 --library-path ./glibc ./mjs ~/exploit.js

Files in /challenge (executables are gzip-compressed): diff.patch, mjs.gz.

Original challenge

Description

clone pwn warmup
Toddler's first browser exploitation: https://github.com/cesanta/mjs

Points

100

Solves

52

Credits

  • Challenge author(s): not recorded (credit goes to the KalmarCTF 2023 organizers)
  • Compiled by: mito753 in Browser-Exploit-Dojo, which also has the original handout, exploits and writeups

corCTF 2021 · difficulty ★★★☆☆ · module: Beyond V8: SpiderMonkey, LibJS, MuJS and mJS

SpiderMonkey gains an Array.prototype.oob. NaN-boxing instead of pointer tagging.

Engine: SpiderMonkey (js shell), Firefox 91 (JavaScript-C91.0)

Running it

Put your exploit at /home/hacker/exploit.js and run /challenge/run. It passes it to the engine as a file, with the original challenge's flags: glibc/ld-linux-x86-64.so.2 --library-path glibc js exploit.js. The engine runs as an unprivileged user (uid 1001) that cannot read /flag.

Once your code runs inside the engine (shellcode, or a shell it spawns), execute /readflag to print the flag, as in the original challenge.

This engine needs a newer glibc than the container has, so it runs through the bundled loader in /challenge/glibc (the binary itself is unchanged; libc addresses differ from the original server).

The original target was a patched Firefox; the handout's patched js shell has the same bug.

Debugging it

Debug your own copy (no root needed):

mkdir -p ~/dbg && cd ~/dbg && cp -r /challenge/. . && gunzip -fr . && chmod +x js glibc/ld-linux-x86-64.so.2
./glibc/ld-linux-x86-64.so.2 --library-path ./glibc ./js ~/exploit.js
gdb -q --args ./glibc/ld-linux-x86-64.so.2 --library-path ./glibc ./js ~/exploit.js

Files in /challenge (executables are gzip-compressed): js.gz, outfoxed.patch.

Original challenge

Description

Just your average, easy browser pwn!

https://outfoxed.be.ax

Points

498

Solves

4

Credits

  • Challenge author(s): clubby789, for corCTF 2021
  • Compiled by: mito753 in Browser-Exploit-Dojo, which also has the original handout, exploits and writeups

ASIS CTF Quals 2023 · difficulty ★★★★☆ · module: Beyond V8: SpiderMonkey, LibJS, MuJS and mJS

SerenityOS LibJS and an ArrayBuffer copy.

Engine: SerenityOS LibJS (Lagom js), commit 799b465

Running it

Put your exploit at /home/hacker/exploit.js and run /challenge/run. It passes it to the engine as a file, with the original challenge's flags: glibc/ld-linux-x86-64.so.2 --library-path glibc js exploit.js. The engine runs as an unprivileged user (uid 1001) that cannot read /flag.

Once your code runs inside the engine (shellcode, or a shell it spawns), execute /readflag to print the flag, as in the original challenge.

This engine needs a newer glibc than the container has, so it runs through the bundled loader in /challenge/glibc (the binary itself is unchanged; libc addresses differ from the original server).

Debugging it

Debug your own copy (no root needed):

mkdir -p ~/dbg && cd ~/dbg && cp -r /challenge/. . && gunzip -fr . && chmod +x js glibc/ld-linux-x86-64.so.2
./glibc/ld-linux-x86-64.so.2 --library-path ./glibc ./js ~/exploit.js
gdb -q --args ./glibc/ld-linux-x86-64.so.2 --library-path ./glibc ./js ~/exploit.js

Files in /challenge (executables are gzip-compressed): chall.patch, js.gz.

Original challenge

Description

Points

271

Solves

11

Credits

  • Challenge author(s): not recorded (credit goes to the ASIS CTF Quals 2023 organizers)
  • Compiled by: mito753 in Browser-Exploit-Dojo, which also has the original handout, exploits and writeups

ASIS CTF Quals 2022 · difficulty ★★★★★ · module: Beyond V8: SpiderMonkey, LibJS, MuJS and mJS

MuJS with a free() you can call from JavaScript.

Engine: MuJS (patched), ASIS 2022 build

Running it

Put your exploit at /home/hacker/exploit.js and run /challenge/run. It passes it to the engine as a file, with the original challenge's flags: glibc/ld-linux-x86-64.so.2 --library-path glibc mujs exploit.js. The engine runs as an unprivileged user (uid 1001) that cannot read /flag.

As in the original challenge, the engine itself may read the flag (/flag): the goal is to make it reveal it.

This engine needs a newer glibc than the container has, so it runs through the bundled loader in /challenge/glibc (the binary itself is unchanged; libc addresses differ from the original server).

As in the original, the interpreter itself can read the flag file once you control it: the flag is /flag (the original kept it at /flag.txt).

Debugging it

Debug your own copy (no root needed):

mkdir -p ~/dbg && cd ~/dbg && cp -r /challenge/. . && gunzip -fr . && chmod +x mujs glibc/ld-linux-x86-64.so.2
./glibc/ld-linux-x86-64.so.2 --library-path ./glibc ./mujs ~/exploit.js
gdb -q --args ./glibc/ld-linux-x86-64.so.2 --library-path ./glibc ./mujs ~/exploit.js

Files in /challenge (executables are gzip-compressed): chall.patch, mujs.gz.

Original challenge

Description

js pwn... yay

Points

375

Solves

5

Credits

  • Challenge author(s): not recorded (credit goes to the ASIS CTF Quals 2022 organizers)
  • Compiled by: mito753 in Browser-Exploit-Dojo, which also has the original handout, exploits and writeups

30-Day Scoreboard:

This scoreboard reflects solves for challenges in this module after the module launched in this dojo.

Rank Hacker Badges Score