zgrep arbitrary file write
CVE-2022-1271 lives in zgrep, the helper that searches inside gzip archives. A filename that contains a newline character confuses zgrep's argument handling and lets an attacker steer it into overwriting files it was never meant to touch. When GNU sed is present as well, that file write turns into command execution. Any service that shells out to zgrep with a user-supplied filename inherits the bug.
Find where the app passes a filename you control into zgrep, build a .gz name with an embedded newline, and use it to drop or overwrite a file that gets you execution. The public proof of concept constructs the malicious name with printf.
How to reach it
Run the challenge locally with its docker-compose. The flagger sidecar writes your per-run flag into the container before it starts. The service speaks HTTP on port 8080.
Run this challenge
Spin it up locally with Docker. The flagger sidecar fetches a per-run flag into a shared volume, then the challenge container boots and reads it.
services:
flagger:
image: matejbasic/rootcause-flagger:1.0
environment:
ROOTCAUSE_API_URL: https://root-cause-api.matejbasic.com
ROOTCAUSE_API_KEY: ${ROOTCAUSE_API_KEY}
ROOTCAUSE_CHALLENGE: zgrep-rce
FLAG_PATH: /flag/flag.txt
volumes:
- flag:/flag
challenge:
image: matejbasic/cve-2022-1271:1.0
depends_on:
flagger:
condition: service_completed_successfully
environment:
FLAG_PATH: /flag/flag.txt
volumes:
- flag:/flag
ports:
- "8080:8080"
volumes:
flag:
rootcause start zgrep-rceThe rootcause CLI does all of this in one command. Running a challenge needs your API key, which you generate in your profile.