├── Dockerfile.alpine ├── Dockerfile.fedora ├── Dockerfile.golang ├── Dockerfile.scratch ├── Dockerfile.ubuntu ├── README.md ├── license └── main.go /Dockerfile.alpine: -------------------------------------------------------------------------------- 1 | FROM alpine 2 | COPY simpleExec / 3 | CMD ["/simpleExec"] 4 | 5 | EXPOSE 8080 6 | 7 | -------------------------------------------------------------------------------- /Dockerfile.fedora: -------------------------------------------------------------------------------- 1 | FROM fedora 2 | COPY simpleExec / 3 | CMD ["/simpleExec"] 4 | EXPOSE 8080 5 | -------------------------------------------------------------------------------- /Dockerfile.golang: -------------------------------------------------------------------------------- 1 | FROM golang 2 | COPY simpleExec / 3 | CMD ["/simpleExec"] 4 | EXPOSE 8080 5 | -------------------------------------------------------------------------------- /Dockerfile.scratch: -------------------------------------------------------------------------------- 1 | FROM scratch 2 | COPY simpleExec / 3 | CMD ["/simpleExec"] 4 | 5 | EXPOSE 8080 6 | 7 | -------------------------------------------------------------------------------- /Dockerfile.ubuntu: -------------------------------------------------------------------------------- 1 | FROM ubuntu 2 | COPY simpleExec / 3 | CMD ["/simpleExec"] 4 | EXPOSE 8080 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # simpleexec - trivial webshell in go 2 | A simple webshell in go to help demonstrate the risks of heavy weight docker images, docker image sizes, and attack surface. 3 | 4 | 5 | ## Compiling: 6 | ``` 7 | CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o simpleExec . 8 | ``` 9 | 10 | **Explanation of above:** 11 | We are statically linking the necessary libraries (though this app doesn't use much). So the go binary will have everything it needs (including the kitchen sink that typically comes with the Linux OS) 12 | 13 | CGO_ENABLED = 0 -installsuffix cgo means to not use go libraries that use "C" go libraries (because we are cross-compiling from a Mac to a linux OS). 14 | 15 | More info on that: 16 | https://golang.org/cmd/cgo/ 17 | https://github.com/golang/go/issues/9344 18 | 19 | 20 | ## Building Containers 21 | 22 | For GoLang: 23 | ``` 24 | docker build -t simple-golang -f Dockerfile.golang . 25 | docker run -p 8004:8080 --name simple-golang -t simple-golang 26 | ``` 27 | 28 | For Fedora: 29 | ``` 30 | docker build -t simple-fedora -f Dockerfile.fedora . 31 | docker run -p 8000:8080 --name simple-fedora -t simple-fedora 32 | ``` 33 | 34 | For Ubuntu: 35 | ``` 36 | docker build -t simple-ubuntu -f Dockerfile.ubuntu . 37 | docker run -p 8001:8080 --name simple-ubuntu -t simple-ubuntu 38 | ``` 39 | 40 | For alpine: 41 | ``` 42 | docker build -t simple-alpine -f Dockerfile.alpine . 43 | docker run -p 8080:8080 --name alpineweb -t simpealpine 44 | ``` 45 | 46 | For scratch: 47 | ``` 48 | docker build -t simple-scratch -f Dockerfile.scratch . 49 | docker run -p 8003:8080 --name simple-scratch -t simple-scratch 50 | ``` 51 | 52 | **Container sizes:** 53 | ``` 54 | $ docker ps -s 55 | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE 56 | f3617c277518 simple-golang "/simpleExec" 27 seconds ago Up 27 seconds 0.0.0.0:8004->8080/tcp simple-golang 0 B (virtual 709 MB) 57 | 9ec20298b489 simple-fedora "/simpleExec" About a minute ago Up About a minute 0.0.0.0:8000->8080/tcp simple-fedora 0 B (virtual 237 MB) 58 | 5dab651ee3af simple-scratch "/simpleExec" 4 hours ago Up 4 hours 0.0.0.0:8003->8080/tcp simple-scratch 0 B (virtual 5.96 MB) 59 | f3d75455ecd2 simple-alpine "/simpleExec" 4 hours ago Up 4 hours 0.0.0.0:8002->8080/tcp simple-alpine 0 B (virtual 9.95 MB) 60 | 33d05c1c7218 simple-ubuntu "/simpleExec" 4 hours ago Up 4 hours 0.0.0.0:8001->8080/tcp simple-ubuntu 0 B (virtual 123 MB) 61 | ``` 62 | 63 | 64 | ## Getting Started (Mac) 65 | 66 | You should have docker and Go installed. 67 | 68 | 69 | 70 | ## Additional Resources 71 | 72 | [Building Minimal Docker Containers for Go Applications](https://blog.codeship.com/building-minimal-docker-containers-for-go-applications/) 73 | 74 | ## TODO: 75 | 76 | - blog posts 77 | - demonstration video 78 | - build instructions for other platforms 79 | - demonstration instructions 80 | 81 | 82 | 83 | ### Docker Install 84 | 85 | *ToDo* 86 | 87 | ### Go Installation 88 | 89 | *ToDo* 90 | 91 | ### Tests; CI/CD; Docker Registry Setup 92 | 93 | *ToDo* 94 | 95 | ## Built With 96 | 97 | * Go 98 | 99 | ## Contributing 100 | 101 | *ToDo:* 102 | 103 | Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us. 104 | 105 | ## Versioning 106 | 107 | We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/your/project/tags). 108 | 109 | ## Authors 110 | 111 | * **Liam Randall** 112 | * **Jeremy Fleitz** 113 | 114 | See also the list of [contributors](https://github.com/criticalstack/simpleexec/contributors) who participated in this project. 115 | 116 | ## License 117 | 118 | This project is licensed under the BSD License - see the [LICENSE](LICENSE) file for details 119 | 120 | ## Acknowledgments 121 | 122 | * Critical Stack Crew 123 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017, Liam Randall 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "os/exec" 7 | ) 8 | 9 | func main() { 10 | http.HandleFunc("/exec", func(w http.ResponseWriter, r *http.Request) { 11 | 12 | cmd := r.URL.Query().Get("cmd") 13 | args := r.URL.Query()["arg"] 14 | 15 | w.Write(runCmd(cmd, args)) 16 | }) 17 | 18 | var port = ":8080" 19 | 20 | fmt.Printf("Server listening - http://%s%s", "127.0.0.1", port) 21 | 22 | err := http.ListenAndServe(port, nil) 23 | 24 | if err != nil { 25 | fmt.Printf(err.Error()) 26 | } 27 | 28 | } 29 | 30 | func runCmd(cmd string, args []string) []byte { 31 | 32 | out, err := exec.Command(cmd, args...).Output() 33 | if err != nil { 34 | return []byte(fmt.Sprintf("
%v
", err)) 35 | } 36 | return []byte(fmt.Sprintf("
%s
", out)) 37 | } 38 | --------------------------------------------------------------------------------