Skip to content

Commit

Permalink
Add tests for XOR Obfuscation
Browse files Browse the repository at this point in the history
  • Loading branch information
nolze committed Jan 5, 2024
1 parent 26d8823 commit 1b79c13
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ msoffcrypto-tool (formerly ms-offcrypto-tool) is Python tool and library for dec
* [Resources](#resources)
* [Use cases and mentions](#use-cases-and-mentions)
* [Contributors](#contributors)
* [Credits](#credits)

## Installation

Expand Down Expand Up @@ -206,3 +207,7 @@ poetry run coverage run -m pytest -v
## Contributors

* <https://github.com/nolze/msoffcrypto-tool/graphs/contributors>

## Credits

* The sample file for XOR Obfuscation is from: <https://github.com/openwall/john-samples/tree/main/Office/Office_Secrets>
Binary file added tests/inputs/xor_password_123456789012345.xls
Binary file not shown.
Binary file not shown.
19 changes: 10 additions & 9 deletions tests/test_compare_known_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@

#: pairs of input/output files
EXAMPLE_FILES = (
("example_password.docx", "example.docx"),
("example_password.xlsx", "example.xlsx"),
("ecma376standard_password.docx", "ecma376standard_password_plain.docx"),
("rc4cryptoapi_password.doc", "rc4cryptoapi_password_plain.doc"),
("rc4cryptoapi_password.xls", "rc4cryptoapi_password_plain.xls"),
("rc4cryptoapi_password.ppt", "rc4cryptoapi_password_plain.ppt"),
("example_password.docx", "example.docx", PASSWORD),
("example_password.xlsx", "example.xlsx", PASSWORD),
("ecma376standard_password.docx", "ecma376standard_password_plain.docx", PASSWORD),
("rc4cryptoapi_password.doc", "rc4cryptoapi_password_plain.doc", PASSWORD),
("rc4cryptoapi_password.xls", "rc4cryptoapi_password_plain.xls", PASSWORD),
("rc4cryptoapi_password.ppt", "rc4cryptoapi_password_plain.ppt", PASSWORD),
("xor_password_123456789012345.xls", "xor_password_123456789012345_plain.xls", "123456789012345"),
)

#: output dir:
Expand All @@ -50,17 +51,17 @@ class KnownOutputCompare(unittest.TestCase):

def test_known_output(self):
"""See module doc."""
for in_name, out_name in EXAMPLE_FILES:
for in_name, out_name, password in EXAMPLE_FILES:
input_path = pjoin(TEST_BASE_DIR, INPUT_DIR, in_name)
expect_path = pjoin(TEST_BASE_DIR, OUTPUT_DIR, out_name)

# now run the relevant parts of __main__.main:
with open(input_path, "rb") as input_handle:
file = msoffcrypto.OfficeFile(input_handle)
if file.format == "ooxml" and file.type in ["standard", "agile"]:
file.load_key(password=PASSWORD, verify_password=True)
file.load_key(password=password, verify_password=True)
else:
file.load_key(password=PASSWORD)
file.load_key(password=password)

out_desc = None
out_path = None
Expand Down

0 comments on commit 1b79c13

Please sign in to comment.