Created
December 8, 2016 15:28
-
-
Save elico/dd09874b011f809e0ca74f89403c505c to your computer and use it in GitHub Desktop.
A tightvnc "attach" proxy that adds the functionality to use ultravnc repeater and ultravnc viewer and connect to the client based on the ID.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/tls" | |
"crypto/x509" | |
"flag" | |
"fmt" | |
"io" | |
"io/ioutil" | |
"net" | |
) | |
var localAddr *string = flag.String("l", "localhost:9999", "local address") | |
var remoteAddr *string = flag.String("r", "www1.ngtech.co.il:5500", "remote address") | |
var connid *string = flag.String("id", "111111", "Connection ID") | |
var certificatePath *string = flag.String("cert", "cert.pem", "Server Certificate file path") | |
var useTls *bool = flag.Bool("use-tls", false, "Use tls connection to the server") | |
var ignoreTlsTrust *bool = flag.Bool("ignore-tls-trust", true, "Use tls connection to any") | |
var localCA_Pool *x509.CertPool | |
var localTlsConfig tls.Config | |
func proxyConn(conn *net.TCPConn) { | |
rAddr, err := net.ResolveTCPAddr("tcp", *remoteAddr) | |
if err != nil { | |
panic(err) | |
} | |
if *useTls { | |
rConn, err := tls.Dial("tcp", rAddr.String(), &localTlsConfig) | |
if err != nil { | |
fmt.Println("client: dial: %s", err) | |
return | |
} | |
defer rConn.Close() | |
defer conn.Close() | |
idstr := "ID:" + *connid | |
bs := make([]byte, 250) | |
for i := range idstr { | |
bs[i] = idstr[i] | |
} | |
rConn.Write(bs) | |
go io.Copy(rConn, conn) | |
io.Copy(conn, rConn) | |
} else { | |
rConn, err := net.DialTCP("tcp", nil, rAddr) | |
if err != nil { | |
fmt.Println("client: dial: %s", err) | |
return | |
} | |
defer rConn.Close() | |
defer conn.Close() | |
idstr := "ID:" + *connid | |
bs := make([]byte, 250) | |
for i := range idstr { | |
bs[i] = idstr[i] | |
} | |
rConn.Write(bs) | |
go io.Copy(rConn, conn) | |
io.Copy(conn, rConn) | |
} | |
} | |
func main() { | |
flag.Parse() | |
if *useTls { | |
localCA_Pool = x509.NewCertPool() | |
severCert, err := ioutil.ReadFile(*certificatePath) | |
if err != nil { | |
fmt.Println("Could not load server certificate!") | |
return | |
} | |
localCA_Pool.AppendCertsFromPEM(severCert) | |
localTlsConfig = tls.Config{RootCAs: localCA_Pool, InsecureSkipVerify: *ignoreTlsTrust,} | |
} | |
fmt.Println("Will use the ID:", *connid) | |
fmt.Printf("Listening: %v\nProxying: %v\n\n", *localAddr, *remoteAddr) | |
addr, err := net.ResolveTCPAddr("tcp", *localAddr) | |
if err != nil { | |
panic(err) | |
} | |
listener, err := net.ListenTCP("tcp", addr) | |
if err != nil { | |
panic(err) | |
} | |
for { | |
conn, err := listener.AcceptTCP() | |
if err != nil { | |
panic(err) | |
} | |
go proxyConn(conn) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment