Browse Source

auto update script executed

tobychui 2 years ago
parent
commit
726fb34409
6 changed files with 91 additions and 4 deletions
  1. 1 1
      api.go
  2. 1 0
      go.mod
  3. 2 0
      go.sum
  4. 17 1
      helpers.go
  5. 68 0
      mod/sshprox/sshprox.go
  6. 2 2
      web/tools/ipscan.html

+ 1 - 1
api.go

@@ -80,7 +80,7 @@ func initAPIs() {
 	//mDNS APIs
 	authRouter.HandleFunc("/api/mdns/list", HandleMdnsListing)
 	authRouter.HandleFunc("/api/mdns/discover", HandleMdnsScanning)
-
+	authRouter.HandleFunc("/api/ssdp/discover", HandleSsdpDiscovery)
 	//Network utilities
 	authRouter.HandleFunc("/api/tools/ipscan", HandleIpScan)
 

+ 1 - 0
go.mod

@@ -3,6 +3,7 @@ module imuslab.com/zoraxy
 go 1.16
 
 require (
+	github.com/bcurren/go-ssdp v0.0.0-20130927201504-ae8e7a0ef8a8 // indirect
 	github.com/boltdb/bolt v1.3.1
 	github.com/go-ping/ping v1.1.0
 	github.com/google/uuid v1.3.0

+ 2 - 0
go.sum

@@ -1,3 +1,5 @@
+github.com/bcurren/go-ssdp v0.0.0-20130927201504-ae8e7a0ef8a8 h1:a5CrzovDwGx3NE8+FXDkx7vyBo0EWeQ/JOKP1Q8VD6I=
+github.com/bcurren/go-ssdp v0.0.0-20130927201504-ae8e7a0ef8a8/go.mod h1:XW7y5ILmTgyAH5CEVZ7fPldvuDl1bYqQsqZrFM/LzKQ=
 github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
 github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
 github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=

+ 17 - 1
helpers.go

@@ -3,9 +3,11 @@ package main
 import (
 	"encoding/json"
 	"fmt"
+	"log"
 	"net/http"
 	"time"
 
+	"github.com/bcurren/go-ssdp"
 	"imuslab.com/zoraxy/mod/dynamicproxy"
 	"imuslab.com/zoraxy/mod/ipscan"
 	"imuslab.com/zoraxy/mod/mdns"
@@ -156,7 +158,7 @@ func HandleMdnsScanning(w http.ResponseWriter, r *http.Request) {
 	utils.SendJSONResponse(w, string(js))
 }
 
-//handle traceroute tools
+//handle ip scanning
 func HandleIpScan(w http.ResponseWriter, r *http.Request) {
 	cidr, err := utils.PostPara(r, "cidr")
 	if err != nil {
@@ -193,3 +195,17 @@ func HandleIpScan(w http.ResponseWriter, r *http.Request) {
 		utils.SendJSONResponse(w, string(js))
 	}
 }
+
+//Handle SSDP discovery
+func HandleSsdpDiscovery(w http.ResponseWriter, r *http.Request) {
+	responses, err := ssdp.Search("ssdp:discover", 10*time.Second)
+	log.Println(responses, err)
+	if err != nil {
+		return
+	}
+
+	for _, response := range responses {
+		// Do something with the response you discover
+		fmt.Println(response)
+	}
+}

+ 68 - 0
mod/sshprox/sshprox.go

@@ -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) {
+
+}

+ 2 - 2
web/tools/ipscan.html

@@ -56,7 +56,7 @@
             <button class="ui basic button" onclick="toggleOfflineHost();"><i class="grey eye icon"></i>View Offline Hosts</button>
             <div class="ui divider"></div>
             <br>
-                <div id="scan-results">
+                <div id="scan-results" style="overflow-x: auto;">
                    
                 </div>
             <br>
@@ -136,7 +136,7 @@
                 }
 
                 function displayResults(data) {
-                    var table = $('<table class="ui celled table"></table>');
+                    var table = $('<table class="ui celled unstackable table"></table>');
                     var header = $('<thead><tr><th>IP Address</th><th>Ping</th><th>Hostname</th><th>HTTP Detected</th><th>HTTPS Detected</th></tr></thead>');
                     table.append(header);
                     var body = $('<tbody></tbody>');