Goal Reached Thanks to every supporter — we hit 100%!

Goal: 1000 CNY · Raised: 1020 CNY

100%

CVE-2021-32804 PoC — Arbitrary File Creation/Overwrite due to insufficient absolute path sanitization

Source
Associated Vulnerability
Title:Arbitrary File Creation/Overwrite due to insufficient absolute path sanitization (CVE-2021-32804)
Description:The npm package "tar" (aka node-tar) before versions 6.1.1, 5.0.6, 4.4.14, and 3.3.2 has a arbitrary File Creation/Overwrite vulnerability due to insufficient absolute path sanitization. node-tar aims to prevent extraction of absolute file paths by turning absolute paths into relative paths when the `preservePaths` flag is not set to `true`. This is achieved by stripping the absolute path root from any absolute file paths contained in a tar file. For example `/home/user/.bashrc` would turn into `home/user/.bashrc`. This logic was insufficient when file paths contained repeated path roots such as `////home/user/.bashrc`. `node-tar` would only strip a single path root from such paths. When given an absolute file path with repeating path roots, the resulting path (e.g. `///home/user/.bashrc`) would still resolve to an absolute path, thus allowing arbitrary file creation and overwrite. This issue was addressed in releases 3.2.2, 4.4.14, 5.0.6 and 6.1.1. Users may work around this vulnerability without upgrading by creating a custom `onentry` method which sanitizes the `entry.path` or a `filter` method which removes entries with absolute paths. See referenced GitHub Advisory for details. Be aware of CVE-2021-32803 which fixes a similar bug in later versions of tar.
Readme
# CVE-2021-32804

yamory blog 「[CVE-2021-32804 npmにも影響があるnode-tarのパストラバーサルの脆弱性](https://yamory.io/blog/cve-2021-32804-node-tar-reproduce/)」 で利用したDocker環境の構築を行うためのレポジトリです。

## 環境構築

```
docker build -t cve-2021-32804 .
docker run -it cve-2021-32804 /bin/bash
```

## 脆弱性の再現

### node-tar

```
root@5e1af2148215:/poc# node tar.js
root@5e1af2148215:/poc# su node
Hello, world!
```

### npm

```
root@5e1af2148215:/poc# npm i bashrc.tgz
root@5e1af2148215:/poc# su node
Hello, world!
```

File Snapshot

[4.0K] /data/pocs/9f371460af50b5df1f65aa1214c6f4c23ebbe2bd ├── [ 107] Dockerfile ├── [4.0K] poc │   ├── [ 151] bashrc.tgz │   ├── [4.0K] node_modules │   │   ├── [4.0K] chownr │   │   │   ├── [4.2K] chownr.js │   │   │   ├── [ 765] LICENSE │   │   │   ├── [ 649] package.json │   │   │   └── [ 59] README.md │   │   ├── [4.0K] fs-minipass │   │   │   ├── [9.8K] index.js │   │   │   ├── [ 765] LICENSE │   │   │   ├── [ 865] package.json │   │   │   └── [2.4K] README.md │   │   ├── [4.0K] minipass │   │   │   ├── [ 14K] index.js │   │   │   ├── [ 756] LICENSE │   │   │   ├── [ 808] package.json │   │   │   └── [ 21K] README.md │   │   ├── [4.0K] minizlib │   │   │   ├── [3.7K] constants.js │   │   │   ├── [9.2K] index.js │   │   │   ├── [1.3K] LICENSE │   │   │   ├── [ 907] package.json │   │   │   └── [1.9K] README.md │   │   ├── [4.0K] mkdirp │   │   │   ├── [4.0K] bin │   │   │   │   └── [1.8K] cmd.js │   │   │   ├── [ 448] CHANGELOG.md │   │   │   ├── [1.0K] index.js │   │   │   ├── [4.0K] lib │   │   │   │   ├── [ 763] find-made.js │   │   │   │   ├── [1.6K] mkdirp-manual.js │   │   │   │   ├── [ 969] mkdirp-native.js │   │   │   │   ├── [ 784] opts-arg.js │   │   │   │   ├── [ 730] path-arg.js │   │   │   │   └── [ 448] use-native.js │   │   │   ├── [1.1K] LICENSE │   │   │   ├── [ 804] package.json │   │   │   └── [8.3K] readme.markdown │   │   ├── [4.0K] tar │   │   │   ├── [1.7K] CHANGELOG.md │   │   │   ├── [ 683] index.js │   │   │   ├── [4.0K] lib │   │   │   │   ├── [2.3K] create.js │   │   │   │   ├── [2.7K] extract.js │   │   │   │   ├── [ 921] get-write-flag.js │   │   │   │   ├── [8.8K] header.js │   │   │   │   ├── [ 760] high-level-opt.js │   │   │   │   ├── [2.1K] large-numbers.js │   │   │   │   ├── [3.1K] list.js │   │   │   │   ├── [5.1K] mkdir.js │   │   │   │   ├── [ 619] mode-fix.js │   │   │   │   ├── [9.5K] pack.js │   │   │   │   ├── [ 14K] parse.js │   │   │   │   ├── [3.2K] path-reservations.js │   │   │   │   ├── [3.9K] pax.js │   │   │   │   ├── [2.6K] read-entry.js │   │   │   │   ├── [5.3K] replace.js │   │   │   │   ├── [1.1K] types.js │   │   │   │   ├── [ 18K] unpack.js │   │   │   │   ├── [ 842] update.js │   │   │   │   ├── [ 697] warn-mixin.js │   │   │   │   ├── [ 535] winchars.js │   │   │   │   └── [ 12K] write-entry.js │   │   │   ├── [ 765] LICENSE │   │   │   ├── [1.4K] package.json │   │   │   └── [ 44K] README.md │   │   └── [4.0K] yallist │   │   ├── [ 207] iterator.js │   │   ├── [ 765] LICENSE │   │   ├── [ 652] package.json │   │   ├── [4.6K] README.md │   │   └── [8.2K] yallist.js │   ├── [ 242] package.json │   ├── [4.8K] package-lock.json │   └── [ 60] tar.js └── [ 596] README.md 12 directories, 66 files
Shenlong Bot has cached this for you
Remarks
    1. It is advised to access via the original source first.
    2. Local POC snapshots are reserved for subscribers — if the original source is unavailable, the local mirror is part of the paid plan.
    3. Mirroring, verifying, and maintaining this POC archive takes ongoing effort, so local snapshots are a paid feature. Your subscription keeps the archive online — thank you for the support. View subscription plans →