1
mirror of https://github.com/rapid7/metasploit-payloads synced 2024-11-26 17:41:08 +01:00

Land #133, add local time command

This commit is contained in:
Brent Cook 2016-10-10 23:28:20 -05:00
commit f302463f94
No known key found for this signature in database
GPG Key ID: 1FFAA0B24B708F96
11 changed files with 94 additions and 4 deletions

View File

@ -6,7 +6,7 @@
#define _METERPRETER_SOURCE_COMMON_COMMON_H
/*! @brief Set to 0 for "normal", and 1 to "verbose", comment out to disable completely. */
//#define DEBUGTRACE 0
#define DEBUGTRACE 0
#include <stdlib.h>
#include <stdio.h>

1
c/meterpreter/source/extensions/stdapi/server/stdapi.c Normal file → Executable file
View File

@ -110,6 +110,7 @@ Command customCommands[] =
// Sys/config
COMMAND_REQ("stdapi_sys_config_getuid", request_sys_config_getuid),
COMMAND_REQ("stdapi_sys_config_localtime", request_sys_config_localtime),
COMMAND_REQ("stdapi_sys_config_sysinfo", request_sys_config_sysinfo),
COMMAND_REQ("stdapi_sys_config_rev2self", request_sys_config_rev2self),
COMMAND_REQ("stdapi_sys_config_getprivs", request_sys_config_getprivs),

View File

@ -574,6 +574,48 @@ DWORD add_windows_os_version(Packet** packet)
}
#endif
/*
* @brief Handle the request to get local date/time information.
* @param remote Pointer to the remote instance.
* @param packet Pointer to the request packet.
* @return Indication of success or failure.
*/
DWORD request_sys_config_localtime(Remote* remote, Packet* packet)
{
Packet *response = packet_create_response(packet);
DWORD result = ERROR_SUCCESS;
char dateTime[128] = { 0 };
#ifdef _WIN32
TIME_ZONE_INFORMATION tzi = { 0 };
SYSTEMTIME localTime = { 0 };
DWORD tziResult = GetTimeZoneInformation(&tzi);
GetLocalTime(&localTime);
_snprintf_s(dateTime, sizeof(dateTime), sizeof(dateTime) - 1, "%d-%02d-%02d %02d:%02d:%02d.%d %S (UTC%s%d)",
localTime.wYear, localTime.wMonth, localTime.wDay,
localTime.wHour, localTime.wMinute, localTime.wSecond, localTime.wMilliseconds,
tziResult == TIME_ZONE_ID_DAYLIGHT ? tzi.DaylightName : tzi.StandardName,
tzi.Bias > 0 ? "-" : "+", abs(tzi.Bias / 60 * 100));
#else
time_t t = time(NULL);
struct tm lt = { 0 };
localtime_r(&t, &lt);
// TODO: bug? Ping @bcook-r7
// For some reason I don't see the correct TZ name/offset coming through. Bionic issue?
strftime(dateTime, sizeof(dateTime) - 1, "%Y-%m-%d %H:%M:%S %Z (UTC%z)", &lt);
#endif
dprintf("[SYSINFO] Local Date/Time: %s", dateTime);
packet_add_tlv_string(response, TLV_TYPE_LOCAL_DATETIME, dateTime);
// Transmit the response
packet_transmit_response(result, remote, response);
return result;
}
/*
* sys_sysinfo
* ----------

View File

@ -5,6 +5,7 @@ DWORD request_sys_config_getenv(Remote *remote, Packet *packet);
DWORD request_sys_config_getuid(Remote *remote, Packet *packet);
DWORD request_sys_config_getsid(Remote *remote, Packet *packet);
DWORD request_sys_config_sysinfo(Remote *remote, Packet *packet);
DWORD request_sys_config_localtime(Remote *remote, Packet *packet);
DWORD request_sys_config_rev2self(Remote *remote, Packet *packet);
DWORD request_sys_config_getprivs(Remote *remote, Packet *packet);
DWORD request_sys_config_steal_token(Remote *remote, Packet *packet);

1
c/meterpreter/source/extensions/stdapi/stdapi.h Normal file → Executable file
View File

@ -115,6 +115,7 @@
#define TLV_TYPE_SID MAKE_CUSTOM_TLV( TLV_META_TYPE_STRING, TLV_TYPE_EXTENSION_STDAPI, 1045 )
#define TLV_TYPE_DOMAIN MAKE_CUSTOM_TLV( TLV_META_TYPE_STRING, TLV_TYPE_EXTENSION_STDAPI, 1046 )
#define TLV_TYPE_LOGGED_ON_USER_COUNT MAKE_CUSTOM_TLV( TLV_META_TYPE_UINT, TLV_TYPE_EXTENSION_STDAPI, 1047 )
#define TLV_TYPE_LOCAL_DATETIME MAKE_CUSTOM_TLV( TLV_META_TYPE_STRING, TLV_TYPE_EXTENSION_STDAPI, 1048 )
// Environment stuff
#define TLV_TYPE_ENV_VARIABLE MAKE_CUSTOM_TLV( TLV_META_TYPE_STRING, TLV_TYPE_EXTENSION_STDAPI, 1100 )

View File

@ -51,6 +51,7 @@ import com.metasploit.meterpreter.stdapi.stdapi_fs_sha1;
import com.metasploit.meterpreter.stdapi.stdapi_fs_stat;
import com.metasploit.meterpreter.stdapi.stdapi_net_config_get_interfaces_V1_4;
import com.metasploit.meterpreter.stdapi.stdapi_net_config_get_routes_V1_4;
import com.metasploit.meterpreter.stdapi.stdapi_sys_config_localtime;
import com.metasploit.meterpreter.stdapi.stdapi_net_socket_tcp_shutdown_V1_3;
import com.metasploit.meterpreter.stdapi.stdapi_sys_process_execute_V1_3;
@ -173,6 +174,7 @@ public class AndroidMeterpreter extends Meterpreter {
mgr.registerCommand("stdapi_net_socket_tcp_shutdown", stdapi_net_socket_tcp_shutdown_V1_3.class);
mgr.registerCommand("stdapi_sys_config_getuid", stdapi_sys_config_getuid.class);
mgr.registerCommand("stdapi_sys_config_sysinfo", stdapi_sys_config_sysinfo_android.class);
mgr.registerCommand("stdapi_sys_config_localtime", stdapi_sys_config_localtime.class);
mgr.registerCommand("stdapi_sys_process_execute", stdapi_sys_process_execute_V1_3.class);
mgr.registerCommand("stdapi_sys_process_get_processes", stdapi_sys_process_get_processes_android.class);
if (context != null) {

View File

@ -118,9 +118,10 @@ public interface TLVType {
public static final int TLV_TYPE_VALUE_DATA = TLVPacket.TLV_META_TYPE_RAW | 1012;
// Config
public static final int TLV_TYPE_COMPUTER_NAME = TLVPacket.TLV_META_TYPE_STRING | 1040;
public static final int TLV_TYPE_OS_NAME = TLVPacket.TLV_META_TYPE_STRING | 1041;
public static final int TLV_TYPE_USER_NAME = TLVPacket.TLV_META_TYPE_STRING | 1042;
public static final int TLV_TYPE_COMPUTER_NAME = TLVPacket.TLV_META_TYPE_STRING | 1040;
public static final int TLV_TYPE_OS_NAME = TLVPacket.TLV_META_TYPE_STRING | 1041;
public static final int TLV_TYPE_USER_NAME = TLVPacket.TLV_META_TYPE_STRING | 1042;
public static final int TLV_TYPE_LOCAL_DATETIME = TLVPacket.TLV_META_TYPE_STRING | 1048;
public static final int TLV_TYPE_ENV_VARIABLE = TLVPacket.TLV_META_TYPE_STRING | 1100;
public static final int TLV_TYPE_ENV_VALUE = TLVPacket.TLV_META_TYPE_STRING | 1101;

View File

@ -45,6 +45,7 @@ public class Loader implements ExtensionLoader {
mgr.registerCommand("stdapi_sys_config_getuid", stdapi_sys_config_getuid.class);
mgr.registerCommand("stdapi_sys_config_getenv", stdapi_sys_config_getenv.class);
mgr.registerCommand("stdapi_sys_config_sysinfo", stdapi_sys_config_sysinfo.class);
mgr.registerCommand("stdapi_sys_config_localtime", stdapi_sys_config_localtime.class);
mgr.registerCommand("stdapi_sys_process_execute", stdapi_sys_process_execute.class, V1_2, V1_3);
mgr.registerCommand("stdapi_sys_process_get_processes", stdapi_sys_process_get_processes.class, V1_2);
mgr.registerCommand("stdapi_ui_desktop_screenshot", stdapi_ui_desktop_screenshot.class, V1_4);

View File

@ -0,0 +1,22 @@
package com.metasploit.meterpreter.stdapi;
import com.metasploit.meterpreter.Meterpreter;
import com.metasploit.meterpreter.TLVPacket;
import com.metasploit.meterpreter.TLVType;
import com.metasploit.meterpreter.command.Command;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class stdapi_sys_config_localtime implements Command {
private static final Format formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z", Locale.ENGLISH);
private static final Format tzformatter = new SimpleDateFormat("Z", Locale.ENGLISH);
public int execute(Meterpreter meterpreter, TLVPacket request, TLVPacket response) throws Exception {
Date date = new Date();
String localTime = formatter.format(date) + " (UTC" + tzformatter.format(date) + ")";
response.addOverflow(TLVType.TLV_TYPE_LOCAL_DATETIME, localTime);
return ERROR_SUCCESS;
}
}

View File

@ -81,6 +81,7 @@ define("TLV_TYPE_OS_NAME", TLV_META_TYPE_STRING | 1041);
define("TLV_TYPE_USER_NAME", TLV_META_TYPE_STRING | 1042);
define("TLV_TYPE_ARCHITECTURE", TLV_META_TYPE_STRING | 1043);
define("TLV_TYPE_LANG_SYSTEM", TLV_META_TYPE_STRING | 1044);
define("TLV_TYPE_LOCAL_DATETIME", TLV_META_TYPE_STRING | 1048);
# Environment
define("TLV_TYPE_ENV_VARIABLE", TLV_META_TYPE_STRING | 1100);
@ -635,6 +636,15 @@ function stdapi_sys_config_sysinfo($req, &$pkt) {
}
}
if (!function_exists('stdapi_sys_config_localtime')) {
register_command('stdapi_sys_config_localtime');
function stdapi_sys_config_localtime($req, &$pkt) {
my_print("doing localtime");
packet_add_tlv($pkt, create_tlv(TLV_TYPE_LOCAL_DATETIME, strftime("%Y-%m-%d %H:%M:%S %Z (UTC%z)")));
return ERROR_SUCCESS;
}
}
# Global list of processes so we know what to kill when a channel gets closed
$GLOBALS['processes'] = array();

View File

@ -376,6 +376,7 @@ TLV_TYPE_OS_NAME = TLV_META_TYPE_STRING | 1041
TLV_TYPE_USER_NAME = TLV_META_TYPE_STRING | 1042
TLV_TYPE_ARCHITECTURE = TLV_META_TYPE_STRING | 1043
TLV_TYPE_SID = TLV_META_TYPE_STRING | 1045
TLV_TYPE_LOCAL_DATETIME = TLV_META_TYPE_STRING | 1048
##
# Environment
@ -718,6 +719,14 @@ def stdapi_sys_config_getuid(request, response):
response += tlv_pack(TLV_TYPE_USER_NAME, username)
return ERROR_SUCCESS, response
@meterpreter.register_function
def stdapi_sys_config_localtime(request, response):
localtime = time.strftime("%Y-%m-%d %H:%M:%S %Z", time.localtime())
direction = "-" if time.timezone > 0 else "+"
localtime += " (UTC{0}{1})".format(direction, int(abs(time.timezone / 36)))
response += tlv_pack(TLV_TYPE_LOCAL_DATETIME, localtime)
return ERROR_SUCCESS, response
@meterpreter.register_function
def stdapi_sys_config_sysinfo(request, response):
uname_info = platform.uname()