34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/msf/ui/console/command_dispatcher/db/klist.rb', line 34
def cmd_klist(*args)
return unless active?
entries_affected = 0
mode = :list
host_ranges = []
id_search = []
verbose = false
trace_target = nil
@@klist_opts.parse(args) do |opt, _idx, val|
case opt
when '-h', '--help'
cmd_klist_help
return
when '-v', '--verbose'
verbose = true
when '-t', '--trace'
trace_target = val
when '-d', '--delete'
mode = :delete
when '-i', '--id'
id_search = (id_search + val.split(/,\s*|\s+/)).uniq when '-a', '--activate'
mode = :activate
when '-A', '--deactivate'
mode = :deactivate
else
unless arg_host_range(val, host_ranges)
return
end
end
end
host_ranges.push(nil) if host_ranges.empty?
trace_path = nil
if trace_target
if trace_target.match?(/\A\d+\z/)
id_search = [trace_target]
else
id_search = []
trace_path = File.expand_path(trace_target)
end
end
id_search = nil if id_search.empty?
ticket_results = ticket_search(host_ranges, id_search)
ticket_results.select! { |ticket_result| File.expand_path(ticket_result.path.to_s) == trace_path } if trace_path
print_line('Kerberos Cache')
print_line('==============')
if ticket_results.empty?
print_line('No tickets')
print_line
return
end
if mode == :delete
result = kerberos_ticket_storage.delete_tickets(ids: ticket_results.map(&:id))
entries_affected = result.size
end
if mode == :activate || mode == :deactivate
result = set_activation_status(mode, ticket_results)
entries_affected = result.size
ticket_results = ticket_search(host_ranges, id_search)
ticket_results.select! { |ticket_result| File.expand_path(ticket_result.path.to_s) == trace_path } if trace_path
end
if trace_target
ticket_results.each.with_index do |ticket_result, index|
presenter = Rex::Proto::Kerberos::CredentialCache::Krb5CcachePresenter.new(ticket_result.ccache)
print_line presenter.present_trace(source: "Cache[#{index}] id=#{ticket_result.id}")
print_line
end
elsif verbose
ticket_results.each.with_index do |ticket_result, index|
ticket_details = Rex::Proto::Kerberos::CredentialCache::Krb5CcachePresenter.new(ticket_result.ccache).present
print_line "Cache[#{index}]:"
print_line ticket_details.indent(2)
print_line
end
else
tbl = Rex::Text::Table.new(
{
'Columns' => ['id', 'host', 'principal', 'sname', 'enctype', 'issued', 'status', 'path'],
'SortIndex' => -1,
'WordWrap' => false,
'Rows' => ticket_results.map do |ticket|
[
ticket.id,
ticket.host_address,
ticket.principal,
ticket.sname,
Rex::Proto::Kerberos::Crypto::Encryption.const_name(ticket.enctype),
ticket.starttime,
ticket_status(ticket),
ticket.path
]
end
}
)
print_line(tbl.to_s)
end
case mode
when :delete
print_status("Deleted #{entries_affected} #{entries_affected > 1 ? 'entries' : 'entry'}") if entries_affected > 0
when :activate
print_status("Activated #{entries_affected} #{entries_affected > 1 ? 'entries' : 'entry'}") if entries_affected > 0
when :deactivate
print_status("Deactivated #{entries_affected} #{entries_affected > 1 ? 'entries' : 'entry'}") if entries_affected > 0
end
end
|