0

I am playing with the web type of ctf Questions are as follows

<?php
if(!isset($_FILES["file"]))
    highlight_file(__file__) && die();
$flag = file_get_contents('/flag');
$node = @`node {$_FILES["file"]["tmp_name"]} 2>&1`;
$python = @`python3 {$_FILES["file"]["tmp_name"]} 2>&1`;
if($flag === $node && $flag === $python)
    echo 'Here is your Flag: '.$flag;
else
    echo 'Fail :(';                                         ?>

According to program logic, I uploaded two files I wrote using postman form-data, They are test.js and test.py respectively, I want to get the flag file content in the script and compare it with the $flag variable, But I can't get the $node variable and the $python variable to be true at the same time, I can't get the flag, ask for help

1 Answers1

1

It looks to me like you need a single file that parses as valid JS and valid Python at the same time.

Here's the same code twice with Python and Javascript syntax highlighting:

Python

a = 1 // 1 ; b = '''

// Put your Javascript code here.
// Python will just assign it to a string variable
console.log('Javascript running here');

/* '''

# Put your Python code here. Javascript will ignore it
# because it's inside a comment
print('Python running here')

# */

Javascript

a = 1 // 1 ; b = '''

// Put your Javascript code here.
// Python will just assign it to a string variable
console.log('Javascript running here');

/* '''

# Put your Python code here. Javascript will ignore it
# because it's inside a comment
print('Python running here')

# */
r3mainer
  • 23,981
  • 3
  • 51
  • 88
  • It's amazing this helped me but I don't know why such a python program can execute a js program – 0xbe61a55f Sep 12 '22 at 13:30
  • It's a [polyglot](https://en.wikipedia.org/wiki/Polyglot_%28computing%29). The Python code only runs in Python, and the JS code only runs in JS. – r3mainer Sep 12 '22 at 13:34
  • Probably got it, thank you very much The grammar is a bit difficult to understand. Are there any learning resources that I can refer to? Thank you – 0xbe61a55f Sep 12 '22 at 13:58
  • Any basic introduction to Python and Javascript will explain the syntax of the language and how to insert comments. Creating a polygot isn't that hard. – r3mainer Sep 12 '22 at 15:28