Commit 7c34036c8a896675ae023f52376524e1213a4004

Authored by Philippe Lagadec
Committed by GitHub
2 parents 08454248 1723e4db

Merge pull request #194 from samiraguiar/oleid-openxml-encryption

oleid: detect OpenXML encryption
oletools/oleid.py
@@ -54,6 +54,7 @@ from __future__ import print_function @@ -54,6 +54,7 @@ from __future__ import print_function
54 # 2016-10-25 v0.50 PL: - fixed print and bytes strings for Python 3 54 # 2016-10-25 v0.50 PL: - fixed print and bytes strings for Python 3
55 # 2016-12-12 v0.51 PL: - fixed relative imports for Python 3 (issue #115) 55 # 2016-12-12 v0.51 PL: - fixed relative imports for Python 3 (issue #115)
56 # 2017-04-26 PL: - fixed absolute imports (issue #141) 56 # 2017-04-26 PL: - fixed absolute imports (issue #141)
  57 +# 2017-09-01 SA: - detect OpenXML encryption
57 58
58 __version__ = '0.51' 59 __version__ = '0.51'
59 60
@@ -211,6 +212,9 @@ class OleID: @@ -211,6 +212,9 @@ class OleID:
211 if 0x13 in self.suminfo: 212 if 0x13 in self.suminfo:
212 if self.suminfo[0x13] & 1: 213 if self.suminfo[0x13] & 1:
213 self.encrypted.value = True 214 self.encrypted.value = True
  215 + # check if this is an OpenXML encrypted file
  216 + elif self.ole.exists('EncryptionInfo'):
  217 + self.encrypted.value = True
214 218
215 def check_word (self): 219 def check_word (self):
216 word = Indicator('word', False, name='Word Document', 220 word = Indicator('word', False, name='Word Document',
tests/oleid/__init__.py 0 โ†’ 100644
tests/oleid/test_issue_166.py 0 โ†’ 100644
  1 +"""
  2 +Test if oleid detects encrypted documents
  3 +"""
  4 +
  5 +import unittest, sys, os
  6 +
  7 +from tests.test_utils import DATA_BASE_DIR
  8 +from os.path import join
  9 +
  10 +from oletools import oleid
  11 +
  12 +class TestEncryptedDocumentDetection(unittest.TestCase):
  13 + def test_encrypted_document_detection(self):
  14 + """ Run oleid and check if the document is flagged as encrypted """
  15 + filename = join(DATA_BASE_DIR, 'basic/encrypted.docx')
  16 +
  17 + oleid_instance = oleid.OleID(filename)
  18 + indicators = oleid_instance.check()
  19 +
  20 + is_encrypted = next(i.value for i in indicators if i.id == 'encrypted')
  21 +
  22 + self.assertEqual(is_encrypted, True)
  23 +
  24 +# just in case somebody calls this file as a script
  25 +if __name__ == '__main__':
  26 + unittest.main()
0 \ No newline at end of file 27 \ No newline at end of file
tests/test-data/basic/encrypted.docx 0 โ†’ 100644
No preview for this file type