Skip to content
Info disclosure Write-up Beginner

$3K Bounty For Elastic-Search Takeover

An Elasticsearch service was exposed on a non-standard port without authentication, allowing anyone to list indices and search all data. The attacker could read and dump the database contents.

Ashish Kunwar Follow

Published on medium.com

Bounty$3,000 View original

It was the end of year 2019 in , Me and My friend were Hunting on A Target (called it REDACTED.COM) , this program is a cypto based company which has a bugbounty program.

Ashish Kunwar, on medium.com

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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

At the end of 2019 the author and a friend were hunting on a target referred to throughout as REDACTED.COM, a crypto based company that runs a bug bounty program. During reconnaissance they found a subdomain, called test.redacted.com in the write-up, with a port 9200 open. Port 9200 is the default HTTP port of Elasticsearch, a document-oriented database that stores data as JSON documents and exposes a REST API for storing, retrieving and managing that data. Unlike MySQL, which keeps information in tables, Elasticsearch organises documents into types and indexes, and each document is a JSON blob such as:

JSON
{"id":1, "name":"test", "password":"test@password"}

An Elasticsearch node that answers on the public internet without authentication lets anyone read the cluster metadata, list the indexes and query the documents inside them. That is the situation described here.

Setup

The work was done from a VPS using the researchers' own automation tools, which ran reconnaissance against the target for almost three days. No accounts, roles or special tooling beyond that are described. The only other tool used later is elasticdump, installed globally with npm, to export data once the exposure was confirmed.

Finding it

After roughly three days of automated recon, the researchers reviewed the logs and noticed something interesting: the subdomain test.redacted.com had a service listening on port 9200. Visiting the root of that service was the next step.

Exploitation

Step 1: Confirm the service is Elasticsearch

Requesting the root URL returned the standard cluster information document:

JSON
{  "name" : "4yXXXXX",  "cluster_name" : "docker-cluster",  "cluster_uuid" : "ulM_pLwNQbWXXXXXXXX",  "version" : {    "number" : "6.x.x",    "build_flavor" : "default",    "build_type" : "tar",    "build_hash" : "3bd3e59",    "build_date" : "2019-03-06T15:16:26.86xxxxxx",    "build_snapshot" : false,    "lucene_version" : "7.6.x",    "minimum_wire_compatibility_version" : "5.6.0",    "minimum_index_compatibility_version" : "5.0.0"  },  "tagline" : "You Know, for Search"}

The author notes that some characters were replaced with X before publication. The response confirms an unauthenticated Elasticsearch 6.x node running in a Docker cluster, with the build hash 3bd3e59 and a build date in March 2019.

Step 2: Enumerate the indexes

Once an exposed Elasticsearch endpoint is known, the next move is to list the available indexes, which are the equivalent of databases. The _cat/indices API does this, and the ?v parameter asks for the column headers:

According to the write-up, the response showed both the production indexes and indexes the researcher was able to add. Being able to create indexes is itself a sign that the node accepts unauthenticated write operations, not just reads.

Step 3: Search across all indexes

Elasticsearch supports a full text search through the _search API. Using _all as the index name queries every index at once, and the q parameter supplies the search term:

This queries every index for the word email. The author lists the terms worth searching for in this kind of data store: username, user, email, password, token, secrete, key. To query a single index instead, replace _all with the name of that index.

Step 4: Dump the data

With the indexes identified, the data can be exported with curl or with elasticdump, a tool for moving and saving indices. It is installed globally through npm:

Bash
sudo npm install elasticdump -g #install globally

The dump itself is run with the input pointing at the index URL and the output at a local JSON file:

--input is the source index on the exposed node, --output is the local file that receives the documents, and --type=data selects the document data rather than the index mapping.

From the original on medium.com

The image sits at the end of the write-up, next to the note that the researchers received the 3K$ bounty in bitcoin on the morning of 1 January 2020.

Root cause

The Elasticsearch node on test.redacted.com was reachable from the internet on port 9200 with no authentication in front of it. The node answered cluster information, index listing and search requests without authentication, and the write-up shows that indexes could also be created. and the write-up shows that indexes could also be created. The exposure was found because the automated recon recorded the open port on the subdomain.

Impact

The exposed node allowed the researchers to enumerate every index and to run full text searches across all of them for terms such as email, password, token and key, and then to dump the contents with elasticdump. The report does not enumerate the specific records retrieved or the number of affected users, and it does not describe any modification or deletion of production data, only that the researcher was able to add indexes of their own. The researchers say they received the 3K$ bounty in bitcoin on the morning of 1 January 2020.

Fix

The report does not describe the remediation the company applied. The measures that address this exposure are to keep Elasticsearch off the public internet, restrict port 9200 to trusted networks, and enable the authentication and TLS features of the stack so that the APIs are not reachable anonymously.

Variants to test

  1. Scan for port 9200 across all subdomains and IP ranges in scope, including hosts that only appear in historical DNS data. A positive result is a JSON response containing cluster_name, version and the You Know, for Search tagline.
  2. Request /_cat/indices?v on any confirmed node. A positive result is a table of index names, including ones that look like production data.
  3. Run /_all/_search?q= with terms such as email, password, token and key. A positive result is hits containing those fields.
  4. Try creating an index to test for write access, as the researcher did. A positive result is that the index appears in the listing afterwards.
  5. Check other common database and search ports on the same hosts, since a recon pipeline that surfaced 9200 may have missed neighbours. A positive result is any unauthenticated service that returns data or metadata.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 13 min read.

What happened, in plain words

At the end of 2019, a researcher and a friend were looking for security bugs in a company they call REDACTED.COM in the write-up. It is a crypto based company that runs a bug bounty program: a scheme where a company invites outside people to find security problems in its systems and pays them for reporting the problems responsibly instead of exploiting them.

The two researchers ran automated reconnaissance (recon) against the company's systems for almost three days. Recon means gathering information about a target: which subdomains exist, which of them are online, and which network ports answer on each one. A subdomain is a name like test.redacted.com that sits under the main domain redacted.com. A port is a numbered channel on a computer that a particular service listens on; think of a building with many numbered doors, each door leading to a different office. Port 9200 is the door that Elasticsearch normally listens on.

When they read the logs from their recon, they noticed that the subdomain test.redacted.com had something answering on port 9200. That something turned out to be Elasticsearch, a database product, and it answered requests from the public internet without authentication. That is the whole bug: a database that should have been private was open to anyone who knew the address.

What Elasticsearch is

The write-up quotes Google's definition: Elasticsearch is a document-oriented database designed to store, retrieve and manage document-oriented or semi-structured data, and you store data in JSON document form and then query it for retrieval.

In plain words: a database is software whose job is to keep data and hand it back when asked. A normal relational database such as MySQL keeps data in tables with rows and columns, like a spreadsheet. Elasticsearch instead keeps JSON documents. JSON is a text format for structured data, built from names and values in curly braces, and it is the same format many web pages use behind the scenes to exchange data. A document is one such JSON blob, for example:

JSON
{"id":1, "name":"test", "password":"test@password"}

Line by line: the outer curly braces mark the start and end of one JSON object. "id":1 is a field named id whose value is the number 1. "name":"test" is a field named name whose value is the text test. "password":"test@password" is a field named password whose value is the text test@password. Fields are separated by commas. So this single document is one record, and a database full of such records is what an attacker would love to read.

Elasticsearch groups documents into indexes, which you can think of as the equivalent of databases in the MySQL world. It also exposes a REST API. An API is a defined set of web addresses that a program can call to make something happen or to fetch data; a REST API is one that uses ordinary web requests (GET to read, and so on) and returns data, usually as JSON. Because Elasticsearch speaks plain HTTP, you can talk to it with nothing more than a browser address bar.

When an Elasticsearch node (one running copy of the software) answers on the public internet without authentication, anyone can read its cluster metadata, list its indexes and query the documents inside them. Authentication means proving who you are, usually with a username and password. None was required here.

How the work was set up

The researchers worked from a VPS. A VPS is a virtual private server: a rented computer in a data centre that you control remotely, often used for long running tasks so your own machine does not have to stay on. On it they ran their own automation tools, which scanned the target for almost three days. The write-up does not describe any accounts, roles or other tooling used during recon. The only other tool mentioned is elasticdump, installed later with npm (the package manager that comes with Node.js, a JavaScript runtime) to export data once the exposure was confirmed.

Finding it

After roughly three days of automated recon, the researchers reviewed the logs and noticed something interesting: the subdomain test.redacted.com had a service listening on port 9200. The natural next step was to visit the root of that service, meaning the bare address with nothing after the slash, to see what it would say about itself.

Step 1: Confirm the service is Elasticsearch

Requesting the root URL returned the standard cluster information document:

Line by line: GET is the HTTP method used to ask a server for something, the same method your browser uses when you type an address. http:// says the request is plain, unencrypted HTTP rather than HTTPS. test.redacted.com is the host name. :9200 is the port number, appended after a colon. The final / is the path, here the root of the service. So the whole line means: please send me the front page of whatever is running on port 9200 of this host.

The answer was:

JSON
{  "name" : "4yXXXXX",  "cluster_name" : "docker-cluster",  "cluster_uuid" : "ulM_pLwNQbWXXXXXXXX",  "version" : {    "number" : "6.x.x",    "build_flavor" : "default",    "build_type" : "tar",    "build_hash" : "3bd3e59",    "build_date" : "2019-03-06T15:16:26.86xxxxxx",    "build_snapshot" : false,    "lucene_version" : "7.6.x",    "minimum_wire_compatibility_version" : "5.6.0",    "minimum_index_compatibility_version" : "5.0.0"  },  "tagline" : "You Know, for Search"}

Line by line: "name" is the name of this particular node. "cluster_name" is the name of the group of nodes working together, here docker-cluster, which hints that the software runs inside Docker, a popular way of packaging and running software in containers. "cluster_uuid" is a unique identifier for the cluster. The nested "version" object describes the software: "number" is the version, "build_flavor" and "build_type" describe how it was built, "build_hash" identifies the exact source code revision, "build_date" is when it was built, "build_snapshot" says whether it is a development snapshot, "lucene_version" is the version of the search library underneath, and the two minimum_..._compatibility_version fields say how old a node may be and still join this cluster. Finally "tagline" is Elasticsearch's own slogan, You Know, for Search, which is the giveaway that you are looking at Elasticsearch and not some other service.

The author notes that some characters were replaced with X before publication, to avoid revealing details about the live system. The response confirms an unauthenticated Elasticsearch 6.x node running in a Docker cluster, with the build hash 3bd3e59 and a build date in March 2019. Unauthenticated here means the server answered a stranger with no credentials at all, which is the core problem.

Step 2: List the indexes

Once an exposed Elasticsearch endpoint is known, the next move is to list the available indexes, the equivalent of databases. The _cat/indices API does this, and the ?v parameter asks for the column headers so the output is readable:

Line by line: again GET asks to read something. The path /_cat/indices is a built-in Elasticsearch address that lists indexes in a compact table, like the cat command on a Unix system prints file contents. The ?v at the end is a query parameter, a small piece of extra instruction attached to the address; here it means verbose, so the table includes a header row naming each column. Without it you would see bare values with no labels.

According to the write-up, the response showed both the production indexes and indexes the researcher was able to add. Production indexes are the ones the company actually uses for real data. Being able to create indexes is itself a sign that the node accepts unauthenticated write operations, not just reads: a stranger can change the database, not merely look at it.

Step 3: Search across all indexes

Elasticsearch supports full text search through the _search API. Full text search means asking for documents that contain a given word anywhere in their text, rather than matching an exact field value. Using _all as the index name queries every index at once, and the q parameter supplies the search term:

Line by line: GET reads. /_all means all indexes, so the search is not limited to one database. /_search is the search API. ?q=email passes the query term email, so the server returns every document in every index that contains the word email. This is the step that turns a list of index names into actual data: you are asking the database to hand you anything that looks like an email address.

This queries every index for the word email. The author lists the terms worth searching for in this kind of data store: username, user, email, password, token, secrete, key. A token is a short string that acts like a temporary password, for example a session token that proves you are logged in; a key is similar, often an API key that lets a program call a service. Finding either in a database is serious, because they can be replayed to impersonate a user or a service. To query a single index instead, replace _all with the name of that index.

Step 4: Dump the data

With the indexes identified, the data can be exported with curl or with elasticdump, a tool for moving and saving indices. curl is a command line program for making web requests, useful for scripting and for saving responses to files. elasticdump is installed globally through npm:

Bash
sudo npm install elasticdump -g #install globally

Line by line: sudo runs the command with administrator rights, needed because a global install writes to system wide locations. npm is the Node.js package manager. install tells it to fetch and set up a package. elasticdump is the package name. -g means global, so the tool becomes available as a command everywhere on the machine rather than only inside one project folder. The #install globally part after the hash is a comment, ignored by the shell, that repeats what the flag does.

The dump itself is run with the input pointing at the index URL and the output at a local JSON file:

Line by line: elasticdump is the command. --input=http://ip:9200/filename is the source: the address of the index on the exposed node, where ip stands for the server's address and filename for the index name. --output=filename.json is the local file that receives the documents, written as JSON. --type=data selects the document data rather than the index mapping; a mapping is the description of which fields an index has and what type each one is, useful but not the actual records. So this command copies the real records out of the database into a file on the researcher's own machine.

From the original on medium.com

The image sits at the end of the write-up, next to the note that the researchers received the 3K$ bounty in bitcoin on the morning of 1 January 2020.

Why it worked

The Elasticsearch node on test.redacted.com was reachable from the internet on port 9200 with no authentication in front of it. The node answered cluster information, index listing and search requests without authentication, and the write-up shows that indexes could also be created. and the write-up shows that indexes could also be created. The exposure was found because the automated recon recorded the open port on the subdomain. A firewall is a filter that decides which network traffic may reach which port; a proxy is an intermediary that sits in front of a service and can enforce rules. Either would have helped here.

What the impact was

The exposed node allowed the researchers to enumerate every index and to run full text searches across all of them for terms such as email, password, token and key, and then to dump the contents with elasticdump. The report does not enumerate the specific records retrieved or the number of affected users, and it does not describe any modification or deletion of production data, only that the researcher was able to add indexes of their own. The researchers say they received the 3K$ bounty in bitcoin on the morning of 1 January 2020.

How to fix it

The measures that address this exposure are to keep Elasticsearch off the public internet, restrict port 9200 to trusted networks, and enable the authentication and TLS features of the stack so that the APIs are not reachable anonymously. TLS is the encryption layer behind HTTPS; with it, traffic between client and server cannot be read or altered in transit.

Variants to test

If you want to look for the same class of problem on a program you are authorised to test, these are the checks the write-up implies:

  1. Scan for port 9200 across all subdomains and IP ranges in scope, including hosts that only appear in historical DNS data. Historical DNS data is a record of names that used to point at a server, even if they no longer do. A positive result is a JSON response containing cluster_name, version and the You Know, for Search tagline.
  2. Request /_cat/indices?v on any confirmed node. A positive result is a table of index names, including ones that look like production data.
  3. Run /_all/_search?q= with terms such as email, password, token and key. A positive result is hits containing those fields. A hit is one matching document returned by a search.
  4. Try creating an index to test for write access, as the researcher did. A positive result is that the index appears in the listing afterwards.
  5. Check other common database and search ports on the same hosts, since a recon pipeline that surfaced 9200 may have missed neighbours. A positive result is any unauthenticated service that returns data or metadata.

Glossary

  • API: a defined set of web addresses a program can call to fetch data or trigger an action.
  • Authentication: proving who you are, usually with a username and password, before a service lets you in.
  • Bug bounty program: a scheme where a company pays outside researchers for responsibly reporting security problems.
  • Cluster: a group of Elasticsearch nodes working together as one system.
  • Confidentiality: the property that data is only seen by people allowed to see it.
  • curl: a command line program for making web requests and saving the responses.
  • Database: software that stores data and hands it back when asked.
  • Document: in Elasticsearch, one JSON record holding a set of fields and values.
  • Docker: a way of packaging and running software in isolated containers.
  • elasticdump: a tool for copying Elasticsearch indexes to and from files.
  • Elasticsearch: a document-oriented database that stores JSON documents and exposes a REST API for searching them.
  • Firewall: a filter that decides which network traffic may reach which port.
  • Full text search: searching for a word anywhere in a document's text rather than matching an exact field value.
  • GET: the HTTP method used to ask a server to return something.
  • Hit: one matching document returned by a search.
  • HTTP: the plain, unencrypted protocol browsers and programs use to talk to web servers.
  • HTTPS: HTTP wrapped in TLS encryption.
  • Index: in Elasticsearch, a collection of documents, roughly the equivalent of a database in MySQL.
  • JSON: a text format for structured data made of names and values in curly braces.
  • Mapping: the description of which fields an index has and what type each one is.
  • MySQL: a relational database that stores data in tables with rows and columns.
  • Node: one running copy of Elasticsearch.
  • npm: the package manager that comes with Node.js, used to install JavaScript tools.
  • Port: a numbered channel on a computer that a particular service listens on; 9200 is Elasticsearch's default.
  • Production: the live systems a company actually uses for real data, as opposed to test systems.
  • Proxy: an intermediary that sits in front of a service and can enforce rules on traffic.
  • Query parameter: a small piece of extra instruction attached to a web address after a question mark.
  • Reconnaissance (recon): gathering information about a target, such as subdomains, hosts and open ports.
  • REST API: an API that uses ordinary web requests and returns data, usually as JSON.
  • Subdomain: a name under a main domain, such as test.redacted.com under redacted.com.
  • TLS: the encryption layer behind HTTPS that protects traffic in transit.
  • Token: a short string that acts like a temporary password, often proving a session or authorising a program.
  • VPS: a rented virtual computer in a data centre that you control remotely.
  • Write access: permission to change data, for example by creating or modifying records, rather than only reading them.

More by Ashish Kunwar

View all

5 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.