示例#1
0
 def test_urls(self):
     """
     Testing URLs extarction using a test conf file.
     """
     conf_file = "test_assets/extractor_confs/urls_conf.yaml"
     in_folder = "test_assets/executables/pe"
     out_folder = "test_assets/extracted_features/urls"
     extractor = mrextractor.new(conf_file, in_folder, out_folder)
     extractor.extract_batch()
     features_dict = extractor.features
     with open("test_assets/expected_features_dicts/urls.json", "rb") as f1:
         expected_feature_dict = json.load(f1)
     with open(out_folder + "/json/0/071df5b74f08fb5a4ce13a6cd2e7f485.json",
               "rb") as f2:
         extracted_feature_dict = json.load(f2)
     self.assertEqual(extracted_feature_dict, expected_feature_dict,
                      "urls don't match")
示例#2
0
 def test_general_file_info(self):
     """
     Testing the file general informations extraction .
     """
     conf_file = "test_assets/extractor_confs/general_file_info_conf.yaml"
     in_folder = "test_assets/executables/pe"
     out_folder = "test_assets/extracted_features/general_file_info"
     extractor = mrextractor.new(conf_file, in_folder, out_folder)
     extractor.extract_batch()
     features_dict = extractor.features
     with open("test_assets/expected_features_dicts/general_file_info.json",
               "rb") as f1:
         expected_feature_dict = json.load(f1)
     with open(out_folder + "/json/0/071df5b74f08fb5a4ce13a6cd2e7f485.json",
               "rb") as f2:
         extracted_feature_dict = json.load(f2)
     self.assertEqual(extracted_feature_dict, expected_feature_dict,
                      "extracted general file informations don't match")
示例#3
0
 def test_optional_header(self):
     """
     Testing the optional header extraction using a test conf file.
     """
     conf_file = "test_assets/extractor_confs/optional_header_conf.yaml"
     in_folder = "test_assets/executables/pe"
     out_folder = "test_assets/extracted_features/optional_header"
     extractor = mrextractor.new(conf_file, in_folder, out_folder)
     extractor.extract_batch()
     features_dict = extractor.features
     with open("test_assets/expected_features_dicts/optional_header.json",
               "rb") as f1:
         expected_feature_dict = json.load(f1)
     with open(out_folder + "/json/0/071df5b74f08fb5a4ce13a6cd2e7f485.json",
               "rb") as f2:
         extracted_feature_dict = json.load(f2)
     self.assertEqual(extracted_feature_dict, expected_feature_dict,
                      "Optional Header dosen't match")
示例#4
0
    def test_Sections(self):
        """
        Test the extracted features of Sections !
        """

        conf_file = "test_assets/extractor_confs/sections_conf.yaml"
        in_folder = "test_assets/executables/pe"
        out_folder = "test_assets/extracted_features/sections"
        extractor = mrextractor.new(conf_file, in_folder, out_folder)
        extractor.extract_batch()
        feature_dict = extractor.features
        with open("test_assets/expected_features_dicts/sections.json",
                  "rb") as f1:
            expected_feature_dict = json.load(f1)
        with open(out_folder + "/json/0/071df5b74f08fb5a4ce13a6cd2e7f485.json",
                  "rb") as f2:
            extracted_feature_dict = json.load(f2)
        self.assertEqual(extracted_feature_dict, expected_feature_dict,
                         "The extracted features of Sections don't match")
示例#5
0
    def test_elf_libraries(self):
        """
        Testing the extraction of ELF library names
        """

        conf_file = "test_assets/extractor_confs/elf_libraries_conf.yaml"
        in_folder = "test_assets/executables/elf"
        out_folder = "test_assets/extracted_features/elf_libraries"
        extractor = mrextractor.new(conf_file, in_folder, out_folder)
        extractor.extract_batch()

        with open("test_assets/expected_features_dicts/elf_libraries.json",
                  "rb") as f1:
            expected_feature_dict = json.load(f1)
        with open(out_folder + "/json/0/0e1631f5eaadf5ac5010530077727092.json",
                  "rb") as f2:
            extracted_feature_dict = json.load(f2)

        self.assertEqual(extracted_feature_dict, expected_feature_dict,
                         "ELF Sections don't match the expected output")
示例#6
0
    def test_elf_header(self):
        """
        Testing the extraction of informations from the header of an example
        ELF file.
        """

        conf_file = "test_assets/extractor_confs/elf_header_conf.yaml"
        in_folder = "test_assets/executables/elf"
        out_folder = "test_assets/extracted_features/elf_header"
        extractor = mrextractor.new(conf_file, in_folder, out_folder)
        extractor.extract_batch()

        with open("test_assets/expected_features_dicts/elf_header.json",
                  "rb") as f1:
            expected_feature_dict = json.load(f1)
        with open(out_folder + "/json/0/0e1631f5eaadf5ac5010530077727092.json",
                  "rb") as f2:
            extracted_feature_dict = json.load(f2)

        self.assertEqual(extracted_feature_dict, expected_feature_dict,
                         "ELF header don't match the expected output")
示例#7
0
def main():
    arg_parser = create_arg_parser()
    args = arg_parser.parse_args()

    # Getting args from the parser
    conf_file = args.conf_file
    in_folder = args.input_dir
    out_folder = args.output_dir
    log_file = args.log_file

    # Making extraction
    log.basicConfig(
        filename=log_file,
        format='[%(levelname)s %(asctime)s] %(message)s',
        datefmt='%m/%d/%Y %H:%M:%S',
        level=log.DEBUG,
    )

    log.info("Starting extraction")
    extractor = mre.new(conf_file, in_folder, out_folder)
    extractor.extract_batch()
    log.info("Extraction ended successfully")
示例#8
0
    def test_binary_image(self):
        """
        Testing the binary image extraction using a test conf file.
        """

        from PIL import Image, ImageChops
        """
        # Funtion that compares the differences of the two images .
        @param1 image, @param2 image   (extracted & expected images)

        @return an image (difference between pixels)
        if they are equal then it returns a black image
        """
        def assertImage(pic_1, pic_2):
            diff = ImageChops.difference(pic_1, pic_2)
            theDifferenceImage = diff.convert('RGB')
            theDifferenceImage.paste(pic_2, mask=diff)
            return theDifferenceImage

        conf_file = "test_assets/extractor_confs/binary_image_conf.yaml"
        in_folder = "test_assets/executables/pe"
        out_folder = "test_assets/extracted_features/binary_image"
        extractor = mrextractor.new(conf_file, in_folder, out_folder)
        extractor.extract_batch()
        extracted_image_features = extractor.features
        extracted_image = Image.open(
            "test_assets/expected_features_images/binary_image.png")
        expected_image = Image.open(
            out_folder +
            "/image/binary_image/0/071df5b74f08fb5a4ce13a6cd2e7f485.png")
        difference = assertImage(extracted_image, expected_image)
        """
        #getbbox(): verifying if all pixels are black it return 'None' if they are
        # if not then the pixels where they are changed
        """
        self.assertTrue(not difference.getbbox(), "Binary images don't match")