-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (68 loc) · 1.16 KB
/
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
60
61
62
63
64
65
66
67
68
69
70
71
package main
// Project gocat
// File: main.go
// Author: Matt Weidner <matt.weidner@gmail.com>
// Description: netcat/socat clone
// current version is listen only,
// spawns a hardcoded application
// on client connect.
import (
"fmt"
"io"
"log"
"net"
"os"
"os/exec"
)
func handleClient(c net.Conn) {
CMD := "/bin/sh"
cmd := exec.Command(CMD)
sip, e := cmd.StdinPipe()
if e != nil {
panic(e)
}
defer sip.Close()
sop, e := cmd.StdoutPipe()
if e != nil {
panic(e)
}
defer sop.Close()
sep, e := cmd.StderrPipe()
if e != nil {
panic(e)
}
defer sep.Close()
go func() {
io.Copy(sip, c)
cmd.Process.Kill()
}()
go func() {
io.Copy(c, sop)
cmd.Process.Kill()
}()
go func() {
io.Copy(c, sep)
cmd.Process.Kill()
}()
cmd.Run()
}
func main() {
build := 7
LHOST := "0.0.0.0"
LPORT := "11621"
fmt.Fprintf(os.Stderr, "gocat build %d\n", build)
fmt.Fprintf(os.Stderr, "Listening on %s:%s\n", LHOST, LPORT)
l, e := net.Listen("tcp", LHOST+":"+LPORT)
if e != nil {
panic(e)
}
defer l.Close()
for {
c, e := l.Accept()
log.Println(c.RemoteAddr())
if e != nil {
panic(e)
}
go handleClient(c)
}
}