From 90e2e053d25feabd2dcf384dfc262a8bcdbe3ab8 Mon Sep 17 00:00:00 2001 From: Cody Hiar Date: Sat, 5 Mar 2022 12:53:15 -0700 Subject: Initial Commit --- termshare/internal/forwarder.go_ | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 termshare/internal/forwarder.go_ (limited to 'termshare/internal/forwarder.go_') diff --git a/termshare/internal/forwarder.go_ b/termshare/internal/forwarder.go_ new file mode 100644 index 0000000..2ce866f --- /dev/null +++ b/termshare/internal/forwarder.go_ @@ -0,0 +1,37 @@ +package main + +import ( + "io" + "log" + + "github.com/gliderlabs/ssh" +) + +func main() { + + log.Println("starting ssh server on port 2222...") + + forwardHandler := &ssh.ForwardedTCPHandler{} + + server := ssh.Server{ + LocalPortForwardingCallback: ssh.LocalPortForwardingCallback(func(ctx ssh.Context, dhost string, dport uint32) bool { + log.Println("Accepted forward", dhost, dport) + return true + }), + Addr: ":2222", + Handler: ssh.Handler(func(s ssh.Session) { + io.WriteString(s, "Remote forwarding available...\n") + select {} + }), + ReversePortForwardingCallback: ssh.ReversePortForwardingCallback(func(ctx ssh.Context, host string, port uint32) bool { + log.Println("attempt to bind", host, port, "granted") + return true + }), + RequestHandlers: map[string]ssh.RequestHandler{ + "tcpip-forward": forwardHandler.HandleSSHRequest, + "cancel-tcpip-forward": forwardHandler.HandleSSHRequest, + }, + } + + log.Fatal(server.ListenAndServe()) +} -- cgit v1.2.3