mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
173 lines
18 KiB
Markdown
173 lines
18 KiB
Markdown
# 9200 - Pentesting Elasticsearch
|
|
|
|
{{#include ../banners/hacktricks-training.md}}
|
|
|
|
## Basic information
|
|
|
|
Elasticsearch एक **distributed**, **open source** खोज और विश्लेषण इंजन है जो **सभी प्रकार के डेटा** के लिए है। यह अपनी **गति**, **स्केलेबिलिटी**, और **सरल REST APIs** के लिए जाना जाता है। Apache Lucene पर आधारित, इसे 2010 में Elasticsearch N.V. (अब Elastic के रूप में जाना जाता है) द्वारा पहली बार जारी किया गया था। Elasticsearch Elastic Stack का मुख्य घटक है, जो डेटा इनजेशन, समृद्धि, भंडारण, विश्लेषण, और दृश्यता के लिए ओपन सोर्स टूल्स का एक संग्रह है। इस स्टैक को सामान्यतः ELK Stack के रूप में जाना जाता है, जिसमें Logstash और Kibana भी शामिल हैं, और अब इसमें हल्के डेटा शिपिंग एजेंट्स होते हैं जिन्हें Beats कहा जाता है।
|
|
|
|
### What is an Elasticsearch index?
|
|
|
|
Elasticsearch का **index** **संबंधित दस्तावेजों** का एक संग्रह है जो **JSON** के रूप में संग्रहीत होते हैं। प्रत्येक दस्तावेज में **keys** और उनके संबंधित **values** (strings, numbers, booleans, dates, arrays, geolocations, आदि) होते हैं।
|
|
|
|
Elasticsearch तेज पूर्ण-पाठ खोजों को सुविधाजनक बनाने के लिए एक कुशल डेटा संरचना का उपयोग करता है जिसे **inverted index** कहा जाता है। यह इंडेक्स दस्तावेजों में प्रत्येक अद्वितीय शब्द को सूचीबद्ध करता है और उन दस्तावेजों की पहचान करता है जिनमें प्रत्येक शब्द प्रकट होता है।
|
|
|
|
इंडेक्सिंग प्रक्रिया के दौरान, Elasticsearch दस्तावेजों को संग्रहीत करता है और उल्टे इंडेक्स का निर्माण करता है, जिससे लगभग वास्तविक समय में खोज करना संभव होता है। **index API** का उपयोग एक विशिष्ट इंडेक्स के भीतर JSON दस्तावेजों को जोड़ने या अपडेट करने के लिए किया जाता है।
|
|
|
|
**Default port**: 9200/tcp
|
|
|
|
## Manual Enumeration
|
|
|
|
### Banner
|
|
|
|
Elasticsearch तक पहुँचने के लिए उपयोग किया जाने वाला प्रोटोकॉल **HTTP** है। जब आप इसे HTTP के माध्यम से एक्सेस करते हैं, तो आपको कुछ दिलचस्प जानकारी मिलेगी: `http://10.10.10.115:9200/`
|
|
|
|
.png>)
|
|
|
|
यदि आप `/` को एक्सेस करते समय वह प्रतिक्रिया नहीं देखते हैं, तो निम्नलिखित अनुभाग देखें।
|
|
|
|
### Authentication
|
|
|
|
**डिफ़ॉल्ट रूप से Elasticsearch में प्रमाणीकरण सक्षम नहीं है**, इसलिए डिफ़ॉल्ट रूप से आप बिना किसी क्रेडेंशियल का उपयोग किए डेटाबेस के अंदर सब कुछ एक्सेस कर सकते हैं।
|
|
|
|
आप एक अनुरोध के साथ सत्यापित कर सकते हैं कि प्रमाणीकरण अक्षम है:
|
|
```bash
|
|
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}
|
|
```
|
|
**हालांकि**, यदि आप `/` पर एक अनुरोध भेजते हैं और निम्नलिखित प्रतिक्रिया प्राप्त करते हैं:
|
|
```bash
|
|
{"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}
|
|
```
|
|
यह मतलब है कि प्रमाणीकरण कॉन्फ़िगर किया गया है और **आपको कोई जानकारी प्राप्त करने के लिए मान्य क्रेडेंशियल्स** की आवश्यकता है। फिर, आप [**इसे ब्रूटफोर्स करने की कोशिश कर सकते हैं**](../generic-hacking/brute-force.md#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/
|
|
```
|
|
### बेसिक यूजर एन्यूमरेशन
|
|
```bash
|
|
#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
|
|
|
|
यहाँ कुछ endpoints हैं जिन्हें आप **GET के माध्यम से** **जानकारी प्राप्त करने** के लिए **एक्सेस** कर सकते हैं elasticsearch के बारे में:
|
|
|
|
| \_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 | | |
|
|
|
|
ये endpoints [**दस्तावेज़ीकरण से लिए गए हैं**](https://www.elastic.co/guide/en/elasticsearch/reference/current/rest-apis.html) जहाँ आप **और अधिक** पा सकते हैं।\
|
|
इसके अलावा, यदि आप `/_cat` को एक्सेस करते हैं तो प्रतिक्रिया में `/_cat/*` endpoints शामिल होंगे जो इंस्टेंस द्वारा समर्थित हैं।
|
|
|
|
`/_security/user` में (यदि auth सक्षम है) आप देख सकते हैं कि कौन सा उपयोगकर्ता `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`
|
|
|
|
.png>)
|
|
|
|
### इंडेक्स डंप करें
|
|
|
|
यदि आप **एक इंडेक्स की सभी सामग्री को डंप करना** चाहते हैं, तो आप एक्सेस कर सकते हैं: `http://host:9200/<index>/_search?pretty=true` जैसे `http://10.10.10.115:9200/bank/_search?pretty=true`
|
|
|
|
.png>)
|
|
|
|
_एक पल लें और बैंक इंडेक्स के प्रत्येक दस्तावेज़ (एंट्री) की सामग्री की तुलना करें और इस इंडेक्स के फ़ील्ड जो हमने पिछले अनुभाग में देखे थे।_
|
|
|
|
तो, इस बिंदु पर आप देख सकते हैं कि **"hits" के अंदर "total" नाम का एक फ़ील्ड है** जो यह दर्शाता है कि **इस इंडेक्स के अंदर 1000 दस्तावेज़ पाए गए** लेकिन केवल 10 को पुनः प्राप्त किया गया। इसका कारण यह है कि **डिफ़ॉल्ट रूप से 10 दस्तावेज़ों की सीमा है।**\
|
|
लेकिन, अब जब आप जानते हैं कि **इस इंडेक्स में 1000 दस्तावेज़ हैं**, आप **उनमें से सभी को डंप कर सकते हैं** यह बताते हुए कि आप कितनी एंट्रीज़ को डंप करना चाहते हैं **`size`** पैरामीटर में: `http://10.10.10.115:9200/quotes/_search?pretty=true&size=1000`asd\
|
|
\_नोट: यदि आप बड़ा नंबर बताते हैं तो सभी एंट्रीज़ वैसे भी डंप हो जाएंगी, उदाहरण के लिए आप `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`
|
|
|
|
.png>)
|
|
|
|
यदि आप केवल **एक इंडेक्स पर खोज** करना चाहते हैं, तो आप बस **पथ** में इसे **निर्दिष्ट** कर सकते हैं: `http://host:9200/<index>/_search?pretty=true&q=<search_term>`
|
|
|
|
_ध्यान दें कि सामग्री को खोजने के लिए उपयोग किया जाने वाला q पैरामीटर **नियमित अभिव्यक्तियों का समर्थन करता है**_
|
|
|
|
आप एक elasticsearch सेवा को फज़ करने के लिए [https://github.com/misalabs/horuz](https://github.com/misalabs/horuz) जैसी चीज़ का भी उपयोग कर सकते हैं।
|
|
|
|
### लिखने की अनुमति
|
|
|
|
आप अपनी लिखने की अनुमति की जांच कर सकते हैं, एक नए इंडेक्स के अंदर एक नया दस्तावेज़ बनाने की कोशिश करके, कुछ इस तरह चलाकर:
|
|
```bash
|
|
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"
|
|
}'
|
|
```
|
|
वह cmd एक **नया इंडेक्स** बनाएगा जिसका नाम `bookindex` होगा, जिसमें `books` प्रकार का एक दस्तावेज़ होगा जिसमें "_bookId_", "_author_", "_publisher_" और "_name_" विशेषताएँ होंगी।
|
|
|
|
ध्यान दें कि **नया इंडेक्स अब सूची में दिखाई दे रहा है**:
|
|
|
|
.png>)
|
|
|
|
और ध्यान दें कि **स्वचालित रूप से बनाए गए गुण**:
|
|
|
|
.png>)
|
|
|
|
## स्वचालित गणना
|
|
|
|
कुछ उपकरण पहले प्रस्तुत किए गए डेटा में से कुछ डेटा प्राप्त करेंगे:
|
|
```bash
|
|
msf > use auxiliary/scanner/elasticsearch/indices_enum
|
|
```
|
|
{{#ref}}
|
|
https://github.com/theMiddleBlue/nmap-elasticsearch-nse
|
|
{{#endref}}
|
|
|
|
## Shodan
|
|
|
|
- `port:9200 elasticsearch`
|
|
|
|
{{#include ../banners/hacktricks-training.md}}
|