See #4986, make unicode encoding optional

git-svn-id: file:///home/svn/framework3/trunk@13275 4d416f70-5f16-0410-b530-b9f4589650da
unstable
HD Moore 2011-07-21 15:26:15 +00:00
parent f6e3065a51
commit 7dfb74be10
9 changed files with 62 additions and 33 deletions

View File

@ -36,7 +36,7 @@ class File < Rex::Post::Meterpreter::Channels::Pool
[
{
'type' => Rex::Post::Meterpreter::Extensions::Stdapi::TLV_TYPE_FILE_PATH,
'value' => Rex::Text.unicode_filter_decode( name )
'value' => client.unicode_filter_decode( name )
},
{
'type' => Rex::Post::Meterpreter::Extensions::Stdapi::TLV_TYPE_FILE_MODE,

View File

@ -115,6 +115,7 @@ class Client
self.response_timeout = opts[:timeout] || self.class.default_timeout
self.send_keepalives = true
self.encode_unicode = opts.has_key?(:encode_unicode) ? opts[:encode_unicode] : true
if opts[:passive_dispatcher]
initialize_passive_dispatcher
@ -367,6 +368,20 @@ class Client
return items.sort
end
#
# Encodes (or not) a UTF-8 string
#
def unicode_filter_encode(str)
self.encode_unicode ? client.unicode_filter_encode(str) : str
end
#
# Decodes (or not) a UTF-8 string
#
def unicode_filter_decode(str)
self.encode_unicode ? client.unicode_filter_decode(str) : str
end
#
# The extension alias under which all extensions can be accessed by name.
# For example:
@ -424,6 +439,10 @@ class Client
# The Passive Dispatcher
#
attr_accessor :passive_dispatcher
#
# Flag indicating whether to hex-encode UTF-8 file names and other strings
#
attr_accessor :encode_unicode
protected
attr_accessor :parser, :ext_aliases # :nodoc:

View File

@ -56,12 +56,12 @@ class Dir < Rex::Post::Dir
request = Packet.create_request('stdapi_fs_ls')
files = []
request.add_tlv(TLV_TYPE_DIRECTORY_PATH, Rex::Text.unicode_filter_decode(name))
request.add_tlv(TLV_TYPE_DIRECTORY_PATH, client.unicode_filter_decode(name))
response = client.send_request(request)
response.each(TLV_TYPE_FILE_NAME) { |file_name|
files << Rex::Text.unicode_filter_encode( file_name.value )
files << client.unicode_filter_encode( file_name.value )
}
return files
@ -74,7 +74,7 @@ class Dir < Rex::Post::Dir
request = Packet.create_request('stdapi_fs_ls')
files = []
request.add_tlv(TLV_TYPE_DIRECTORY_PATH, Rex::Text.unicode_filter_decode(name))
request.add_tlv(TLV_TYPE_DIRECTORY_PATH, client.unicode_filter_decode(name))
response = client.send_request(request)
@ -96,8 +96,8 @@ class Dir < Rex::Post::Dir
files <<
{
'FileName' => Rex::Text.unicode_filter_encode( file_name.value ),
'FilePath' => Rex::Text.unicode_filter_encode( fpath[idx].value ),
'FileName' => client.unicode_filter_encode( file_name.value ),
'FilePath' => client.unicode_filter_encode( fpath[idx].value ),
'StatBuf' => st,
}
}
@ -117,7 +117,7 @@ class Dir < Rex::Post::Dir
def Dir.chdir(path)
request = Packet.create_request('stdapi_fs_chdir')
request.add_tlv(TLV_TYPE_DIRECTORY_PATH, Rex::Text.unicode_filter_decode( path ))
request.add_tlv(TLV_TYPE_DIRECTORY_PATH, client.unicode_filter_decode( path ))
response = client.send_request(request)
@ -130,7 +130,7 @@ class Dir < Rex::Post::Dir
def Dir.mkdir(path)
request = Packet.create_request('stdapi_fs_mkdir')
request.add_tlv(TLV_TYPE_DIRECTORY_PATH, Rex::Text.unicode_filter_decode( path ))
request.add_tlv(TLV_TYPE_DIRECTORY_PATH, client.unicode_filter_decode( path ))
response = client.send_request(request)
@ -145,7 +145,7 @@ class Dir < Rex::Post::Dir
response = client.send_request(request)
return Rex::Text.unicode_filter_encode( response.get_tlv(TLV_TYPE_DIRECTORY_PATH).value )
return client.unicode_filter_encode( response.get_tlv(TLV_TYPE_DIRECTORY_PATH).value )
end
#
@ -161,7 +161,7 @@ class Dir < Rex::Post::Dir
def Dir.delete(path)
request = Packet.create_request('stdapi_fs_delete_dir')
request.add_tlv(TLV_TYPE_DIRECTORY_PATH, Rex::Text.unicode_filter_decode( path ))
request.add_tlv(TLV_TYPE_DIRECTORY_PATH, client.unicode_filter_decode( path ))
response = client.send_request(request)
@ -195,8 +195,8 @@ class Dir < Rex::Post::Dir
def Dir.download(dst, src, recursive = false, force = true, &stat)
self.entries(src).each { |src_sub|
dst_item = dst + ::File::SEPARATOR + Rex::Text.unicode_filter_encode( src_sub )
src_item = src + File::SEPARATOR + Rex::Text.unicode_filter_encode( src_sub )
dst_item = dst + ::File::SEPARATOR + client.unicode_filter_encode( src_sub )
src_item = src + File::SEPARATOR + client.unicode_filter_encode( src_sub )
if (src_sub == '.' or src_sub == '..')
next
@ -240,8 +240,8 @@ class Dir < Rex::Post::Dir
#
def Dir.upload(dst, src, recursive = false, &stat)
::Dir.entries(src).each { |src_sub|
dst_item = dst + File::SEPARATOR + Rex::Text.unicode_filter_encode( src_sub )
src_item = src + ::File::SEPARATOR + Rex::Text.unicode_filter_encode( src_sub )
dst_item = dst + File::SEPARATOR + client.unicode_filter_encode( src_sub )
src_item = src + ::File::SEPARATOR + client.unicode_filter_encode( src_sub )
if (src_sub == '.' or src_sub == '..')
next

View File

@ -44,7 +44,7 @@ class File < Rex::Post::Meterpreter::Extensions::Stdapi::Fs::IO
request = Packet.create_request( 'stdapi_fs_search' )
root = Rex::Text.unicode_filter_decode(root) if root
root = client.unicode_filter_decode(root) if root
root = root.chomp( '\\' ) if root
request.add_tlv( TLV_TYPE_SEARCH_ROOT, root )
@ -57,8 +57,8 @@ class File < Rex::Post::Meterpreter::Extensions::Stdapi::Fs::IO
if( response.result == 0 )
response.each( TLV_TYPE_SEARCH_RESULTS ) do | results |
files << {
'path' => Rex::Text.unicode_filter_encode( results.get_tlv_value( TLV_TYPE_FILE_PATH ).chomp( '\\' ) ),
'name' => Rex::Text.unicode_filter_encode( results.get_tlv_value( TLV_TYPE_FILE_NAME ) ),
'path' => client.unicode_filter_encode( results.get_tlv_value( TLV_TYPE_FILE_PATH ).chomp( '\\' ) ),
'name' => client.unicode_filter_encode( results.get_tlv_value( TLV_TYPE_FILE_NAME ) ),
'size' => results.get_tlv_value( TLV_TYPE_FILE_SIZE )
}
end
@ -88,11 +88,11 @@ class File < Rex::Post::Meterpreter::Extensions::Stdapi::Fs::IO
def File.expand_path(path)
request = Packet.create_request('stdapi_fs_file_expand_path')
request.add_tlv(TLV_TYPE_FILE_PATH, Rex::Text.unicode_filter_decode( path ))
request.add_tlv(TLV_TYPE_FILE_PATH, client.unicode_filter_decode( path ))
response = client.send_request(request)
return Rex::Text.unicode_filter_encode( response.get_tlv_value(TLV_TYPE_FILE_PATH) )
return client.unicode_filter_encode( response.get_tlv_value(TLV_TYPE_FILE_PATH) )
end
@ -102,7 +102,7 @@ class File < Rex::Post::Meterpreter::Extensions::Stdapi::Fs::IO
def File.md5(path)
request = Packet.create_request('stdapi_fs_md5')
request.add_tlv(TLV_TYPE_FILE_PATH, Rex::Text.unicode_filter_decode( path ))
request.add_tlv(TLV_TYPE_FILE_PATH, client.unicode_filter_decode( path ))
response = client.send_request(request)
@ -116,7 +116,7 @@ class File < Rex::Post::Meterpreter::Extensions::Stdapi::Fs::IO
def File.sha1(path)
request = Packet.create_request('stdapi_fs_sha1')
request.add_tlv(TLV_TYPE_FILE_PATH, Rex::Text.unicode_filter_decode( path ))
request.add_tlv(TLV_TYPE_FILE_PATH, client.unicode_filter_decode( path ))
response = client.send_request(request)
@ -145,7 +145,7 @@ class File < Rex::Post::Meterpreter::Extensions::Stdapi::Fs::IO
def File.rm(name)
request = Packet.create_request('stdapi_fs_delete_file')
request.add_tlv(TLV_TYPE_FILE_PATH, Rex::Text.unicode_filter_decode( name ))
request.add_tlv(TLV_TYPE_FILE_PATH, client.unicode_filter_decode( name ))
response = client.send_request(request)

View File

@ -88,7 +88,7 @@ protected
def stat(file)
request = Packet.create_request('stdapi_fs_stat')
request.add_tlv(TLV_TYPE_FILE_PATH, Rex::Text.unicode_filter_decode( file ))
request.add_tlv(TLV_TYPE_FILE_PATH, client.unicode_filter_decode( file ))
response = self.class.client.send_request(request)
stat_buf = response.get_tlv(TLV_TYPE_STAT_BUF).value

View File

@ -30,7 +30,7 @@ class Config
def getuid
request = Packet.create_request('stdapi_sys_config_getuid')
response = client.send_request(request)
return Rex::Text.unicode_filter_encode( response.get_tlv_value(TLV_TYPE_USER_NAME) )
return client.unicode_filter_encode( response.get_tlv_value(TLV_TYPE_USER_NAME) )
end
#
@ -62,7 +62,7 @@ class Config
req = Packet.create_request('stdapi_sys_config_steal_token')
req.add_tlv(TLV_TYPE_PID, pid.to_i)
res = client.send_request(req)
return Rex::Text.unicode_filter_encode( res.get_tlv_value(TLV_TYPE_USER_NAME) )
return client.unicode_filter_encode( res.get_tlv_value(TLV_TYPE_USER_NAME) )
end
#
@ -71,7 +71,7 @@ class Config
def drop_token
req = Packet.create_request('stdapi_sys_config_drop_token')
res = client.send_request(req)
return Rex::Text.unicode_filter_encode( res.get_tlv_value(TLV_TYPE_USER_NAME) )
return client.unicode_filter_encode( res.get_tlv_value(TLV_TYPE_USER_NAME) )
end
#

View File

@ -151,7 +151,7 @@ class Process < Rex::Post::Process
end
end
request.add_tlv(TLV_TYPE_PROCESS_PATH, Rex::Text.unicode_filter_decode( path ));
request.add_tlv(TLV_TYPE_PROCESS_PATH, client.unicode_filter_decode( path ));
# If process arguments were supplied
if (arguments != nil)
@ -237,10 +237,10 @@ class Process < Rex::Post::Process
{
'pid' => p.get_tlv_value(TLV_TYPE_PID),
'parentid' => p.get_tlv_value(TLV_TYPE_PARENT_PID),
'name' => Rex::Text.unicode_filter_encode( p.get_tlv_value(TLV_TYPE_PROCESS_NAME) ),
'path' => Rex::Text.unicode_filter_encode( p.get_tlv_value(TLV_TYPE_PROCESS_PATH) ),
'name' => client.unicode_filter_encode( p.get_tlv_value(TLV_TYPE_PROCESS_NAME) ),
'path' => client.unicode_filter_encode( p.get_tlv_value(TLV_TYPE_PROCESS_PATH) ),
'session' => p.get_tlv_value(TLV_TYPE_PROCESS_SESSION),
'user' => Rex::Text.unicode_filter_encode( p.get_tlv_value(TLV_TYPE_USER_NAME) ),
'user' => client.unicode_filter_encode( p.get_tlv_value(TLV_TYPE_USER_NAME) ),
'arch' => arch
}
}
@ -358,8 +358,8 @@ protected
response = client.send_request(request)
# Populate the hash
info['name'] = Rex::Text.unicode_filter_encode( response.get_tlv_value(TLV_TYPE_PROCESS_NAME) )
info['path'] = Rex::Text.unicode_filter_encode( response.get_tlv_value(TLV_TYPE_PROCESS_PATH) )
info['name'] = client.unicode_filter_encode( response.get_tlv_value(TLV_TYPE_PROCESS_NAME) )
info['path'] = client.unicode_filter_encode( response.get_tlv_value(TLV_TYPE_PROCESS_PATH) )
return info
end

View File

@ -44,7 +44,7 @@ class Registry
request = Packet.create_request('stdapi_registry_load_key')
request.add_tlv(TLV_TYPE_ROOT_KEY, root_key)
request.add_tlv(TLV_TYPE_BASE_KEY, base_key)
request.add_tlv(TLV_TYPE_FILE_PATH, Rex::Text.unicode_filter_decode( hive_file ))
request.add_tlv(TLV_TYPE_FILE_PATH, client.unicode_filter_decode( hive_file ))
response = client.send_request(request)
return response.get_tlv(TLV_TYPE_RESULT).value

View File

@ -58,6 +58,8 @@ class Console::CommandDispatcher::Core
"bgkill" => "Kills a background meterpreter script",
"bglist" => "Lists running background scripts",
"write" => "Writes data to a channel",
"enable_unicode_encoding" => "Enables encoding of unicode strings",
"disable_unicode_encoding" => "Disables encoding of unicode strings"
}
if (msf_loaded?)
c["info"] = "Displays information about a Post module"
@ -707,7 +709,15 @@ class Console::CommandDispatcher::Core
end
end
def cmd_enable_unicode_encoding
client.encode_unicode = true
print_status("Unicode encoding is enabled")
end
def cmd_disable_unicode_encoding
client.encode_unicode = false
print_status("Unicode encoding is disabled")
end
@@client_extension_search_paths = [ ::File.join(Rex::Root, "post", "meterpreter", "ui", "console", "command_dispatcher") ]