From 2e33218408e854a378f98fb5bfea24a8331539dc Mon Sep 17 00:00:00 2001 From: Patterbear Date: Sun, 20 Oct 2024 11:07:15 +0100 Subject: [PATCH 1/2] add BFF tests and updated detection --- docubleach/bleach.py | 49 +++++++++++++----- tests/test_bff_files.py | 48 +++++++++++++++++ .../bff_files/legacy_excel_spreadsheet.xls | Bin 0 -> 31232 bytes .../bff_files/legacy_word_document.doc | Bin 0 -> 36352 bytes 4 files changed, 83 insertions(+), 14 deletions(-) create mode 100644 tests/test_bff_files.py create mode 100644 tests/test_files/bff_files/legacy_excel_spreadsheet.xls create mode 100644 tests/test_files/bff_files/legacy_word_document.doc diff --git a/docubleach/bleach.py b/docubleach/bleach.py index 44a13b4..d60ee4a 100644 --- a/docubleach/bleach.py +++ b/docubleach/bleach.py @@ -73,7 +73,29 @@ def unzip_file(file): def detect_macros(file): - return VBA_Parser(file).detect_macros() + file_type = file.split(".")[-1].lower() + + if file_type in bff_formats: + with OleFileIO(file, write_mode=False) as ole: + streams = ole.listdir(streams=True) + macro_streams = [] + + for stream in streams: + if stream[0] in bff_macro_folders: + macro_streams.append(stream) + + # Check each macro stream to see if it's empty (bleached) + for macro_stream in macro_streams: + macro_stream_size = ole.get_size(macro_stream) + stream_contents = ole.openstream(macro_stream).read(macro_stream_size) + stream_bytes = bytes(bytearray(stream_contents)) + + if stream_bytes != bytes(bytearray(macro_stream_size)): + return True + + return False + else: + return VBA_Parser(file).detect_macros() def remove_macros(file, notify=False): @@ -93,19 +115,18 @@ def remove_bff_macros(file, notify): macros_found = False if file_type == "doc" or file_type == "xls": - streams = OleFileIO(file).listdir(streams=True) - macro_streams = [] - - for stream in streams: - if stream[0] in bff_macro_folders: - macro_streams.append(stream) - - ole = OleFileIO(file, write_mode=True) - - for macro_stream in macro_streams: - macro_stream_size = ole.get_size(macro_stream) - ole.write_stream(macro_stream, bytes(bytearray(macro_stream_size))) - ole.close() + with OleFileIO(file, write_mode=True) as ole: + streams = ole.listdir(streams=True) + macro_streams = [] + + for stream in streams: + if stream[0] in bff_macro_folders: + macro_streams.append(stream) + + # Replace macro stream contents with empty bytes + for macro_stream in macro_streams: + macro_stream_size = ole.get_size(macro_stream) + ole.write_stream(macro_stream, bytes(bytearray(macro_stream_size))) if len(macro_streams) > 0: macros_found = True diff --git a/tests/test_bff_files.py b/tests/test_bff_files.py new file mode 100644 index 0000000..8a3fee8 --- /dev/null +++ b/tests/test_bff_files.py @@ -0,0 +1,48 @@ +"""These tests are designed to test the tool's compatibility with supported BFF file formats. + +Each test runs the 'bleach' on their respective file. + +The 'bleached' files are then scanned for macros using the 'detect_macros' function + +Valid files containing macros are restored to their original form after testing to ensure test repeatability. + +All tests are written for and conducted using pytest. +""" +from os import listdir, remove, rename +from shutil import copyfile + +from docubleach.bleach import detect_macros, remove_macros + + +test_dir = "tests/test_files/bff_files/" + + +def setup_module(): + for file in listdir(test_dir): + copyfile(test_dir + file, test_dir + file + ".bak") + + +def teardown_module(): + for file in listdir(test_dir): + if file.split(".")[-1] != "bak": + remove(test_dir + file) + + for file in listdir(test_dir): + if file.split(".")[-1] == "bak": + rename(test_dir + file, test_dir + file[:-4]) + + +def test_legacy_word_document(): + test_file = f"{test_dir}legacy_word_document.doc" + + remove_macros(test_file) + + assert detect_macros(test_file) is False + + +def test_legacy_excel_spreadsheet(): + test_file = f"{test_dir}legacy_excel_spreadsheet.xls" + + remove_macros(test_file) + + assert detect_macros(test_file) is False diff --git a/tests/test_files/bff_files/legacy_excel_spreadsheet.xls b/tests/test_files/bff_files/legacy_excel_spreadsheet.xls new file mode 100644 index 0000000000000000000000000000000000000000..884a95dfb8a677c8dbe465e648d6e5d23720d33f GIT binary patch literal 31232 zcmeHw30#y__y3&*7!VYM5H}nFHv}Ap)dkrV6$F)BazU0sQDBrsF*R{1&0KIdHPg)0 z%011@jkLw0a?MOD_uR@feN9d0_dU_v z07`%jfco4HpaR$f8~}9yjsPb>T|hkmRDihv>H}N>Zh+?i?tlgW4?sgeBS2$76F^gd zC!iTX4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M~=f5hn2wf8T(fjh=j&)fPCB+(IOvonJqU=^lStTo%Pe%PIfT@6KfR_QU0Hy@Yw#(7`NA@?Q)=>#q!6Y23&xlluKOUdUS z;Oen1I31)QkKtp6*#v6~vh1Q^=j^)hl9VIbcEPlRr9ptOfIvj?VPxAy`l7=H+2jUA za5yR%Wny2FFNTg^WkNkFxLWd@LJ1~8Y>KPd|EVKTk<;BK3RRk7{-Blbj~JdrpldTM2-E1cKZzS=@yJ z6j9VSQ%_Njr_Is@{5EnnT6iStt0m83gIiJtj_wumJSJDEq(ubewo(+5r3SnnT&SGu z`B&?oH9!9s42WcYH;xODaf*qSab;n;St$&@9vcb!#jXu6BWbk(Z<@hMLr#i$Z;cf~NFqQrol)oxhPWbOI0$ zrn#2i<{|mGFhkhD3q;?}rh!I2R{D8`YA#M$zf)xd z?(5wqo+v)Ork~y7BD}`OYePeWLSr@lF(F}H{DZY&LH^NkF(LjTv0VaVy2Qq5+iQa+ z;t+*b)(AmoogCuynZPAgQmepb)=n0~tR;vXK6o^gg8sQZe9v7_*j0@9-NCCNV zDKW_H5*McpjSJL9$8`zP#A|p!Zr9idulUgT;J_|aJw8<1K0b^fE)+WU z+-T!^-#oRZUC)(!0*!a5+}|0il6s$e`OP~Il7~CLH&4adw%UGLgR}zxnw2O&3PAQe z0YJ0BZ~$4^830=Ftpd=vdLQ5l*ae`OjdotN1@!u(*Pt7vY#ZMHvv+4KrCF~d3EM+ zQ3BzlU>F%l2v|M#aFB|Oarm>O0$NL`5*?oNFFA}2dLoGxnO*QnrJ4&Zpff6{oj{kG9a L{BQU-O5lG0L&dGn literal 0 HcmV?d00001 diff --git a/tests/test_files/bff_files/legacy_word_document.doc b/tests/test_files/bff_files/legacy_word_document.doc new file mode 100644 index 0000000000000000000000000000000000000000..257b08b42f2b3d878406891df1e26a93268bcc84 GIT binary patch literal 36352 zcmeHw2|!cF_V?Tn5D+9FB5oJ~6)l8>-30{#hzo*1-M0Xd#Xv9w#jS$7)wXE0F13nv z*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;$-j*F;&#s#b@yqxF_i20j&95&$X3Vx=C9ng>A}{GcgOz(gXX08W7?KR`5koS;LI zh&A-3AR|72?^DEmSdF#hAL&yG;4l_@14?l9Tx$|gzR;Vh(-%`+`ztylf;HkWb#s9j zT}2#o1JHN48^Ui4@HEbVNys#o7}n%ulArGp5}q(McU&dCH9XALiSTyE+{o#Q)@g$t z(FXby44=O2tU#&FMdtIAm(%o!ccdisV1?wcFglD^-b zQQ)vX^j7B??nm#ejw(AW;K`@CU=aZCFtLAP!`;Pps#r|ddbbRfFe`D-sK`e*B+Ocj zT`NV%zBi1)z<^rgjKPqgLIkbESkY|SC_!dq3HjK|7z$m7kgeFb=ccf)FTo!{z-}5g z)7~8{VYP%9zjYGkAU5s@@f$+z7fF~MSSz=}_uONKt270e1G!&Be&aRfs}~TSh$SZy z7_KAND%N3`?zb+2F&NI#)e{U&!6?6L1_e&f@ghr-foM3Fnt# zScUZkcQ!mP9HRx9dSvhtRM5yBEzOD-qiACa;~MQ|3s5(rXt72MyoVrE%g6;5eT4d; zhlIh@aok|W@WEGF9ve(wbEuZE9quE-tggJZNL-<8bzmaP%O$+}`6Dc(q((LG?D#iT z9KSh@;{MsLb9A`p=r*yT%IKi5AivZ`HV0JOg#sDzHspKmfjQMG2Jgoqz}o zR0PIG#|8w)1eyZrWnvUQyA`YmRkTqm6m22{6p;o%Tqk9?XKZL}aBNgeU|?)OXn;H* zj37D|k&gEL;qj^;my)>S~8zn1jTagY_J$oTVPT>`V xp8xQKv`wfV+B8rqSQ7rdX?!w`UO@4tj>0k_UKYlFX|r+IOIff){ufK&{{Zp*(boU~ literal 0 HcmV?d00001 From 1482d4cc8e2063b713cd9365d8dba3ff4fd4798e Mon Sep 17 00:00:00 2001 From: Patterbear Date: Fri, 25 Oct 2024 11:39:49 +0100 Subject: [PATCH 2/2] fix BFF notify bug --- docubleach/bleach.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docubleach/bleach.py b/docubleach/bleach.py index d60ee4a..748d50d 100644 --- a/docubleach/bleach.py +++ b/docubleach/bleach.py @@ -123,13 +123,15 @@ def remove_bff_macros(file, notify): if stream[0] in bff_macro_folders: macro_streams.append(stream) - # Replace macro stream contents with empty bytes for macro_stream in macro_streams: macro_stream_size = ole.get_size(macro_stream) - ole.write_stream(macro_stream, bytes(bytearray(macro_stream_size))) + macro_stream_contents = ole.openstream(macro_stream).read(macro_stream_size) - if len(macro_streams) > 0: - macros_found = True + # Check each macro stream to see if it's already empty (bleached) + if macro_stream_contents != bytes(bytearray(macro_stream_size)): + # Replace macro stream contents with empty bytes + ole.write_stream(macro_stream, bytes(bytearray(macro_stream_size))) + macros_found = True if file_type == "ppt": streams = OleFileIO(file).listdir(streams=True)