commit
25b1ec5b75
|
@ -78,6 +78,14 @@ define("TLV_TYPE_VALUE_DATA", TLV_META_TYPE_RAW | 1012);
|
|||
define("TLV_TYPE_COMPUTER_NAME", TLV_META_TYPE_STRING | 1040);
|
||||
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);
|
||||
|
||||
# Environment
|
||||
define("TLV_TYPE_ENV_VARIABLE", TLV_META_TYPE_STRING | 1100);
|
||||
define("TLV_TYPE_ENV_VALUE", TLV_META_TYPE_STRING | 1101);
|
||||
define("TLV_TYPE_ENV_GROUP", TLV_META_TYPE_GROUP | 1102);
|
||||
|
||||
|
||||
define("DELETE_KEY_FLAG_RECURSIVE", (1 << 0));
|
||||
|
||||
|
@ -162,7 +170,7 @@ define("ERROR_CONNECTION_ERROR", 10000);
|
|||
# eval'd twice
|
||||
my_print("Evaling stdapi");
|
||||
|
||||
##
|
||||
##
|
||||
# Search Helpers
|
||||
##
|
||||
|
||||
|
@ -197,38 +205,38 @@ define('GLOB_RECURSE',2048);
|
|||
*/
|
||||
if (!function_exists('safe_glob')) {
|
||||
function safe_glob($pattern, $flags=0) {
|
||||
$split=explode('/',str_replace('\\','/',$pattern));
|
||||
$mask=array_pop($split);
|
||||
$path=implode('/',$split);
|
||||
if (($dir=opendir($path))!==false) {
|
||||
$glob=array();
|
||||
while (($file=readdir($dir))!==false) {
|
||||
// Recurse subdirectories (GLOB_RECURSE)
|
||||
if (
|
||||
(
|
||||
$flags&GLOB_RECURSE) && is_dir($path."/".$file)
|
||||
&& (!in_array($file,array('.','..'))
|
||||
# don't follow links to avoid infinite recursion
|
||||
&& (!is_link($path."/".$file))
|
||||
)
|
||||
) {
|
||||
$glob = array_merge($glob, array_prepend(safe_glob($path.'/'.$file.'/'.$mask, $flags),
|
||||
($flags&GLOB_PATH?'':$file.'/')));
|
||||
$split=explode('/',str_replace('\\','/',$pattern));
|
||||
$mask=array_pop($split);
|
||||
$path=implode('/',$split);
|
||||
if (($dir=opendir($path))!==false) {
|
||||
$glob=array();
|
||||
while (($file=readdir($dir))!==false) {
|
||||
// Recurse subdirectories (GLOB_RECURSE)
|
||||
if (
|
||||
(
|
||||
$flags&GLOB_RECURSE) && is_dir($path."/".$file)
|
||||
&& (!in_array($file,array('.','..'))
|
||||
# don't follow links to avoid infinite recursion
|
||||
&& (!is_link($path."/".$file))
|
||||
)
|
||||
) {
|
||||
$glob = array_merge($glob, array_prepend(safe_glob($path.'/'.$file.'/'.$mask, $flags),
|
||||
($flags&GLOB_PATH?'':$file.'/')));
|
||||
}
|
||||
// Match file mask
|
||||
if (fnmatch($mask,$file)) {
|
||||
if ( ( (!($flags&GLOB_ONLYDIR)) || is_dir("$path/$file") )
|
||||
&& ( (!($flags&GLOB_NODIR)) || (!is_dir($path.'/'.$file)) )
|
||||
&& ( (!($flags&GLOB_NODOTS)) || (!in_array($file,array('.','..'))) ) )
|
||||
$glob[] = ($flags&GLOB_PATH?$path.'/':'') . $file . ($flags&GLOB_MARK?'/':'');
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
if (!($flags&GLOB_NOSORT)) sort($glob);
|
||||
return $glob;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
// Match file mask
|
||||
if (fnmatch($mask,$file)) {
|
||||
if ( ( (!($flags&GLOB_ONLYDIR)) || is_dir("$path/$file") )
|
||||
&& ( (!($flags&GLOB_NODIR)) || (!is_dir($path.'/'.$file)) )
|
||||
&& ( (!($flags&GLOB_NODOTS)) || (!in_array($file,array('.','..'))) ) )
|
||||
$glob[] = ($flags&GLOB_PATH?$path.'/':'') . $file . ($flags&GLOB_MARK?'/':'');
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
if (!($flags&GLOB_NOSORT)) sort($glob);
|
||||
return $glob;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
@ -239,7 +247,7 @@ function safe_glob($pattern, $flags=0) {
|
|||
*/
|
||||
if (!function_exists('fnmatch')) {
|
||||
function fnmatch($pattern, $string) {
|
||||
return @preg_match('/^' . strtr(addcslashes($pattern, '\\/.+^$(){}=!<>|'), array('*' => '.*', '?' => '.?')) . '$/i', $string);
|
||||
return @preg_match('/^' . strtr(addcslashes($pattern, '\\/.+^$(){}=!<>|'), array('*' => '.*', '?' => '.?')) . '$/i', $string);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -261,7 +269,7 @@ function array_prepend($array, $string, $deep=false) {
|
|||
else
|
||||
$array[$key] = $string.$element;
|
||||
return $array;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -519,13 +527,13 @@ function stdapi_fs_md5($req, &$pkt) {
|
|||
$path_tlv = packet_get_tlv($req, TLV_TYPE_FILE_PATH);
|
||||
$path = cononicalize_path($path_tlv['value']);
|
||||
|
||||
if (is_callable("md5_file")) {
|
||||
$md5 = md5_file($path);
|
||||
} else {
|
||||
$md5 = md5(file_get_contents($path));
|
||||
}
|
||||
$md5 = pack("H*", $md5);
|
||||
# Ghetto abuse of file name type to indicate the md5 result
|
||||
if (is_callable("md5_file")) {
|
||||
$md5 = md5_file($path);
|
||||
} else {
|
||||
$md5 = md5(file_get_contents($path));
|
||||
}
|
||||
$md5 = pack("H*", $md5);
|
||||
# Ghetto abuse of file name type to indicate the md5 result
|
||||
packet_add_tlv($pkt, create_tlv(TLV_TYPE_FILE_NAME, $md5));
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
@ -538,13 +546,13 @@ function stdapi_fs_sha1($req, &$pkt) {
|
|||
$path_tlv = packet_get_tlv($req, TLV_TYPE_FILE_PATH);
|
||||
$path = cononicalize_path($path_tlv['value']);
|
||||
|
||||
if (is_callable("sha1_file")) {
|
||||
$sha1 = sha1_file($path);
|
||||
} else {
|
||||
$sha1 = sha1(file_get_contents($path));
|
||||
}
|
||||
$sha1 = pack("H*", $sha1);
|
||||
# Ghetto abuse of file name type to indicate the sha1 result
|
||||
if (is_callable("sha1_file")) {
|
||||
$sha1 = sha1_file($path);
|
||||
} else {
|
||||
$sha1 = sha1(file_get_contents($path));
|
||||
}
|
||||
$sha1 = pack("H*", $sha1);
|
||||
# Ghetto abuse of file name type to indicate the sha1 result
|
||||
packet_add_tlv($pkt, create_tlv(TLV_TYPE_FILE_NAME, $sha1));
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
@ -573,6 +581,41 @@ function stdapi_sys_config_getuid($req, &$pkt) {
|
|||
}
|
||||
}
|
||||
|
||||
if (!function_exists('stdapi_sys_config_getenv')) {
|
||||
register_command('stdapi_sys_config_getenv');
|
||||
function stdapi_sys_config_getenv($req, &$pkt) {
|
||||
my_print("doing getenv");
|
||||
|
||||
$variable_tlvs = packet_get_all_tlvs($req, TLV_TYPE_ENV_VARIABLE);
|
||||
|
||||
# If we decide some day to have sys.config.getenv return all env
|
||||
# vars when given an empty search list, this is one way to do it.
|
||||
#if (empty($variable_tlvs)) {
|
||||
# # We don't have a var to look up, return all of 'em
|
||||
# $variables = array_keys($_SERVER);
|
||||
#} else {
|
||||
# $variables = array();
|
||||
# foreach ($variable_tlvs as $tlv) {
|
||||
# array_push($variables, $tlv['value']);
|
||||
# }
|
||||
#}
|
||||
|
||||
foreach ($variable_tlvs as $name) {
|
||||
$canonical_name = str_replace(array("$","%"), "", $name['value']);
|
||||
$env = getenv($canonical_name);
|
||||
if ($env !== FALSE) {
|
||||
$grp = "";
|
||||
$grp .= tlv_pack(create_tlv(TLV_TYPE_ENV_VARIABLE, $canonical_name));
|
||||
$grp .= tlv_pack(create_tlv(TLV_TYPE_ENV_VALUE, $env));
|
||||
packet_add_tlv($pkt, create_tlv(TLV_TYPE_ENV_GROUP, $grp));
|
||||
}
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Unimplemented becuase it's unimplementable
|
||||
#if (!function_exists('stdapi_sys_config_rev2self')) {
|
||||
#register_command('stdapi_sys_config_rev2self');
|
||||
|
@ -696,24 +739,24 @@ function close_process($proc) {
|
|||
foreach ($proc['pipes'] as $f) {
|
||||
@fclose($f);
|
||||
}
|
||||
if (is_callable('proc_get_status')) {
|
||||
$status = proc_get_status($proc['handle']);
|
||||
} else {
|
||||
# fake a running process on php < 4.3
|
||||
$status = array('running' => true);
|
||||
}
|
||||
if (is_callable('proc_get_status')) {
|
||||
$status = proc_get_status($proc['handle']);
|
||||
} else {
|
||||
# fake a running process on php < 4.3
|
||||
$status = array('running' => true);
|
||||
}
|
||||
|
||||
# proc_close blocks waiting for the child to exit, so if it's still
|
||||
# running, don't take a chance on deadlock and just sigkill it if we
|
||||
# can. We can't on php < 4.3, so don't do anything. This will leave
|
||||
# zombie processes, but that's better than deadlock.
|
||||
if ($status['running'] == false) {
|
||||
proc_close($proc['handle']);
|
||||
} else {
|
||||
if (is_callable('proc_terminate')) {
|
||||
proc_terminate($proc['handle'], 9);
|
||||
}
|
||||
}
|
||||
# proc_close blocks waiting for the child to exit, so if it's still
|
||||
# running, don't take a chance on deadlock and just sigkill it if we
|
||||
# can. We can't on php < 4.3, so don't do anything. This will leave
|
||||
# zombie processes, but that's better than deadlock.
|
||||
if ($status['running'] == false) {
|
||||
proc_close($proc['handle']);
|
||||
} else {
|
||||
if (is_callable('proc_terminate')) {
|
||||
proc_terminate($proc['handle'], 9);
|
||||
}
|
||||
}
|
||||
if (array_key_exists('cid', $proc) && $channel_process_map[$proc['cid']]) {
|
||||
unset($channel_process_map[$proc['cid']]);
|
||||
}
|
||||
|
|
|
@ -86,170 +86,185 @@ TLV_META_TYPE_MASK = (1<<31)+(1<<30)+(1<<29)+(1<<19)+(1<<18)+(1<<17)+(1<<16)
|
|||
#
|
||||
# TLV Specific Types
|
||||
#
|
||||
TLV_TYPE_ANY = TLV_META_TYPE_NONE | 0
|
||||
TLV_TYPE_METHOD = TLV_META_TYPE_STRING | 1
|
||||
TLV_TYPE_REQUEST_ID = TLV_META_TYPE_STRING | 2
|
||||
TLV_TYPE_EXCEPTION = TLV_META_TYPE_GROUP | 3
|
||||
TLV_TYPE_RESULT = TLV_META_TYPE_UINT | 4
|
||||
TLV_TYPE_ANY = TLV_META_TYPE_NONE | 0
|
||||
TLV_TYPE_METHOD = TLV_META_TYPE_STRING | 1
|
||||
TLV_TYPE_REQUEST_ID = TLV_META_TYPE_STRING | 2
|
||||
TLV_TYPE_EXCEPTION = TLV_META_TYPE_GROUP | 3
|
||||
TLV_TYPE_RESULT = TLV_META_TYPE_UINT | 4
|
||||
|
||||
TLV_TYPE_STRING = TLV_META_TYPE_STRING | 10
|
||||
TLV_TYPE_UINT = TLV_META_TYPE_UINT | 11
|
||||
TLV_TYPE_BOOL = TLV_META_TYPE_BOOL | 12
|
||||
TLV_TYPE_STRING = TLV_META_TYPE_STRING | 10
|
||||
TLV_TYPE_UINT = TLV_META_TYPE_UINT | 11
|
||||
TLV_TYPE_BOOL = TLV_META_TYPE_BOOL | 12
|
||||
|
||||
TLV_TYPE_LENGTH = TLV_META_TYPE_UINT | 25
|
||||
TLV_TYPE_DATA = TLV_META_TYPE_RAW | 26
|
||||
TLV_TYPE_FLAGS = TLV_META_TYPE_UINT | 27
|
||||
TLV_TYPE_LENGTH = TLV_META_TYPE_UINT | 25
|
||||
TLV_TYPE_DATA = TLV_META_TYPE_RAW | 26
|
||||
TLV_TYPE_FLAGS = TLV_META_TYPE_UINT | 27
|
||||
|
||||
TLV_TYPE_CHANNEL_ID = TLV_META_TYPE_UINT | 50
|
||||
TLV_TYPE_CHANNEL_TYPE = TLV_META_TYPE_STRING | 51
|
||||
TLV_TYPE_CHANNEL_DATA = TLV_META_TYPE_RAW | 52
|
||||
TLV_TYPE_CHANNEL_DATA_GROUP = TLV_META_TYPE_GROUP | 53
|
||||
TLV_TYPE_CHANNEL_CLASS = TLV_META_TYPE_UINT | 54
|
||||
TLV_TYPE_CHANNEL_ID = TLV_META_TYPE_UINT | 50
|
||||
TLV_TYPE_CHANNEL_TYPE = TLV_META_TYPE_STRING | 51
|
||||
TLV_TYPE_CHANNEL_DATA = TLV_META_TYPE_RAW | 52
|
||||
TLV_TYPE_CHANNEL_DATA_GROUP = TLV_META_TYPE_GROUP | 53
|
||||
TLV_TYPE_CHANNEL_CLASS = TLV_META_TYPE_UINT | 54
|
||||
|
||||
##
|
||||
# General
|
||||
##
|
||||
TLV_TYPE_HANDLE = TLV_META_TYPE_UINT | 600
|
||||
TLV_TYPE_INHERIT = TLV_META_TYPE_BOOL | 601
|
||||
TLV_TYPE_PROCESS_HANDLE = TLV_META_TYPE_UINT | 630
|
||||
TLV_TYPE_THREAD_HANDLE = TLV_META_TYPE_UINT | 631
|
||||
TLV_TYPE_HANDLE = TLV_META_TYPE_UINT | 600
|
||||
TLV_TYPE_INHERIT = TLV_META_TYPE_BOOL | 601
|
||||
TLV_TYPE_PROCESS_HANDLE = TLV_META_TYPE_UINT | 630
|
||||
TLV_TYPE_THREAD_HANDLE = TLV_META_TYPE_UINT | 631
|
||||
|
||||
##
|
||||
# Fs
|
||||
##
|
||||
TLV_TYPE_DIRECTORY_PATH = TLV_META_TYPE_STRING | 1200
|
||||
TLV_TYPE_FILE_NAME = TLV_META_TYPE_STRING | 1201
|
||||
TLV_TYPE_FILE_PATH = TLV_META_TYPE_STRING | 1202
|
||||
TLV_TYPE_FILE_MODE = TLV_META_TYPE_STRING | 1203
|
||||
TLV_TYPE_FILE_SIZE = TLV_META_TYPE_UINT | 1204
|
||||
TLV_TYPE_DIRECTORY_PATH = TLV_META_TYPE_STRING | 1200
|
||||
TLV_TYPE_FILE_NAME = TLV_META_TYPE_STRING | 1201
|
||||
TLV_TYPE_FILE_PATH = TLV_META_TYPE_STRING | 1202
|
||||
TLV_TYPE_FILE_MODE = TLV_META_TYPE_STRING | 1203
|
||||
TLV_TYPE_FILE_SIZE = TLV_META_TYPE_UINT | 1204
|
||||
|
||||
TLV_TYPE_STAT_BUF = TLV_META_TYPE_COMPLEX | 1220
|
||||
TLV_TYPE_STAT_BUF = TLV_META_TYPE_COMPLEX | 1220
|
||||
|
||||
TLV_TYPE_SEARCH_RECURSE = TLV_META_TYPE_BOOL | 1230
|
||||
TLV_TYPE_SEARCH_GLOB = TLV_META_TYPE_STRING | 1231
|
||||
TLV_TYPE_SEARCH_ROOT = TLV_META_TYPE_STRING | 1232
|
||||
TLV_TYPE_SEARCH_RESULTS = TLV_META_TYPE_GROUP | 1233
|
||||
TLV_TYPE_SEARCH_RECURSE = TLV_META_TYPE_BOOL | 1230
|
||||
TLV_TYPE_SEARCH_GLOB = TLV_META_TYPE_STRING | 1231
|
||||
TLV_TYPE_SEARCH_ROOT = TLV_META_TYPE_STRING | 1232
|
||||
TLV_TYPE_SEARCH_RESULTS = TLV_META_TYPE_GROUP | 1233
|
||||
|
||||
##
|
||||
# Net
|
||||
##
|
||||
TLV_TYPE_HOST_NAME = TLV_META_TYPE_STRING | 1400
|
||||
TLV_TYPE_PORT = TLV_META_TYPE_UINT | 1401
|
||||
TLV_TYPE_HOST_NAME = TLV_META_TYPE_STRING | 1400
|
||||
TLV_TYPE_PORT = TLV_META_TYPE_UINT | 1401
|
||||
|
||||
TLV_TYPE_SUBNET = TLV_META_TYPE_RAW | 1420
|
||||
TLV_TYPE_NETMASK = TLV_META_TYPE_RAW | 1421
|
||||
TLV_TYPE_GATEWAY = TLV_META_TYPE_RAW | 1422
|
||||
TLV_TYPE_NETWORK_ROUTE = TLV_META_TYPE_GROUP | 1423
|
||||
TLV_TYPE_SUBNET = TLV_META_TYPE_RAW | 1420
|
||||
TLV_TYPE_NETMASK = TLV_META_TYPE_RAW | 1421
|
||||
TLV_TYPE_GATEWAY = TLV_META_TYPE_RAW | 1422
|
||||
TLV_TYPE_NETWORK_ROUTE = TLV_META_TYPE_GROUP | 1423
|
||||
|
||||
TLV_TYPE_IP = TLV_META_TYPE_RAW | 1430
|
||||
TLV_TYPE_MAC_ADDRESS = TLV_META_TYPE_RAW | 1431
|
||||
TLV_TYPE_MAC_NAME = TLV_META_TYPE_STRING | 1432
|
||||
TLV_TYPE_NETWORK_INTERFACE = TLV_META_TYPE_GROUP | 1433
|
||||
TLV_TYPE_IP = TLV_META_TYPE_RAW | 1430
|
||||
TLV_TYPE_MAC_ADDRESS = TLV_META_TYPE_RAW | 1431
|
||||
TLV_TYPE_MAC_NAME = TLV_META_TYPE_STRING | 1432
|
||||
TLV_TYPE_NETWORK_INTERFACE = TLV_META_TYPE_GROUP | 1433
|
||||
|
||||
TLV_TYPE_SUBNET_STRING = TLV_META_TYPE_STRING | 1440
|
||||
TLV_TYPE_NETMASK_STRING = TLV_META_TYPE_STRING | 1441
|
||||
TLV_TYPE_GATEWAY_STRING = TLV_META_TYPE_STRING | 1442
|
||||
TLV_TYPE_ROUTE_METRIC = TLV_META_TYPE_UINT | 1443
|
||||
TLV_TYPE_ADDR_TYPE = TLV_META_TYPE_UINT | 1444
|
||||
TLV_TYPE_SUBNET_STRING = TLV_META_TYPE_STRING | 1440
|
||||
TLV_TYPE_NETMASK_STRING = TLV_META_TYPE_STRING | 1441
|
||||
TLV_TYPE_GATEWAY_STRING = TLV_META_TYPE_STRING | 1442
|
||||
TLV_TYPE_ROUTE_METRIC = TLV_META_TYPE_UINT | 1443
|
||||
TLV_TYPE_ADDR_TYPE = TLV_META_TYPE_UINT | 1444
|
||||
|
||||
##
|
||||
# Socket
|
||||
TLV_TYPE_PEER_HOST = TLV_META_TYPE_STRING | 1500
|
||||
TLV_TYPE_PEER_PORT = TLV_META_TYPE_UINT | 1501
|
||||
TLV_TYPE_LOCAL_HOST = TLV_META_TYPE_STRING | 1502
|
||||
TLV_TYPE_LOCAL_PORT = TLV_META_TYPE_UINT | 1503
|
||||
TLV_TYPE_CONNECT_RETRIES = TLV_META_TYPE_UINT | 1504
|
||||
##
|
||||
TLV_TYPE_PEER_HOST = TLV_META_TYPE_STRING | 1500
|
||||
TLV_TYPE_PEER_PORT = TLV_META_TYPE_UINT | 1501
|
||||
TLV_TYPE_LOCAL_HOST = TLV_META_TYPE_STRING | 1502
|
||||
TLV_TYPE_LOCAL_PORT = TLV_META_TYPE_UINT | 1503
|
||||
TLV_TYPE_CONNECT_RETRIES = TLV_META_TYPE_UINT | 1504
|
||||
|
||||
TLV_TYPE_SHUTDOWN_HOW = TLV_META_TYPE_UINT | 1530
|
||||
TLV_TYPE_SHUTDOWN_HOW = TLV_META_TYPE_UINT | 1530
|
||||
|
||||
##
|
||||
# Registry
|
||||
TLV_TYPE_HKEY = TLV_META_TYPE_UINT | 1000
|
||||
TLV_TYPE_ROOT_KEY = TLV_TYPE_HKEY
|
||||
TLV_TYPE_BASE_KEY = TLV_META_TYPE_STRING | 1001
|
||||
TLV_TYPE_PERMISSION = TLV_META_TYPE_UINT | 1002
|
||||
TLV_TYPE_KEY_NAME = TLV_META_TYPE_STRING | 1003
|
||||
TLV_TYPE_VALUE_NAME = TLV_META_TYPE_STRING | 1010
|
||||
TLV_TYPE_VALUE_TYPE = TLV_META_TYPE_UINT | 1011
|
||||
TLV_TYPE_VALUE_DATA = TLV_META_TYPE_RAW | 1012
|
||||
TLV_TYPE_TARGET_HOST = TLV_META_TYPE_STRING | 1013
|
||||
##
|
||||
TLV_TYPE_HKEY = TLV_META_TYPE_UINT | 1000
|
||||
TLV_TYPE_ROOT_KEY = TLV_TYPE_HKEY
|
||||
TLV_TYPE_BASE_KEY = TLV_META_TYPE_STRING | 1001
|
||||
TLV_TYPE_PERMISSION = TLV_META_TYPE_UINT | 1002
|
||||
TLV_TYPE_KEY_NAME = TLV_META_TYPE_STRING | 1003
|
||||
TLV_TYPE_VALUE_NAME = TLV_META_TYPE_STRING | 1010
|
||||
TLV_TYPE_VALUE_TYPE = TLV_META_TYPE_UINT | 1011
|
||||
TLV_TYPE_VALUE_DATA = TLV_META_TYPE_RAW | 1012
|
||||
TLV_TYPE_TARGET_HOST = TLV_META_TYPE_STRING | 1013
|
||||
|
||||
##
|
||||
# Config
|
||||
TLV_TYPE_COMPUTER_NAME = TLV_META_TYPE_STRING | 1040
|
||||
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_COMPUTER_NAME = TLV_META_TYPE_STRING | 1040
|
||||
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
|
||||
|
||||
##
|
||||
# Environment
|
||||
##
|
||||
TLV_TYPE_ENV_VARIABLE = TLV_META_TYPE_STRING | 1100
|
||||
TLV_TYPE_ENV_VALUE = TLV_META_TYPE_STRING | 1101
|
||||
TLV_TYPE_ENV_GROUP = TLV_META_TYPE_GROUP | 1102
|
||||
|
||||
DELETE_KEY_FLAG_RECURSIVE = (1 << 0)
|
||||
|
||||
##
|
||||
# Process
|
||||
TLV_TYPE_BASE_ADDRESS = TLV_META_TYPE_UINT | 2000
|
||||
TLV_TYPE_ALLOCATION_TYPE = TLV_META_TYPE_UINT | 2001
|
||||
TLV_TYPE_PROTECTION = TLV_META_TYPE_UINT | 2002
|
||||
TLV_TYPE_PROCESS_PERMS = TLV_META_TYPE_UINT | 2003
|
||||
TLV_TYPE_PROCESS_MEMORY = TLV_META_TYPE_RAW | 2004
|
||||
TLV_TYPE_ALLOC_BASE_ADDRESS = TLV_META_TYPE_UINT | 2005
|
||||
TLV_TYPE_MEMORY_STATE = TLV_META_TYPE_UINT | 2006
|
||||
TLV_TYPE_MEMORY_TYPE = TLV_META_TYPE_UINT | 2007
|
||||
TLV_TYPE_ALLOC_PROTECTION = TLV_META_TYPE_UINT | 2008
|
||||
TLV_TYPE_PID = TLV_META_TYPE_UINT | 2300
|
||||
TLV_TYPE_PROCESS_NAME = TLV_META_TYPE_STRING | 2301
|
||||
TLV_TYPE_PROCESS_PATH = TLV_META_TYPE_STRING | 2302
|
||||
TLV_TYPE_PROCESS_GROUP = TLV_META_TYPE_GROUP | 2303
|
||||
TLV_TYPE_PROCESS_FLAGS = TLV_META_TYPE_UINT | 2304
|
||||
TLV_TYPE_PROCESS_ARGUMENTS = TLV_META_TYPE_STRING | 2305
|
||||
TLV_TYPE_PROCESS_ARCH = TLV_META_TYPE_UINT | 2306
|
||||
TLV_TYPE_PARENT_PID = TLV_META_TYPE_UINT | 2307
|
||||
##
|
||||
TLV_TYPE_BASE_ADDRESS = TLV_META_TYPE_UINT | 2000
|
||||
TLV_TYPE_ALLOCATION_TYPE = TLV_META_TYPE_UINT | 2001
|
||||
TLV_TYPE_PROTECTION = TLV_META_TYPE_UINT | 2002
|
||||
TLV_TYPE_PROCESS_PERMS = TLV_META_TYPE_UINT | 2003
|
||||
TLV_TYPE_PROCESS_MEMORY = TLV_META_TYPE_RAW | 2004
|
||||
TLV_TYPE_ALLOC_BASE_ADDRESS = TLV_META_TYPE_UINT | 2005
|
||||
TLV_TYPE_MEMORY_STATE = TLV_META_TYPE_UINT | 2006
|
||||
TLV_TYPE_MEMORY_TYPE = TLV_META_TYPE_UINT | 2007
|
||||
TLV_TYPE_ALLOC_PROTECTION = TLV_META_TYPE_UINT | 2008
|
||||
TLV_TYPE_PID = TLV_META_TYPE_UINT | 2300
|
||||
TLV_TYPE_PROCESS_NAME = TLV_META_TYPE_STRING | 2301
|
||||
TLV_TYPE_PROCESS_PATH = TLV_META_TYPE_STRING | 2302
|
||||
TLV_TYPE_PROCESS_GROUP = TLV_META_TYPE_GROUP | 2303
|
||||
TLV_TYPE_PROCESS_FLAGS = TLV_META_TYPE_UINT | 2304
|
||||
TLV_TYPE_PROCESS_ARGUMENTS = TLV_META_TYPE_STRING | 2305
|
||||
TLV_TYPE_PROCESS_ARCH = TLV_META_TYPE_UINT | 2306
|
||||
TLV_TYPE_PARENT_PID = TLV_META_TYPE_UINT | 2307
|
||||
|
||||
TLV_TYPE_IMAGE_FILE = TLV_META_TYPE_STRING | 2400
|
||||
TLV_TYPE_IMAGE_FILE_PATH = TLV_META_TYPE_STRING | 2401
|
||||
TLV_TYPE_PROCEDURE_NAME = TLV_META_TYPE_STRING | 2402
|
||||
TLV_TYPE_PROCEDURE_ADDRESS = TLV_META_TYPE_UINT | 2403
|
||||
TLV_TYPE_IMAGE_BASE = TLV_META_TYPE_UINT | 2404
|
||||
TLV_TYPE_IMAGE_GROUP = TLV_META_TYPE_GROUP | 2405
|
||||
TLV_TYPE_IMAGE_NAME = TLV_META_TYPE_STRING | 2406
|
||||
TLV_TYPE_IMAGE_FILE = TLV_META_TYPE_STRING | 2400
|
||||
TLV_TYPE_IMAGE_FILE_PATH = TLV_META_TYPE_STRING | 2401
|
||||
TLV_TYPE_PROCEDURE_NAME = TLV_META_TYPE_STRING | 2402
|
||||
TLV_TYPE_PROCEDURE_ADDRESS = TLV_META_TYPE_UINT | 2403
|
||||
TLV_TYPE_IMAGE_BASE = TLV_META_TYPE_UINT | 2404
|
||||
TLV_TYPE_IMAGE_GROUP = TLV_META_TYPE_GROUP | 2405
|
||||
TLV_TYPE_IMAGE_NAME = TLV_META_TYPE_STRING | 2406
|
||||
|
||||
TLV_TYPE_THREAD_ID = TLV_META_TYPE_UINT | 2500
|
||||
TLV_TYPE_THREAD_PERMS = TLV_META_TYPE_UINT | 2502
|
||||
TLV_TYPE_EXIT_CODE = TLV_META_TYPE_UINT | 2510
|
||||
TLV_TYPE_ENTRY_POINT = TLV_META_TYPE_UINT | 2511
|
||||
TLV_TYPE_ENTRY_PARAMETER = TLV_META_TYPE_UINT | 2512
|
||||
TLV_TYPE_CREATION_FLAGS = TLV_META_TYPE_UINT | 2513
|
||||
TLV_TYPE_THREAD_ID = TLV_META_TYPE_UINT | 2500
|
||||
TLV_TYPE_THREAD_PERMS = TLV_META_TYPE_UINT | 2502
|
||||
TLV_TYPE_EXIT_CODE = TLV_META_TYPE_UINT | 2510
|
||||
TLV_TYPE_ENTRY_POINT = TLV_META_TYPE_UINT | 2511
|
||||
TLV_TYPE_ENTRY_PARAMETER = TLV_META_TYPE_UINT | 2512
|
||||
TLV_TYPE_CREATION_FLAGS = TLV_META_TYPE_UINT | 2513
|
||||
|
||||
TLV_TYPE_REGISTER_NAME = TLV_META_TYPE_STRING | 2540
|
||||
TLV_TYPE_REGISTER_SIZE = TLV_META_TYPE_UINT | 2541
|
||||
TLV_TYPE_REGISTER_VALUE_32 = TLV_META_TYPE_UINT | 2542
|
||||
TLV_TYPE_REGISTER = TLV_META_TYPE_GROUP | 2550
|
||||
TLV_TYPE_REGISTER_NAME = TLV_META_TYPE_STRING | 2540
|
||||
TLV_TYPE_REGISTER_SIZE = TLV_META_TYPE_UINT | 2541
|
||||
TLV_TYPE_REGISTER_VALUE_32 = TLV_META_TYPE_UINT | 2542
|
||||
TLV_TYPE_REGISTER = TLV_META_TYPE_GROUP | 2550
|
||||
|
||||
##
|
||||
# Ui
|
||||
##
|
||||
TLV_TYPE_IDLE_TIME = TLV_META_TYPE_UINT | 3000
|
||||
TLV_TYPE_KEYS_DUMP = TLV_META_TYPE_STRING | 3001
|
||||
TLV_TYPE_DESKTOP = TLV_META_TYPE_STRING | 3002
|
||||
TLV_TYPE_IDLE_TIME = TLV_META_TYPE_UINT | 3000
|
||||
TLV_TYPE_KEYS_DUMP = TLV_META_TYPE_STRING | 3001
|
||||
TLV_TYPE_DESKTOP = TLV_META_TYPE_STRING | 3002
|
||||
|
||||
##
|
||||
# Event Log
|
||||
##
|
||||
TLV_TYPE_EVENT_SOURCENAME = TLV_META_TYPE_STRING | 4000
|
||||
TLV_TYPE_EVENT_HANDLE = TLV_META_TYPE_UINT | 4001
|
||||
TLV_TYPE_EVENT_NUMRECORDS = TLV_META_TYPE_UINT | 4002
|
||||
TLV_TYPE_EVENT_SOURCENAME = TLV_META_TYPE_STRING | 4000
|
||||
TLV_TYPE_EVENT_HANDLE = TLV_META_TYPE_UINT | 4001
|
||||
TLV_TYPE_EVENT_NUMRECORDS = TLV_META_TYPE_UINT | 4002
|
||||
|
||||
TLV_TYPE_EVENT_READFLAGS = TLV_META_TYPE_UINT | 4003
|
||||
TLV_TYPE_EVENT_RECORDOFFSET = TLV_META_TYPE_UINT | 4004
|
||||
TLV_TYPE_EVENT_READFLAGS = TLV_META_TYPE_UINT | 4003
|
||||
TLV_TYPE_EVENT_RECORDOFFSET = TLV_META_TYPE_UINT | 4004
|
||||
|
||||
TLV_TYPE_EVENT_RECORDNUMBER = TLV_META_TYPE_UINT | 4006
|
||||
TLV_TYPE_EVENT_TIMEGENERATED = TLV_META_TYPE_UINT | 4007
|
||||
TLV_TYPE_EVENT_TIMEWRITTEN = TLV_META_TYPE_UINT | 4008
|
||||
TLV_TYPE_EVENT_ID = TLV_META_TYPE_UINT | 4009
|
||||
TLV_TYPE_EVENT_TYPE = TLV_META_TYPE_UINT | 4010
|
||||
TLV_TYPE_EVENT_CATEGORY = TLV_META_TYPE_UINT | 4011
|
||||
TLV_TYPE_EVENT_STRING = TLV_META_TYPE_STRING | 4012
|
||||
TLV_TYPE_EVENT_DATA = TLV_META_TYPE_RAW | 4013
|
||||
TLV_TYPE_EVENT_RECORDNUMBER = TLV_META_TYPE_UINT | 4006
|
||||
TLV_TYPE_EVENT_TIMEGENERATED = TLV_META_TYPE_UINT | 4007
|
||||
TLV_TYPE_EVENT_TIMEWRITTEN = TLV_META_TYPE_UINT | 4008
|
||||
TLV_TYPE_EVENT_ID = TLV_META_TYPE_UINT | 4009
|
||||
TLV_TYPE_EVENT_TYPE = TLV_META_TYPE_UINT | 4010
|
||||
TLV_TYPE_EVENT_CATEGORY = TLV_META_TYPE_UINT | 4011
|
||||
TLV_TYPE_EVENT_STRING = TLV_META_TYPE_STRING | 4012
|
||||
TLV_TYPE_EVENT_DATA = TLV_META_TYPE_RAW | 4013
|
||||
|
||||
##
|
||||
# Power
|
||||
##
|
||||
TLV_TYPE_POWER_FLAGS = TLV_META_TYPE_UINT | 4100
|
||||
TLV_TYPE_POWER_REASON = TLV_META_TYPE_UINT | 4101
|
||||
TLV_TYPE_POWER_FLAGS = TLV_META_TYPE_UINT | 4100
|
||||
TLV_TYPE_POWER_REASON = TLV_META_TYPE_UINT | 4101
|
||||
|
||||
##
|
||||
# Sys
|
||||
|
@ -367,6 +382,18 @@ def stdapi_sys_config_getuid(request, response):
|
|||
response += tlv_pack(TLV_TYPE_USER_NAME, getpass.getuser())
|
||||
return ERROR_SUCCESS, response
|
||||
|
||||
@meterpreter.register_function
|
||||
def stdapi_sys_config_getenv(request, response):
|
||||
for env_var in packet_enum_tlvs(request, TLV_TYPE_ENV_VARIABLE):
|
||||
pgroup = ''
|
||||
env_var = env_var['value'].translate(None, '%$')
|
||||
env_val = os.environ.get(env_var)
|
||||
if env_val:
|
||||
pgroup += tlv_pack(TLV_TYPE_ENV_VARIABLE, env_var)
|
||||
pgroup += tlv_pack(TLV_TYPE_ENV_VALUE, env_val)
|
||||
response += tlv_pack(TLV_TYPE_ENV_GROUP, pgroup)
|
||||
return ERROR_SUCCESS, response
|
||||
|
||||
@meterpreter.register_function
|
||||
def stdapi_sys_config_sysinfo(request, response):
|
||||
uname_info = platform.uname()
|
||||
|
|
|
@ -680,6 +680,30 @@ function tlv_pack($tlv) {
|
|||
return $ret;
|
||||
}
|
||||
|
||||
function tlv_unpack($raw_tlv) {
|
||||
$tlv = unpack("Nlen/Ntype", substr($raw_tlv, 0, 8));
|
||||
$type = $tlv['type'];
|
||||
my_print("len: {$tlv['len']}, type: {$tlv['type']}");
|
||||
if (($type & TLV_META_TYPE_STRING) == TLV_META_TYPE_STRING) {
|
||||
$tlv = unpack("Nlen/Ntype/a*value", substr($raw_tlv, 0, $tlv['len']));
|
||||
}
|
||||
elseif (($type & TLV_META_TYPE_UINT) == TLV_META_TYPE_UINT) {
|
||||
$tlv = unpack("Nlen/Ntype/Nvalue", substr($raw_tlv, 0, $tlv['len']));
|
||||
}
|
||||
elseif (($type & TLV_META_TYPE_BOOL) == TLV_META_TYPE_BOOL) {
|
||||
$tlv = unpack("Nlen/Ntype/cvalue", substr($raw_tlv, 0, $tlv['len']));
|
||||
}
|
||||
elseif (($type & TLV_META_TYPE_RAW) == TLV_META_TYPE_RAW) {
|
||||
$tlv = unpack("Nlen/Ntype", $raw_tlv);
|
||||
$tlv['value'] = substr($raw_tlv, 8, $tlv['len']-8);
|
||||
}
|
||||
else {
|
||||
my_print("Wtf type is this? $type");
|
||||
$tlv = null;
|
||||
}
|
||||
return $tlv;
|
||||
}
|
||||
|
||||
function packet_add_tlv(&$pkt, $tlv) {
|
||||
$pkt .= tlv_pack($tlv);
|
||||
}
|
||||
|
@ -689,27 +713,10 @@ function packet_get_tlv($pkt, $type) {
|
|||
# Start at offset 8 to skip past the packet header
|
||||
$offset = 8;
|
||||
while ($offset < strlen($pkt)) {
|
||||
$tlv = unpack("Nlen/Ntype", substr($pkt, $offset, 8));
|
||||
$tlv = tlv_unpack(substr($pkt, $offset));
|
||||
#my_print("len: {$tlv['len']}, type: {$tlv['type']}");
|
||||
if ($type == ($tlv['type'] & ~TLV_META_TYPE_COMPRESSED)) {
|
||||
#my_print("Found one at offset $offset");
|
||||
if (($type & TLV_META_TYPE_STRING) == TLV_META_TYPE_STRING) {
|
||||
$tlv = unpack("Nlen/Ntype/a*value", substr($pkt, $offset, $tlv['len']));
|
||||
}
|
||||
elseif (($type & TLV_META_TYPE_UINT) == TLV_META_TYPE_UINT) {
|
||||
$tlv = unpack("Nlen/Ntype/Nvalue", substr($pkt, $offset, $tlv['len']));
|
||||
}
|
||||
elseif (($type & TLV_META_TYPE_BOOL) == TLV_META_TYPE_BOOL) {
|
||||
$tlv = unpack("Nlen/Ntype/cvalue", substr($pkt, $offset, $tlv['len']));
|
||||
}
|
||||
elseif (($type & TLV_META_TYPE_RAW) == TLV_META_TYPE_RAW) {
|
||||
$tlv = unpack("Nlen/Ntype", substr($pkt, $offset, 8));
|
||||
$tlv['value'] = substr($pkt, $offset+8, $tlv['len']-8);
|
||||
}
|
||||
else {
|
||||
my_print("Wtf type is this? $type");
|
||||
$tlv = null;
|
||||
}
|
||||
return $tlv;
|
||||
}
|
||||
$offset += $tlv['len'];
|
||||
|
@ -719,6 +726,27 @@ function packet_get_tlv($pkt, $type) {
|
|||
}
|
||||
|
||||
|
||||
function packet_get_all_tlvs($pkt, $type) {
|
||||
my_print("Looking for all tlvs of type $type");
|
||||
# Start at offset 8 to skip past the packet header
|
||||
$offset = 8;
|
||||
$all = array();
|
||||
while ($offset < strlen($pkt)) {
|
||||
$tlv = tlv_unpack(substr($pkt, $offset));
|
||||
if ($tlv == NULL) {
|
||||
break;
|
||||
}
|
||||
my_print("len: {$tlv['len']}, type: {$tlv['type']}");
|
||||
if (empty($type) || $type == ($tlv['type'] & ~TLV_META_TYPE_COMPRESSED)) {
|
||||
my_print("Found one at offset $offset");
|
||||
array_push($all, $tlv);
|
||||
}
|
||||
$offset += $tlv['len'];
|
||||
}
|
||||
return $all;
|
||||
}
|
||||
|
||||
|
||||
##
|
||||
# Functions for genericizing the stream/socket conundrum
|
||||
##
|
||||
|
|
|
@ -33,6 +33,29 @@ class Config
|
|||
return client.unicode_filter_encode( response.get_tlv_value(TLV_TYPE_USER_NAME) )
|
||||
end
|
||||
|
||||
#
|
||||
# Returns a hash of requested environment variables, along with their values.
|
||||
# If a requested value doesn't exist in the response, then the value wasn't found.
|
||||
#
|
||||
def getenv(var_names)
|
||||
request = Packet.create_request('stdapi_sys_config_getenv')
|
||||
|
||||
var_names.each do |v|
|
||||
request.add_tlv(TLV_TYPE_ENV_VARIABLE, v)
|
||||
end
|
||||
|
||||
response = client.send_request(request)
|
||||
result = {}
|
||||
|
||||
response.each(TLV_TYPE_ENV_GROUP) do |env|
|
||||
var_name = env.get_tlv_value(TLV_TYPE_ENV_VARIABLE)
|
||||
var_value = env.get_tlv_value(TLV_TYPE_ENV_VALUE)
|
||||
result[var_name] = var_value
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
#
|
||||
# Returns a hash of information about the remote computer.
|
||||
#
|
||||
|
|
|
@ -117,6 +117,11 @@ TLV_TYPE_USER_NAME = TLV_META_TYPE_STRING | 1042
|
|||
TLV_TYPE_ARCHITECTURE = TLV_META_TYPE_STRING | 1043
|
||||
TLV_TYPE_LANG_SYSTEM = TLV_META_TYPE_STRING | 1044
|
||||
|
||||
# Environment
|
||||
TLV_TYPE_ENV_VARIABLE = TLV_META_TYPE_STRING | 1100
|
||||
TLV_TYPE_ENV_VALUE = TLV_META_TYPE_STRING | 1101
|
||||
TLV_TYPE_ENV_GROUP = TLV_META_TYPE_GROUP | 1102
|
||||
|
||||
DELETE_KEY_FLAG_RECURSIVE = (1 << 0)
|
||||
|
||||
# Process
|
||||
|
|
|
@ -88,6 +88,7 @@ class Console::CommandDispatcher::Stdapi::Sys
|
|||
"getpid" => "Get the current process identifier",
|
||||
"getprivs" => "Attempt to enable all privileges available to the current process",
|
||||
"getuid" => "Get the user that the server is running as",
|
||||
"getenv" => "Get one or more environment variable values",
|
||||
"kill" => "Terminate a process",
|
||||
"ps" => "List running processes",
|
||||
"reboot" => "Reboots the remote computer",
|
||||
|
@ -106,6 +107,7 @@ class Console::CommandDispatcher::Stdapi::Sys
|
|||
"getpid" => [ "stdapi_sys_process_getpid" ],
|
||||
"getprivs" => [ "stdapi_sys_config_getprivs" ],
|
||||
"getuid" => [ "stdapi_sys_config_getuid" ],
|
||||
"getenv" => [ "stdapi_sys_config_getenv" ],
|
||||
"kill" => [ "stdapi_sys_process_kill" ],
|
||||
"ps" => [ "stdapi_sys_process_get_processes" ],
|
||||
"reboot" => [ "stdapi_sys_power_exitwindows" ],
|
||||
|
@ -277,6 +279,30 @@ class Console::CommandDispatcher::Stdapi::Sys
|
|||
print_line("Server username: #{client.sys.config.getuid}")
|
||||
end
|
||||
|
||||
def cmd_getenv(*args)
|
||||
vars = client.sys.config.getenv(args)
|
||||
|
||||
if vars.length == 0
|
||||
print_error("None of the specified environment variables were found/set.")
|
||||
else
|
||||
table = Rex::Ui::Text::Table.new(
|
||||
'Header' => 'Environment Variables',
|
||||
'Indent' => 0,
|
||||
'SortIndex' => 1,
|
||||
'Columns' => [
|
||||
'Variable', 'Value'
|
||||
]
|
||||
)
|
||||
|
||||
vars.each do |var, val|
|
||||
table << [ var, val ]
|
||||
end
|
||||
|
||||
print_line
|
||||
print_line(table.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Clears the event log
|
||||
#
|
||||
|
|
Loading…
Reference in New Issue