Skip to content
Misconfiguration Write-up Intermediate

root with a single command: sudo logrotate

A user restricted to running only `sudo logrotate *` could exploit logrotate's `-l` flag to write arbitrary content to files owned by root, such as scripts in `/etc/cron.daily/`, leading to root code execution. The attacker could then overwrite a cron script to run commands as root.

Joshua Rogers Follow

Published on joshua.hu

The scenario is this: a brand new Ubuntu 22.04 server has an account which is restricted to running sudo logrotate . Can we get root?

Joshua Rogers, on joshua.hu

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the sudoers rule allowed the `-l` flag, which lets logrotate write to arbitrary paths with root privileges, without restricting the target file.

Impact

An attacker with this restricted sudo access could execute arbitrary commands as root, leading to full system compromise.

What the attacker needed

Sudo access to logrotate with -l flag; ability to write to a root-owned file path

The fix

The sudoers rule should be replaced with a wrapper script that only allows rotating specific log files, as shown in the report.

How it was found

  1. Check that the user can run `sudo logrotate *`.
  2. Use `sudo logrotate -l` with a target file path and arbitrary data to overwrite a root-owned script, such as one in `/etc/cron.daily/`.
  3. Wait for the cron job to execute the modified script as root.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

The `sudo` command lets users run specific programs with administrator privileges. Here, a user was only allowed to run `logrotate`, a tool for managing log files. The `-l` option of logrotate writes a log file, and the user could choose where that file goes. By pointing it at a script that runs automatically as root, the user could make the system run their own commands as root.

What is Misconfiguration?

Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.

Similar reports

View all

Same bug class and techniques, clearest first.

Security misconfiguration

The lesson behind this report.

Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.