Skip to content

Commit 23e1b5b

Browse files
committed
Add search term support
1 parent 664fd1f commit 23e1b5b

File tree

1 file changed

+19
-5
lines changed
  • lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi

1 file changed

+19
-5
lines changed

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ class Console::CommandDispatcher::Stdapi::Fs
5454
"-R" => [ false, "Recursively list subdirectories encountered" ])
5555

5656
#
57-
# Options for the ls command
57+
# Options for the lls command
5858
#
5959
@@lls_opts = Rex::Parser::Arguments.new(
6060
"-h" => [ false, "Help banner." ],
61+
"-S" => [ true, "Search string." ],
6162
"-t" => [ false, "Sort by time" ],
6263
"-s" => [ false, "Sort by size" ],
6364
"-r" => [ false, "Reverse sort order" ])
@@ -689,7 +690,7 @@ def cmd_lls_help
689690
#
690691
# Get list local path information for lls command
691692
#
692-
def list_local_path(path, sort, order)
693+
def list_local_path(path, sort, order, search_term = nil)
693694
if !::File.directory?(path)
694695
perms = pretty_perms(path)
695696
stat = ::File.stat(path)
@@ -721,8 +722,10 @@ def list_local_path(path, sort, order)
721722
file
722723
]
723724
if file != '.' && file != '..'
724-
tbl << row
725-
items += 1
725+
if row.join(' ') =~ /#{search_term}/
726+
tbl << row
727+
items += 1
728+
end
726729
end
727730
end
728731
if items > 0
@@ -753,9 +756,11 @@ def pretty_perms(path)
753756
# List local files
754757
#
755758
def cmd_lls(*args)
759+
# Set Defaults
756760
path = ::Dir.pwd
757761
sort = 'Name'
758762
order = :forward
763+
search_term = nil
759764

760765
# Parse the args
761766
@@lls_opts.parse(args) { |opt, idx, val|
@@ -768,6 +773,15 @@ def cmd_lls(*args)
768773
# Output options
769774
when '-r'
770775
order = :reverse
776+
# Search
777+
when '-S'
778+
search_term = val
779+
if search_term.nil?
780+
print_error("Enter a search term")
781+
return true
782+
else
783+
search_term = /#{search_term}/nmi
784+
end
771785
# Help and path
772786
when "-h"
773787
cmd_lls_help
@@ -777,7 +791,7 @@ def cmd_lls(*args)
777791
end
778792
}
779793

780-
list_local_path(path, sort, order)
794+
list_local_path(path, sort, order, search_term)
781795
end
782796

783797
#

0 commit comments

Comments
 (0)