From 585245501a2e087ae35ee1b34b9f0747e0769d4e Mon Sep 17 00:00:00 2001 From: James Lee Date: Thu, 5 Apr 2012 11:38:44 -0600 Subject: [PATCH] Print an error when trying to open a dir as a file Prevents unnecessary stack traces --- .../ui/console/command_dispatcher/stdapi/fs.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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 72d7f277cd..7b4a120f8c 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 @@ -124,14 +124,18 @@ class Console::CommandDispatcher::Stdapi::Fs return true end - fd = client.fs.file.new(args[0], "rb") + if (client.fs.stat(args[0]).directory?) + print_error("#{args[0]} is a directory") + else + fd = client.fs.file.new(args[0], "rb") - until fd.eof? - print(fd.read) + until fd.eof? + print(fd.read) + end + + fd.close end - fd.close - true end