# [CS 1.6] Map cycle abuse allows arbitrary file read/write

RCON-authenticated attacker sets mapcyclefile cvar to a path-traversal path, causing the GoldSrc server to read or write arbitrary host files.

- Payout: $750
- Severity: medium
- Program: Valve
- Found by: fe7ch
- Disclosed: 2021-02-22
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/590279
- Library page: https://bugbountylibrary.com/r/h1%3A590279
- Tags: area:devices domain:desktop domain:network impact:data-leak impact:integrity kind:bounty platform:hackerone sev:medium tech:windows technique:source-review vuln:access-control vuln:path-traversal

**Target:** GoldSrc/Source engine HLDS (hl.exe) mapcyclefile cvar and CServerRemoteAccess::SetValue
**Root cause:** The mapcyclefile cvar is user-settable via RCON with no path sanitization, and CServerRemoteAccess::SetValue blindly FS_Open()s the cvar path for read (listmaps/ServerInfo) and write (mapcycle command).
**Steps:**
1. Authenticate to RCON on the HLDS server.
2. Send `rcon <pw> mapcyclefile ../../../../../etc/passwd` to point the cvar at an arbitrary path.
3. Run `listmaps` in the game console (or connect to receive ServerInfo) to trigger the read; file lines appear in HLDS console as 'Skipping ... from mapcycle'.
4. For write: set `mapcyclefile` to a target path, then invoke the `mapcycle` command with payload via the GameServerData001 interface to FS_Write attacker data into that file.
**How found:** Noticed mapcyclefile is a user-controllable cvar with no sanitization, then traced how listmaps/ServerInfo and the mapcycle command consume it, and read CServerRemoteAccess::SetValue to confirm FS_Open on the raw cvar path.
**Exploitation:** With RCON access, set mapcyclefile to a traversal path; listmaps/ServerInfo leaks file contents line-by-line via 'Skipping ... not a valid map' log lines. Via the GameServerData001 remote-control interface, the mapcycle command writes attacker-controlled bytes to the cvar-specified path, enabling overwrite of host files for DoS or RCE.
**Escalation:** Read-only info disclosure escalates to arbitrary file write (and potential RCE/DoS) when the GameServerData001 interface is reachable, since SetValue writes to the same unsanitized path.
**Insight:** Game-server cvars that name files (mapcyclefile, motd, config paths) are classic traversal sinks; check both the read path (listmaps/ServerInfo) and the write path (mapcycle) since one cvar feeds both FS_Open modes.

## Proof of concept (copied exactly from the original report)

**RCON sets mapcyclefile to /etc/passwd**

```
Rcon from 192.168.42.181:27005:
rcon 1753030938 "asd" mapcyclefile ../../../../../etc/passwd
Skipping root:x:0:0:root:/root:/bin/bash from mapcycle, not a valid map
```

**Vulnerable SetValue mapcycle file write code**

```
else if ( !strcasecmp(variable, "mapcycle") )
  {
    file = FS_Open(mapcyclefile.string, "wt");
    if ( file
      || (Con_Printf(
            "Couldn't write to read-only file %s, using file _dev_mapcycle.txt instead.\n",
            mapcyclefile.string),
          Cvar_DirectSet(&mapcyclefile, "_temp_mapcycle.txt"),
          (file = FS_Open(mapcyclefile.string, "wt")) != 0) )
    {
      v4 = strlen(value);
      FS_Write(value, v4 + 1, 1, file);
      FS_Close(file);
    }
  }
```

