9200 - Pentesting Elasticsearch

htARTE (HackTricks AWS Red Team Expert)를 통해 **제로**부터 **히어로**까지 AWS 해킹을 배우세요!

HackTricks를 지원하는 다른 방법:

기본 정보

Elasticsearch는 분산, 오픈 소스 검색 및 분석 엔진으로 모든 유형의 데이터에 대해 사용됩니다. 속도, 확장성, 간단한 REST API로 유명합니다. Apache Lucene 위에 구축되어 2010년에 Elasticsearch N.V. (현재 Elastic으로 알려짐)에 의해 처음 출시되었습니다. Elasticsearch는 데이터 수집, 풍부화, 저장, 분석 및 시각화를 위한 오픈 소스 도구 모음인 Elastic Stack의 핵심 구성 요소입니다. 이 스택은 ELK 스택으로도 알려져 있으며 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}

이것은 인증이 구성되어 있고 유효한 자격 증명이 필요하므로 elasticserach에서 정보를 얻으려면 유효한 자격 증명이 필요합니다. 그런 다음 브루트포스를 시도할 수 있습니다(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 정보

다음은 Elasticsearch에 대한 일부 정보를 얻기 위해 GET을 통해 액세스할 수 있는 몇 가지 엔드포인트입니다:

_cat/_cluster/_security

/_cat/segments

/_cluster/allocation/explain

/_security/user

/_cat/shards

/_cluster/settings

/_security/privilege

/_cat/repositories

/_cluster/health

/_security/role_mapping

/_cat/recovery

/_cluster/state

/_security/role

/_cat/plugins

/_cluster/stats

/_security/api_key

/_cat/pending_tasks

/_cluster/pending_tasks

/_cat/nodes

/_nodes

/_cat/tasks

/_nodes/usage

/_cat/templates

/_nodes/hot_threads

/_cat/thread_pool

/_nodes/stats

/_cat/ml/trained_models

/_tasks

/_cat/transforms/_all

/_remote/info

/_cat/aliases

/_cat/allocation

/_cat/ml/anomaly_detectors

/_cat/count

/_cat/ml/data_frame/analytics

/_cat/ml/datafeeds

/_cat/fielddata

/_cat/health

/_cat/indices

/_cat/master

/_cat/nodeattrs

/_cat/nodes

이러한 엔드포인트는 문서에서 가져온 것이며, 여기에서 더 많은 정보를 찾을 수 있습니다. 또한, /_cat에 액세스하면 응답에 인스턴스에서 지원하는 /_cat/* 엔드포인트가 포함됩니다.

/_security/user에서 (인증이 활성화된 경우) superuser 역할을 가진 사용자를 볼 수 있습니다.

인덱스

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 서비스를 fuzz할 수 있습니다.

쓰기 권한

다음과 같이 새 인덱스 내에 새 문서를 생성하는 권한을 확인할 수 있습니다.

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라는 새 인덱스를 생성하며, "bookId", "author", "publisher", "name" 속성을 가진 books 유형의 문서를 만듭니다.

새 인덱스가 목록에 나타나는 모습을 확인하세요:

그리고 자동으로 생성된 속성을 확인하세요:

자동 열거

일부 도구는 이전에 제시된 데이터 중 일부를 획득할 것입니다:

msf > use auxiliary/scanner/elasticsearch/indices_enum

Shodan

  • 포트:9200 elasticsearch

AWS 해킹을 제로부터 전문가로 배우세요 htARTE (HackTricks AWS Red Team Expert)!

다른 방법으로 HackTricks를 지원하는 방법:

Last updated