Skip to content

Instantly share code, notes, and snippets.

@sergio11
Created November 29, 2024 20:02
Show Gist options
  • Select an option

  • Save sergio11/70fa0ed91bd54a62694b114856526242 to your computer and use it in GitHub Desktop.

Select an option

Save sergio11/70fa0ed91bd54a62694b114856526242 to your computer and use it in GitHub Desktop.
MetasploitClient
from nemesys.utils.logger import nemesysLogger
from pymetasploit3.msfrpc import MsfRpcClient
class MetasploitClient:
def __init__(self, password, ssl=True):
"""
Initializes the connection to Metasploit RPC client.
Args:
password (str): The password for authenticating with the Metasploit RPC service.
ssl (bool): Flag to determine if SSL should be used for the connection (default is True).
"""
try:
# Establish connection to Metasploit
self.client = MsfRpcClient(password, ssl=ssl)
nemesysLogger.info("๐Ÿ’€ Connection established: Metasploit is ready for action.")
except Exception as e:
# Log the error in case the connection fails
nemesysLogger.error(f"โŒ [METASPLOIT] Connection failed: {e}. Check if Metasploit is running and the password is correct.")
self.client = None
def get_client(self):
"""
Returns the Metasploit RPC client instance.
Returns:
MsfRpcClient: The Metasploit RPC client object if connected, None otherwise.
"""
if self.client:
nemesysLogger.debug("๐Ÿ” [METASPLOIT] Returning connected Metasploit client.")
else:
nemesysLogger.warning("โš ๏ธ [METASPLOIT] No active client. Unable to return client instance.")
return self.client
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment