Reading through a vulnerability report about ClamAV, I came across a phrase that filled me with dread: “The file name is not sanitized”. It’s a feature, VirusEvent
, that can be enabled in the ClamnAV config. And that configuration includes a string formatting function, where the string includes %v
and %s
, which gets replaced with a detected virus name and the file name from the email. And now you see the problem, I hope: The filename is attacker supplied input.
Where this really gets out of hand is what ClamAV does with this string. execle("/bin/sh", "sh", "-c", buffer_cmd, NULL, env)
. So let’s talk defensive program design for a minute. When it comes to running a secondary command, there are two general options, system()
and the exec*()
family of system calls. system()
is very simple to use. It pauses execution of the main process and asks the operating system to run a string, just as if the user had typed that command into the shell. While this is very convenient to use, there is a security problem if any of that command string is user-supplied. All it takes is a semicolon or ampersand to break assumptions and inject a command.
To the rescue comes exec()
. It’s a bit more complicated to use, requiring the programmer to manually call fork()
and wait()
. But it’s not running the command via the shell. exec()
executes a program directly, totally eliminating the potential for command injection! Except… oops.
Yeah, exec()
and related calls don’t offer any security protections when you use them to execute /bin/sh
. I suspect the code was written this way to allow running a script without specifying /bin/sh
in the config. The official fix was to disable the filename format character, and instead supply it as an environment variable. That certainly works, and that fix is available in 1.0.5, 1.2.2, and 1.3.0.
The real danger here is that we have another case where some hardware appliance manufacturer has used ClamAV for email filtering, and uses this configuration by default. That’s how we get orders from CISA to unplug your hardware, because it’s already compromised. Continue reading “This Week In Security: Filename Not Sanitized, MonikerLink, And Snap Attack!”