I am trying to execute a c code in a sandbox. I am using the libsandbox 0.3.5. This is how I go about it: 1) The PHP file uses shell_exec to compile the sandbox first
shell_exec("gcc -o sandbox Sandbox.c -lsandbox");
2) Then I also compile the program to be sandboxed
shell_exec("gcc -static -o 19 19.c");
3) Then I execute the programs
shell_exec("./sandbox ./19<inputFile>outputFile");
The above code takes the stdin from inputFile and writes output to outputFile for the 19 program. The sandbox program returns "OK", "RF", "TL", "ML", etc. I want the output of the sandbox program to be received into a string in the PHP file that calls it. How do I do it?
Another problem that I am facing is that the ouptputFile is not getting created despite sufficient privileges.
Also, will executing the C program in the sandbox ensure security? As in, is that sufficient or do I need to take more precautions?