9200 - Pentesting Elasticsearch

Support HackTricks

基本信息

Elasticsearch 是一个 分布式开源 的搜索和分析引擎,适用于 所有类型的数据。它以 速度可扩展性简单的 REST API 而闻名。基于 Apache Lucene,它于 2010 年首次由 Elasticsearch N.V.(现在称为 Elastic)发布。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基本身份验证,因此可以使用任何可以暴力破解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

支持 HackTricks

Last updated