7
2
Here you can see g-code parser, written in JavaScript to use in microcontroller (like espruino). But you can run it in browser, because it don't use any specific features.
function gcode(str){
//Removes comment, parses command name and args
const [,f,args] = (str.match(/^([GM]\d+) ([^;]+)/) || [,"",""]);
//A1.2 B43 C -> {A: 1.2, B: 42, C: 0}
eval(f+"({"+args.replace(/(\w)([\d\.]*)/g,"$1: $2+0,")+"})");
}
const G1 = console.log;
gcode(prompt("crackme"));
When you pass G1 X3 Y4.53 Z42 to gcode(), it runs G1({X: 3, Y: 4.53, Z: 42}). As you can see, it uses eval, protected by regexp. But despite of this, you can attack this function and cause remote code execution. Your goal is to run alert("pwned"). This is code golf, so shortest working input wins

Is
alert`pwned`fine? – l4m2 – 2018-10-29T11:22:36.2072I suggest editing the post to say [[your goal is to display a dialog box with the text "pwned", as if
alert("pwned")was run]]. – user202729 – 2018-10-29T14:39:18.573@l4m2 if it opens box with "pwned" – Евгений Новиков – 2018-10-29T19:01:27.053