piston/readme.md

46 lines
2.3 KiB
Markdown
Raw Normal View History

2018-09-21 20:45:09 +02:00
## Piston
2018-09-22 06:15:24 +02:00
Piston is the underlying engine for running untrusted and possibly malicious code that originates
from from EMKC contests and challenges. It's also used in the Engineer Man Discord server via
[felix bot](https://github.com/engineer-man/felix).
2018-09-21 20:45:09 +02:00
#### Installation
- Install Docker https://www.docker.com/get-started
- `git clone https://github.com/engineer-man/piston`
- `cd piston/docker`
- `./build`
#### Usage
2018-10-06 18:48:10 +02:00
- `docker/execute [language] [path] [arg]...`
2018-09-21 20:45:09 +02:00
#### Supported Languages
2018-10-06 04:31:36 +02:00
Currently python2, python3, c, c++, go, node, ruby, r, c#, nasm, php, and java is supported.
2018-09-21 20:45:09 +02:00
2018-09-22 06:15:24 +02:00
#### Principle of Operation
Piston utilizes Docker as the primary mechanism for sandboxing. There is a small API written in Go which takes
in execution requests and spawns new containers to execute the source from that request. High level, the API writes
2018-09-22 18:52:19 +02:00
a temporary source file to `/tmp` and that gets mounted read-only along with the execution scripts into the container.
The source file is either ran or compiled and ran (in the case of languages like c, c++, c#, go, etc.).
2018-09-22 06:15:24 +02:00
#### Security
Docker provides a great deal of security out of the box. Piston takes additional steps to make it resistant to
various privilege escalation, denial-of-service, and resource saturation threats. These steps include:
- Disabling outgoing network interaction
- Capping memory at 64mb (resists RAM saturation)
- Capping max processes at 16 (resists `:(){ :|: &}:;`, `while True: os.fork()`, etc.)
2018-09-22 18:52:19 +02:00
- Capping max files at 256 (resists various file based attacks)
2018-09-22 06:15:24 +02:00
- Mounting all resources read-only (resists `sudo rm -rf --no-preserve-root /`)
2018-09-22 18:52:19 +02:00
- Capping runtime execution at 3 seconds
2018-09-22 06:15:24 +02:00
- Capping stdout to 65536 characters (resists yes/no bombs and runaway output)
- SIGKILLing misbehaving code
- Disabling journald logs (resists log flood)
#### Performance
One thing that needs investigation is how to spawn containers faster. The Docker daemon is synchronous in its
container spawning. This means the bottleneck for code execution is how fast containers can start. Environments
2018-09-22 18:52:19 +02:00
vary, but, in ours they start at a rate of no more than 1-2 per second. One possibility is Docker in Docker where by
X number of containers stay running all the time and then requests are delivered to each in a round robin and spawn
new Piston containers.
2018-09-21 20:45:09 +02:00
#### License
Piston is licensed under the MIT license.