repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
3632-pentesting-distcc.mdMarkdown94 lines6.0 KiBrendered raw download
---
title: "3632 - Pentesting Distcc"
section: "Network Services"
sectionSlug: "network-services-pentesting"
sourcePath: "src/network-services-pentesting/3632-pentesting-distcc.md"
sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/network-services-pentesting/3632-pentesting-distcc.md"
sha: "188de82beb54e70956b2952367a0af91d26758b8"
isIndex: false
modified: true
license: "CC-BY-NC-4.0"
---

# 3632 - Pentesting Distcc

## Basic Information

`distcc` distributes compilation jobs across networked machines. A client preprocesses source locally and sends the result to a server running `distccd`, which invokes a compiler and returns the output.<sup>[[1]](#references)</sup>

**Common port:** 3632/TCP

```text
PORT     STATE SERVICE
3632/tcp open  distccd
```

The native TCP transport is a trust boundary: unless GSS-API support is compiled in and `--auth` is enabled, access control is based on source IP rather than user identity. The transport also provides no confidentiality or integrity for preprocessed source and returned object files.<sup>[[6]](#references)[[7]](#references)</sup>

## Enumeration

```bash
nmap -Pn -sV -p 3632 <IP>
```

An open TCP port is not enough to prove command execution. In daemon mode, `distccd` applies IP allow rules and silently closes connections from addresses that do not match one; therefore, an immediate EOF/reset after sending a request often indicates an IP allowlist rather than a patched service. Test from the same network position as an authorized build client when the assessment scope permits it.<sup>[[6]](#references)</sup>

### Protocol-aware identification

The version 1 request used by common exploit tools is a fixed token stream. Every header is a four-byte ASCII token followed by an eight-character hexadecimal value; body-bearing tokens then contain exactly that many bytes. A request contains `DIST` (protocol version), `ARGC`, repeated `ARGV` values and `DOTI` (preprocessed input). The response contains `DONE`, `STAT`, `SERR`, `SOUT` and `DOTO` (object output). The ASCII tokens make packet captures and partial/error responses useful even when generic service detection returns no banner.<sup>[[5]](#references)</sup>

```bash
# Inspect tokens and payloads in a lab capture
sudo tcpdump -ni <iface> -s0 -A 'tcp port 3632'
```

## Exploitation

Older or explicitly insecure `distccd` deployments that accept the tester's address may be vulnerable to CVE-2004-2687. The classic primitive submits a fake compilation whose argument vector starts with `sh -c <command>` and appends compile-looking arguments; the command output is recovered from the `SOUT`/`SERR` response fields.<sup>[[2]](#references)[[3]](#references)[[5]](#references)</sup>

Nmap provides an NSE check and Metasploit provides a corresponding module. Both checks are **intrusive** because they confirm the issue by executing a command; the NSE argument prefix is the current script name, `distcc-cve2004-2687.cmd`.<sup>[[3]](#references)[[4]](#references)</sup>

```bash
nmap -p 3632 <IP> --script distcc-cve2004-2687 \
  --script-args="distcc-cve2004-2687.cmd='id'"

msfconsole
use exploit/unix/misc/distcc_exec
set RHOSTS <IP>
set RPORT 3632
check
set PAYLOAD cmd/unix/generic
set CMD id
run
```

For environments where those frameworks are unavailable, DarkCoderSc's standalone Python proof of concept shows the raw command-execution exchange.<sup>[[5]](#references)</sup>

### Interpreting failed exploitation

Do not treat a failed `sh` payload as proof that the exposed build service is safe:

- Since distcc 3.3, TCP mode normally accepts only compiler names represented by masquerade links under the distcc compiler directory. The server option `--enable-tcp-insecure` disables that check and explicitly re-enables arbitrary executable names.<sup>[[6]](#references)</sup>
- A connection closed without a protocol response commonly means that the source address missed the effective IP allowlist (`--allow`/`--allow-private`). A compiler-whitelist rejection instead means the client passed network authorization but the requested `argv[0]` was rejected.<sup>[[6]](#references)</sup>
- Even a compiler-only command list is not a strong sandbox. Upstream warns that compilers process hostile arguments and inputs and recommends assuming that any client allowed to submit jobs can act with the privileges of the `distccd` account.<sup>[[7]](#references)</sup>

### On-path build poisoning

Plain TCP mode neither encrypts nor signs requests or responses. A passive observer can recover preprocessed source and object code, while an active on-path attacker can change either side of the exchange. Replacing the returned object file can implant code into the final locally linked binary without needing the direct `sh` primitive on the server.<sup>[[7]](#references)</sup>

## Hardening notes

Keep TCP/3632 on a trusted build network, bind it to the build interface with `--listen`, use narrow `--allow` CIDRs plus a firewall, and run the daemon as an unprivileged dedicated account. Do not enable `--enable-tcp-insecure`. Where clients cannot be fully trusted at the network layer, use SSH transport or a build with GSS-API mutual authentication (`--auth` and principal allowlisting) rather than relying only on source IP.<sup>[[6]](#references)[[7]](#references)</sup>

Post created by **Álex B (@r1p)**.


## References

- [1] [distcc documentation - How distcc works](https://www.distcc.org/man/distcc_1.html)
- [2] [NIST NVD - CVE-2004-2687](https://nvd.nist.gov/vuln/detail/CVE-2004-2687)
- [3] [Nmap NSE documentation - `distcc-cve2004-2687`](https://nmap.org/nsedoc/scripts/distcc-cve2004-2687.html)
- [4] [Rapid7 - DistCC Daemon Command Execution module](https://www.rapid7.com/db/modules/exploit/unix/misc/distcc_exec/)
- [5] [DarkCoderSc - standalone DistCC command-execution proof of concept](https://gist.github.com/DarkCoderSc/4dbf6229a93e75c3bdf6b467e67a9855)
- [6] [distcc upstream - current `distccd(1)` manual](https://github.com/distcc/distcc/blob/master/man/distccd.1)
- [7] [distcc upstream - security notes](https://www.distcc.org/security.html)