Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pymilter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
misc
pymilter
Commits
8fef7025
Commit
8fef7025
authored
19 years ago
by
Stuart Gathman
Browse files
Options
Downloads
Patches
Plain Diff
Handle corrupt and empty ZIP files.
parent
62b33bd9
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
mime.py
+24
-14
24 additions, 14 deletions
mime.py
test/zip2
+49
-0
49 additions, 0 deletions
test/zip2
test/zip3
+51
-0
51 additions, 0 deletions
test/zip3
testmime.py
+10
-0
10 additions, 0 deletions
testmime.py
with
134 additions
and
14 deletions
mime.py
+
24
−
14
View file @
8fef7025
# $Log$
# Revision 1.4 2005/06/17 01:49:39 customdesigned
# Handle zip within zip.
#
# Revision 1.3 2005/06/02 15:00:17 customdesigned
# Configure banned extensions. Scan zipfile option with test case.
#
...
...
@@ -193,6 +196,7 @@ class MimeMessage(Message):
for
key
,
name
in
tuple
(
names
):
# copy by converting to tuple
if
name
and
name
.
lower
().
endswith
(
'
.zip
'
):
txt
=
self
.
get_payload
(
decode
=
True
)
if
txt
.
strip
():
names
+=
zipnames
(
txt
)
return
names
...
...
@@ -304,19 +308,25 @@ See your administrator.
def
check_name
(
msg
,
savname
=
None
,
ckname
=
check_ext
,
scan_zip
=
False
):
"
Replace attachment with a warning if its name is suspicious.
"
try
:
for
key
,
name
in
msg
.
getnames
(
scan_zip
):
badname
=
ckname
(
name
)
if
badname
:
hostname
=
socket
.
gethostname
()
if
key
==
'
zipname
'
:
badname
=
msg
.
get_filename
()
break
else
:
return
Milter
.
CONTINUE
except
zipfile
.
BadZipfile
:
# a ZIP that is not a zip is very suspicious
badname
=
msg
.
get_filename
()
hostname
=
socket
.
gethostname
()
msg
.
set_payload
(
virus_msg
%
(
badname
,
hostname
,
savname
))
del
msg
[
"
content-type
"
]
del
msg
[
"
content-disposition
"
]
del
msg
[
"
content-transfer-encoding
"
]
name
=
"
WARNING.TXT
"
msg
[
"
Content-Type
"
]
=
"
text/plain; name=
"
+
name
break
return
Milter
.
CONTINUE
import
email.Iterators
...
...
This diff is collapsed.
Click to expand it.
test/zip2
0 → 100644
+
49
−
0
View file @
8fef7025
From paulp@go2net.com Wed Jun 1 22:35:12 2005
Return-Path: <paulp@go2net.com>
Received: from mail.bmsi.com (spidey.bmsi.com [192.168.9.81])
by bmsred.bmsi.com (8.13.1/8.12.10) with ESMTP id j522ZCQg014058
for <stuart@bmsred.bmsi.com>; Wed, 1 Jun 2005 22:35:12 -0400
Received: from 127.0.0.1 ([220.117.92.241])
by mail.bmsi.com (8.13.1/8.13.1) with ESMTP id j522Ynjm028604
for stuart@bmsi.com; Wed, 1 Jun 2005 22:34:51 -0400
Message-Id: <200506020234.j522Ynjm028604@mail.bmsi.com>
SUBJECT: urgent
FROM: paulp@go2net.com
TO: stuart@bmsi.com
DATE: [[ , 02 6 2005 11:34:47 ]]
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="--------bound--"
X-DSpam-Score: 0.081200
Received-SPF: neutral (mail.bmsi.com: guessing: 220.117.92.241 is neither permitted nor denied by domain of go2net.com)
Status: RO
X-Status:
X-Keywords: NonJunk
----------bound--
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi
Sorry, I forgot to send an important
document to you in that last email. I had an important phone call.
Please checkout attached doc file when you have a moment.
Best Regards
<!DSPAM:1043AE6B6492860536935410>
----------bound--
Content-Type: application/octet-stream;
name="Readme.zip"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="Readme.zip"
----------bound--
----------bound----
This diff is collapsed.
Click to expand it.
test/zip3
0 → 100644
+
51
−
0
View file @
8fef7025
From paulp@go2net.com Wed Jun 1 22:35:12 2005
Return-Path: <paulp@go2net.com>
Received: from mail.bmsi.com (spidey.bmsi.com [192.168.9.81])
by bmsred.bmsi.com (8.13.1/8.12.10) with ESMTP id j522ZCQg014058
for <stuart@bmsred.bmsi.com>; Wed, 1 Jun 2005 22:35:12 -0400
Received: from 127.0.0.1 ([220.117.92.241])
by mail.bmsi.com (8.13.1/8.13.1) with ESMTP id j522Ynjm028604
for stuart@bmsi.com; Wed, 1 Jun 2005 22:34:51 -0400
Message-Id: <200506020234.j522Ynjm028604@mail.bmsi.com>
SUBJECT: urgent
FROM: paulp@go2net.com
TO: stuart@bmsi.com
DATE: [[ , 02 6 2005 11:34:47 ]]
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="--------bound--"
X-DSpam-Score: 0.081200
Received-SPF: neutral (mail.bmsi.com: guessing: 220.117.92.241 is neither permitted nor denied by domain of go2net.com)
Status: RO
X-Status:
X-Keywords: NonJunk
----------bound--
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi
Sorry, I forgot to send an important
document to you in that last email. I had an important phone call.
Please checkout attached doc file when you have a moment.
Best Regards
<!DSPAM:1043AE6B6492860536935410>
----------bound--
Content-Type: application/x-msdownload; name="zip.zip"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="zip.zip"
USsDBAoBAAAAADVVwjLaV2nEGgAAABoAAAAzABUAemlwLmRvYyAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAuZXhlVVQJAAOmGp9CphqfQlV4BACGA2UAVGhpcyBw
cm9ncmFtIHdhcyBhIHZpcnVzLgpQSwECFwMKAAAAAAA1VcIy2ldpxBoAAAAaAAAAMwANAAAA
AAABAAAAtIEAAAAAemlwLmRvYyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAuZXhlVVQFAAOmGp9CVXgAAFBLBQYAAAAAAQABAG4AAACAAAAAAAA=
----------bound--
----------bound----
This diff is collapsed.
Click to expand it.
testmime.py
+
10
−
0
View file @
8fef7025
# $Log$
# Revision 1.3 2005/06/17 01:49:39 customdesigned
# Handle zip within zip.
#
# Revision 1.2 2005/06/02 15:00:17 customdesigned
# Configure banned extensions. Scan zipfile option with test case.
#
...
...
@@ -130,9 +133,16 @@ class MimeTestCase(unittest.TestCase):
def
testZip
(
self
,
vname
=
"
zip1
"
,
fname
=
'
zip.zip
'
):
self
.
testDefang
(
vname
,
1
,
'
zip.zip
'
)
# test scan_zip flag
msg
=
mime
.
message_from_file
(
open
(
'
test/
'
+
vname
,
"
r
"
))
mime
.
defang
(
msg
,
scan_zip
=
False
)
self
.
failIf
(
msg
.
ismodified
())
# test ignoring empty zip (often found in DSNs)
msg
=
mime
.
message_from_file
(
open
(
'
test/zip2
'
,
'
r
'
))
mime
.
defang
(
msg
,
scan_zip
=
True
)
self
.
failIf
(
msg
.
ismodified
())
# test corrupt zip (often an EXE named as a ZIP)
self
.
testDefang
(
'
zip3
'
,
1
,
'
zip.zip
'
)
# test zip within zip
self
.
testDefang
(
'
ziploop
'
,
1
,
'
stuart@bmsi.com.zip
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment