MCPcopy Create free account
hub / github.com/GH05TCREW/MetasploitMCP / run_post_module

Function run_post_module

MetasploitMCP.py:1083–1134  ·  view source on GitHub ↗

Run a Metasploit post-exploitation module against a session. Args: module_name: Name/path of the post module (e.g., 'windows/gather/enum_shares'). session_id: The ID of the target session. options: Dictionary of module options. 'SESSION' will be added automatically.

(
    module_name: str,
    session_id: int,
    options: Dict[str, Any] = None,
    run_as_job: bool = False,
    timeout_seconds: int = LONG_CONSOLE_READ_TIMEOUT
)

Source from the content-addressed store, hash-verified

1081
1082@mcp.tool()
1083async def run_post_module(
1084 module_name: str,
1085 session_id: int,
1086 options: Dict[str, Any] = None,
1087 run_as_job: bool = False,
1088 timeout_seconds: int = LONG_CONSOLE_READ_TIMEOUT
1089) -> Dict[str, Any]:
1090 """
1091 Run a Metasploit post-exploitation module against a session.
1092
1093 Args:
1094 module_name: Name/path of the post module (e.g., 'windows/gather/enum_shares').
1095 session_id: The ID of the target session.
1096 options: Dictionary of module options. 'SESSION' will be added automatically.
1097 run_as_job: If False (default), run sync via console. If True, run async via RPC.
1098 timeout_seconds: Max time for synchronous run via console.
1099
1100 Returns:
1101 Dictionary with execution results or error details.
1102 """
1103 logger.info(f"Request to run post module {module_name} on session {session_id}. Job: {run_as_job}")
1104 module_options = options or {}
1105 module_options['SESSION'] = session_id # Ensure SESSION is always set
1106
1107 # Add basic session validation before running
1108 client = get_msf_client()
1109 try:
1110 current_sessions = await asyncio.to_thread(lambda: client.sessions.list)
1111 if str(session_id) not in current_sessions:
1112 logger.error(f"Session {session_id} not found for post module {module_name}.")
1113 return {"status": "error", "message": f"Session {session_id} not found.", "module": module_name}
1114 except MsfRpcError as e:
1115 logger.error(f"Failed to validate session {session_id} before running post module: {e}")
1116 # Optionally proceed with caution or return error
1117 return {"status": "error", "message": f"Error validating session {session_id}: {e}", "module": module_name}
1118
1119
1120 if run_as_job:
1121 return await _execute_module_rpc(
1122 module_type='post',
1123 module_name=module_name,
1124 module_options=module_options
1125 # No payload for post modules
1126 )
1127 else:
1128 return await _execute_module_console(
1129 module_type='post',
1130 module_name=module_name,
1131 module_options=module_options,
1132 command='run',
1133 timeout=timeout_seconds
1134 )
1135
1136@mcp.tool()
1137async def run_auxiliary_module(

Callers

nothing calls this directly

Calls 3

get_msf_clientFunction · 0.85
_execute_module_rpcFunction · 0.85
_execute_module_consoleFunction · 0.85

Tested by

no test coverage detected