mirror of
https://github.com/lwch/natpass.git
synced 2024-04-21 12:41:54 +00:00
WIP
This commit is contained in:
@@ -8,4 +8,4 @@ docker run -it --rm \
|
||||
-v $HOME/.cache/go-build:/root/.cache/go-build \
|
||||
-v $HOME/go/pkg/mod:/root/go/pkg/mod \
|
||||
-e BUILD_VERSION=$VERSION \
|
||||
natpass /build/contrib/build/build
|
||||
natpass /build/contrib/build/build "$@"
|
||||
@@ -43,6 +43,12 @@ func (conn *Conn) SendConnectReq(id string, cfg global.Tunnel) {
|
||||
},
|
||||
}
|
||||
case "vnc":
|
||||
fps := cfg.Fps
|
||||
if fps > 50 {
|
||||
fps = 50
|
||||
} else if fps == 0 {
|
||||
fps = 10
|
||||
}
|
||||
msg.Payload = &network.Msg_Creq{
|
||||
Creq: &network.ConnectRequest{
|
||||
Name: cfg.Name,
|
||||
|
||||
@@ -33,7 +33,7 @@ type Link struct {
|
||||
// NewLink create link
|
||||
func NewLink(parent *Shell, id, target string, remote *pool.Conn) *Link {
|
||||
remote.AddLink(id)
|
||||
logging.Info("create shell %s for tunnel %s on connection %d",
|
||||
logging.Info("create link %s for shell %s on connection %d",
|
||||
id, parent.Name, remote.Idx)
|
||||
return &Link{
|
||||
parent: parent,
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
/assets.go
|
||||
@@ -0,0 +1,6 @@
|
||||
package core
|
||||
|
||||
import "errors"
|
||||
|
||||
// ErrNotSupported not supported
|
||||
var ErrNotSupported = errors.New("not supported")
|
||||
@@ -0,0 +1,58 @@
|
||||
package core
|
||||
|
||||
import "golang.org/x/sys/windows"
|
||||
|
||||
// Process process
|
||||
type Process struct {
|
||||
}
|
||||
|
||||
func getLogonPid(sessionID uintptr) uint32 {
|
||||
snapshot, err := syscall.CreateToolhelp32Snapshot(syscall.TH32CS_SNAPPROCESS, 0)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
defer syscall.CloseHandle(snapshot)
|
||||
var procEntry syscall.ProcessEntry32
|
||||
procEntry.Size = uint32(unsafe.Sizeof(procEntry))
|
||||
err = syscall.Process32First(snapshot, &procEntry)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
var ret uint32
|
||||
for {
|
||||
var sid uint32
|
||||
name := parseProcessName(procEntry.ExeFile)
|
||||
if strings.ToLower(name) != "winlogon.exe" {
|
||||
goto next
|
||||
}
|
||||
err = windows.ProcessIdToSessionId(procEntry.ProcessID, &sid)
|
||||
if err != nil {
|
||||
return ret
|
||||
}
|
||||
if sid == uint32(sessionID) {
|
||||
ret = procEntry.ProcessID
|
||||
}
|
||||
next:
|
||||
err = syscall.Process32Next(snapshot, &procEntry)
|
||||
if err != nil {
|
||||
return ret
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getSessionUserTokenWin() windows.Token {
|
||||
pid := getLogonPid(getSessionID())
|
||||
process, err := windows.OpenProcess(PROCESS_ALL_ACCESS, false, pid)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
defer windows.CloseHandle(process)
|
||||
var ret windows.Token
|
||||
windows.OpenProcessToken(process, windows.TOKEN_ALL_ACCESS, &ret)
|
||||
return ret
|
||||
}
|
||||
|
||||
// CreateWorkerProcess create worker process
|
||||
func CreateWorkerProcess() (*Process, error) {
|
||||
tk := getSessionUserTokenWin()
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// +build !windows
|
||||
|
||||
package core
|
||||
|
||||
// Process process
|
||||
type Process struct {
|
||||
}
|
||||
|
||||
// CreateWorkerProcess create worker process
|
||||
func CreateWorkerProcess() (*Process, error) {
|
||||
return nil, ErrNotSupported
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package vnc
|
||||
|
||||
import (
|
||||
"natpass/code/client/pool"
|
||||
"natpass/code/client/tunnel/vnc/core"
|
||||
|
||||
"github.com/lwch/logging"
|
||||
)
|
||||
@@ -13,6 +14,8 @@ type Link struct {
|
||||
target string // target id
|
||||
targetIdx uint32 // target idx
|
||||
remote *pool.Conn
|
||||
// vnc
|
||||
ps *core.Process
|
||||
// runtime
|
||||
sendBytes uint64
|
||||
recvBytes uint64
|
||||
@@ -23,7 +26,7 @@ type Link struct {
|
||||
// NewLink create link
|
||||
func NewLink(parent *VNC, id, target string, remote *pool.Conn) *Link {
|
||||
remote.AddLink(id)
|
||||
logging.Info("create vnc %s for tunnel %s on connection %d",
|
||||
logging.Info("create link %s for tunnel %s on connection %d",
|
||||
id, parent.Name, remote.Idx)
|
||||
return &Link{
|
||||
parent: parent,
|
||||
@@ -55,6 +58,11 @@ func (link *Link) SetTargetIdx(idx uint32) {
|
||||
|
||||
// Fork fork worker process
|
||||
func (link *Link) Fork() error {
|
||||
p, err := core.CreateWorkerProcess()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
link.ps = p
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ require (
|
||||
github.com/lwch/logging v0.0.0-20210831025517-ae81047d6190
|
||||
github.com/lwch/runtime v0.0.0-20190520054850-8c97e19e0c6d
|
||||
github.com/lwch/yaml v0.0.0-20211009070949-2d4c64e2b789
|
||||
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211
|
||||
golang.org/x/text v0.3.7
|
||||
google.golang.org/protobuf v1.27.1
|
||||
)
|
||||
|
||||
@@ -13,8 +13,6 @@ github.com/kardianos/service v1.2.0 h1:bGuZ/epo3vrt8IPC7mnKQolqFeYJb7Cs8Rk4PSOBB
|
||||
github.com/kardianos/service v1.2.0/go.mod h1:CIMRFEJVL+0DS1a3Nx06NaMn4Dz63Ng6O7dl0qH0zVM=
|
||||
github.com/kisielk/errcheck v1.2.0 h1:reN85Pxc5larApoH1keMBiu2GWtPqXQ1nc9gx+jOU+E=
|
||||
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
|
||||
github.com/lwch/logging v0.0.0-20210528090125-a154917d90c6 h1:R52s6I/vW1NfNaJdY+Yr/ivkiFicouKmK0v3nvDQh4s=
|
||||
github.com/lwch/logging v0.0.0-20210528090125-a154917d90c6/go.mod h1:aXQui5bsF/d4I+z6szuiBWY5m4y9t6pyZ2Q/sLgkBBg=
|
||||
github.com/lwch/logging v0.0.0-20210831025517-ae81047d6190 h1:C0Fpn2r+o13bVljlrKmpVe1LECPsFLtex5Mrt/v07H0=
|
||||
github.com/lwch/logging v0.0.0-20210831025517-ae81047d6190/go.mod h1:aXQui5bsF/d4I+z6szuiBWY5m4y9t6pyZ2Q/sLgkBBg=
|
||||
github.com/lwch/runtime v0.0.0-20190520054850-8c97e19e0c6d h1:Xg+zzPtvX22DaoJD5Bp0tqPdB8gn5WypghIJ4fluqiQ=
|
||||
|
||||
Reference in New Issue
Block a user