Skip to content

Commit

Permalink
Land #66, update is_name to support underscores
Browse files Browse the repository at this point in the history
  • Loading branch information
adfoster-r7 authored Mar 25, 2024
2 parents fba62cd + 9937ebb commit e224ff5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/rex/socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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*$/

Expand Down Expand Up @@ -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

#
Expand Down
22 changes: 19 additions & 3 deletions spec/rex/socket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down

0 comments on commit e224ff5

Please sign in to comment.