|
@@ -0,0 +1,68 @@
|
|
|
+package sshprox
|
|
|
+
|
|
|
+import (
|
|
|
+ "errors"
|
|
|
+ "net/http"
|
|
|
+ "net/url"
|
|
|
+ "os"
|
|
|
+ "os/exec"
|
|
|
+ "path/filepath"
|
|
|
+ "runtime"
|
|
|
+
|
|
|
+ "imuslab.com/zoraxy/mod/reverseproxy"
|
|
|
+ "imuslab.com/zoraxy/mod/utils"
|
|
|
+)
|
|
|
+
|
|
|
+/*
|
|
|
+ SSH Proxy
|
|
|
+
|
|
|
+ This is a tool to bind gotty into Zoraxy
|
|
|
+ so that you can do something similar to
|
|
|
+ online ssh terminal
|
|
|
+*/
|
|
|
+
|
|
|
+type Instance struct {
|
|
|
+ ExecPath string
|
|
|
+}
|
|
|
+
|
|
|
+func NewSSHProxy(binaryRoot string) (*Instance, error) {
|
|
|
+ //Check if the binary exists in system/gotty/
|
|
|
+ binary := "gotty_" + runtime.GOOS + "_" + runtime.GOARCH
|
|
|
+ execPath := filepath.Join(binaryRoot, binary)
|
|
|
+
|
|
|
+ if !utils.FileExists(execPath) {
|
|
|
+ //Binary not found
|
|
|
+ return nil, errors.New("binary not found at " + execPath)
|
|
|
+ }
|
|
|
+
|
|
|
+ //Convert the binary path to realpath
|
|
|
+ realpath, err := filepath.Abs(execPath)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return &Instance{
|
|
|
+ ExecPath: realpath,
|
|
|
+ }, nil
|
|
|
+}
|
|
|
+
|
|
|
+//Create a new Connection to target address
|
|
|
+func (i *Instance) CreateNewConnection(ipaddr string) (*reverseproxy.ReverseProxy, error) {
|
|
|
+ //Create a gotty instance
|
|
|
+ cmd := exec.Command(i.ExecPath, "-p", "8080", "-w", "ssh", ipaddr)
|
|
|
+ cmd.Stdout = os.Stdout
|
|
|
+ cmd.Stderr = os.Stderr
|
|
|
+ cmd.Run()
|
|
|
+ //Create a new proxy agent for this root
|
|
|
+ path, err := url.Parse(ipaddr)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ proxy := reverseproxy.NewReverseProxy(path)
|
|
|
+ return proxy, nil
|
|
|
+}
|
|
|
+
|
|
|
+func HandleWebSSHConnection(w http.ResponseWriter, r *http.Request) {
|
|
|
+
|
|
|
+}
|