Merlin Server
The quickest and recommended way is to download Merlin Server from the releases page for your host operating system (i.e Windows, macOS, or Linux). The following single line of code can be used to download, extract, and run Merlin Server on an Ubuntu Server:x flag so that the files are extracted into their respective directories.
The Merlin Server file download includes the CLI and compiled agents for all 3 major platforms in the
data/bin/ directoryMerlin Agent
Merlin is a post-exploitation framework and therefore documentation doesn’t cover any of the steps required to get to a point where you can execute code or commands on a compromised host. Exploiting or accessing a host must performed prior to leveraging Merlin.Pre-compiled Merlin Agent binary files are distributed with the server download in the
data/bin/ directory of MerlinUpload & Execute
One of the more simple ways to run Merlin is by uploading the compiled binary file to a compromised host and then execute that binary.Don’t forget to specify the address of your Merlin server with the
-url flag. Default is https://127.0.0.1:443/Windows Local Command Execution
This section covers executing the Merlin agent with local command execution.Windows EXE - cmd.exe
With themerlinAgent.exe binary file already downloaded on to the compromised host, execute it by calling it from the
command line. Double clicking the executable file will cause the agent to run without a window, so you will not see
anything, and it will connect to the default URL of https://127.0.0.1:443/.
This can be changed by recompiling the agent with the hardcoded address of your Merlin server.
Windows DLL - rundll32.exe
With themerlin.dll binary file already downloaded on to the compromised host, execute it by calling it from the
command line using the rundll32.exe program that comes with Windows.
Run is the name of the DLL entrypoint called when the DLL is executed.
Provide the URL for your listening Merlin server after the entrypoint.
Windows Remote Command Execution
This section covers executing Merlin agent when remotely accessing a host.Windows EXE - PsExec.exe
The Microsoft Sysinternals PsExec.exe application can be used to connect to a remote host, upload the Merlin agent file, and execute it. The downside to this is the Merlin agent binary file is “on disk” and provides an opportunity for Anti-Virus software to detect the application. Use PsExec’s-c flag to specify the location of the Merlin agent file on the attacker’s
host that will be uploaded to the remote host. The PsExec -d flag is required so that control is returned to the user
after executing the Merlin agent file.
Windows DLL - Metasploit’s SMB Delivery
One method for delivery is to use an SMB server to host the payload and execute a command on the remote host to download and run the Merlin agent file. The Metasploitwindows/smb/smb_delivery module is a good way to quickly stand up an SMB
server for delivering the payload.
Setup the windows/smb/smb_delivery module:
NOTE: We must change the DLL entry point from
0 to Run and provide the URL of the listening Merlin servermerlin.dll file, we need to remotely access the target host and
execute the command. By default, Metasploit sets the entry point to 0. We need to modify the command to change the
entry point to Run and specify the location of our listening Merlin server.
Impacket’s wmiexec.py Python program is one way to remotely access a host.
wmiexec.py example:
NOTE: We must change the DLL entry point from
0 to Run and provide the URL of the listening Merlin serverAdvanced
The quick start examples above executed the Merlin agent and allowed the user to dynamically specify the location of the listening Merlin server with a command line parameter. There are a few instances where we the user is unable to specify, or simply don’t want to, the URL for the listening Merlin server. In this case, the Merlin agent binary should be recompiled with a hardcoded URL of the listening Merlin server so that it does not need to be specified by the user during execution.This will require that you have Go and gcc installed on the host compiling the application
Recompile DLL
Themerlin.dll file can be configured with the hardcoded url of your Merlin server.
To do this, clone the repo, modify the file, and recompile it.
- Clone the merlin repository using git
- Edit the
main.gofile - Find the string
var url = "https://127.0.0.1:443/"and change the address - Compile the DLL
merlin.dll in the bin/v0.5.0/ directory where v0.5.0 is the current version number of Merlin.
Now the recompiled version of the DLL can be run without having to specify the address of the Merlin server.
rundll32.exe examples:
rundll32.exe merlin,mainrundll32.exe merlin,Run
regsvr32.exe /s merlin.dllregsvr32.exe /s /u merlin.dllregsvr32.exe /s /n /i merlin.dll