Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
    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.'})
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
    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
Ejemplo n.º 8
0
 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)
Ejemplo n.º 9
0
    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))
Ejemplo n.º 10
0
 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.'})
Ejemplo n.º 12
0
 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."})
Ejemplo n.º 13
0
 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'")
Ejemplo n.º 14
0
    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))
Ejemplo n.º 15
0
    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))
Ejemplo n.º 16
0
 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")
Ejemplo n.º 17
0
 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))
Ejemplo n.º 18
0
 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")
Ejemplo n.º 19
0
 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))
Ejemplo n.º 20
0
 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")
Ejemplo n.º 21
0
 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)
Ejemplo n.º 22
0
 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)