Exploit databaseDownload repository ZIP
GH-01444087b01aeb1dee1796a8839b8ee1
297855/nwctbf
Sources for CVE-2025-22870
5 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files6
297855/nwctbfRevision 281652541089
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
web/controllers/index.go
Go · 12,376 bytespackage controllers
import (
"strings"
"github.com/beego/beego"
"github.com/djylb/nps/lib/common"
"github.com/djylb/nps/lib/file"
"github.com/djylb/nps/server"
"github.com/djylb/nps/server/tool"
)
type IndexController struct {
BaseController
}
func (s *IndexController) Index() {
s.Data["web_base_url"] = beego.AppConfig.String("web_base_url")
s.Data["data"] = server.GetDashboardData()
s.SetInfo("dashboard")
s.display("index/index")
}
func (s *IndexController) Help() {
s.SetInfo("about")
s.display("index/help")
}
func (s *IndexController) Tcp() {
s.SetInfo("tcp")
s.SetType("tcp")
s.display("index/list")
}
func (s *IndexController) Udp() {
s.SetInfo("udp")
s.SetType("udp")
s.display("index/list")
}
func (s *IndexController) Socks5() {
s.SetInfo("socks5")
s.SetType("socks5")
s.display("index/list")
}
func (s *IndexController) Http() {
s.SetInfo("http proxy")
s.SetType("httpProxy")
s.display("index/list")
}
func (s *IndexController) File() {
s.SetInfo("file server")
s.SetType("file")
s.display("index/list")
}
func (s *IndexController) Secret() {
s.SetInfo("secret")
s.SetType("secret")
s.display("index/list")
}
func (s *IndexController) P2p() {
s.SetInfo("p2p")
s.SetType("p2p")
s.display("index/list")
}
func (s *IndexController) Host() {
s.SetInfo("host")
s.SetType("hostServer")
s.display("index/list")
}
func (s *IndexController) All() {
s.Data["menu"] = "client"
clientId := s.getEscapeString("client_id")
s.Data["client_id"] = clientId
s.SetInfo("client id:" + clientId)
s.display("index/list")
}
func (s *IndexController) GetTunnel() {
start, length := s.GetAjaxParams()
taskType := s.getEscapeString("type")
clientId := s.GetIntNoErr("client_id")
list, cnt := server.GetTunnel(start, length, taskType, clientId, s.getEscapeString("search"), s.getEscapeString("sort"), s.getEscapeString("order"))
s.AjaxTable(list, cnt, cnt, nil)
}
func (s *IndexController) Add() {
if s.Ctx.Request.Method == "GET" {
s.Data["type"] = s.getEscapeString("type")
s.Data["client_id"] = s.getEscapeString("client_id")
s.SetInfo("add tunnel")
s.display()
} else {
id := int(file.GetDb().JsonDb.GetTaskId())
clientId := s.GetIntNoErr("client_id")
t := &file.Tunnel{
Port: s.GetIntNoErr("port"),
ServerIp: s.getEscapeString("server_ip"),
Mode: s.getEscapeString("type"),
Target: &file.Target{
TargetStr: strings.ReplaceAll(s.getEscapeString("target"), "\r\n", "\n"),
ProxyProtocol: s.GetIntNoErr("proxy_protocol"),
LocalProxy: (clientId > 0 && s.GetBoolNoErr("local_proxy")) || clientId <= 0,
},
UserAuth: &file.MultiAccount{
Content: s.getEscapeString("auth"),
AccountMap: common.DealMultiUser(s.getEscapeString("auth")),
},
Id: id,
Status: true,
Remark: s.getEscapeString("remark"),
Password: s.getEscapeString("password"),
LocalPath: s.getEscapeString("local_path"),
StripPre: s.getEscapeString("strip_pre"),
Flow: &file.Flow{
FlowLimit: int64(s.GetIntNoErr("flow_limit")),
TimeLimit: common.GetTimeNoErrByStr(s.getEscapeString("time_limit")),
},
}
if t.Port <= 0 {
t.Port = tool.GenerateServerPort(t.Mode)
}
if !tool.TestServerPort(t.Port, t.Mode) {
s.AjaxErr("The port cannot be opened because it may has been occupied or is no longer allowed.")
}
var err error
if t.Client, err = file.GetDb().GetClient(clientId); err != nil {
s.AjaxErr(err.Error())
}
if t.Client.MaxTunnelNum != 0 && t.Client.GetTunnelNum() >= t.Client.MaxTunnelNum {
s.AjaxErr("The number of tunnels exceeds the limit")
}
if err := file.GetDb().NewTask(t); err != nil {
s.AjaxErr(err.Error())
}
if err := server.AddTask(t); err != nil {
s.AjaxErr(err.Error())
} else {
s.AjaxOkWithId("add success", id)
}
}
}
func (s *IndexController) GetOneTunnel() {
id := s.GetIntNoErr("id")
data := make(map[string]interface{})
if t, err := file.GetDb().GetTask(id); err != nil {
data["code"] = 0
} else {
data["code"] = 1
data["data"] = t
}
s.Data["json"] = data
s.ServeJSON()
}
func (s *IndexController) Edit() {
id := s.GetIntNoErr("id")
if s.Ctx.Request.Method == "GET" {
if t, err := file.GetDb().GetTask(id); err != nil {
s.error()
} else {
s.Data["t"] = t
if t.UserAuth == nil {
s.Data["auth"] = ""
} else {
s.Data["auth"] = t.UserAuth.Content
}
}
s.SetInfo("edit tunnel")
s.display()
} else {
if t, err := file.GetDb().GetTask(id); err != nil {
s.error()
} else {
clientId := s.GetIntNoErr("client_id")
if client, err := file.GetDb().GetClient(clientId); err != nil {
s.AjaxErr("modified error,the client is not exist")
return
} else {
t.Client = client
}
if s.GetIntNoErr("port") != t.Port {
t.Port = s.GetIntNoErr("port")
if t.Port <= 0 {
t.Port = tool.GenerateServerPort(t.Mode)
}
if !tool.TestServerPort(s.GetIntNoErr("port"), t.Mode) {
s.AjaxErr("The port cannot be opened because it may has been occupied or is no longer allowed.")
return
}
}
t.ServerIp = s.getEscapeString("server_ip")
t.Mode = s.getEscapeString("type")
t.Target = &file.Target{TargetStr: strings.ReplaceAll(s.getEscapeString("target"), "\r\n", "\n")}
t.UserAuth = &file.MultiAccount{Content: s.getEscapeString("auth"), AccountMap: common.DealMultiUser(s.getEscapeString("auth"))}
t.Password = s.getEscapeString("password")
t.Id = id
t.LocalPath = s.getEscapeString("local_path")
t.StripPre = s.getEscapeString("strip_pre")
t.Remark = s.getEscapeString("remark")
t.Flow.FlowLimit = int64(s.GetIntNoErr("flow_limit"))
t.Flow.TimeLimit = common.GetTimeNoErrByStr(s.getEscapeString("time_limit"))
if s.GetBoolNoErr("flow_reset") {
t.Flow.ExportFlow = 0
t.Flow.InletFlow = 0
}
t.Target.ProxyProtocol = s.GetIntNoErr("proxy_protocol")
t.Target.LocalProxy = (clientId > 0 && s.GetBoolNoErr("local_proxy")) || clientId <= 0
file.GetDb().UpdateTask(t)
server.StopServer(t.Id)
server.StartTask(t.Id)
}
s.AjaxOk("modified success")
}
}
func (s *IndexController) Stop() {
id := s.GetIntNoErr("id")
if err := server.StopServer(id); err != nil {
s.AjaxErr("stop error")
}
s.AjaxOk("stop success")
}
func (s *IndexController) Del() {
id := s.GetIntNoErr("id")
if err := server.DelTask(id); err != nil {
s.AjaxErr("delete error")
}
s.AjaxOk("delete success")
}
func (s *IndexController) Start() {
id := s.GetIntNoErr("id")
if err := server.StartTask(id); err != nil {
s.AjaxErr("start error")
}
s.AjaxOk("start success")
}
func (s *IndexController) HostList() {
if s.Ctx.Request.Method == "GET" {
s.Data["data"] = server.GetDashboardData()
s.Data["client_id"] = s.getEscapeString("client_id")
s.Data["menu"] = "host"
s.SetInfo("host list")
s.display("index/hlist")
} else {
start, length := s.GetAjaxParams()
clientId := s.GetIntNoErr("client_id")
//list, cnt := file.GetDb().GetHost(start, length, clientId, s.getEscapeString("search"))
list, cnt := server.GetHostList(start, length, clientId, s.getEscapeString("search"), s.getEscapeString("sort"), s.getEscapeString("order"))
s.AjaxTable(list, cnt, cnt, nil)
}
}
func (s *IndexController) GetHost() {
if s.Ctx.Request.Method == "POST" {
data := make(map[string]interface{})
if h, err := file.GetDb().GetHostById(s.GetIntNoErr("id")); err != nil {
data["code"] = 0
} else {
data["data"] = h
data["code"] = 1
}
s.Data["json"] = data
s.ServeJSON()
}
}
func (s *IndexController) DelHost() {
id := s.GetIntNoErr("id")
if err := file.GetDb().DelHost(id); err != nil {
s.AjaxErr("delete error")
}
s.AjaxOk("delete success")
}
func (s *IndexController) StartHost() {
id := s.GetIntNoErr("id")
h, err := file.GetDb().GetHostById(id)
if err != nil {
s.error()
return
}
h.IsClose = false
file.GetDb().JsonDb.StoreHostToJsonFile()
s.AjaxOk("start success")
}
func (s *IndexController) StopHost() {
id := s.GetIntNoErr("id")
h, err := file.GetDb().GetHostById(id)
if err != nil {
s.error()
return
}
h.IsClose = true
file.GetDb().JsonDb.StoreHostToJsonFile()
s.AjaxOk("stop success")
}
func (s *IndexController) AddHost() {
if s.Ctx.Request.Method == "GET" {
s.Data["client_id"] = s.getEscapeString("client_id")
s.Data["menu"] = "host"
s.SetInfo("add host")
s.display("index/hadd")
} else {
id := int(file.GetDb().JsonDb.GetHostId())
clientId := s.GetIntNoErr("client_id")
h := &file.Host{
Id: id,
Host: s.getEscapeString("host"),
Target: &file.Target{
TargetStr: strings.ReplaceAll(s.getEscapeString("target"), "\r\n", "\n"),
ProxyProtocol: s.GetIntNoErr("proxy_protocol"),
LocalProxy: (clientId > 0 && s.GetBoolNoErr("local_proxy")) || clientId <= 0,
},
UserAuth: &file.MultiAccount{
Content: s.getEscapeString("auth"),
AccountMap: common.DealMultiUser(s.getEscapeString("auth")),
},
HeaderChange: s.getEscapeString("header"),
HostChange: s.getEscapeString("hostchange"),
Remark: s.getEscapeString("remark"),
Location: s.getEscapeString("location"),
Flow: &file.Flow{
FlowLimit: int64(s.GetIntNoErr("flow_limit")),
TimeLimit: common.GetTimeNoErrByStr(s.getEscapeString("time_limit")),
},
Scheme: s.getEscapeString("scheme"),
HttpsJustProxy: s.GetBoolNoErr("https_just_proxy"),
KeyFilePath: s.getEscapeString("key_file_path"),
CertFilePath: s.getEscapeString("cert_file_path"),
AutoHttps: s.GetBoolNoErr("auto_https"),
AutoCORS: s.GetBoolNoErr("auto_cors"),
TargetIsHttps: s.GetBoolNoErr("target_is_https"),
}
var err error
if h.Client, err = file.GetDb().GetClient(s.GetIntNoErr("client_id")); err != nil {
s.AjaxErr("add error the client can not be found")
}
if h.Client.MaxTunnelNum != 0 && h.Client.GetTunnelNum() >= h.Client.MaxTunnelNum {
s.AjaxErr("The number of tunnels exceeds the limit")
}
if err := file.GetDb().NewHost(h); err != nil {
s.AjaxErr("add fail" + err.Error())
}
s.AjaxOkWithId("add success", id)
}
}
func (s *IndexController) EditHost() {
id := s.GetIntNoErr("id")
if s.Ctx.Request.Method == "GET" {
s.Data["menu"] = "host"
if h, err := file.GetDb().GetHostById(id); err != nil {
s.error()
} else {
s.Data["h"] = h
if h.UserAuth == nil {
s.Data["auth"] = ""
} else {
s.Data["auth"] = h.UserAuth.Content
}
}
s.SetInfo("edit")
s.display("index/hedit")
} else {
if h, err := file.GetDb().GetHostById(id); err != nil {
s.error()
} else {
if h.Host != s.getEscapeString("host") {
tmpHost := new(file.Host)
tmpHost.Host = s.getEscapeString("host")
tmpHost.Location = s.getEscapeString("location")
tmpHost.Scheme = s.getEscapeString("scheme")
if file.GetDb().IsHostExist(tmpHost) {
s.AjaxErr("host has exist")
return
}
}
clientId := s.GetIntNoErr("client_id")
if client, err := file.GetDb().GetClient(clientId); err != nil {
s.AjaxErr("modified error, the client is not exist")
} else {
h.Client = client
}
h.Host = s.getEscapeString("host")
h.Target = &file.Target{TargetStr: strings.ReplaceAll(s.getEscapeString("target"), "\r\n", "\n")}
h.UserAuth = &file.MultiAccount{Content: s.getEscapeString("auth"), AccountMap: common.DealMultiUser(s.getEscapeString("auth"))}
h.HeaderChange = s.getEscapeString("header")
h.HostChange = s.getEscapeString("hostchange")
h.Remark = s.getEscapeString("remark")
h.Location = s.getEscapeString("location")
h.Scheme = s.getEscapeString("scheme")
h.HttpsJustProxy = s.GetBoolNoErr("https_just_proxy")
h.KeyFilePath = s.getEscapeString("key_file_path")
h.CertFilePath = s.getEscapeString("cert_file_path")
h.Target.ProxyProtocol = s.GetIntNoErr("proxy_protocol")
h.Target.LocalProxy = (clientId > 0 && s.GetBoolNoErr("local_proxy")) || clientId <= 0
h.Flow.FlowLimit = int64(s.GetIntNoErr("flow_limit"))
h.Flow.TimeLimit = common.GetTimeNoErrByStr(s.getEscapeString("time_limit"))
if s.GetBoolNoErr("flow_reset") {
h.Flow.ExportFlow = 0
h.Flow.InletFlow = 0
}
h.AutoHttps = s.GetBoolNoErr("auto_https")
h.AutoCORS = s.GetBoolNoErr("auto_cors")
h.TargetIsHttps = s.GetBoolNoErr("target_is_https")
file.GetDb().JsonDb.StoreHostToJsonFile()
}
s.AjaxOk("modified success")
}
}