Commit 1009dda58dd7f0d6a210510fe5cfcf517b915ed0

Authored by Philippe Lagadec
1 parent a299cc6d

olevba: improved filter_vba to detect colons

Showing 1 changed file with 10 additions and 4 deletions
oletools/olevba.py
@@ -22,7 +22,7 @@ https://github.com/unixfreak0037/officeparser @@ -22,7 +22,7 @@ https://github.com/unixfreak0037/officeparser
22 22
23 #=== LICENSE ================================================================== 23 #=== LICENSE ==================================================================
24 24
25 -# olevba is copyright (c) 2014 Philippe Lagadec (http://www.decalage.info) 25 +# olevba is copyright (c) 2014-2015 Philippe Lagadec (http://www.decalage.info)
26 # All rights reserved. 26 # All rights reserved.
27 # 27 #
28 # Redistribution and use in source and binary forms, with or without modification, 28 # Redistribution and use in source and binary forms, with or without modification,
@@ -90,8 +90,9 @@ https://github.com/unixfreak0037/officeparser @@ -90,8 +90,9 @@ https://github.com/unixfreak0037/officeparser
90 # - uses xglob to scan several files with wildcards 90 # - uses xglob to scan several files with wildcards
91 # - option -r to recurse subdirectories 91 # - option -r to recurse subdirectories
92 # - option -z to scan files in password-protected zips 92 # - option -z to scan files in password-protected zips
  93 +# 2015-01-02 v0.11 PL: - improved filter_vba to detect colons
93 94
94 -__version__ = '0.10' 95 +__version__ = '0.11'
95 96
96 #------------------------------------------------------------------------------ 97 #------------------------------------------------------------------------------
97 # TODO: 98 # TODO:
@@ -723,7 +724,12 @@ def _extract_vba (ole, vba_root, project_path, dir_path): @@ -723,7 +724,12 @@ def _extract_vba (ole, vba_root, project_path, dir_path):
723 724
724 def filter_vba(vba_code): 725 def filter_vba(vba_code):
725 """ 726 """
726 - Filter VBA source code to remove the first lines starting with "Attribute VB_" 727 + Filter VBA source code to remove the first lines starting with "Attribute VB_",
  728 + which are automatically added by MS Office and not displayed in the VBA Editor.
  729 + This should only be used when displaying source code for human analysis.
  730 +
  731 + Note: lines are not filtered if they contain a colon, because it could be
  732 + used to hide malicious instructions.
727 733
728 :param vba_code: str, VBA source code 734 :param vba_code: str, VBA source code
729 :return: str, filtered VBA source code 735 :return: str, filtered VBA source code
@@ -731,7 +737,7 @@ def filter_vba(vba_code): @@ -731,7 +737,7 @@ def filter_vba(vba_code):
731 vba_lines = vba_code.splitlines() 737 vba_lines = vba_code.splitlines()
732 start = 0 738 start = 0
733 for line in vba_lines: 739 for line in vba_lines:
734 - if line.startswith("Attribute VB_"): 740 + if line.startswith("Attribute VB_") and not ':' in line:
735 start += 1 741 start += 1
736 else: 742 else:
737 break 743 break