From f84ab7e50d98706e064093e7b7c8c9c72938c9b9 Mon Sep 17 00:00:00 2001 From: Brian Seymour Date: Fri, 28 Sep 2018 15:24:24 -0500 Subject: [PATCH] asm support --- api/main.go | 42 ++++++++++++++++-------------------------- docker/Dockerfile | 1 + docker/execute | 4 ++++ docker/executors/nasm | 4 ++++ readme.md | 2 +- 5 files changed, 26 insertions(+), 27 deletions(-) create mode 100644 docker/executors/nasm diff --git a/api/main.go b/api/main.go index 94ec64b..b334429 100644 --- a/api/main.go +++ b/api/main.go @@ -33,7 +33,6 @@ func main() { } func Execute(res http.ResponseWriter, req *http.Request) { - var found = false res.Header().Set("Content-Type", "application/json") // get json @@ -42,22 +41,16 @@ func Execute(res http.ResponseWriter, req *http.Request) { message.Decode(&inbound) whitelist := []string{ - "python", - "python2", - "python3", + "python", "python2", "python3", "ruby", - "javascript", - "js", - "node", + "javascript", "js", "node", "c", - "cpp", - "c++", + "cpp", "c++", "go", "r", "php", - "c#", - "csharp", - "cs", + "c#", "csharp", "cs", + "nasm", "asm", } // check if the supplied language is supported @@ -70,33 +63,30 @@ func Execute(res http.ResponseWriter, req *http.Request) { } // now only called when the language is not supported - if !found { - problem := problem{ - Code: "unsupported_language", - Message: inbound.Language + " is not supported by Piston", - } - - pres, _ := json.Marshal(problem) - - res.Write(pres) - return + problem := problem{ + Code: "unsupported_language", + Message: inbound.Language + " is not supported by Piston", } + + pres, _ := json.Marshal(problem) + + res.Write(pres) } -func launch(inbound2 inbound, res http.ResponseWriter){ +func launch(request inbound, res http.ResponseWriter) { var ext string = "code"; - if inbound2.Language == "go" { + if request.Language == "go" { ext = "go" } // write the code to temp dir filename := fmt.Sprintf("/tmp/%d." + ext, time.Now().UnixNano()) - ioutil.WriteFile(filename, []byte(inbound2.Source), 0644) + ioutil.WriteFile(filename, []byte(request.Source), 0644) // set up the execution - cmd := exec.Command("../docker/execute", inbound2.Language, filename) + cmd := exec.Command("../docker/execute", request.Language, filename) // capture out/err var stdout, stderr bytes.Buffer diff --git a/docker/Dockerfile b/docker/Dockerfile index 42b5764..d926bb7 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -17,6 +17,7 @@ RUN apt-get -y install golang RUN apt-get -y install php7.2 RUN apt-get -y install r-base RUN apt-get -y install mono-complete +RUN apt-get -y install nasm RUN useradd -m runner diff --git a/docker/execute b/docker/execute index 7a32954..e44029d 100755 --- a/docker/execute +++ b/docker/execute @@ -47,6 +47,9 @@ case "$lang" in "php") bin=executor_php ;; +"nasm" | "asm") + bin=executor_nasm + ;; *) echo "invalid language" exit @@ -68,6 +71,7 @@ docker run \ -v $dir/executors/csharp:/executor_csharp:ro \ -v $dir/executors/r:/executor_r:ro \ -v $dir/executors/php:/executor_php:ro \ + -v $dir/executors/nasm:/executor_nasm:ro \ piston \ runuser \ -l runner \ diff --git a/docker/executors/nasm b/docker/executors/nasm new file mode 100644 index 0000000..d412cb6 --- /dev/null +++ b/docker/executors/nasm @@ -0,0 +1,4 @@ +#!/bin/sh + +nasm -f elf64 -o binary.o $1 +ld binary.o -o binary diff --git a/readme.md b/readme.md index f521bda..e13dfc7 100644 --- a/readme.md +++ b/readme.md @@ -13,7 +13,7 @@ from from EMKC contests and challenges. It's also used in the Engineer Man Disco - `docker/execute ` #### Supported Languages -Currently python2, python3, c, c++, go, node, ruby, r, c#, and php is supported. +Currently python2, python3, c, c++, go, node, ruby, r, c#, nasm, and php is supported. #### Principle of Operation Piston utilizes Docker as the primary mechanism for sandboxing. There is a small API written in Go which takes