[Mimedefang] Two questions

Ole Craig olc at cs.umass.edu
Tue Aug 30 16:11:29 EDT 2005

On 08/30/05 at 14:47, 'twas brillig and Jim McCullars scrobe:
> > 2) Does mimedefang have a way to detect and deny encrypted archives
> > (like encrypted zip files), while still allowing through unencrypted
> > archives.  (it's ok if zip files are the only such archive)
>    You could do something like this (untested!) in sub filter():

Here's our version. It's been in production for well over a year, so I
guess it qualifies as "somewhat-tested"...
# within filter_initialize ()
    use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
# [...]

sub filter ($$$$) {
    my($entity, $fname, $ext, $type) = @_;
    return if message_rejected(); # Avoid unnecessary effort

# check for banned files in ZIP archives. Requires
# Archive::Zip. Adapted from/inspired by code from Michal Jankowski
# and Paul Murphy on MIMEDefang-users list.
    if (lc($ext) =~ /\.zip$/) {
        my $path = $entity->bodyhandle->path;
        my $zipfile = Archive::Zip->new();
        if ($zipfile->read($path) == AZ_OK) {
            md_syslog('debug', "Unpacking/checking ZIP archive in
            if (defined(&Archive::Zip::tempFileName)) {
                my $tmpfn = Archive::Zip::tempFileName('.');
            } else {
                my $tmpfn = Archive::Zip::tempFile('.');
            my @contents = $zipfile->members();
            foreach my $content (@contents) {
                my $fn = $content->fileName();
                my $fsize = $content->uncompressedSize();
                md_syslog('debug', "Checking zipfile contents $fn,
                # unpacked size limit
                if ($fsize > 50e6) {
                    md_graphdefang_log('Zip archive contents too big
', $fn, $RelayAddr);
                    return action_bounce("rejection: possible DOS
attack: overlarge archive content, file $fn, size=$fsize");
                # quarantine encrypted files (Bagle-H and similar)
                if ($content->isEncrypted()) {
                    md_syslog('debug', "Checking encrypted ZIP content
                    my $badex =
                    my $regx = '\.' . $badex .
                    if (lc($fn) =~ $regx) {
                        md_graphdefang_log('crypt_bad_ext', $fn,
ZIP file with executable content");
                        return action_replace_with_warning("An
encrypted ZIP archive containing \"$fn\" was removed \nfrom this
document as it constituted a likely security hazard \n(cf. Bagel worm
or similar). If you require this document, \nplease contact your
friendly neighborhood mail admin. \n\n        Otherwise, the
quarantined content will be deleted in two weeks.\n");
                    # no exe content, just log it
                    md_syslog('warning', "Encrypted file $fn in zip
                # could put extra virus checking here but clamav
should already
be checking unencrypted zips
        } else {
            md_syslog('warning', "Zipfile read returned error");
# [...]

Ole Craig * UNIX, linux, SMTP-fu; news, web; SGI martyr * admin-at-large

   Need a seasoned *NIX admin in the Denver/Boulder area? Hire me!

More information about the MIMEDefang mailing list