Cgi / py call inside PHP with parameters

I am trying to execute a cgi / python script from php and at the same time pass the cgi / python script parameter.

in my php i

<? echo exec('/var/www/cgi-bin/test.cgi ' + $_POST["var"]); ?>

However, this does not work, and the apache log says: "sh: 0 not Found"

This test script is very simple:

#!/usr/bin/python
import cgi, sys, os

for arg in sys.argv:
    print arg
+3
source share
1 answer

As someone remarked, the string concatenation operator in PHP is equal ., not +.

The result of "adding" non-numeric strings is 0. That the shell tries to run the command "0" and returns an error: "sh: 0 not found".

Try the following:

exec('/var/www/cgi-bin/test.cgi ' . escapeshellcmd($_POST["var"]));

Also note that shell arguments must be escaped using escapeshellcmd .

+2
source

Source: https://habr.com/ru/post/1792083/


All Articles