Skip to content

Commit

Permalink
Have Post::File use shiny new session.fs.file.mv
Browse files Browse the repository at this point in the history
Also adds a quick and dirty test. Verified working on Linux shell, Linux
meterpreter, and Windows x86 and x64 meterpreter.
  • Loading branch information
egypt committed Apr 5, 2013
1 parent 7fbe477 commit cd86a69
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
17 changes: 11 additions & 6 deletions lib/msf/core/post/file.rb
Expand Up @@ -299,13 +299,18 @@ def rm_f(*remote_files)
end

#
# Rename a remote file. This is a stopgap until a proper API version is added:
# http://dev.metasploit.com/redmine/issues/7288
# Rename a remote file.
#
def rename_file(new_file, old_file)
#TODO: this is not ideal as the file contents are sent to meterp server and back to the client
write_file(new_file, read_file(old_file))
rm_f(old_file)
def rename_file(old_file, new_file)
if session.respond_to? :commands and session.commands.include?("stdapi_fs_file_move")
session.fs.file.mv(old_file, new_file)
else
if session.platform =~ /win/
cmd_exec(%Q|move /y "#{old_file}" "#{new_file}"|)
else
cmd_exec(%Q|mv -f "#{old_file}" "#{new_file}"|)
end
end
end
alias :move_file :rename_file
alias :mv_file :rename_file
Expand Down
20 changes: 18 additions & 2 deletions test/modules/post/test/file.rb
Expand Up @@ -13,11 +13,10 @@ class Metasploit4 < Msf::Post

def initialize(info={})
super( update_info( info,
'Name' => 'Testing remote file manipulation',
'Name' => 'Testing Remote File Manipulation',
'Description' => %q{ This module will test Post::File API methods },
'License' => MSF_LICENSE,
'Author' => [ 'egypt'],
'Version' => '$Revision$',
'Platform' => [ 'windows', 'linux', 'java' ],
'SessionTypes' => [ 'meterpreter', 'shell' ]
))
Expand Down Expand Up @@ -102,6 +101,23 @@ def test_file
not file_exist?("pwned")
end

it "should move files" do
# Make sure we don't have leftovers from a previous run
file_rm("meterpreter-test") rescue nil
file_rm("meterpreter-test-moved") rescue nil

# touch a new file
write_file("meterpreter-test", "")

rename_file("meterpreter-test", "meterpreter-test-moved")
res &&= exist?("meterpreter-test-moved")
res &&= !exist?("meterpreter-test")

# clean up
file_rm("meterpreter-test") rescue nil
file_rm("meterpreter-test-moved") rescue nil
end

end

def test_binary_files
Expand Down

0 comments on commit cd86a69

Please sign in to comment.