Пример #1
0
    def test_import(self):
        path = os.path.normpath('../example/import_test_project/main.py')

        project_modules = get_python_modules(os.path.dirname(path))
        local_modules = get_directory_modules(os.path.dirname(path))

        self.cfg_create_from_file(path, project_modules, local_modules)

        cfg_list = [self.cfg]
Пример #2
0
    def add_module(self, module, module_name, local_names):
        module_path = module[1]
        self.filenames.append(module_path)
        self.local_modules = get_directory_modules(module_path)
        tree = generate_ast(module_path)

        parent_definitions = self.module_definitions_stack[-1]
        parent_definitions.import_names = local_names

        module_definitions = ModuleDefinitions(local_names, module_name)
        self.module_definitions_stack.append(module_definitions)

        self.append_node(EntryExitNode('Entry ' + module[0]))
        self.visit(tree)
        exit_node = self.append_node(EntryExitNode('Exit ' + module[0]))

        self.module_definitions_stack.pop()
        self.filenames.pop()

        return exit_node
Пример #3
0
 def test_import_from(self):
     path = '../example/import_test/import_from.py'
     tree = generate_ast(path)
     v = Visitor(tree, get_python_modules(path),
                 get_directory_modules(path), path)
Пример #4
0
                    help='Draws a lattice.')

args = parser.parse_args()

if __name__ == '__main__':
    log.set_logger(args.log_level, show_path=False)

    path = os.path.normpath(args.filepath)

    directory = None
    if args.project_root:
        directory = os.path.normpath(args.project_root)
    else:
        directory = os.path.dirname(path)
    project_modules = get_python_modules(directory)
    local_modules = get_directory_modules(directory)

    tree = generate_ast(path)
    cfg = build_cfg(tree, project_modules, local_modules, path)

    cfg_list = [cfg]

    adaptor_type = FlaskAdaptor(cfg_list, project_modules, local_modules)

    analyse(cfg_list, analysis_type=ReachingDefinitionsTaintAnalysis)

    vulnerability_log = None
    if args.trigger_word_file:
        vulnerability_log = find_vulnerabilities(cfg_list,
                                                 args.trigger_word_file)
    else: