Skip to content

Commit 664fd1f

Browse files
committed
Support single file path
1 parent 9f0ff3f commit 664fd1f

File tree

1 file changed

+31
-21
lines changed
  • lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi

1 file changed

+31
-21
lines changed

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

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,13 @@ def cmd_lls_help
690690
# Get list local path information for lls command
691691
#
692692
def list_local_path(path, sort, order)
693+
if !::File.directory?(path)
694+
perms = pretty_perms(path)
695+
stat = ::File.stat(path)
696+
print_line("#{perms} #{stat.size} #{stat.ftype[0,3]} #{stat.mtime} #{path}")
697+
return
698+
end
699+
693700
columns = [ 'Mode', 'Size', 'Type', 'Last modified', 'Name' ]
694701
tbl = Rex::Text::Table.new(
695702
'Header' => "Listing Local: #{path}",
@@ -698,32 +705,19 @@ def list_local_path(path, sort, order)
698705
'Columns' => columns)
699706

700707
items = 0
701-
702708
files = ::Dir.entries(path)
703709

704710
files.each do |file|
705711
file_path = ::File.join(path, file)
706-
m = ::File.stat(file_path).mode
707-
om = '%04o' % m
708-
perms = ''
709-
710-
3.times {
711-
perms = ((m & 01) == 01 ? 'x' : '-') + perms
712-
perms = ((m & 02) == 02 ? 'w' : '-') + perms
713-
perms = ((m & 04) == 04 ? 'r' : '-') + perms
714-
m >>= 3
715-
}
716-
717-
perm = "#{om}/#{perms}"
718-
size = ::File.stat(file_path).size
719-
ftype = ::File.stat(file_path).ftype[0,3]
720-
mtime = ::File.stat(file_path).mtime
712+
713+
perms = pretty_perms(file_path)
714+
stat = ::File.stat(file_path)
721715

722716
row = [
723-
perm ? perm : '',
724-
size ? size.to_s : '',
725-
ftype ? ftype[0,3] : '',
726-
mtime ? mtime : '',
717+
perms ? perms : '',
718+
stat.size ? stat.size.to_s : '',
719+
stat.ftype ? stat.ftype[0,3] : '',
720+
stat.mtime ? stat.mtime : '',
727721
file
728722
]
729723
if file != '.' && file != '..'
@@ -738,6 +732,23 @@ def list_local_path(path, sort, order)
738732
end
739733
end
740734

735+
# Code from prettymode in lib/rex/post/file_stat.rb
736+
# adapted for local file usage
737+
def pretty_perms(path)
738+
m = ::File.stat(path).mode
739+
om = '%04o' % m
740+
perms = ''
741+
742+
3.times {
743+
perms = ((m & 01) == 01 ? 'x' : '-') + perms
744+
perms = ((m & 02) == 02 ? 'w' : '-') + perms
745+
perms = ((m & 04) == 04 ? 'r' : '-') + perms
746+
m >>= 3
747+
}
748+
749+
return "#{om}/#{perms}"
750+
end
751+
741752
#
742753
# List local files
743754
#
@@ -774,7 +785,6 @@ def cmd_lls(*args)
774785
#
775786
alias cmd_ldir cmd_lls
776787

777-
778788
#
779789
# Make one or more directory.
780790
#

0 commit comments

Comments
 (0)