Skip to content
RCE Write-up Advanced

Possible RCE vulnerability in mailing action using mailutils (mail-whois)

The mail-whois action in fail2ban pipes whois output into the mail command from mailutils, which interprets tilde escape sequences. An attacker who can control the whois response (e.g., via MITM or a malicious referral server) could inject a tilde escape to execute arbitrary commands as root.

github.com

Published on github.com

Command mail from mailutils package used in mail actions like mail-whois can execute command if unescaped sequences (\n~) are available in "foreign" input (for instance in whois output).

The author, on github.com

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

Impact

An attacker who can control the whois response could execute arbitrary commands with the privileges of the fail2ban process (often root), but this requires specific conditions such as a MITM or control over a referral whois server.

What the attacker needed

Fail2ban configured with mail-whois action; attacker can control whois response (MITM or malicious…

The fix

The issue was fixed by updating fail2ban to versions 0.10.7 or 0.11.3, which likely escape or disable tilde escapes in the mail command.

How it was found

  1. Configure a jail to use the mail-whois action.
  2. Set up a local whois server that returns a response containing a tilde escape sequence.
  3. Redirect the whois client to the local server (e.g., by editing /etc/hosts).
  4. Trigger the jail action by causing a ban.
  5. Observe that the command in the tilde escape is executed and the email is sent.

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.

Fail2ban is a tool that blocks bad IP addresses. When it blocks one, it can send an email that includes information from a whois lookup. The mail program used to send that email treats lines starting with a tilde as special commands. If an attacker can make the whois lookup return a line starting with a tilde, the mail program will run it as a command, letting the attacker run code on the server.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.