MythicAgents / merlin

Cross-platform post-exploitation HTTP Command & Control agent written in golang
GNU General Public License v3.0
86 stars 11 forks source link

Freebsd payload build fails #17

Open timukas opened 5 months ago

timukas commented 5 months ago

Hello,

Using latest Merlin agent on latest Mythic. When building default Merlin payload, then it fails with following message:

Build Message:
Processing C2 Profile - http:
Step 1/3 - Issuing OPSEC Check
No immediate issues with configuration
Step 2/3 - Issuing Config Check
C2 Profile container and agent configuration match port, 80, and SSL expectations (false)

Step 3/3 - Issuing Start command

Sending Build command
there was an error compiling the agent
StdErr: 
exit status 1
StdOut: 
# github.com/Ne0nd0g/merlin-agent/v2/commands
/go/pkg/mod/github.com/!ne0nd0g/merlin-agent/v2@v2.4.1/commands/shell_freebsd.go:36:12: undefined: fmt

Build: go build -o merlin.bin -buildmode=default -ldflags -s -w -X "main.payloadID=6201ac61-ef45-42ac-b36d-7105b33e3fae" -X "main.profile=http" -X "main.httpClient=go" -X "main.url=http://XX.XX.XX.XX:80/data" -X "main.psk=ohA2fedPRZsaWDHrizzVO8ApZUBC4PQF9u0HTXI5Re0=" -X "main.useragent=Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko" -X "main.sleep=53s" -X "main.skew=19610" -X "main.killdate=1745625600" -X "main.maxretry=7" -X "main.padding=4096" -X "main.verbose=false" -X "main.debug=false" -buildid= -tags=mythic main.go

Any thoughts on that?

Ne0nd0g commented 5 months ago

Looks like import for the fmt package in the shell_freebsd.go was removed. It will be a relatively easy fix to add the package import back.

Ne0nd0g commented 4 weeks ago

@timukas here is a temporary work around that you can use until I push new version to main.

This temporary fix will need to be done each time the Merlin container restarts

  1. Connect to the running Merlin Docker container: sudo docker exec -it merlin /bin/bash
  2. Install nano so you can edit files later: apt install nano -y
  3. Clone the Merlin Agent repository to the /opt directory: git clone https://github.com/Ne0nd0g/merlin-agent /opt/merlin-agent
  4. Edit the shell_freebsd.go file and add the string "fmt" after the import statement: nano /opt/merlin-agent/commands/shell_freebsd.go so that it looks like this:
    import (
       "fmt"
    "os/exec"
    "strings"
    )
  5. Change directories to where the agent code is: cd /Mythic/agent
  6. Update the go.mod file to point to your modified directory: go mod edit -replace=github.com/Ne0nd0g/merlin-agent/v2=/opt/merlin-agent
  7. Build the Merlin agent through the Mythic interface
sudo docker exec -it merlin /bin/bash
root@merlin:/Mythic/container# apt install nano -y
root@merlin:/Mythic/container# git clone https://github.com/Ne0nd0g/merlin-agent /opt/merlin-agent
root@merlin:/Mythic/agent# nano /opt/merlin-agent/commands/shell_freebsd.go 
root@merlin:/Mythic/container# cd /Mythic/agent/
root@merlin:/Mythic/agent# go mod edit -replace=github.com/Ne0nd0g/merlin-agent/v2=/opt/merlin-agent
timukas commented 3 weeks ago

Thanks.

Now i can compile merlin payload for freebsd, but only help and clear commands are available for freebsd.