Commit c555887be4a587e833437637f857103fd8eb6db3
Committed by
GitHub
Merge pull request #88 from sebdraven/master
modify import to package oletools
Showing
3 changed files
with
24 additions
and
24 deletions
oletools/olevba3.py
| @@ -244,15 +244,15 @@ except ImportError: | @@ -244,15 +244,15 @@ except ImportError: | ||
| 244 | + "see http://codespeak.net/lxml " \ | 244 | + "see http://codespeak.net/lxml " \ |
| 245 | + "or http://effbot.org/zone/element-index.htm") | 245 | + "or http://effbot.org/zone/element-index.htm") |
| 246 | 246 | ||
| 247 | -import thirdparty.olefile as olefile | ||
| 248 | -from thirdparty.prettytable import prettytable | ||
| 249 | -from thirdparty.xglob import xglob, PathNotFoundException | ||
| 250 | -from thirdparty.pyparsing.pyparsing import \ | 247 | +import oletools.thirdparty.olefile as olefile |
| 248 | +from oletools.thirdparty.prettytable import prettytable | ||
| 249 | +from oletools.thirdparty.xglob import xglob, PathNotFoundException | ||
| 250 | +from oletools.thirdparty.pyparsing.pyparsing import \ | ||
| 251 | CaselessKeyword, CaselessLiteral, Combine, Forward, Literal, \ | 251 | CaselessKeyword, CaselessLiteral, Combine, Forward, Literal, \ |
| 252 | Optional, QuotedString,Regex, Suppress, Word, WordStart, \ | 252 | Optional, QuotedString,Regex, Suppress, Word, WordStart, \ |
| 253 | alphanums, alphas, hexnums,nums, opAssoc, srange, \ | 253 | alphanums, alphas, hexnums,nums, opAssoc, srange, \ |
| 254 | infixNotation | 254 | infixNotation |
| 255 | -import ppt_parser | 255 | +import oletools.ppt_parser as ppt_parser |
| 256 | 256 | ||
| 257 | # monkeypatch email to fix issue #32: | 257 | # monkeypatch email to fix issue #32: |
| 258 | # allow header lines without ":" | 258 | # allow header lines without ":" |
| @@ -1774,7 +1774,7 @@ def detect_hex_strings(vba_code): | @@ -1774,7 +1774,7 @@ def detect_hex_strings(vba_code): | ||
| 1774 | value = match.group() | 1774 | value = match.group() |
| 1775 | if value not in found: | 1775 | if value not in found: |
| 1776 | decoded = binascii.unhexlify(value) | 1776 | decoded = binascii.unhexlify(value) |
| 1777 | - results.append((value, decoded)) | 1777 | + results.append((value, decoded.decode('utf-8','replace'))) |
| 1778 | found.add(value) | 1778 | found.add(value) |
| 1779 | return results | 1779 | return results |
| 1780 | 1780 | ||
| @@ -1799,7 +1799,7 @@ def detect_base64_strings(vba_code): | @@ -1799,7 +1799,7 @@ def detect_base64_strings(vba_code): | ||
| 1799 | if value not in found and value.lower() not in BASE64_WHITELIST: | 1799 | if value not in found and value.lower() not in BASE64_WHITELIST: |
| 1800 | try: | 1800 | try: |
| 1801 | decoded = base64.b64decode(value) | 1801 | decoded = base64.b64decode(value) |
| 1802 | - results.append((value, decoded)) | 1802 | + results.append((value, decoded.decode('utf-8','replace'))) |
| 1803 | found.add(value) | 1803 | found.add(value) |
| 1804 | except (TypeError, ValueError) as exc: | 1804 | except (TypeError, ValueError) as exc: |
| 1805 | log.debug('Failed to base64-decode (%s)' % exc) | 1805 | log.debug('Failed to base64-decode (%s)' % exc) |
| @@ -1814,7 +1814,7 @@ def detect_dridex_strings(vba_code): | @@ -1814,7 +1814,7 @@ def detect_dridex_strings(vba_code): | ||
| 1814 | :param vba_code: str, VBA source code | 1814 | :param vba_code: str, VBA source code |
| 1815 | :return: list of str tuples (encoded string, decoded string) | 1815 | :return: list of str tuples (encoded string, decoded string) |
| 1816 | """ | 1816 | """ |
| 1817 | - from thirdparty.DridexUrlDecoder.DridexUrlDecoder import DridexUrlDecode | 1817 | + from oletools.thirdparty.DridexUrlDecoder.DridexUrlDecoder import DridexUrlDecode |
| 1818 | 1818 | ||
| 1819 | results = [] | 1819 | results = [] |
| 1820 | found = set() | 1820 | found = set() |
| @@ -1959,10 +1959,10 @@ class VBA_Scanner(object): | @@ -1959,10 +1959,10 @@ class VBA_Scanner(object): | ||
| 1959 | """ | 1959 | """ |
| 1960 | # join long lines ending with " _": | 1960 | # join long lines ending with " _": |
| 1961 | self.code = vba_collapse_long_lines(vba_code) | 1961 | self.code = vba_collapse_long_lines(vba_code) |
| 1962 | - self.code_hex = b'' | ||
| 1963 | - self.code_hex_rev = b'' | ||
| 1964 | - self.code_rev_hex = b'' | ||
| 1965 | - self.code_base64 = b'' | 1962 | + self.code_hex = '' |
| 1963 | + self.code_hex_rev = '' | ||
| 1964 | + self.code_rev_hex = '' | ||
| 1965 | + self.code_base64 = '' | ||
| 1966 | self.code_dridex = '' | 1966 | self.code_dridex = '' |
| 1967 | self.code_vba = '' | 1967 | self.code_vba = '' |
| 1968 | self.strReverse = None | 1968 | self.strReverse = None |
| @@ -1995,19 +1995,19 @@ class VBA_Scanner(object): | @@ -1995,19 +1995,19 @@ class VBA_Scanner(object): | ||
| 1995 | if 'strreverse' in self.code.lower(): self.strReverse = True | 1995 | if 'strreverse' in self.code.lower(): self.strReverse = True |
| 1996 | # Then append the decoded strings to the VBA code, to detect obfuscated IOCs and keywords: | 1996 | # Then append the decoded strings to the VBA code, to detect obfuscated IOCs and keywords: |
| 1997 | for encoded, decoded in self.hex_strings: | 1997 | for encoded, decoded in self.hex_strings: |
| 1998 | - self.code_hex += b'\n' + decoded | 1998 | + self.code_hex += '\n' + decoded |
| 1999 | # if the code contains "StrReverse", also append the hex strings in reverse order: | 1999 | # if the code contains "StrReverse", also append the hex strings in reverse order: |
| 2000 | if self.strReverse: | 2000 | if self.strReverse: |
| 2001 | # StrReverse after hex decoding: | 2001 | # StrReverse after hex decoding: |
| 2002 | - self.code_hex_rev += b'\n' + decoded[::-1] | 2002 | + self.code_hex_rev += '\n' + decoded[::-1] |
| 2003 | # StrReverse before hex decoding: | 2003 | # StrReverse before hex decoding: |
| 2004 | - self.code_rev_hex += b'\n' + binascii.unhexlify(encoded[::-1]) | 2004 | + self.code_rev_hex += '\n' + str(binascii.unhexlify(encoded[::-1])) |
| 2005 | #example: https://malwr.com/analysis/NmFlMGI4YTY1YzYyNDkwNTg1ZTBiZmY5OGI3YjlhYzU/ | 2005 | #example: https://malwr.com/analysis/NmFlMGI4YTY1YzYyNDkwNTg1ZTBiZmY5OGI3YjlhYzU/ |
| 2006 | #TODO: also append the full code reversed if StrReverse? (risk of false positives?) | 2006 | #TODO: also append the full code reversed if StrReverse? (risk of false positives?) |
| 2007 | # Detect Base64-encoded strings | 2007 | # Detect Base64-encoded strings |
| 2008 | self.base64_strings = detect_base64_strings(self.code) | 2008 | self.base64_strings = detect_base64_strings(self.code) |
| 2009 | for encoded, decoded in self.base64_strings: | 2009 | for encoded, decoded in self.base64_strings: |
| 2010 | - self.code_base64 += b'\n' + decoded | 2010 | + self.code_base64 += '\n' + decoded |
| 2011 | # Detect Dridex-encoded strings | 2011 | # Detect Dridex-encoded strings |
| 2012 | self.dridex_strings = detect_dridex_strings(self.code) | 2012 | self.dridex_strings = detect_dridex_strings(self.code) |
| 2013 | for encoded, decoded in self.dridex_strings: | 2013 | for encoded, decoded in self.dridex_strings: |
| @@ -2026,10 +2026,10 @@ class VBA_Scanner(object): | @@ -2026,10 +2026,10 @@ class VBA_Scanner(object): | ||
| 2026 | 2026 | ||
| 2027 | for code, obfuscation in ( | 2027 | for code, obfuscation in ( |
| 2028 | (self.code, None), | 2028 | (self.code, None), |
| 2029 | - (self.code_hex.decode('utf-8','replace'), 'Hex'), | 2029 | + (self.code_hex, 'Hex'), |
| 2030 | (self.code_hex_rev, 'Hex+StrReverse'), | 2030 | (self.code_hex_rev, 'Hex+StrReverse'), |
| 2031 | (self.code_rev_hex, 'StrReverse+Hex'), | 2031 | (self.code_rev_hex, 'StrReverse+Hex'), |
| 2032 | - (self.code_base64.decode('utf-8', 'replace'), 'Base64'), | 2032 | + (self.code_base64, 'Base64'), |
| 2033 | (self.code_dridex, 'Dridex'), | 2033 | (self.code_dridex, 'Dridex'), |
| 2034 | (self.code_vba, 'VBA expression'), | 2034 | (self.code_vba, 'VBA expression'), |
| 2035 | ): | 2035 | ): |
oletools/ppt_parser.py
setup.py
| @@ -287,11 +287,11 @@ entry_points = { | @@ -287,11 +287,11 @@ entry_points = { | ||
| 287 | def main(): | 287 | def main(): |
| 288 | # TODO: remove this test once all tools are ported to Python 3 | 288 | # TODO: remove this test once all tools are ported to Python 3 |
| 289 | # TODO: warning about Python 2.6 | 289 | # TODO: warning about Python 2.6 |
| 290 | - if sys.version >= '3.0': | ||
| 291 | - s = "Sorry, %s %s requires Python 2.x." | ||
| 292 | - print(s % (name, version)) | ||
| 293 | - sys.exit(1) | ||
| 294 | -## if sys.version < required_python_version: | 290 | +# if sys.version >= '3.0': |
| 291 | +# s = "Sorry, %s %s requires Python 2.x." | ||
| 292 | +# print(s % (name, version)) | ||
| 293 | +# sys.exit(1) | ||
| 294 | +# ## if sys.version < required_python_version: | ||
| 295 | ## s = "I'm sorry, but %s %s requires Python %s or later." | 295 | ## s = "I'm sorry, but %s %s requires Python %s or later." |
| 296 | ## print(s % (name, version, required_python_version)) | 296 | ## print(s % (name, version, required_python_version)) |
| 297 | ## sys.exit(1) | 297 | ## sys.exit(1) |