netexec: Multiple fixes and enhancements to netexec

* Added upload functionality
* More logging
* Moved to test/images
* Image file fixes
pull/6/head
Steve Milner 2015-09-17 11:19:48 -04:00
parent 6439486512
commit e5b85194aa
5 changed files with 57 additions and 0 deletions

View File

@ -3,5 +3,9 @@ MAINTAINER Abhishek Shah "abshah@google.com"
ADD netexec netexec
ADD netexec.go netexec.go
EXPOSE 8080
EXPOSE 8081
RUN mkdir /uploads
ENTRYPOINT ["/netexec"]

View File

@ -20,6 +20,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net"
@ -58,6 +59,7 @@ func startHTTPServer(httpPort int) {
http.HandleFunc("/shutdown", shutdownHandler)
http.HandleFunc("/hostName", hostNameHandler)
http.HandleFunc("/shell", shellHandler)
http.HandleFunc("/upload", uploadHandler)
http.HandleFunc("/dial", dialHandler)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", httpPort), nil))
}
@ -191,6 +193,7 @@ func dialUDP(request string, remoteAddress *net.UDPAddr) (string, error) {
func shellHandler(w http.ResponseWriter, r *http.Request) {
log.Println(r.FormValue("shellCommand"))
log.Printf("%s %s %s\n", shellPath, "-c", r.FormValue("shellCommand"))
cmdOut, err := exec.Command(shellPath, "-c", r.FormValue("shellCommand")).CombinedOutput()
output := map[string]string{}
if len(cmdOut) > 0 {
@ -207,6 +210,43 @@ func shellHandler(w http.ResponseWriter, r *http.Request) {
}
}
func uploadHandler(w http.ResponseWriter, r *http.Request) {
file, _, err := r.FormFile("file")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(w, "Unable to upload file.")
log.Printf("Unable to upload file: %s", err)
return
}
defer file.Close()
f, err := ioutil.TempFile("/uploads", "upload")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(w, "Unable to open file for write.")
log.Printf("Unable to open file for write: %s", err)
return
}
defer f.Close()
if _, err = io.Copy(f, file); err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("Unable to write file."))
log.Printf("Unable to write file: %s", err)
return
}
UploadFile := f.Name()
if err := os.Chmod(UploadFile, 0700); err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(w, "Unable to chmod file.")
log.Printf("Unable to chmod file: %s", err)
return
}
log.Printf("Wrote upload to %s", UploadFile)
w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, UploadFile)
}
func hostNameHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, getHostName())
}

View File

@ -0,0 +1,13 @@
apiVersion: v1
kind: Pod
metadata:
name: netexec
labels:
app: netexec
spec:
containers:
- name: netexec
image: gcr.io/google_containers/netexec:1.1
ports:
- containerPort: 8080
- containerPort: 8081