Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only retrieve cached credentials that match the requested KrbOfferedEncryptionTypes #19553

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,8 @@ def get_cached_credential(options = {})
host: options.fetch(:host) { rhost },
client: options.fetch(:username) { self.username },
server: options.fetch(:sname, nil),
realm: options.fetch(:realm) { self.realm }
realm: options.fetch(:realm) { self.realm },
offered_etypes: options.fetch(:offered_etypes) { self.offered_etypes }
)
end

Expand Down
30 changes: 24 additions & 6 deletions lib/msf/core/exploit/remote/kerberos/ticket/storage/read_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ def load_credential(options = {})
return nil unless active_db?

now = Time.now.utc
tickets(options) do |ticket|
next if ticket.expired?(now)

available_tickets = tickets(options).select do |ticket|
!ticket.expired?(now)
end
if options[:offered_etypes].present?
# Prefer etypes mentioned first
options[:offered_etypes].each do |etype|
available_tickets.each do |t|
if t.enctype == etype
return t.ccache.credentials.first
end
end
end
else
return ticket.ccache.credentials.first
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's a bug here; ticket is no longer in scope

end

Expand All @@ -17,10 +27,18 @@ def load_credential(options = {})

# (see Base#tickets)
def tickets(options = {}, &block)
objects(options).map do |stored_loot|
mapped = objects(options).map do |stored_loot|
stored_ticket = StoredTicket.new(stored_loot)
block.call(stored_ticket) if block_given?
stored_ticket
end

mapped.select do |stored_ticket|
# If we were provided a set of etypes to look for, restrict to that
if options[:offered_etypes].nil? || options[:offered_etypes].include?(stored_ticket.enctype)
block.call(stored_ticket) if block_given?
true
else
false
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def starttime
credential.starttime
end

def enctype
credential.keyblock.enctype
end

# @return [Rex::Proto::Kerberos::CredentialCache::Krb5Ccache]
def ccache
@ccache ||= Rex::Proto::Kerberos::CredentialCache::Krb5Ccache.read(loot.data)
Expand Down
3 changes: 2 additions & 1 deletion lib/msf/ui/console/command_dispatcher/db/klist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def cmd_klist(*args)
else
tbl = Rex::Text::Table.new(
{
'Columns' => ['id', 'host', 'principal', 'sname', 'issued', 'status', 'path'],
'Columns' => ['id', 'host', 'principal', 'sname', 'enctype', 'issued', 'status', 'path'],
'SortIndex' => -1,
# For now, don't perform any word wrapping on the table as it breaks the workflow of
# copying file paths and pasting them into applications
Expand All @@ -111,6 +111,7 @@ def cmd_klist(*args)
ticket.host_address,
ticket.principal,
ticket.sname,
Rex::Proto::Kerberos::Crypto::Encryption.const_name(ticket.enctype),
ticket.starttime,
ticket_status(ticket),
ticket.path
Expand Down
Loading
Loading