LISTSERV: Pre-Authentication Remote Code Execution

Introduction

LISTSERV has been running mailing lists since 1986, which makes it older than the web itself. So when one of the assets in scope of a pentest turned out to be running it, I got curious. From L-Soft's mailing list manager, it's still around today, and luckily for us, the software can be downloaded. So I grabbed the Linux build and started reversing it and at the end, what started as a curiosity being such old software, ended in a chain that goes from no account at all to running commands on the server.

I ended up with two issues that chain into unauthenticated remote code execution that were :

  • Predictable password reset tokens: every confirmation token comes from one global, non-cryptographic random generator.
  • System function call to RCE via SMTP_ENQUEUE: a site setting the postmaster can change from the web, which the SMTP worker uses as a sprintf format string and then passes to system().

Let's get started!

About LISTSERV

A LISTSERV install has two parts that matter here:

  • lsv: It manages the lists, runs the commands and sends all the mail.
  • wa: the web interface, a CGI binary that turns HTTP requests into LISTSERV commands and forwards them to lsv.

Every account has an email address with a personal password and the site admin is called the postmaster, and logs into the same web interface with the same kind of personal password as everyone else. A postmaster can run every LISTSERV command, including the site configuration ones Right from the back, this is a very interesting account in order to escalate to RCE in the future.

Predictable Password Reset Tokens

How is the reset password token generated

Luckily for us, anyone can register a LISTSERV password for their email address, which is effectively creating an account. The bad news is that a regular user can't do much. They can join and leave mailing lists, change their subscription settings, read the archives and post to lists that allow it. Nothing interesting to mess around with. However, I started to wonder. What about the reset password feature, what's the process for that? Everything starts with this request:

Y is the email address, p and q are the new password twice. LISTSERV mails a confirmation link to that address, and opening it activates the new password:

That token is the only thing LISTSERV checks. There's no session, no cookie and no email address tied to it, so whoever opens the link activates the password chosen in the request. That also means that if I can guess the token for someone else's reset, I own their account (and that someone would be the postmaster account). So let's understand how the token is generated. Every token comes from LTRAND24(), the function lsv uses to make random numbers:

This kind of generator is called a Linear Congruential Generator (LCG). Each new number is just the previous one multiplied by a constant, plus another constant, keeping only the last 32 bits. LCGs are fine for games or simulations, but they're well known for being predictable because the whole internal state is that one number, so anyone who learns it can calculate every value that comes next. That's why they should never be used for secrets like password reset tokens. Yet, here we are. LISTSERV keeps one number, the seed (seed_4188), for the whole server. The first time the function runs, the seed comes from the clock. After that first call, every call only runs the last two lines:

  1. Update the seed with a fixed formula: multiply by 1664525, add 1.
  2. Return the new seed with 9 bits cut off - the most significant and the 8 least significant.

There's no secret key and nothing else mixed in, and the formula is the same on every install. So if you know the seed, you can run the formula yourself and get every number LISTSERV will produce next, including the tokens it mails to other people. To make a token, LSWCNFNK calls LTRAND24() three times (r1, r2 and r3) and glues pieces of the results together. Here's one I got, split back into its three numbers:

Image

Predicting someone else's token

The tokens come out in the same order the requests arrive. To get the postmaster's token, I sandwich their reset between two of mine:

  1. Reset my own password. Token A lands in my inbox.
  2. Reset the postmaster's password, with a new password I choose. Their token goes to their inbox, not mine.
  3. Reset my own password again. Token B lands in my inbox.

The middle of token A is r2 in full, and r2 is just the seed with pieces cut off. So we already know most of the seed, 6F55E4, and only two pieces are missing:

  • The 8 least significant bits, meaning 2 ^ 8 = 256 options
  • The very first bit, which LTRAND24() always clears. If it was set, the seed starts with E instead of 6 meaning only 2 options here.

That's 2 * 256 = 512 possible seeds, so I can try every combination.

Getting the seed back from token AGetting the seed back from token A

With the seed, I run the formula forward and the next token comes out: D763C548F0BE. If nothing else used the generator in between, that's the postmaster's token. On a live server, though, other parts of LISTSERV also call LTRAND24(), and other people may reset their passwords at the same time. That's what token B is for: I keep predicting tokens from A until I reach B, and the postmaster's token is one of the few in between. On a quiet server there's exactly one.

Finding the Postmaster

Now that we have a way to reset someone's password, how can I find the email of the postmaster account ? LISTSERV is our friend and gives this info away and we only need to send HELP to the server email address via our actual email.

Then the server replies with a This server is managed by: block listing the postmasters (unless the admin configured them as hidden which is not by default).

Image

With the postmaster address now known, we could recover his password reset token by “sandwiching” two password resets of my own account with the postmaster password reset in the middle thus being easier to discover because we only had to discover the token between our two tokens. So, token A was 5D6F55E4921E, token B was F83AA319D6A9, and the only token that fit between them was D763C548F0BE. Confirming it needs no session:

And log in with the password I chose in step 2:

Achieving RCE via SMTP_ENQUEUE

Now we have the admin’s account, but we want RCE and we know from the reversing that the admin has really interesting features. o On Linux, LISTSERV sends outbound mail through SMTP worker processes. When a worker starts, it reads SMTP_ENQUEUE:

And for every queued mail file:

The setting is used as the sprintf format string, and the result goes straight to system(). The postmaster can change it from the web through SYSCFG. In syscfg.file, the list of settings SYSCFG accepts, it's declared as:

*UNIX* means it exists on the Unix builds, and *SMTPW* means it's applied when the SMTP workers start. Setting it with the postmaster cookie:

Decoded:

The trailing %s is where sprintf puts the mail file path, and the # turns that path into a shell comment. So the worker runs:

The value is saved in sitecfg.file right away, but the workers only read it when they start, so LISTSERV has to restart. The postmaster user can do that too:

REBOOT here restarts LISTSERV, not the machine. lsv exits with a REBOOT status and the shipped startup script (go, which the systemd unit in the installer also uses) starts /lsv again. In my lab the PID went from 919 to 1151 and the new workers came up with my SMTP_ENQUEUE. From here, anything that makes LISTSERV send an email runs the command. A password reset is the easiest one, and it needs no cookie:

LISTSERV queues the confirmation email, the worker formats its path into my string and calls system().

Finally, I sent this anonymous request, and /tmp/listserv-rce-confirmed was created again by the SMTP worker.

Disclosure Timeline

Final Notes

At the end, we achieve the final exploit chain! Three anonymous password resets give us the postmaster account, and one site setting turns that account into command execution on the server, never needing an account to start with.

Hope you enjoyed it and stay safe!

Validate your exposure

before attackers do.

30-day free trial. No commitment.

def hello(self): print("We are ethical hackers")

class Ethiack: def continuous_vulnerability_discovery(self: Ethiack): self.scan_attack_surface() self.report_all_findings() def proof_of_exploit_validation(self: Ethiack): self.simulate_attack() self.confirm_exploitability() self.validate_impact()

while time.time() < math.inf: ethiack.map_attack_surface() ethiack.discover_vulnerabilities() ethiack.validate_exploits() ethiack.generate_mitigations() ethiack.calculate_risk() ethiack.notify_users() log.success("✓ Iteration complete")

ISO27001

Compliant

Activate AI penTesting

Console.log
001
 
Ethiack — Autonomous Ethical Hacking for continuous security Continuous Attack Surface Management & Testing