Although I know that system calls and security do not go hand in hand, there is a project for which I need it. I am writing a small code check, and I need to compile and execute the user-submitted code to test my test cases.
Basically, I want to run the code in the sandbox so that it cannot touch any files outside the temporary directory, and any files that it creates cannot be accessible to the outside world. Recently, I came across an exploit with which the user could create a file, say shell.php with the following contents.
<?php echo system($_GET['x']); ?>
This gives the attacker a remote shell, and since the file owner is apache, the attacker can basically move my entire /var/www where mysql passwords are stored along with other configuration information.
While I know about threats such as SQL Injections, and have deactivated user input before any database operations, I donโt know how to configure the sandbox. What are the methods that I can use to turn off system calls (right now I'm looking for the word "system" in the code submitted by the user and do not execute these fragments where it is found) and restricts access to the files that the user generated code.
At the moment, my code check only works for C, and I plan to add support for other languages, such as C ++, Java, Ruby, and Python, after I can protect it. I would also like to know more about this issue that I have encountered, so pointers to a place where I could learn more about Internet security will also be appreciated.
My development machine runs Mac OS Lion, and the deployment machine is a Linux server, so if a solution that was a cross platform would be very useful, but one that only applies to a Linux machine would work too .
nikhil
source share