procmail
[Top] [All Lists]

Re: Help! Need to use procmail to fight dangerous security exploit

1998-07-28 23:55:08
I would like to try to use procmail to plug the hole at the mail server,
by truncating the excessively long file names in the MIME headers. (Procmail
seems to be the best tool for the job). However, I have no experience with 
procmail. Could someone help me write a procmail.rc that will eliminate the 
extra-long filenames, truncating them back to (say) 64 characters max? 
All that's required is to recognize the header

Content-Disposition: attachment; filename="<verylongname>"

Kind of scary, isn't it?  Anyone know if procmail has been given a decent
security check?  I started going through the source this morning, but I
don't claim to be an expert in buffer overflows.

Anyhow, here's a recipe to give you the filename length in a variable.  It
assumes that the header is in the the same format as what you listed above,
with no trailing stuff.

   :0
   * ^Content-Disposition: attachment; filename=\/"<[^\<"]+>"
   * 1^1 MATCH ?? .
   { FILENAMELENGTH=`expr $= - 4` }

Now you can use FILENAMELENGTH to do things with the mail...

   # if FILENAMELENGTH longer than 63, dump to /var/spool/mail/danger
   :0:
   * FILENAMELENGTH ?? (6[4-9]|[7-9][0-9]|[1-9][0-9][0-9]+)
   /var/spool/mail/danger

Chris