Skip to content

Commit 039357a

Browse files
committed
Land rapid7#7387, checksum command for Meterpreter
2 parents f6b2a3a + 8e09b17 commit 039357a

File tree

1 file changed

+35
-1
lines changed
  • lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi

1 file changed

+35
-1
lines changed

lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class Console::CommandDispatcher::Stdapi::Fs
1919

2020
include Console::CommandDispatcher
2121

22+
CHECKSUM_ALGORITHMS = %w{ md5 sha1 }
23+
private_constant :CHECKSUM_ALGORITHMS
24+
2225
#
2326
# Options for the download command.
2427
#
@@ -54,6 +57,7 @@ def commands
5457
all = {
5558
'cat' => 'Read the contents of a file to the screen',
5659
'cd' => 'Change directory',
60+
'checksum' => 'Retrieve the checksum of a file',
5761
'del' => 'Delete the specified file',
5862
'dir' => 'List files (alias for ls)',
5963
'download' => 'Download a file or directory',
@@ -76,6 +80,7 @@ def commands
7680
reqs = {
7781
'cat' => [],
7882
'cd' => ['stdapi_fs_chdir'],
83+
'checksum' => CHECKSUM_ALGORITHMS.map { |a| "stdapi_fs_#{a}" },
7984
'del' => ['stdapi_fs_rm'],
8085
'dir' => ['stdapi_fs_stat', 'stdapi_fs_ls'],
8186
'download' => [],
@@ -271,6 +276,36 @@ def cmd_lcd(*args)
271276
return true
272277
end
273278

279+
#
280+
# Retrieve the checksum of a file
281+
#
282+
def cmd_checksum(*args)
283+
algorithm = args.shift
284+
algorithm.downcase! unless algorithm.nil?
285+
unless args.length > 0 and CHECKSUM_ALGORITHMS.include?(algorithm)
286+
print_line("Usage: checksum [#{ CHECKSUM_ALGORITHMS.join(' / ') }] file1 file2 file3 ...")
287+
return true
288+
end
289+
290+
args.each do |filepath|
291+
checksum = client.fs.file.send(algorithm, filepath)
292+
print_line("#{Rex::Text.to_hex(checksum, '')} #{filepath}")
293+
end
294+
295+
return true
296+
end
297+
298+
def cmd_checksum_tabs(str, words)
299+
tabs = []
300+
return tabs unless words.length == 1
301+
302+
CHECKSUM_ALGORITHMS.each do |algorithm|
303+
tabs << algorithm if algorithm.start_with?(str.downcase)
304+
end
305+
306+
tabs
307+
end
308+
274309
#
275310
# Delete the specified file.
276311
#
@@ -635,7 +670,6 @@ def cmd_ls(*args)
635670
#
636671
alias cmd_dir cmd_ls
637672

638-
639673
#
640674
# Make one or more directory.
641675
#

0 commit comments

Comments
 (0)