diff --git a/lib/rex/socket.rb b/lib/rex/socket.rb index 7fd2665..8e83637 100644 --- a/lib/rex/socket.rb +++ b/lib/rex/socket.rb @@ -85,7 +85,7 @@ def self.create_ip(opts = {}) # # see: https://debugpointer.com/regex/regex-for-dns-name - MATCH_DNS_NAME = /^(((?!-))(xn--)?([a-z0-9][a-z0-9\-]{0,59})?[a-z0-9]\.)*(xn--)?([a-z0-9\-]{1,61}|[a-z0-9-]{1,30}\.[a-z]{2,})$/i + MATCH_DNS_NAME = /^(((?!-))(xn--)?([a-z0-9_][a-z0-9_\-]{0,59})?[a-z0-9_]\.)*(xn--)?([a-z0-9_\-]{1,61}|[a-z0-9_-]{1,30}\.[a-z]{2,})$/i MATCH_IPV6 = /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/ @@ -133,7 +133,7 @@ def self.support_ipv6? # def self.is_name?(name) return false if name.length > 253 - name =~ MATCH_DNS_NAME ? (name =~ /\s/).nil? : false + name.delete_suffix('.') =~ MATCH_DNS_NAME ? (name =~ /\s/).nil? : false end # diff --git a/spec/rex/socket_spec.rb b/spec/rex/socket_spec.rb index f2c9ca0..1bd619a 100644 --- a/spec/rex/socket_spec.rb +++ b/spec/rex/socket_spec.rb @@ -342,13 +342,29 @@ end end - context 'with a fully qualified domain name' do - let(:try) { "www.metasploit.com" } - it "should return true" do + context 'with a name containing underscores' do + let(:try) { '_ldap._tcp.msflab.local' } + it 'should return true' do expect(name).to eq true end end + context 'with a fully qualified domain name' do + context 'and a trailing dot' do + let(:try) { "www.metasploit.com." } + it "should return true" do + expect(name).to eq true + end + end + + context 'and no trailing dot' do + let(:try) { "www.metasploit.com" } + it "should return true" do + expect(name).to eq true + end + end + end + context 'with multiple fully qualified domain names' do context 'separated by newlines' do let(:try) { "www.metasploit.com\nmetasploit.com" }