Sandbox does not restrict file access and execution
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1k
- Forks
- 412
- Avg merge
- 6d 10h
- Merged PRs (30d)
- 3
Description
The sandbox does not restrict writing to local files and allows access to a large part of the directory tree, in particular everything in /usr/. Here are some examples how this can be exploited:
-
In the Batch task type (but not restricted to Batch), linking the solution file to the output file can trick the system.
#include <unistd.h> int main() { return symlink("output.txt", "res.txt"); }When
res.txtgets copied to the sandbox directory, it overwrites theoutput.txtfile. This can be fixed in Sandbox.py, see this patch for a possible fix. I have not checked if this fix breaks other task types, but those who are, are vulnerable to this attack anyway. Whitelisting files as proposed in #309 would also work.This is also a privilege escalation, because the path linked to does not need to exist. It is perfectly fine to link to
/tmp/i_was_here(or any other path) and the EvaluationService process will happily write to that file. -
Execute installed binaries and load installed libraries. For example, running a Python interpreter from C, even if Python is not an allowed language:
#include <unistd.h> static const char *code = "print(eval('+'.join(raw_input().split())))"; int main() { return execl("/usr/bin/python2", "/usr/bin/python2", "-S", "-c", code, NULL); }This is possible because
execldoes not start a new process, it just replaces the old one.On a similar note, one could submit a source file that contains a Base64-encoding of a binary file that makes use of "unallowed features" such as being compiling with
-O3or-pthread, using a bigint library-lgmpor similar. This data can be written to a file and executed like above. -
Access to all header files in
/usr/include. This is more of a gray zone. Is it allowed to#include <boost/graph/dijkstra_shortest_paths.hpp>? While those files should not be available in the first place, it would be nice to be able to whitelist only the standard library headers and their dependencies for compiling.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Sandbox.py and the Batch task path described in the issue, then trace how files are copied and how EvaluationService launches submissions. Review the linked patch and issue #309 for the proposed approaches. Done means submissions cannot overwrite or write arbitrary files, access unintended system paths, or execute unallowed binaries and libraries across task types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, python
- Domain
- operating-systems, security
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100