-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (60 loc) · 1.65 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
72
73
74
75
package main
import (
"flag"
"fmt"
"io"
"net"
"os"
"sync"
"github.com/geistesk/zwiebelpfanne/hiddenserv"
)
// handleConn takes an incomming net.Conn from a listener and tries to bind it
// to a connection to a Hidden Service created by hiddenserv.HiddenServiceConn.
func handleConn(conn net.Conn, torSocks, hiddenService string) {
defer conn.Close()
torConn, err := hiddenserv.HiddenServiceConn(torSocks, hiddenService)
if err != nil {
fmt.Printf("Failed to establish Hidden Service connection for %s: %v\n",
conn.RemoteAddr(), err.Error())
return
}
defer torConn.Close()
var wg sync.WaitGroup
wg.Add(2)
go func() {
io.Copy(torConn, conn)
wg.Done()
}()
go func() {
io.Copy(conn, torConn)
wg.Done()
}()
wg.Wait()
fmt.Printf("Close connection to %s\n", conn.RemoteAddr())
}
func main() {
var localAddr, torSocks, hiddenService string
flag.StringVar(&localAddr, "listen", "localhost:1337", "Bind to this address")
flag.StringVar(&torSocks, "tor-socks5", "localhost:9050", "Tor's SOCKS5 proxy")
flag.StringVar(&hiddenService, "onion", "", "Hidden Service to be bound to")
flag.Parse()
if hiddenService == "" {
fmt.Println("zwiebelpfanne: --onion is missing")
os.Exit(1)
}
fmt.Printf("zwiebelpfanne: %s -> %s\n", hiddenService, localAddr)
ln, err := net.Listen("tcp", localAddr)
if err != nil {
fmt.Printf("Could not listen on %s: %v\n", localAddr, err.Error())
os.Exit(1)
}
for {
conn, err := ln.Accept()
if err != nil {
fmt.Printf("Failed to accept connection: %v\n", err.Error())
continue
}
fmt.Printf("Established connection to %s\n", conn.RemoteAddr())
go handleConn(conn, torSocks, hiddenService)
}
}