ctfsolver.venv.manager_venv¶
Attributes¶
Classes¶
ManagerFolder provides utilities for managing folder structures and files for CTF (Capture The Flag) challenges. |
Module Contents¶
- class ManagerVenv(*args, **kwargs)[source]¶
Bases:
ctfsolver.managers.manager_folder.ManagerFolderManagerFolder provides utilities for managing folder structures and files for CTF (Capture The Flag) challenges. This class handles the creation, organization, and manipulation of challenge-related directories and files, including payloads, data, and solution scripts. It offers methods for searching files, executing functions on files, cleaning up empty directories, and extracting function definitions from Python files.
verbose (bool): Enables verbose output for debugging and logging. Path (type): Reference to the pathlib.Path class for file system operations. parent (Path): The resolved parent directory of the calling file. file (str): The filename associated with the challenge. folders_name_list (list): List of folder names to be managed. folders (defaultdict): Mapping of folder names to their Path objects. folder_payloads (Path): Path to the payloads folder. folder_data (Path): Path to the data folder. folder_files (Path): Path to the files folder. challenge_file (Path): Path to the challenge file. solution_file (Path): Path to the solution file.
- prepare_space(files=None, folder=None, test_text='flag{test}')[source]¶
Prepares challenge space by creating files and folders.
- clean_folders(folders
list = None): Removes empty folders.
- get_solution_file(*args, solution_name='solution.py', save=False, display=False, **kwargs)[source]¶
Retrieves the solution file path.
- search_for_pattern_in_file(file, func=None, display=False, save=False, *args, **kwargs)[source]¶
Searches for a pattern in a file.
- search_files(directory, exclude_dirs, search_string, save=False, display=False)[source]¶
Searches for a string in files within a directory.
- find_function_from_file(file_path, function_name)[source]¶
Finds and returns the source code of a function from a file.
- recursive_folder_search(function, *args, path=None, **kwargs)[source]¶
Recursively applies a function to folders and files.
- single_folder_search(*args, **kwargs)[source]¶
Applies a function to the contents of a single folder.
Example
manager = ManagerFolder(file=”challenge.txt”, verbose=True) manager.prepare_space(files=[“input.txt”, “output.txt”])
- look_for_venvs(filepath=None)[source]¶
Recursively searches for Python virtual environments within a specified directory. :param filepath: The path to the directory in which to search for virtual environments.
If not provided, the search will be performed in the instance’s venv_dir attribute.
- Returns:
A list of Path objects representing directories identified as Python virtual environments.
- Return type:
list[Path]
- Raises:
FileNotFoundError – If the specified path does not exist or is not a directory.
- Parameters:
filepath (str, optional)
Notes
A directory is considered a virtual environment if self.check_venv_dir(item) returns True.
The search is performed recursively using Path.rglob(“*”).
- move_venv(folder=None)[source]¶
- Parameters:
folder (pathlib.Path)