Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/proto/kerberos/kerberos_readable_text_presenter.rb
74553 views
1
# -*- coding: binary -*-
2
3
module Rex
4
module Proto
5
module Kerberos
6
# Presenter for formatting Kerberos data structures as human-readable text
7
class KerberosReadableTextPresenter
8
READABLE_TEXT_LABELS = {
9
'pvno' => 'Protocol Version',
10
'msg_type' => 'Message Type',
11
'pa_data' => 'Pre-Authentication Data',
12
'req_body' => 'Request Body',
13
'crealm' => 'Client Realm',
14
'cname' => 'Client Name',
15
'realm' => 'Realm',
16
'sname' => 'Server Name',
17
'enc_part' => 'Encrypted Part',
18
'etype' => 'Encryption Type',
19
'name_type' => 'Name Type',
20
'name_string' => 'Name String',
21
'error_code' => 'Error Code',
22
'e_data' => 'Error Data',
23
'etext' => 'Error Text',
24
'stime' => 'Server Time',
25
'ctime' => 'Client Time',
26
'susec' => 'Server Microseconds',
27
'cusec' => 'Client Microseconds',
28
'ap_options' => 'AP Options',
29
'kdc_options' => 'KDC Options',
30
'ticket' => 'Ticket',
31
'tkt_vno' => 'Ticket Version Number',
32
'kvno' => 'Key Version Number',
33
'flags' => 'Flags'
34
}.freeze
35
36
def present(serialized_message)
37
lines = []
38
case serialized_message
39
when Hash
40
append_hash(lines, serialized_message, indent: 0)
41
when Array
42
append_array(lines, serialized_message, indent: 0)
43
else
44
lines << serialized_message.to_s
45
end
46
lines.join("\n")
47
end
48
49
private
50
51
def append_hash(lines, value, indent:)
52
value.each do |key, entry|
53
append_field(lines, key, entry, indent: indent)
54
end
55
end
56
57
def append_field(lines, key, value, indent:)
58
label = readable_text_label(key)
59
spacing = ' ' * indent
60
case value
61
when Hash
62
lines << "#{spacing}#{label}:"
63
append_hash(lines, value, indent: indent + 2)
64
when Array
65
if value.empty?
66
lines << "#{spacing}#{label}: []"
67
else
68
lines << "#{spacing}#{label}:"
69
append_array(lines, value, indent: indent + 2)
70
end
71
else
72
lines << "#{spacing}#{label}: #{value}"
73
end
74
end
75
76
def append_array(lines, value, indent:)
77
spacing = ' ' * indent
78
value.each_with_index do |entry, index|
79
case entry
80
when Hash
81
lines << "#{spacing}Entry[#{index}]:"
82
append_hash(lines, entry, indent: indent + 2)
83
when Array
84
lines << "#{spacing}Entry[#{index}]:"
85
append_array(lines, entry, indent: indent + 2)
86
else
87
lines << "#{spacing}- #{entry}"
88
end
89
end
90
end
91
92
def readable_text_label(key)
93
READABLE_TEXT_LABELS[key.to_s] || key.to_s.split('_').map(&:capitalize).join(' ')
94
end
95
end
96
end
97
end
98
end
99
100