From 8e09b172f65a7b53f8ece32e78d41e82ed074f4c Mon Sep 17 00:00:00 2001 From: Spencer McIntyre Date: Sat, 1 Oct 2016 14:29:35 -0400 Subject: [PATCH] Add a meterpreter checksum command --- .../console/command_dispatcher/stdapi/fs.rb | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) 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 94cb289d9a..9e1ef52bc1 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 @@ -19,6 +19,9 @@ class Console::CommandDispatcher::Stdapi::Fs include Console::CommandDispatcher + CHECKSUM_ALGORITHMS = %w{ md5 sha1 } + private_constant :CHECKSUM_ALGORITHMS + # # Options for the download command. # @@ -54,6 +57,7 @@ class Console::CommandDispatcher::Stdapi::Fs all = { 'cat' => 'Read the contents of a file to the screen', 'cd' => 'Change directory', + 'checksum' => 'Retrieve the checksum of a file', 'del' => 'Delete the specified file', 'dir' => 'List files (alias for ls)', 'download' => 'Download a file or directory', @@ -76,6 +80,7 @@ class Console::CommandDispatcher::Stdapi::Fs reqs = { 'cat' => [], 'cd' => ['stdapi_fs_chdir'], + 'checksum' => CHECKSUM_ALGORITHMS.map { |a| "stdapi_fs_#{a}" }, 'del' => ['stdapi_fs_rm'], 'dir' => ['stdapi_fs_stat', 'stdapi_fs_ls'], 'download' => [], @@ -271,6 +276,36 @@ class Console::CommandDispatcher::Stdapi::Fs return true end + # + # Retrieve the checksum of a file + # + def cmd_checksum(*args) + algorithm = args.shift + algorithm.downcase! unless algorithm.nil? + unless args.length > 0 and CHECKSUM_ALGORITHMS.include?(algorithm) + print_line("Usage: checksum [#{ CHECKSUM_ALGORITHMS.join(' / ') }] file1 file2 file3 ...") + return true + end + + args.each do |filepath| + checksum = client.fs.file.send(algorithm, filepath) + print_line("#{Rex::Text.to_hex(checksum, '')} #{filepath}") + end + + return true + end + + def cmd_checksum_tabs(str, words) + tabs = [] + return tabs unless words.length == 1 + + CHECKSUM_ALGORITHMS.each do |algorithm| + tabs << algorithm if algorithm.start_with?(str.downcase) + end + + tabs + end + # # Delete the specified file. # @@ -635,7 +670,6 @@ class Console::CommandDispatcher::Stdapi::Fs # alias cmd_dir cmd_ls - # # Make one or more directory. #