1
mirror of https://github.com/rapid7/metasploit-framework synced 2024-11-12 11:52:01 +01:00

add a request type for grabbing the host's directory separator, fixes #4892

git-svn-id: file:///home/svn/framework3/trunk@13346 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
James Lee 2011-07-26 20:51:33 +00:00
parent d5ce83e136
commit 0f95070f3f
9 changed files with 79 additions and 6 deletions

View File

@ -391,6 +391,13 @@ function stdapi_fs_ls($req, &$pkt) {
}
}
if (!function_exists('stdapi_fs_separator')) {
function stdapi_fs_separator($req, &$pkt) {
packet_add_tlv($pkt, create_tlv(TLV_TYPE_STRING, DIRECTORY_SEPARATOR));
return ERROR_SUCCESS;
}
}
if (!function_exists('stdapi_fs_stat')) {
function stdapi_fs_stat($req, &$pkt) {
my_print("doing stat");

Binary file not shown.

View File

@ -35,6 +35,7 @@ public class Loader implements ExtensionLoader {
mgr.registerCommand("stdapi_fs_ls", stdapi_fs_ls.class);
mgr.registerCommand("stdapi_fs_mkdir", stdapi_fs_mkdir.class);
mgr.registerCommand("stdapi_fs_search", stdapi_fs_search.class);
mgr.registerCommand("stdapi_fs_separator", stdapi_fs_separator.class);
mgr.registerCommand("stdapi_fs_stat", stdapi_fs_stat.class, V1_2, V1_6);
mgr.registerCommand("stdapi_net_config_get_interfaces", stdapi_net_config_get_interfaces.class, V1_4, V1_6);
mgr.registerCommand("stdapi_net_config_get_routes", stdapi_net_config_get_routes.class, V1_4);

View File

@ -0,0 +1,20 @@
package com.metasploit.meterpreter.stdapi;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import com.metasploit.meterpreter.Meterpreter;
import com.metasploit.meterpreter.TLVPacket;
import com.metasploit.meterpreter.TLVType;
import com.metasploit.meterpreter.command.Command;
public class stdapi_fs_separator implements Command {
public int execute(Meterpreter meterpreter, TLVPacket request, TLVPacket response) throws Exception {
response.add(TLVType.TLV_TYPE_STRING, File.separator);
return ERROR_SUCCESS;
}
}

View File

@ -223,6 +223,29 @@ DWORD request_fs_file_channel_open(Remote *remote, Packet *packet)
return res;
}
/*
* Gets the directory separator for this system
*/
DWORD request_fs_separator(Remote *remote, Packet *packet)
{
Packet *response = packet_create_response(packet);
#ifdef _WIN32
LPCSTR separator = "\\";
#else
LPCSTR separator = "/";
#endif
packet_add_tlv_string(response, TLV_TYPE_STRING, separator);
// Set the result and transmit the response
packet_add_tlv_uint(response, TLV_TYPE_RESULT, ERROR_SUCCESS);
packet_transmit(remote, response, NULL);
return ERROR_SUCCESS;
}
/*
* Gets information about the file path that is supplied and returns it to the
* requestor

View File

@ -12,6 +12,7 @@ DWORD request_fs_chdir(Remote *remote, Packet *packet);
DWORD request_fs_mkdir(Remote *remote, Packet *packet);
DWORD request_fs_delete_dir(Remote *remote, Packet *packet);
DWORD request_fs_delete_file(Remote *remote, Packet *packet);
DWORD request_fs_separator(Remote *remote, Packet *packet);
DWORD request_fs_stat(Remote *remote, Packet *packet);
DWORD request_fs_file_expand_path(Remote *remote, Packet *packet);
DWORD request_fs_search( Remote * remote, Packet * packet );

View File

@ -71,6 +71,10 @@ Command customCommands[] =
{ request_fs_delete_file, { 0 }, 0 },
{ EMPTY_DISPATCH_HANDLER },
},
{ "stdapi_fs_separator",
{ request_fs_separator, { 0 }, 0 },
{ EMPTY_DISPATCH_HANDLER },
},
{ "stdapi_fs_stat",
{ request_fs_stat, { 0 }, 0 },
{ EMPTY_DISPATCH_HANDLER },

View File

@ -24,15 +24,32 @@ module Fs
class File < Rex::Post::Meterpreter::Extensions::Stdapi::Fs::IO
#
# This should be replaced with a platform-specific value.
# Return the directory separator, i.e.: "/" on unix, "\\" on windows
#
SEPARATOR = "\\"
Separator = "\\"
def File.separator()
# The separator won't change, so cache it to prevent sending
# unnecessary requests.
return @separator if @separator
include Rex::Post::File
request = Packet.create_request('stdapi_fs_separator')
# Fall back to the old behavior of always assuming windows. This
# allows meterpreter executables built before the addition of this
# command to continue functioning.
begin
response = client.send_request(request)
@separator = response.get_tlv_value(TLV_TYPE_STRING)
rescue RequestError
@separator = "\\"
end
return @separator
end
class << self
attr_accessor :client
alias :Separator :separator
alias :SEPARATOR :separator
end
#
@ -169,7 +186,7 @@ class File < Rex::Post::Meterpreter::Extensions::Stdapi::Fs::IO
stat.call('uploading', src, dest) if (stat)
if (File.basename(destination) != ::File.basename(src))
dest += File::SEPARATOR + ::File.basename(src)
dest += File.separator + ::File.basename(src)
end
upload_file(dest, src)