[go: up one dir, main page]

Library dnssd

Library for supporting DNS Service Discovery

The library supports

  • Unicast and Multicast requests
  • Decoding responses
  • Running requests in parallel using Lua coroutines

The library contains the following classes

  • Comm
** A class with static functions that handle communication using the dns library
  • Helper
** The helper class wraps the Comm class using functions with a more descriptive name. ** The purpose of this class is to give developers easy access to some of the common DNS-SD tasks.
  • Util
** The Util class contains a number of static functions mainly used to convert data.

The following code snippet queries all mDNS resolvers on the network for a full list of their supported services and returns the formatted output:

  local helper = dnssd.Helper:new( )
  helper:setMulticast(true)
  return stdnse.format_output(helper:queryServices())

This next snippet queries a specific host for the same information:

  local helper = dnssd.Helper:new( host, port )
  return stdnse.format_output(helper:queryServices())

In order to query for a specific service a string or table with service names can be passed to the Helper.queryServices method.

Author:

  • Patrik Karlsson <patrik@cqure.net>

Copyright © Same as Nmap--See https://nmap.org/book/man-legal.html

Source: https://svn.nmap.org/nmap/nselib/dnssd.lua

Script Arguments

dnssd.services

string or table containing services to query

Functions

createSvcHostTbl (response)

Creates a service host table

decodeRecords (response, result)

Decodes a record received from the queryService function

getRecordType (dtype, response, retAll)

Gets a record from both the Answer and Additional section

getUniqueServices (response)

Creates a unique list of services

ipCompare (a, b)

Compare function used for sorting IP-addresses

new (self, host, port)

Creates a new helper instance

queryAllServices (host, port, multiple)

Query the mDNS resolvers for a list of their services

queryService (host, port, svc, multiple, svcresponse)

Send a query for a particular service and store the response in a table

queryServices (self, service, host, port, mcast)

Performs a DNS-SD query against a host

serviceCompare (a, b)

Function used to compare discovered DNS services so they can be sorted

setMulticast (self, mcast)

Instructs the helper to use unconnected sockets supporting multicast

threadCount (threads)

Returns the amount of currently active threads

Functions

createSvcHostTbl (response)

Creates a service host table

['_ftp._tcp.local'] = {10.10.10.10,20.20.20.20} ['_http._tcp.local'] = {30.30.30.30,40.40.40.40}

Parameters

response
containing multiple responses from dns.query

Return value:

services table containing the service name as a key and all host addresses as value
decodeRecords (response, result)

Decodes a record received from the queryService function

Parameters

response
as returned by queryService
result
table into which the decoded output should be stored
getRecordType (dtype, response, retAll)

Gets a record from both the Answer and Additional section

Parameters

dtype
DNS resource record type.
response
Decoded DNS response.
retAll
If true, return all entries, not just the first.

Return values:

  1. True if one or more answers of the required type were found - otherwise false.
  2. Answer according to the answer fetcher for dtype or an Error message.
getUniqueServices (response)

Creates a unique list of services

Parameters

response
containing a single or multiple responses from dns.query

Return value:

array of strings containing service names
ipCompare (a, b)

Compare function used for sorting IP-addresses

Parameters

a
table containing first item
b
table containing second item

Return value:

true if a is less than b
new (self, host, port)

Creates a new helper instance

Parameters

self
 
host
string containing the host name or ip
port
number containing the port to connect to

Return value:

o a new instance of Helper
queryAllServices (host, port, multiple)

Query the mDNS resolvers for a list of their services

Parameters

host
table as received by the action function
port
number specifying the port to connect to
multiple
receive multiple responses (multicast)

Return values:

  1. True if a dns response was received and contained an answer of the requested type, or the decoded dns response was requested (retPkt) and is being returned - or False otherwise.
  2. String answer of the requested type, Table of answers or a String error message of one of the following: "No Such Name", "No Servers", "No Answers", "Unable to handle response"
queryService (host, port, svc, multiple, svcresponse)

Send a query for a particular service and store the response in a table

Parameters

host
string containing the ip to connect to
port
number containing the port to connect to
svc
the service record to retrieve
multiple
true if responses from multiple hosts are expected
svcresponse
table to which results are stored
queryServices (self, service, host, port, mcast)

Performs a DNS-SD query against a host

Parameters

self
 
service
string or table with the service(s) to query eg. _ssh._tcp.local, _afpovertcp._tcp.local if nil defaults to _services._dns-sd._udp.local (all)
host
table as received by the action function
port
number specifying the port to connect to
mcast
boolean true if a multicast query is to be done

Return values:

  1. status true on success, false on failure
  2. response table suitable for stdnse.format_output
serviceCompare (a, b)

Function used to compare discovered DNS services so they can be sorted

Parameters

a
table containing first item
b
table containing second item

Return value:

true if the port of a is less than the port of b
setMulticast (self, mcast)

Instructs the helper to use unconnected sockets supporting multicast

Parameters

self
 
mcast
boolean true if multicast is to be used, false otherwise
threadCount (threads)

Returns the amount of currently active threads

Parameters

threads
table containing the list of threads

Return value:

count number containing the number of non-dead threads