Skip to content

Commit b5a41c3

Browse files
committed
Convert ANSI data to UTF-8 char by char because MS might
put an invalid character in the WORKGROUP name during SMB handshake
1 parent 1644a1e commit b5a41c3

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

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)