Is a New Vulnerability the Tip of the Perl Iceberg?

Opinion: It's probably not the basis for a new network worm, but Perl format strings could be fertile ground for more targeted hacking.

Last week a serious vulnerability was revealed to relatively little attention from the press, or even from security circles. I think its a real nasty one, especially in as much as it will go widely unpatched.

The program at issue is the ubiquitous Perl programming language. Perl is a scripting language, which means a lot of things to different people, but I think the main characteristic is that its interpreted in source form in a sort of virtual machine. Perl is widely used for system administration scripting as well as for server-side Web site programming, although in recent years it has been substantially supplanted by PHP, ASP and other server-side scripting languages.

This specific vulnerability, the "Perl_sv_vcatpvfn Format String Integer Wrap Vulnerability," relates to the use of string formatting. Perl has string formatting features very similar to those in the C language string library functions, wherein you might use printf("the number is %4u\n",x) to print the value of the integer variable x as a 4-digit unsigned integer.

String formatting like this has a sad history of exploit in the C world, and theres every reason to assume the same about Perl. As the SecurityFocus advisory I linked to above makes clear, if your programs pass data to these functions you should first sanitize the data to make sure its in the proper bounds. The specified format string instance is almost certainly just an example, and numerous others must exist in other Perl cases.

Another point about this vulnerability that will serve to confuse is that it is often described as a vulnerability in Webmin, a Web-based system administration tool written in Perl. But some reports, which I have confirmed with Dave Aitel of Immunity Inc., make it clear the underlying problem is in Perl itself.

Its easy for SecurityFocus (and me) to tell all of you do check all your data before calling functions like this, but the fact is that not a lot of this gets done. In fact, from my own experience digging around Perl programs, theyre among the sloppiest and most unreadable programs out there.

A colleague of mine derides Perl programs as "modem noise," and hes got a point. Its not just the impossibly-terse regular expressions that dot the landscape of Perl source, its that Perl is designed for quick-hack programming. You can get something up and running quickly. Presumably, if its not a one-time type program, you should polish it up afterwards, adding things like error checking and security checks but, shocking as it might seem, this doesnt always happen.

A great example of why Perl programs are written and how they could be abused in this way came from one of the few observers that I saw comment on the vulnerability online. Michael J. Pomraning nominated the syslog() function from the Sys::Syslog module, observing: "Its common in *NIX environments regardless of programmers backgrounds and is extremely likely to be called with untrusted data interpolated directly in the format string argument—syslog("info", "A user said $user_input"), for example." [Correction: This paragraph has been changed. The syslog() remark was originally attributed to Steven Christey, but was in fact made by Pomraning, following up to a different comment by Christey.]

I bet there are many, many systems out there running Perl scripts that have been forgotten with the programmer on his fourth new job since it was written. And undoubtedly there is a lot of Perl CGI code that was written before we were concerned about things like this (I know, I wrote some if it myself; I could go back and fix it, but nobodys paying for it, so it wont get done).

Im not immediately worried about a major attack based on these vulnerabilities, but they could be a great entry point for someone trying to break into a specific system, especially if the execution context of the Perl interpreter itself is not well-managed.

Theres an assumption out there, even among people who should know better, that "VM" languages like Perl are inherently safer. This may be true to a degree, but they are not inherently "safe." In fact, Perls roots in the pre-security days of the Internet make it especially suspect. I think well be hearing more about this over time.

Security Center Editor Larry Seltzer has worked in and written about the computer industry since 1983.

28571.gif

Check out eWEEK.coms for the latest security news, reviews and analysis. And for insights on security coverage around the Web, take a look at eWEEK.com Security Center Editor Larry Seltzers Weblog.

More from Larry Seltzer