|
| 1 | +# Jeil - Web |
| 2 | +> You are awesome at breaking into stuff, how about breaking out? |
| 3 | +
|
| 4 | +In this challenge, we need to break out of a Javascript jail. This is the source code of it: |
| 5 | + |
| 6 | +``` |
| 7 | +var readline = require('readline'); |
| 8 | +var rl = readline.createInterface(process.stdin, process.stdout); |
| 9 | +
|
| 10 | +var Jail = (function() { |
| 11 | + var rv = {}; |
| 12 | +
|
| 13 | + function secretFuncUnguessable{{ENV_SECRET_0}}(a,b,c){ |
| 14 | + if(a === '{{ENV_SECRET_1}}' && b === '{{ENV_SECRET_2}}' && c === '{{ENV_SECRET_3}}'){ |
| 15 | + return true; |
| 16 | + } |
| 17 | + } |
| 18 | +
|
| 19 | + function call(code) { |
| 20 | + var line = ""; |
| 21 | +
|
| 22 | + if(new RegExp(/[\[\]\.\\\+\-\/;a-zA-Z{}`'"\s]/).test(code)){ |
| 23 | + console.log("Unrecognized code."); |
| 24 | + throw 123; |
| 25 | + return; |
| 26 | + } |
| 27 | +
|
| 28 | + if(!(code.length == 32)){ |
| 29 | + console.log("Incorrect code length."); |
| 30 | + throw 123; |
| 31 | + return; |
| 32 | + } |
| 33 | +
|
| 34 | + arguments = undefined; |
| 35 | +
|
| 36 | + ret = null; |
| 37 | + ret = eval("this.secretFuncUnguessable"+code); |
| 38 | +
|
| 39 | + if(typeof ret == "function"){ |
| 40 | + if(ret.call(this,'{{ENV_SECRET_1}}', '{{ENV_SECRET_2}}', '{{ENV_SECRET_3}}') === true){ |
| 41 | + console.log("{{ENV_SECRET_FLAG}}"); |
| 42 | + }else{ |
| 43 | + console.log("Incorrect code."); |
| 44 | + } |
| 45 | + }else{ |
| 46 | + console.log("Incorrect code."); |
| 47 | + } |
| 48 | + throw 123; |
| 49 | + }; |
| 50 | + rv.call = call; |
| 51 | + rv.toString = function(){return rv.call.toString()}; |
| 52 | +
|
| 53 | + return rv; |
| 54 | +})(); |
| 55 | +
|
| 56 | +template = `| ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄| |
| 57 | +| Internal | |
| 58 | +|________| |
| 59 | + || |
| 60 | +(\\__/) || |
| 61 | +(•ㅅ•) || |
| 62 | +/ づ |
| 63 | +Code: `; |
| 64 | +
|
| 65 | +function ask(){ |
| 66 | + rl.question(template,function(answer){ |
| 67 | + Jail.call(answer); |
| 68 | + }); |
| 69 | +} |
| 70 | +
|
| 71 | +ask(); |
| 72 | +``` |
| 73 | + |
| 74 | +From this code, we can see that we need to fulfil the following: |
| 75 | +- input must be 32 bytes |
| 76 | +- chars must not be any of [\[\]\.\\\+\-\/;a-zA-Z{}`'"\s] |
| 77 | +- need ret to become a function which returns true |
| 78 | + |
| 79 | +Therefore, we remove the prefix by issuing it a value with = operator and random garbage. Then we use the ? ternary operator to get code execution again. Since the = operator returns true, we can use the "true case" of the ? operator to get code execution to create a lambda function with "=>". The payload that we needed was: |
| 80 | +```=1?_1=>1==1:11111111111111111111``` |
0 commit comments