First, let me brief describe what is included in the core system.
- Compile program
- distinguish what programming language the user is using; (basically it only support Pascal, C and C++)
- use the corresponding compiler to compile the source code;
- limit the size of the objective program it can generate;
- report the compilation is success or not.
- Judge program
- run the compiled objective program with specific test input;
- limit its running time, memory used when it is executing;
- restrict its function call (or system call); (more on this later)
- compare its output with the test output;
- or, special judge if necessary.
Let's discuss the prevention on cheating first. Obviously, if the user know the judge system architecture, one way to cheat is to open the test output file and print it, then he must get an Accept on the task. Or, if the system has stored other users solution, the cheater may hack in and use the solution as his own, even get a copy.
The most serious problem is that, the hacker may write a program which is trying to damage the operating system (OS). He may delete files, change the ownership of files, even get copy of some private files, then he can do some further attack. How horrible it is!
What most commonly use in C is a function ptrace (if I remember correctly, it only available *nix system). How it works is as follow.
- ptrace is called in a child process and stating that ptracing on itself;
- then parent process keep ptracing on its child process, for each signal the child process send out, parent process is first capture it before it send the signal away;
- at this point, the parent process is trying to recognize what child is doing by reading this signal, if its child is a bad guy, parent will kill him immediately;
- otherwise, parent will allow the child continue its process.
However, I am still trying to figure out how to do the same thing in Python. Actually, I cannot find something in Python which is similar to ptrace.