Exemplo n.º 1
0
def __listDirectory__(directory, files=False, exclude_pattern_starts_with=None):
    """
    Devuelve las carpetas contenidas en el directorio indicado. Si se quieren listar los 
    ficheros se deberá indicar el argumento files=True. En el caso de querer excluir ficheros o carpetas
    se indicará en el argumento exclude_pattern_starts_with con el comienzo de los mism__os.
    """
    mypath = __join(__this_dir__, directory)
    data = ''

    if files:
        data = [f for f in __listdir(mypath) if __isfile(__join(mypath, f))]
    else:
        data = [f for f in __listdir(mypath) if not __isfile(__join(mypath, f))]

    if __blacklist_extensions__:
        new_data = []
        for d in data:
            has_extension = False
            for black_ext in __blacklist_extensions__:
                if black_ext in d:
                    has_extension = True
            if not has_extension:
                new_data.append(d)
        data = new_data

    if exclude_pattern_starts_with:
        new_data = []
        for d in data:
            if not d.startswith(exclude_pattern_starts_with):
                new_data.append(d)
        data = new_data

    if __blacklist_directories__:
        new_data = []
        for d in data:
            for direc in __blacklist_directories__:
                if not direc in d:
                    new_data.append(d)
        data = new_data

    if __ignore_folders__:
        new_data = []
        for d in data:
            exists = False
            for direc in __ignore_folders__:
                if direc in d:
                    exists = True
            if not exists:
                new_data.append(d)
        data = new_data

    if files and __ignore_files__:
        new_data = []
        for d in data:
            for file_ign in __ignore_files__:
                if not file_ign in d:
                    new_data.append(d)
        data = new_data

    return data
def which(program):
    """returns path to an executable if it is found in the path"""
    fpath, fname = __os.path.split(program)
    if fpath:
        if __isfile(program) and __os.access(program, __os.X_OK):
            return program
    else:
        paths_to_search = __os.environ["PATH"].split(__os.pathsep)
        paths_to_search.append(sequtil_dir)
        for path in paths_to_search:
            exe_file = __os.path.join(path, program)
            if __isfile(exe_file) and __os.access(exe_file, __os.X_OK):
                return exe_file
    return ""
Exemplo n.º 3
0
def which(program):
    """returns path to an executable if it is found in the path"""
    fpath, fname = __split(program)
    if fpath:
        if __isfile(program) and __os.access(program, __os.X_OK):
            return program
    else:
        paths_to_search = __os.environ["PATH"].split(__os.pathsep)
        paths_to_search.extend((trnlib_directory, trn_directory))
        for path in paths_to_search:
            exe_file = __join(path, program)
            if __isfile(exe_file) and __os.access(exe_file, __os.X_OK):
                return exe_file
    if __os.name == "nt" and not program.endswith(".exe"):
        return which(program + ".exe")
    return None
Exemplo n.º 4
0
def which(program):
    """returns path to an executable if it is found in the path"""
    fpath, fname = __split(program)
    if fpath:
        if __isfile(program) and __os.access(program, __os.X_OK):
            return program
    else:
        paths_to_search = __os.environ["PATH"].split(__os.pathsep)
        paths_to_search.extend((omelib_directory, ome_directory))
        for path in paths_to_search:
            exe_file = __join(path, program)
            if __isfile(exe_file) and __os.access(exe_file, __os.X_OK):
                return exe_file
    if __os.name == "nt" and not program.endswith(".exe"):
        return which(program + ".exe")
    return None
Exemplo n.º 5
0
def __getModules__(directory='', exclude_pattern_starts_with='.'):
    """
    Devuelve las carpetas o ficheros contenidas en cada módulo del directorio actual, expluyendo de la raiz 
    los directorios que empiecen por punto. 
    """
    data = {}
    dirs = __listDirectory__(directory=directory, exclude_pattern_starts_with=exclude_pattern_starts_with)
    if dirs:
        for d in dirs:
            if not __isfile(d):
                sub_dirs = __listDirectory__(directory=d)  # Tengo que excluir el __pycache__
                data[d] = {}
                for sub in sub_dirs:  # Tipo de Herramientas (OSINT, SQLi, etc.)
                    sub_dirs_tools = __listDirectory__(directory='{d}/{sub}'.format(d=d, sub=sub))
                    data[d][sub] = {}
                    for tool in sub_dirs_tools:
                        sub_dirs_tool_files = __listDirectory__(directory='{d}/{sub}/{tool}'.format(d=d, sub=sub, tool=tool), files=True)
                        data[d][sub][tool] = sub_dirs_tool_files
                subdirectorio = __listDirectory__(directory=d, files=True)
                if len(subdirectorio) > 0:
                    data[d]['files'] = subdirectorio
            else:
                try:
                    data['files'].append(d)
                except:
                    data['files'] = []
                    data['files'].append(d)
    else:
        dirs_files = __listDirectory__(directory=directory, files=True)
        data[directory] = dirs_files
    return data
Exemplo n.º 6
0
def __createModule__(moduleName, category):
    """
    Iniciamos con el comando anterior la instancia del modulo
    """
    Logger.printMessage('Creating {moduleName} on {category}'.format(moduleName=moduleName, category=category),
                        debug_module=True)
    moduleName = moduleName.replace(" ", "_").lower()
    category = category.lower()
    categories = getCategories()
    if category not in categories:
        __createCategory__(category)
    dir_actual = __os.path.dirname(__file__)
    if not __os.path.isdir(
            '{dir}/modules/{category}/{moduleName}'.format(dir=dir_actual, category=category, moduleName=moduleName)):
        __os.makedirs(
            '{dir}/modules/{category}/{moduleName}'.format(dir=dir_actual, category=category, moduleName=moduleName))
    if not __os.path.exists('{dir}/modules/{category}/__init__.py'.format(dir=dir_actual, category=category)):
        f = open('{dir}/modules/{category}/__init__.py'.format(dir=dir_actual, category=category), "w")
        f.write('')
    if not __os.path.exists(
            '{dir}/modules/{category}/{moduleName}/ht_{moduleName}.py'.format(dir=dir_actual, category=category,
                                                                              moduleName=moduleName)):
        f = open('{dir}/modules/{category}/{moduleName}/ht_{moduleName}.py'.format(dir=dir_actual, category=category,
                                                                                   moduleName=moduleName), "w")
        f.write(__default_template_modules_ht__.replace('{moduleName}', moduleName))
    if not __os.path.exists(
            '{dir}/modules/{category}/{moduleName}/__init__.py'.format(dir=dir_actual, category=category,
                                                                       moduleName=moduleName)):
        f = open('{dir}/modules/{category}/{moduleName}/__init__.py'.format(dir=dir_actual, category=category,
                                                                            moduleName=moduleName), "w")
        f.write('')
    if not __os.path.isdir('{dir}/core/config_modules_django/{category}/'.format(dir=dir_actual, category=category)):
        __os.mkdir('{dir}/core/config_modules_django/{category}/'.format(dir=dir_actual, category=category))
    if not __isfile(
            '{dir}/core/config_modules_django/{category}/{moduleName}.json'.format(dir=dir_actual, category=category,
                                                                                   moduleName=moduleName)):
        with open('{dir}/core/config_modules_django/{category}/ht_{moduleName}.json'.format(dir=dir_actual,
                                                                                            category=category,
                                                                                            moduleName=moduleName),
                  "w") as fp:
            fp.write(__json.dumps({}))
    # temp_path, hackingtools_dir = __os.path.split(dir_actual)
    # temp_path, library_dir = __os.path.split(temp_path)
    # urls_file = __os.path.join(temp_path, 'urls.py')
    # insert_url_django(urls_file, moduleName) # TODO edit urls for auto URLs when creating module
    # print("{msg}".format(msg=urls_file))
    # Reload variables on client side
    # global hackingtools
    # reload(hackingtools)
    Config.__createModuleTemplateConfig__(moduleName, category)
    __importModules__()
    return