From 675b7f2f9bfa1a67a143a2d9d273b1388b6b4977 Mon Sep 17 00:00:00 2001 From: DullJZ <79080562+DullJZ@users.noreply.github.com> Date: Mon, 14 Jul 2025 07:18:16 +0000 Subject: [PATCH] Support shell switch in meterpreter session --- MetasploitMCP.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/MetasploitMCP.py b/MetasploitMCP.py index a6d971e..0cd770a 100644 --- a/MetasploitMCP.py +++ b/MetasploitMCP.py @@ -1076,10 +1076,17 @@ async def send_session_command( logger.debug(f"Using session.run_with_output for Meterpreter session {session_id}") try: # Use asyncio.wait_for to handle timeout manually since run_with_output doesn't support timeout parameter - output = await asyncio.wait_for( - asyncio.to_thread(lambda: session.run_with_output(command)), - timeout=timeout_seconds - ) + if command == "shell": + output = session.run_with_output(command, end_strs=['created.']) + session.read() # Clear buffer + elif command == "exit": + session.read() # Clear buffer + session.detach() + else: + output = await asyncio.wait_for( + asyncio.to_thread(lambda: session.run_with_output(command)), + timeout=timeout_seconds + ) status = "success" message = "Meterpreter command executed successfully." logger.debug(f"Meterpreter command '{command}' completed.")