|
@@ -5,6 +5,7 @@ import (
|
|
|
"fmt"
|
|
|
"net/http"
|
|
|
"strconv"
|
|
|
+ "strings"
|
|
|
|
|
|
"imuslab.com/zoraxy/mod/sshprox"
|
|
|
"imuslab.com/zoraxy/mod/utils"
|
|
@@ -18,45 +19,45 @@ import (
|
|
|
|
|
|
func HandleCreateProxySession(w http.ResponseWriter, r *http.Request) {
|
|
|
//Get what ip address and port to connect to
|
|
|
- ipaddr, err := utils.GetPara(r, "ipaddr")
|
|
|
+ ipaddr, err := utils.PostPara(r, "ipaddr")
|
|
|
if err != nil {
|
|
|
http.Error(w, "Invalid Usage", http.StatusInternalServerError)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- portString, err := utils.GetPara(r, "port")
|
|
|
+ portString, err := utils.PostPara(r, "port")
|
|
|
if err != nil {
|
|
|
portString = "22"
|
|
|
}
|
|
|
|
|
|
- username, err := utils.GetPara(r, "username")
|
|
|
+ username, err := utils.PostPara(r, "username")
|
|
|
if err != nil {
|
|
|
username = ""
|
|
|
}
|
|
|
|
|
|
port, err := strconv.Atoi(portString)
|
|
|
if err != nil {
|
|
|
- http.Error(w, "Invalid port number given", http.StatusInternalServerError)
|
|
|
+ utils.SendErrorResponse(w, "invalid port number given")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//Check if the target is a valid ssh endpoint
|
|
|
if !sshprox.IsSSHConnectable(ipaddr, port) {
|
|
|
- http.Error(w, ipaddr+":"+strconv.Itoa(port)+" is not a valid SSH server", http.StatusInternalServerError)
|
|
|
+ utils.SendErrorResponse(w, ipaddr+":"+strconv.Itoa(port)+" is not a valid SSH server")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//Create a new proxy instance
|
|
|
instance, err := webSshManager.NewSSHProxy("./system/gotty")
|
|
|
if err != nil {
|
|
|
- http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
+ utils.SendErrorResponse(w, strings.ReplaceAll(err.Error(), "\\", "/"))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//Create an ssh process to the target address
|
|
|
err = instance.CreateNewConnection(webSshManager.GetNextPort(), username, ipaddr, port)
|
|
|
if err != nil {
|
|
|
- http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
+ utils.SendErrorResponse(w, err.Error())
|
|
|
return
|
|
|
}
|
|
|
|