Skip to content

Commit 9672759

Browse files
committed
Land rapid7#7462, Add support for Unicode domains
2 parents 33e0d1f + b5a41c3 commit 9672759

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

lib/rex/proto/ntlm/utils.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -402,16 +402,19 @@ def self.parse_ntlm_type_2_blob(blob)
402402
data[:default_name] = temp_name.encode("UTF-8")
403403
when 2
404404
#netbios domain
405-
data[:default_domain] = addr
406-
data[:default_domain].force_encoding("UTF-16LE")
405+
temp_domain = addr
406+
temp_domain.force_encoding("UTF-16LE")
407+
data[:default_domain] = temp_domain.encode("UTF-8")
407408
when 3
408409
#dns name
409-
data[:dns_host_name] = addr
410-
data[:dns_host_name].force_encoding("UTF-16LE")
410+
temp_dns = addr
411+
temp_dns.force_encoding("UTF-16LE")
412+
data[:dns_host_name] = temp_dns.encode("UTF-8")
411413
when 4
412414
#dns domain
413-
data[:dns_domain_name] = addr
414-
data[:dns_domain_name].force_encoding("UTF-16LE")
415+
temp_dns_domain = addr
416+
temp_dns_domain.force_encoding("UTF-16LE")
417+
data[:dns_domain_name] = temp_dns_domain.encode("UTF-8")
415418
when 5
416419
#The FQDN of the forest.
417420
when 6

lib/rex/proto/smb/client.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,13 @@ def session_setup_no_ntlmssp(user = '', pass = '', domain = '', do_recv = true)
760760

761761
self.peer_native_os = info[0]
762762
self.peer_native_lm = info[1]
763-
self.default_domain = info[2]
763+
#
764+
# if the PC belongs to a domain, this value is already populated
765+
# if it is not populated, we're in a workgroup and need to pupulate it now
766+
#
767+
if self.default_domain.nil?
768+
self.default_domain = info[2]
769+
end
764770

765771
return ack
766772
end
@@ -906,7 +912,13 @@ def session_setup_with_ntlmssp(user = '', pass = '', domain = '', name = nil, do
906912
#dns name
907913
self.dns_host_name = blob_data[:dns_host_name] || ''
908914
#dns domain
909-
self.dns_domain_name = blob_data[:dns_domain_name] || ''
915+
if blob_data[:default_name] != blob_data[:default_domain]
916+
# We're in a domain; get the domain name now
917+
self.default_domain = blob_data[:default_domain] || ''
918+
else
919+
# We're in a workgroup; workgroup names come later in the handshake
920+
self.default_domain = nil
921+
end
910922

911923
type3 = @ntlm_client.init_context([blob].pack('m'))
912924
type3_blob = type3.serialize

modules/auxiliary/scanner/smb/smb_version.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,23 @@ def run_host(ip)
108108
end
109109

110110
if simple.client.default_domain
111-
desc << " (domain:#{simple.client.default_domain})"
111+
if simple.client.default_domain.encoding.name == "UTF-8"
112+
desc << " (domain:#{simple.client.default_domain})"
113+
else
114+
# Workgroup names are in ANSI, but may contain invalid characters
115+
# Go through each char and convert/check
116+
temp_workgroup = simple.client.default_domain.dup
117+
desc << " (workgroup:"
118+
temp_workgroup.each_char do |i|
119+
begin
120+
desc << i.encode("UTF-8")
121+
rescue Encoding::UndefinedConversionError => e
122+
desc << '?'
123+
print_error("Found incompatible (non-ANSI) character in Workgroup name. Replaced with '?'")
124+
end
125+
end
126+
desc << " )"
127+
end
112128
conf[:SMBDomain] = simple.client.default_domain
113129
match_conf['host.domain'] = conf[:SMBDomain]
114130
end

0 commit comments

Comments
 (0)