diff --git a/external/source/meterpreter/source/common/base.c b/external/source/meterpreter/source/common/base.c index f467e4d6d4..499cfcaa80 100644 --- a/external/source/meterpreter/source/common/base.c +++ b/external/source/meterpreter/source/common/base.c @@ -14,6 +14,8 @@ extern DWORD remote_request_core_channel_interact(Remote *remote, Packet *packet extern DWORD remote_request_core_crypto_negotiate(Remote *remote, Packet *packet); +extern DWORD remote_request_core_shutdown(Remote *remote, Packet *packet); + extern DWORD remote_request_core_migrate(Remote *remote, Packet *packet); // Local remote response implementors @@ -100,6 +102,12 @@ Command commands[] = { EMPTY_DISPATCH_HANDLER }, }, + // Shutdown + { "core_shutdown", + { remote_request_core_shutdown, { 0 }, 0 }, + { EMPTY_DISPATCH_HANDLER }, + }, + // Terminator { NULL, { NULL, { 0 }, 0 }, diff --git a/external/source/meterpreter/source/common/base_dispatch_common.c b/external/source/meterpreter/source/common/base_dispatch_common.c index 5ddb84c547..92bd43a3e7 100644 --- a/external/source/meterpreter/source/common/base_dispatch_common.c +++ b/external/source/meterpreter/source/common/base_dispatch_common.c @@ -1,5 +1,8 @@ #include "common.h" +// An external reference to the meterpreters main server thread, so we can shutdown gracefully after successfull migration. +extern THREAD * serverThread; + /* * core_channel_open * ----------------- @@ -604,3 +607,27 @@ DWORD remote_request_core_crypto_negotiate(Remote *remote, Packet *packet) return ERROR_SUCCESS; } + + + +/* + * core_shutdown + * ----------------- + * + */ +DWORD remote_request_core_shutdown(Remote *remote, Packet *packet) +{ + Channel *channel = NULL; + Packet *response = packet_create_response(packet); + DWORD result = ERROR_SUCCESS; + + // Acknowledge the shutdown request + packet_add_tlv_bool(response, TLV_TYPE_BOOL, TRUE); + + // Transmit the response + packet_transmit_response(result, remote, response); + + dprintf("[SHUTDOWN] Shutting down the Meterpreter thread 1 (killing the main thread)..."); + thread_kill( serverThread ); + return result; +} \ No newline at end of file diff --git a/external/source/meterpreter/source/common/common.h b/external/source/meterpreter/source/common/common.h index 2c6bd9098f..507a7bf11e 100644 --- a/external/source/meterpreter/source/common/common.h +++ b/external/source/meterpreter/source/common/common.h @@ -75,7 +75,7 @@ void real_dprintf(char *filename, int line, const char *function, char *format, #define METERPRETER_TRANSPORT_HTTPS 2 // Enable debugging -//#define DEBUGTRACE 1 +// #define DEBUGTRACE 1 #ifdef DEBUGTRACE #define dprintf(...) real_dprintf(__VA_ARGS__)