9200 - Pentesting Elasticsearch

从零开始学习 AWS 黑客技术,成为专家 htARTE(HackTricks AWS 红队专家)

支持 HackTricks 的其他方式:

基本信息

Elasticsearch 是一款用于各种类型数据分布式开源搜索和分析引擎。以其速度可扩展性简单的 REST API 而闻名。它是基于 Apache Lucene 构建的,由 Elasticsearch N.V.(现在称为 Elastic)于 2010 年首次发布。Elasticsearch 是 Elastic Stack 的核心组件,这是一套用于数据摄入、丰富、存储、分析和可视化的开源工具集。这个堆栈通常被称为 ELK Stack,还包括 Logstash 和 Kibana,现在还有称为 Beats 的轻量级数据传输代理。

什么是 Elasticsearch 索引?

Elasticsearch 索引是存储为 JSON相关文档集合。每个文档由及其对应的(字符串、数字、布尔值、日期、数组、地理位置等)组成。

Elasticsearch 使用一种高效的数据结构称为倒排索引来实现快速全文搜索。该索引列出了文档中的每个唯一单词,并标识每个单词出现在哪些文档中。

在索引过程中,Elasticsearch 存储文档并构建倒排索引,从而实现几乎实时的搜索。索引 API 用于在特定索引中添加或更新 JSON 文档。

默认端口:9200/tcp

手动枚举

横幅

访问 Elasticsearch 的协议是 HTTP。当通过 HTTP 访问时,您将找到一些有趣的信息:http://10.10.10.115:9200/

如果在访问 / 时未看到该响应,请查看以下部分。

认证

默认情况下,Elasticsearch 未启用身份验证,因此默认情况下,您可以在不使用任何凭据的情况下访问数据库中的所有内容。

您可以通过请求验证身份验证是否已禁用:

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}

然而,如果您发送一个请求到 / 并收到以下类似的响应:

{"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}

这意味着身份验证已配置,您需要有效的凭据才能从Elasticsearch获取任何信息。然后,您可以尝试暴力破解(它使用HTTP基本身份验证,因此可以使用任何适用于BF HTTP基本身份验证的方法)。 这里有一个默认用户名列表elastic(超级用户),remote_monitoring_user,beats_system,logstash_system,kibana,kibana_system,apm_system, _anonymous_._ Elasticsearch的旧版本使用此用户的默认密码为changeme

curl -X GET http://user:password@IP:9200/

基本用户枚举

#List all roles on the system:
curl -X GET "ELASTICSEARCH-SERVER:9200/_security/role"

#List all users on the system:
curl -X GET "ELASTICSEARCH-SERVER:9200/_security/user"

#Get more information about the rights of an user:
curl -X GET "ELASTICSEARCH-SERVER:9200/_security/user/<USERNAME>"

Elastic Info

以下是一些端点,您可以通过GET访问以获取有关elasticsearch的一些信息:

这些端点是从文档中获取的,您可以在那里找到更多。 此外,如果访问/_cat,响应将包含实例支持的/_cat/*端点。

/_security/user(如果启用了身份验证),您可以看到具有superuser角色的用户。

Indices

您可以通过访问http://10.10.10.115:9200/_cat/indices?v收集所有索引

health status index   uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   .kibana 6tjAYZrgQ5CwwR0g6VOoRg   1   0          1            0        4kb            4kb
yellow open   quotes  ZG2D1IqkQNiNZmi2HRImnQ   5   1        253            0    262.7kb        262.7kb
yellow open   bank    eSVpNfCfREyYoVigNWcrMw   5   1       1000            0    483.2kb        483.2kb

要获取保存在索引中的数据类型信息,您可以访问:http://host:9200/<index>,例如在这种情况下是http://10.10.10.115:9200/bank

转储索引

如果您想转储索引的所有内容,您可以访问:http://host:9200/<index>/_search?pretty=true,如http://10.10.10.115:9200/bank/_search?pretty=true

花点时间比较银行索引中每个文档(条目)的内容和我们在上一节中看到的该索引的字段。

因此,此时您可能会注意到**"hits"内有一个名为"total"的字段**,指示在此索引中找到了1000个文档,但只检索了10个。这是因为默认情况下限制为10个文档。 但是,现在您知道此索引包含1000个文档,您可以指定要在**size参数中转储的条目数来转储所有这些文档**:http://10.10.10.115:9200/quotes/_search?pretty=true&size=1000asd 注意:如果指定更大的数字,所有条目都将被转储,例如,您可以指定size=9999,如果有更多条目,那将很奇怪(但您应该检查)。

转储所有

为了转储所有内容,您可以直接转到之前的相同路径,但不指定任何索引http://host:9200/_search?pretty=true,如http://10.10.10.115:9200/_search?pretty=true 请记住,在这种情况下将应用默认的10个结果限制。您可以使用size参数来转储更多的结果。阅读上一节获取更多信息。

搜索

如果您正在寻找某些信息,您可以对所有索引进行原始搜索,转到http://host:9200/_search?pretty=true&q=<search_term>,如http://10.10.10.115:9200/_search?pretty=true&q=Rockwell

如果您只想在一个索引上搜索,您可以在路径指定它:http://host:9200/<index>/_search?pretty=true&q=<search_term>

请注意,用于搜索内容的q参数支持正则表达式

您还可以使用类似https://github.com/misalabs/horuz的工具来模糊搜索elasticsearch服务。

写入权限

您可以通过尝试在新索引中创建新文档来检查您的写入权限,运行类似以下内容:

curl -X POST '10.10.10.115:9200/bookindex/books' -H 'Content-Type: application/json' -d'
{
"bookId" : "A00-3",
"author" : "Sankaran",
"publisher" : "Mcgrahill",
"name" : "how to get a job"
}'

该命令将创建一个名为bookindex新索引,其中包含一个名为books的文档,该文档具有属性"bookId"、"author"、"publisher"和"name"

注意现在列表中出现的新索引

并注意自动生成的属性

自动枚举

一些工具将获取之前呈现的一些数据:

msf > use auxiliary/scanner/elasticsearch/indices_enum

Shodan

  • port:9200 elasticsearch

从零开始学习AWS黑客技术,成为专家 htARTE(HackTricks AWS Red Team Expert)

支持HackTricks的其他方式:

最后更新于