Commit 537fb409c6f08cb4b82d7721859f8d77a18a216e
1 parent
b7cb5b22
updated pyxswf to use olefile, improved usage display and comments
Showing
1 changed file
with
39 additions
and
29 deletions
oletools/pyxswf.py
| ... | ... | @@ -21,37 +21,41 @@ pyxswf project website: http://www.decalage.info/python/pyxswf |
| 21 | 21 | |
| 22 | 22 | pyxswf is part of the python-oletools package: |
| 23 | 23 | http://www.decalage.info/python/oletools |
| 24 | - | |
| 25 | -pyxswf is copyright (c) 2012, Philippe Lagadec (http://www.decalage.info) | |
| 26 | -All rights reserved. | |
| 27 | - | |
| 28 | -Redistribution and use in source and binary forms, with or without modification, | |
| 29 | -are permitted provided that the following conditions are met: | |
| 30 | - | |
| 31 | - * Redistributions of source code must retain the above copyright notice, this | |
| 32 | - list of conditions and the following disclaimer. | |
| 33 | - * Redistributions in binary form must reproduce the above copyright notice, | |
| 34 | - this list of conditions and the following disclaimer in the documentation | |
| 35 | - and/or other materials provided with the distribution. | |
| 36 | - | |
| 37 | -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
| 38 | -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 39 | -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 40 | -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
| 41 | -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
| 42 | -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
| 43 | -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 44 | -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
| 45 | -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 46 | -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 47 | 24 | """ |
| 48 | 25 | |
| 49 | -__version__ = '0.02' | |
| 26 | +#=== LICENSE ================================================================= | |
| 27 | + | |
| 28 | +# pyxswf is copyright (c) 2012-2014, Philippe Lagadec (http://www.decalage.info) | |
| 29 | +# All rights reserved. | |
| 30 | +# | |
| 31 | +# Redistribution and use in source and binary forms, with or without modification, | |
| 32 | +# are permitted provided that the following conditions are met: | |
| 33 | +# | |
| 34 | +# * Redistributions of source code must retain the above copyright notice, this | |
| 35 | +# list of conditions and the following disclaimer. | |
| 36 | +# * Redistributions in binary form must reproduce the above copyright notice, | |
| 37 | +# this list of conditions and the following disclaimer in the documentation | |
| 38 | +# and/or other materials provided with the distribution. | |
| 39 | +# | |
| 40 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
| 41 | +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 42 | +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 43 | +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
| 44 | +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
| 45 | +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
| 46 | +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 47 | +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
| 48 | +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 49 | +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 50 | 50 | |
| 51 | 51 | #------------------------------------------------------------------------------ |
| 52 | 52 | # CHANGELOG: |
| 53 | 53 | # 2012-09-17 v0.01 PL: - first version |
| 54 | 54 | # 2012-11-09 v0.02 PL: - added RTF embedded objects extraction |
| 55 | +# 2014-11-29 v0.03 PL: - use olefile instead of OleFileIO_PL | |
| 56 | +# - improved usage display with -h | |
| 57 | + | |
| 58 | +__version__ = '0.03' | |
| 55 | 59 | |
| 56 | 60 | #------------------------------------------------------------------------------ |
| 57 | 61 | # TODO: |
| ... | ... | @@ -63,9 +67,15 @@ __version__ = '0.02' |
| 63 | 67 | # - check if file is OLE |
| 64 | 68 | # - support -r |
| 65 | 69 | |
| 70 | + | |
| 71 | +#=== IMPORTS ================================================================= | |
| 72 | + | |
| 66 | 73 | import optparse, sys, os, rtfobj, StringIO |
| 67 | 74 | from thirdparty.xxxswf import xxxswf |
| 68 | -from thirdparty.OleFileIO_PL import OleFileIO_PL | |
| 75 | +import thirdparty.olefile as olefile | |
| 76 | + | |
| 77 | + | |
| 78 | +#=== MAIN ================================================================= | |
| 69 | 79 | |
| 70 | 80 | def main(): |
| 71 | 81 | # Scenarios: |
| ... | ... | @@ -77,7 +87,7 @@ def main(): |
| 77 | 87 | # Scan directory recursively for files that contain SWF(s) and extract them |
| 78 | 88 | |
| 79 | 89 | usage = 'usage: %prog [options] <file.bad>' |
| 80 | - parser = optparse.OptionParser(usage=usage) | |
| 90 | + parser = optparse.OptionParser(usage=__doc__ + '\n' + usage) | |
| 81 | 91 | parser.add_option('-x', '--extract', action='store_true', dest='extract', help='Extracts the embedded SWF(s), names it MD5HASH.swf & saves it in the working dir. No addition args needed') |
| 82 | 92 | parser.add_option('-y', '--yara', action='store_true', dest='yara', help='Scans the SWF(s) with yara. If the SWF(s) is compressed it will be deflated. No addition args needed') |
| 83 | 93 | parser.add_option('-s', '--md5scan', action='store_true', dest='md5scan', help='Scans the SWF(s) for MD5 signatures. Please see func checkMD5 to define hashes. No addition args needed') |
| ... | ... | @@ -92,7 +102,7 @@ def main(): |
| 92 | 102 | |
| 93 | 103 | (options, args) = parser.parse_args() |
| 94 | 104 | |
| 95 | - # Print help if no argurments are passed | |
| 105 | + # Print help if no arguments are passed | |
| 96 | 106 | if len(args) == 0: |
| 97 | 107 | parser.print_help() |
| 98 | 108 | return |
| ... | ... | @@ -100,9 +110,9 @@ def main(): |
| 100 | 110 | # OLE MODE: |
| 101 | 111 | if options.ole: |
| 102 | 112 | for filename in args: |
| 103 | - ole = OleFileIO_PL.OleFileIO(filename) | |
| 113 | + ole = olefile.OleFileIO(filename) | |
| 104 | 114 | for direntry in ole.direntries: |
| 105 | - if direntry is not None and direntry.entry_type == OleFileIO_PL.STGTY_STREAM: | |
| 115 | + if direntry is not None and direntry.entry_type == olefile.STGTY_STREAM: | |
| 106 | 116 | f = ole._open(direntry.isectStart, direntry.size) |
| 107 | 117 | # check if data contains the SWF magic: FWS or CWS |
| 108 | 118 | data = f.getvalue() | ... | ... |