Skip to content

Commit 2068514

Browse files
committed
Add initial lls command
1 parent e8eeb78 commit 2068514

File tree

1 file changed

+95
-0
lines changed
  • lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi

1 file changed

+95
-0
lines changed

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

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Console::CommandDispatcher::Stdapi::Fs
3939
@@upload_opts = Rex::Parser::Arguments.new(
4040
"-h" => [ false, "Help banner." ],
4141
"-r" => [ false, "Upload recursively." ])
42+
4243
#
4344
# Options for the ls command
4445
#
@@ -52,6 +53,12 @@ class Console::CommandDispatcher::Stdapi::Fs
5253
"-l" => [ false, "List in long format (default)" ],
5354
"-R" => [ false, "Recursively list subdirectories encountered" ])
5455

56+
#
57+
# Options for the ls command
58+
#
59+
@@lls_opts = Rex::Parser::Arguments.new(
60+
"-h" => [ false, "Help banner." ])
61+
5562
#
5663
# List of supported commands.
5764
#
@@ -69,6 +76,7 @@ def commands
6976
'lcd' => 'Change local working directory',
7077
'lpwd' => 'Print local working directory',
7178
'ls' => 'List files',
79+
'lls' => 'List local files',
7280
'mkdir' => 'Make directory',
7381
'pwd' => 'Print working directory',
7482
'rm' => 'Delete the specified file',
@@ -93,6 +101,7 @@ def commands
93101
'lcd' => [],
94102
'lpwd' => [],
95103
'ls' => ['stdapi_fs_stat', 'stdapi_fs_ls'],
104+
'lls' => [],
96105
'mkdir' => ['stdapi_fs_mkdir'],
97106
'pwd' => ['stdapi_fs_getwd'],
98107
'rmdir' => ['stdapi_fs_delete_dir'],
@@ -667,6 +676,92 @@ def cmd_ls(*args)
667676
#
668677
alias cmd_dir cmd_ls
669678

679+
def cmd_lls_help
680+
print_line "Usage: lls [options]"
681+
print_line
682+
print_line "Lists contents of a local directory or file info"
683+
print_line @@lls_opts.usage
684+
end
685+
686+
#
687+
# Get list local path information for lls command
688+
#
689+
def list_local_path(path)
690+
columns = [ 'Mode', 'Size', 'Type', 'Last modified', 'Name' ]
691+
tbl = Rex::Text::Table.new(
692+
'Header' => "Listing Local: #{path}",
693+
'SortIndex' => columns.index("Name"),
694+
'SortOrder' => :forward,
695+
'Columns' => columns)
696+
697+
items = 0
698+
699+
files = ::Dir.entries(path)
700+
701+
files.each do |file|
702+
file_path = ::File.join(path, file)
703+
m = ::File.stat(file_path).mode
704+
om = '%04o' % m
705+
perms = ''
706+
707+
3.times {
708+
perms = ((m & 01) == 01 ? 'x' : '-') + perms
709+
perms = ((m & 02) == 02 ? 'w' : '-') + perms
710+
perms = ((m & 04) == 04 ? 'r' : '-') + perms
711+
m >>= 3
712+
}
713+
714+
perm = "#{om}/#{perms}"
715+
size = ::File.stat(file_path).size
716+
ftype = ::File.stat(file_path).ftype[0,3]
717+
mtime = ::File.stat(file_path).mtime
718+
719+
row = [
720+
perm ? perm : '',
721+
size ? size.to_s : '',
722+
ftype ? ftype[0,3] : '',
723+
mtime ? mtime : '',
724+
file
725+
]
726+
if file != '.' && file != '..'
727+
tbl << row
728+
items += 1
729+
end
730+
end
731+
if items > 0
732+
print_line(tbl.to_s)
733+
else
734+
print_line("No entries exist in #{path}")
735+
end
736+
end
737+
738+
#
739+
# List local files
740+
#
741+
def cmd_lls(*args)
742+
path = ::Dir.pwd
743+
744+
# Parse the args
745+
@@lls_opts.parse(args) { |opt, idx, val|
746+
case opt
747+
# Help and path
748+
when "-h"
749+
cmd_lls_help
750+
return 0
751+
when nil
752+
path = val
753+
end
754+
}
755+
756+
list_local_path(path)
757+
end
758+
759+
#
760+
# Alias the lls command to dir, for those of us who have windows muscle-memory
761+
#
762+
alias cmd_ldir cmd_lls
763+
764+
670765
#
671766
# Make one or more directory.
672767
#

0 commit comments

Comments
 (0)