ctfsolver.managers.manager_connections¶
manager_connections.py
This module provides the ManagerConnections class for managing connections to CTF challenges, supporting both local and remote connection types using the pwntools library.
- Classes:
ManagerConnections: Handles connection setup, interaction, and communication with CTF challenges.
- Typical usage example:
manager = ManagerConnections(url=”example.com”, port=1337, conn=”remote”) manager.initiate_connection() output = manager.recv_lines(number=3, display=True, save=True) manager.send_menu(choice=1, menu_num=3, menu_text=”Your choice:”)
Number of menu options.
- Type:
Text prompt for menu selection.
- Type:
Classes¶
Manages connections to CTF challenges, supporting both local and remote modes. |
Module Contents¶
- class ManagerConnections(*args, **kwargs)[source]¶
Manages connections to CTF challenges, supporting both local and remote modes. This class provides methods to initiate and manage connections to CTF challenges, either by spawning a local process or connecting to a remote host. It also offers utilities for interacting with typical menu-driven CTF binaries, including sending choices, receiving lines, and handling menu prompts. .. attribute:: pwn
The pwntools module or object used for process and remote connections.
Number of menu options expected.
- Type:
Text prompt expected before sending a menu choice.
- Type:
- __init__(*args, **kwargs)[source]¶
Initializes the ManagerConnections instance with connection parameters.
- Return type:
None
- initiate_connection(*args, **kwargs)[source]¶
Initiates the connection based on the specified connection type.
- Return type:
None
- connect(*args, **kwargs)[source]¶
Connects to the challenge locally or remotely, depending on conn_type.
- Return type:
None
Deprecated. Use recv_lines instead.
- recv_lines(number=1, display=False, save=False)[source]¶
Receives a specified number of lines from the connection.
Sends a choice to a menu-driven binary, handling menu prompts and output.
- recv_send(text, lines=None, text_until=None, display=False, save=False)[source]¶
Receives lines and/or text until a prompt, then sends a response.
- send(text, encode=True)[source]¶
Sends text to the connection, optionally encoding it.
- Return type:
None
- recv_until(text, **kwargs)[source]¶
Receives data until a specified delimiter is encountered.
- Return type:
- initiate_connection(*args, **kwargs)[source]¶
Initiates a connection using the specified connection type and parameters. :param *args: Variable length argument list to be passed to the connection method. :param **kwargs: Arbitrary keyword arguments to be passed to the connection method.
- Returns:
None
- Return type:
None
- connect(*args, **kwargs)[source]¶
- Description:
Connects to the challenge based on the connection type. If the connection type is remote, it connects to the url and port provided. If the connection type is local, it starts a process with the file provided.
- local:
- kwargs :
argv: Any | None = None, shell: bool = False, executable: Any | None = None, cwd: Any | None = None, env: Any | None = None, ignore_environ: Any | None = None, stdin: int = PIPE, stdout: PTY | int = PTY if not IS_WINDOWS else PIPE, stderr: int = STDOUT, close_fds: bool = True, preexec_fn: Any = lambda : None, raw: bool = True, aslr: Any | None = None, setuid: Any | None = None, where: str = ‘local’, display: Any | None = None, alarm: Any | None = None, creationflags: int = 0
- Return type:
None
- recv_lines(number=1, display=False, save=False, *args, **kwargs)[source]¶
- Description:
Receives the output of the menu based on the number of lines provided. If display is True, it prints the output of everything received. If save is True, it saves the output in a list and returns it.
- Parameters:
- Returns:
list of the lines received if save is True
- Return type:
- send_menu(choice, menu_num=None, menu_text=None, display=False, save=False)[source]¶
- Description:
Gets the menu num either from the class or from the function call and saves it to the class. Gets the menu text that the menu is providing, receives until the menu asks for choice and then send out the choice. If save is True, it saves the output of the menu in a list and returns it. If display is True, it prints the output of everything received.
- Parameters:
menu_num (int, optional) – Number of options printed in the menu. Defaults to None.
menu_text (str, optional) – Text that the menu asks before sending your choice. Defaults to None.
display (bool, optional) – Variable to print every received line. Defaults to False.
save (bool, optional) – . Defaults to False.
- Returns:
List of output of the menu if save is True
- Return type:
- recv_send(text, lines=None, text_until=None, display=False, save=False)[source]¶
- Description:
Receives lines and sends a response. It can receive a number or lines, and/or specific text. If save is True, it saves the output of the menu in a list and returns it. If display is True, it prints the output of everything received.
- Parameters:
menu_num (int, optional) – Number of options printed in the menu. Defaults to None.
menu_text (str, optional) – Text that the menu asks before sending your choice. Defaults to None.
display (bool, optional) – Variable to print every received line. Defaults to False.
save (bool, optional) – . Defaults to False.
- Returns:
List of output of the menu if save is True
- Return type:
- send(text, encode=True)[source]¶
- Description:
Sends the text to the connection after it encodes it. Wrapper for self.conn.sendline(str(text).encode())
- Parameters:
text (str) – Text to send
- Return type:
None
- recv_until(text, **kwargs)[source]¶
- Description:
Receive data until one of delims`(text) provided is encountered. It encodes the text before sending it. Wrapper for self.conn.recvuntil(text.encode()) Can also drop the ending if drop is True. If the request is not satisfied before ``timeout` seconds pass, all data is buffered and an empty string (
'') is returned.
- Parameters:
text (str) – Text to receive until
**kwargs – Additional keyword arguments to pass to the recv - drop (bool, optional): Drop the ending. If
Trueit is removed from the end of the return value. Defaults to False. - timeout (int, optional): Timeout in seconds. Defaults to default.
- Raises:
exceptions.EOFError – The connection closed before the request could be satisfied
- Returns:
A string containing bytes received from the socket, or
''if a timeout occurred while waiting.- Return type: