Skip to content

Commit

Permalink
Populate SMB shares if they're empty
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanusz-r7 committed Apr 2, 2024
1 parent 6a32f81 commit 1e8467e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/rex/post/smb/ui/console/command_dispatcher/shares.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ def cmd_shares(*args)
# Perform action
case method
when :list
@share_search_results = client.net_share_enum_all(session.address)
@valid_share_names = @share_search_results.map { |result| result[:name] }
populate_shares

table = Rex::Text::Table.new(
'Header' => 'Shares',
Expand All @@ -139,6 +138,7 @@ def cmd_shares(*args)

print_line table.to_s
when :interact
populate_shares if @valid_share_names.nil?
# Share names can be comprised only of digits so prioritise a share name over the share index
if share_name.match?(/\A\d+\z/) && !@valid_share_names.include?(share_name)
share_name = (@share_search_results[share_name.to_i] || {})[:name]
Expand Down Expand Up @@ -626,6 +626,13 @@ def download_file(dest_file, src_file)
dst_fd.close unless dst_fd.nil?
end
end

private

def populate_shares
@share_search_results = client.net_share_enum_all(session.address)
@valid_share_names = @share_search_results.map { |result| result[:name] }
end
end
end
end
Expand Down

0 comments on commit 1e8467e

Please sign in to comment.