def test_no_dde(self): """ check that no dde links appear on stdout """ filename = 'harmless-clean.doc' output = msodde.process_file( join(BASE_DIR, 'msodde', filename), msodde.FIELD_FILTER_BLACKLIST) self.assertEqual(len(self.get_dde_from_output(output)), 0, msg='Found dde links in output of ' + filename)
def test_no_dde(self): """ check that no dde links appear on stdout """ filename = 'harmless-clean.doc' output = msodde.process_file( join(BASE_DIR, 'msodde', filename), msodde.FIELD_FILTER_BLACKLIST) self.assertEqual(len(self.get_dde_from_output(output)), 0, msg='Found dde links in output of ' + filename)
def test_clean_rtf_ddeonly(self): """ find no dde links in rtf spec """ filename = 'RTF-Spec-1.7.rtf' output = msodde.process_file( join(BASE_DIR, 'msodde', filename), msodde.FIELD_FILTER_DDE) self.assertEqual(len(self.get_dde_from_output(output)), 0, msg='Found dde links in output of ' + filename)
def do_test_validity(self, args, expect_error=False): """ helper for test_valid_doc[x] """ have_exception = False try: msodde.process_file(args, msodde.FIELD_FILTER_BLACKLIST) except Exception: have_exception = True print_exc() except SystemExit as exc: # sys.exit() was called have_exception = True if exc.code is None: have_exception = False self.assertEqual(expect_error, have_exception, msg='Args={0}, expect={1}, exc={2}' .format(args, expect_error, have_exception))
def analyze_dde(self, path): version = {'Msodde version': msodde_version} results = process_file(path) if len(results) > 0: self.add_result_subsection('DDE Analysis', {'DDEUrl': results}) else: self.add_result_subsection('DDE Analysis', {'Info': 'No DDE URLs found.'})
def test_clean_rtf_ddeonly(self): """ find no dde links in rtf spec """ filename = 'RTF-Spec-1.7.rtf' output = msodde.process_file( join(BASE_DIR, 'msodde', filename), msodde.FIELD_FILTER_DDE) self.assertEqual(len(self.get_dde_from_output(output)), 0, msg='Found dde links in output of ' + filename)
def write_and_run(self, sample_text): """ helper for test_texts: save text to file, run through msodde """ filename = None handle = 0 try: handle, filename = mkstemp(prefix='oletools-test-csv-', text=True) os.write(handle, sample_text.encode('ascii')) os.close(handle) handle = 0 args = [filename, ] if self.DO_DEBUG: args += ['-l', 'debug'] processed_args = msodde.process_args(args) return msodde.process_file( processed_args.filepath, processed_args.field_filter_mode) except Exception: raise finally: if handle: os.close(handle) handle = 0 # just in case if filename: if self.DO_DEBUG: print('keeping for debug purposes: {0}'.format(filename)) else: os.remove(filename) filename = None # just in case
def test_with_dde(self): """ check that dde links appear on stdout """ filename = 'dde-test-from-office2003.doc' output = msodde.process_file( join(BASE_DIR, 'msodde', filename), msodde.FIELD_FILTER_BLACKLIST) self.assertNotEqual(len(self.get_dde_from_output(output)), 0, msg='Found no dde links in output of ' + filename)
def do_test_validity(self, args, expect_error=False): """ helper for test_valid_doc[x] """ have_exception = False try: msodde.process_file(args, msodde.FIELD_FILTER_BLACKLIST) except Exception: have_exception = True print_exc() except SystemExit as exc: # sys.exit() was called have_exception = True if exc.code is None: have_exception = False self.assertEqual(expect_error, have_exception, msg='Args={0}, expect={1}, exc={2}' .format(args, expect_error, have_exception))
def test_with_dde(self): """ check that dde links appear on stdout """ filename = 'dde-test-from-office2003.doc' output = msodde.process_file( join(BASE_DIR, 'msodde', filename), msodde.FIELD_FILTER_BLACKLIST) self.assertNotEqual(len(self.get_dde_from_output(output)), 0, msg='Found no dde links in output of ' + filename)
def analyze_dde(self, path): # version = {'Msodde version': msodde_version} results = process_file(path) if len(results) > 0: self.add_result_subsection('DDE Analysis', {'DDEUrl': results}) else: self.add_result_subsection('DDE Analysis', {'Info': 'No DDE URLs found.'})
def analyze_dde(self, path): # version = {'Msodde version': msodde_version} results = process_file(path) if len(results) > 0: self.add_result_subsection("DDE Analysis", {"DDEUrl": results}) else: self.add_result_subsection("DDE Analysis", {"Info": "No DDE URLs found."})
def test_file(self): """ test simple small example file """ filename = join(DATA_BASE_DIR, 'msodde', 'dde-in-csv.csv') output = msodde.process_file(filename, msodde.FIELD_FILTER_BLACKLIST) links = self.get_dde_from_output(output) self.assertEqual(len(links), 1) self.assertEqual(links[0], r"cmd '/k \..\..\..\Windows\System32\calc.exe'")
def test_excel(self): """ check that dde links are found in excel 2007+ files """ expect = ['DDE-Link cmd /c calc.exe', ] for extn in 'xlsx', 'xlsm', 'xlsb': output = msodde.process_file( join(BASE_DIR, 'msodde', 'dde-test.' + extn), msodde.FIELD_FILTER_BLACKLIST) self.assertEqual(expect, self.get_dde_from_output(output), msg='unexpected output for dde-test.{0}: {1}' .format(extn, output))
def test_excel(self): """ check that dde links are found in excel 2007+ files """ expect = ['cmd /c calc.exe', ] for extn in 'xlsx', 'xlsm', 'xlsb': output = msodde.process_file( join(BASE_DIR, 'msodde', 'dde-test.' + extn), msodde.FIELD_FILTER_BLACKLIST) self.assertEqual(expect, self.get_dde_from_output(output), msg='unexpected output for dde-test.{0}: {1}' .format(extn, output))
def get_dde(self, file_path): try: dde_result = msodde.process_file(file_path, 'only dde') dde_fields = [[i + 1, x.strip()] for i, x in enumerate(dde_result.split('\n'))] if (len(dde_fields) == 1) and (dde_fields[0][1] == ''): self.log('info', "No DDE Links Detected.") else: self.log('success', "DDE Links Detected.") header = ['#', 'DDE'] self.log('table', dict(header=header, rows=dde_fields)) except Exception as exc: self.log('error', "Unable to Process File")
def test_xml(self): """ check that dde in xml from word / excel is found """ for name_part in 'excel2003', 'word2003', 'word2007': filename = 'dde-in-' + name_part + '.xml' output = msodde.process_file( join(BASE_DIR, 'msodde', filename), msodde.FIELD_FILTER_BLACKLIST) links = self.get_dde_from_output(output) self.assertEqual(len(links), 1, 'found {0} dde-links in {1}' .format(len(links), filename)) self.assertTrue('cmd' in links[0], 'no "cmd" in dde-link for {0}' .format(filename)) self.assertTrue('calc' in links[0], 'no "calc" in dde-link for {0}' .format(filename))
def get_dde(self, file_path): try: dde_result = msodde.process_file(file_path, 'only dde') dde_fields = [[i + 1, x.strip()] for i, x in enumerate(dde_result.split('\n'))] if (len(dde_fields) == 1) and (dde_fields[0][1] == ''): self.log('info', "No DDE Links Detected.") else: self.log('success', "DDE Links Detected.") header = ['#', 'DDE'] self.log('table', dict(header=header, rows=dde_fields)) except Exception: self.log('error', "Unable to Process File")
def test_xml(self): """ check that dde in xml from word / excel is found """ for name_part in 'excel2003', 'word2003', 'word2007': filename = 'dde-in-' + name_part + '.xml' output = msodde.process_file( join(BASE_DIR, 'msodde', filename), msodde.FIELD_FILTER_BLACKLIST) links = self.get_dde_from_output(output) self.assertEqual(len(links), 1, 'found {0} dde-links in {1}' .format(len(links), filename)) self.assertTrue('cmd' in links[0], 'no "cmd" in dde-link for {0}' .format(filename)) self.assertTrue('calc' in links[0], 'no "calc" in dde-link for {0}' .format(filename))
def get_dde(self, file_path): """ Find DDE links. """ try: dde_result = msodde.process_file(file_path, "only dde") dde_fields = [[i + 1, x.strip()] for i, x in enumerate(dde_result.split("\n"))] if (len(dde_fields) == 1) and (dde_fields[0][1] == ""): self.log("info", "No DDE links detected.") else: self.log("success", "DDE links detected.") header = ["#", "DDE"] self.log("table", dict(header=header, rows=dde_fields)) except Exception: self.log("error", "Unable to process file")
def test_clean_rtf_blacklist(self): """ find a lot of hyperlinks in rtf spec """ filename = 'RTF-Spec-1.7.rtf' output = msodde.process_file(join(BASE_DIR, 'msodde', filename), msodde.FIELD_FILTER_BLACKLIST) self.assertEqual(len(self.get_dde_from_output(output)), 1413)
def test_clean_rtf_blacklist(self): """ find a lot of hyperlinks in rtf spec """ filename = 'RTF-Spec-1.7.rtf' output = msodde.process_file( join(BASE_DIR, 'msodde', filename), msodde.FIELD_FILTER_BLACKLIST) self.assertEqual(len(self.get_dde_from_output(output)), 1413)