Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/msf/core/auxiliary/mdns.rb
Views: 11784
# -*- coding: binary -*-1require 'net/dns'23module Msf4# This module provides methods for working with mDNS5module Auxiliary::MDNS6# Initializes an instance of an auxiliary module that uses mDNS7def initialize(info = {})8super9register_options(10[11OptAddressRange.new('RHOSTS', [true, 'The multicast address or CIDR range of targets to query', '224.0.0.251']),12Opt::RPORT(5353),13OptString.new('NAME', [true, 'The name to query', '_services._dns-sd._udp.local']),14OptString.new('TYPE', [true, 'The query type (name, # or TYPE#)', 'PTR']),15OptString.new('CLASS', [true, 'The query class (name, # or CLASS#)', 'IN'])16],17self.class18)19end2021def setup22query_class_name23query_type_name24end2526def build_probe27@probe ||= ::Net::DNS::Packet.new(query_name, query_type_num, query_class_num).data28# TODO: support QU vs QM probes29#+ @probe[@probe.size-2] = [0x80].pack('C')30#+ @probe31end3233def query_class34if datastore['CLASS'] =~ /^\d+$/35datastore['CLASS'].to_i36else37datastore['CLASS'].upcase38end39end4041def query_class_name42Net::DNS::RR::Classes.new(query_class).to_s43end4445def query_class_num46Net::DNS::RR::Classes.new(query_class).to_i47end4849def query_type50if datastore['TYPE'] =~ /^\d+$/51datastore['TYPE'].to_i52else53datastore['TYPE'].upcase54end55end5657def query_name58datastore['NAME']59end6061def query_type_name62Net::DNS::RR::Types.new(query_type).to_s63end6465def query_type_num66Net::DNS::RR::Types.new(query_type).to_i67end6869def describe_response(response)70decoded = Resolv::DNS::Message.decode(response)71answers = decoded.answer7273if answers.empty? # not sure this will ever happen...74"no answers"75else76# there are often many answers for the same RR, so group them77grouped_answers = answers.group_by { |name, _, _| name }78# now summarize each group by noting the resource type and the notable79# part(s) of that RR80summarized_answers = grouped_answers.map do |name, these_answers|81summarized_group = these_answers.map do |_, _, data|82case data83when Resolv::DNS::Resource::IN::A84"A #{data.address}"85when Resolv::DNS::Resource::IN::AAAA86"AAAA #{data.address}"87when Resolv::DNS::Resource::IN::PTR88"PTR #{data.name}"89when Resolv::DNS::Resource::IN::SRV90"SRV #{data.target}"91when Resolv::DNS::Resource::IN::TXT92"TXT #{data.strings.join(',')}"93else94data.inspect95end96end97"#{name}: (#{summarized_group.join(", ")})"98end99summarized_answers.join(', ')100end101end102103def request_info104"#{query_name} #{query_class}/#{query_type}"105end106end107end108109110