From ed8fec255ed3c39dc97cf77233b5df14312c9da3 Mon Sep 17 00:00:00 2001 From: caye Date: Tue, 12 Jul 2016 23:05:50 +0000 Subject: [PATCH] Fixed dir download. Retry when no network even at the download start --- .../meterpreter/extensions/stdapi/fs/dir.rb | 4 ++-- .../ui/console/command_dispatcher/stdapi/fs.rb | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/rex/post/meterpreter/extensions/stdapi/fs/dir.rb b/lib/rex/post/meterpreter/extensions/stdapi/fs/dir.rb index 4c7c755fd7..61d409f8f8 100644 --- a/lib/rex/post/meterpreter/extensions/stdapi/fs/dir.rb +++ b/lib/rex/post/meterpreter/extensions/stdapi/fs/dir.rb @@ -236,9 +236,9 @@ class Dir < Rex::Post::Dir stat.call('dir downloading', src_item, dst_item) if (stat) begin if (continue || tries) # allow to file.download to log messages - result = client.fs.file.download(dst_item, src_item, continue, tries, tries_no, &stat) + result = client.fs.file.download_file(dst_item, src_item, continue, tries, tries_no, &stat) else - result = client.fs.file.download(dst_item, src_item, continue, tries, tries_no) + result = client.fs.file.download_file(dst_item, src_item, continue, tries, tries_no) end stat.call(result, src_item, dst_item) if (stat) rescue ::Rex::Post::Meterpreter::RequestError => e diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb index 3dd3b58f3e..d41aff7006 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb @@ -399,7 +399,7 @@ class Console::CommandDispatcher::Stdapi::Fs src_path = file['path'] + client.fs.file.separator + file['name'] dest_path = src_path.tr(src_separator, ::File::SEPARATOR) - client.fs.file.download(dest_path, src_path) do |step, src, dst| + client.fs.file.download(dest_path, src_path, continue, tries, tries_no) do |step, src, dst| puts step print_status("#{step.ljust(11)}: #{src} -> #{dst}") client.framework.events.on_session_download(client, src, dest) if msf_loaded? @@ -412,7 +412,20 @@ class Console::CommandDispatcher::Stdapi::Fs else # Perform direct matching - stat = client.fs.file.stat(src) + tries_cnt = 0 + begin + stat = client.fs.file.stat(src) + rescue Rex::TimeoutError + if (tries && (tries_no == 0 || tries_cnt < tries_no)) + tries_cnt += 1 + print_error("Error opening: #{src} - retry (#{tries_cnt})") + retry + else + print_error("Error opening: #{src} - giving up") + raise + end + end + if (stat.directory?) client.fs.dir.download(dest, src, recursive, true, glob, continue, tries, tries_no) do |step, src, dst| print_status("#{step.ljust(11)}: #{src} -> #{dst}")