@@ -19,6 +19,9 @@ class Console::CommandDispatcher::Stdapi::Fs
19
19
20
20
include Console ::CommandDispatcher
21
21
22
+ CHECKSUM_ALGORITHMS = %w{ md5 sha1 }
23
+ private_constant :CHECKSUM_ALGORITHMS
24
+
22
25
#
23
26
# Options for the download command.
24
27
#
@@ -54,6 +57,7 @@ def commands
54
57
all = {
55
58
'cat' => 'Read the contents of a file to the screen' ,
56
59
'cd' => 'Change directory' ,
60
+ 'checksum' => 'Retrieve the checksum of a file' ,
57
61
'del' => 'Delete the specified file' ,
58
62
'dir' => 'List files (alias for ls)' ,
59
63
'download' => 'Download a file or directory' ,
@@ -76,6 +80,7 @@ def commands
76
80
reqs = {
77
81
'cat' => [ ] ,
78
82
'cd' => [ 'stdapi_fs_chdir' ] ,
83
+ 'checksum' => CHECKSUM_ALGORITHMS . map { |a | "stdapi_fs_#{ a } " } ,
79
84
'del' => [ 'stdapi_fs_rm' ] ,
80
85
'dir' => [ 'stdapi_fs_stat' , 'stdapi_fs_ls' ] ,
81
86
'download' => [ ] ,
@@ -271,6 +276,36 @@ def cmd_lcd(*args)
271
276
return true
272
277
end
273
278
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
+
274
309
#
275
310
# Delete the specified file.
276
311
#
@@ -635,7 +670,6 @@ def cmd_ls(*args)
635
670
#
636
671
alias cmd_dir cmd_ls
637
672
638
-
639
673
#
640
674
# Make one or more directory.
641
675
#
0 commit comments