This commit is contained in:
+5
-5
@@ -6,10 +6,10 @@ internal/runtime/full/wintun.dll
|
||||
server.js
|
||||
node_modules/
|
||||
last.log
|
||||
tsrun
|
||||
tsrun.exe
|
||||
tsrun-upx.exe
|
||||
tsrun-linux
|
||||
tsrun-linux-upx
|
||||
/tsrun
|
||||
/tsrun.exe
|
||||
/tsrun-upx.exe
|
||||
/tsrun-linux
|
||||
/tsrun-linux-upx
|
||||
result
|
||||
result-*
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"tsrun/internal/embedded"
|
||||
"tsrun/internal/prompt"
|
||||
"tsrun/internal/runtime/full"
|
||||
"tsrun/internal/runtime/proxy"
|
||||
"tsrun/internal/vault"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) > 1 && os.Args[1] == "clear" {
|
||||
if err := full.Clear(); err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
fmt.Println("cleanup complete")
|
||||
return
|
||||
}
|
||||
|
||||
useProxy := flag.Bool("proxy", false, "run proxy mode instead of full client mode")
|
||||
userFlag := flag.String("u", "", "username or username:password")
|
||||
flag.Parse()
|
||||
|
||||
username, password, err := resolveCredentials(*userFlag)
|
||||
if err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
|
||||
payload, err := vault.Unlock(embedded.Blob, username, password)
|
||||
vault.Zero(password)
|
||||
if err != nil {
|
||||
if errors.Is(err, vault.ErrAuthFailed) {
|
||||
fatal(errors.New("authentication failed"))
|
||||
}
|
||||
fatal(err)
|
||||
}
|
||||
|
||||
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
defer cancel()
|
||||
|
||||
if *useProxy {
|
||||
err = proxy.Run(ctx, payload)
|
||||
} else {
|
||||
err = full.Run(ctx, payload)
|
||||
}
|
||||
if err != nil && !errors.Is(err, context.Canceled) {
|
||||
fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println("shutting down")
|
||||
}
|
||||
|
||||
func resolveCredentials(arg string) (string, []byte, error) {
|
||||
if arg == "" {
|
||||
username, err := prompt.Line("Username: ")
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
password, err := prompt.Password("Password: ")
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
return username, password, nil
|
||||
}
|
||||
username, password, hasPassword := strings.Cut(arg, ":")
|
||||
if username == "" {
|
||||
return "", nil, errors.New("-u requires a username or username:password")
|
||||
}
|
||||
if hasPassword {
|
||||
return username, []byte(password), nil
|
||||
}
|
||||
passwordBytes, err := prompt.Password("Password: ")
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
return username, passwordBytes, nil
|
||||
}
|
||||
|
||||
func fatal(err error) {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
if runtime.GOOS == "windows" {
|
||||
prompt.FatalDialog(err.Error())
|
||||
prompt.WaitForEnter("Press Enter to exit...")
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
Reference in New Issue
Block a user