Commit Graph

7 Commits (1fd065403897e005dc41c391eca6e2f1a9d6365d)

Author SHA1 Message Date
RageLtMan c65c03722c Migrate native DNS services to Dnsruby data format
Dnsruby provides advanced options like DNSSEC in its data format
and is a current and well supported library.
The infrastructure services - resolver, server, etc, were designed
for a standalone configuration, and carry entirely too much weight
and redundancy to implement for this context. Instead of porting
over their native resolver, update the Net::DNS subclassed Rex
Resolver to use Dnsruby data formats and method calls.
Update the Msf namespace infrastructure mixins and native server
module with new method calls and workarounds for some instance
variables having only readers without writers. Implement the Rex
ServerManager to start and stop the DNS service adding relevant
alias methods to the Rex::Proto::DNS::Server class.

Rex services are designed to be modular and lightweight, as well
as implement the sockets, threads, and other low-level interfaces.
Dnsruby's operations classes implement their own threading and
socket semantics, and do not fit with the modular mixin workflow
used throughout Framework. So while the updated resolver can be
seen as adding rubber to the tire fire, converting to dnsruby's
native classes for resolvers, servers, and caches, would be more
like adding oxy acetylene and heavy metals.

Testing:
  Internal tests for resolution of different record types locally
and over pivot sessions.
2018-01-12 05:00:00 -05:00
RageLtMan a9f1fcec7f Set resolver comm and ctx manually 2017-06-23 19:58:36 -04:00
RageLtMan 7b370622c4 Resolver - add accessors for comm and ctx 2017-06-23 19:58:34 -04:00
RageLtMan b1b43555cf Fixup Resolver socket creation slop 2017-06-23 19:58:33 -04:00
RageLtMan 6e86ac6e1b Tweak Server and Resolver
Create default_dispatch_request method in Server to allow an
intercepted dispatch request to fall back into default exec flow.

Add attr_reader to the records hash in Cache

Provide Resolver and Server with comm option for their sockets.
2017-06-23 19:58:33 -04:00
RageLtMan e3c372834e Update Resolver's use of Rex Sockets
Compose configuration hashes for the Rex Sockets used in requests
based on the Resolver's own configuration, including passing the
Framework context, and CHOST/CPORT options in from Msf namespaces.
2017-06-23 19:58:32 -04:00
RageLtMan 9f49903b14 Initial implementation of Rex::Proto::DNS
Add Rex::Proto::DNS and Rex::Proto::DNS::Constants namespaces
Create Rex::Proto::DNS::Resolver from Net::DNS::Resolver
Create Rex::Proto::DNS::Server and Rex::Proto::DNS::Server::Cache

Constants -
  A Rex::Socket style MATCH_HOSTNAME regex has been added to
help validate DNS names.

Resolver -
  Based off of old work creating Rex socket overrides in the
Net::DNS::Resolver as well as allowing for proxying and making
automatic adjustments to use TCP for proxied connections. This
resolver pivots with MSF, uses proxies, and doesnt pull in the
default /etc/resolv.conf information which can lead to info leak.
  Automatically sends Net::DNS::Packet and Resolv::DNS::Message
objects to the appropriate nameservers.
  TODO: Review for potential low level concurrent resolution impl.

Server::Cache -
  Threadsafe wrapper around a Hash which holds Net::DNS::RR keys
with Time.to_i values for counting eviction/stale time without
altering the original record.
  Takes records with a TTL of < 1 as static entries which are not
flushed or pruned by the monitor thread.

Server -
  A standard Rex level server allowing for client connections with
TCP and UDP listeners. Provides common framework for handling the
different transports by creating a "client" type object as a Rex
UDP socket and passing it back to the dispatch/sender methods.
This server can host listeners on remote pivot targets since it
utilizes Rex sockets, and should not leak internal information
from the resolver as easily either.
  Can be configured with a custom resolver regardless of its own
listener configuration (UDP/TCP mix is fine), and carries a
threadsafe wrapper for swapping the resolvers nameservers under
a Mutex.synchronize. Since listeners and resolvers can pivot,
a compromised host in one environment can serve DNS information
obtained by the resolver pivoting through a completely different
target.
  The server takes blocks for dispatch and send functions which
when defined, will intercept the standard execution flow which is
to parse the request, check the cache for corresponding records,
then forward the remaining questions in a request via the resolver,
and build + send a response back to the client.
  The accessors for dispatch and send, resolver, and cache are
accessible at runtime, though it is likely unsafe to replace the
cache and resolver while they are accessed from other threads.

-----

Testing:
  Initial testing performed in IRB/Pry generating manual requests.
  Subsequent checks performed using the running server as the sys
resolver.
  Additional testing is needed - the default dispatch_request
behavior may not be correct (i need to check the RFCs for this) as
it handles multiple questions for A records. This should be tuned
to be RFC compliant, with inheriting classes changing behavior as
needed. We also need to ensure that we're not leaking our own DNS
information to our targets, so all sorts of abuse is in order.

-----

TODO:
  Create Msf::Exploit::DNS namespace utilizing this functionality.
  - Move the threaded enum_dns work, as well as work from 6187,
into the namespace
  - Review existing modules for functional overlap and move here
as needed. This should be done in separate commits/PRs.
  Create specific DNS servers for spoofing, exploit delivery, and
finally handling DNS tunnels (the primary reason for this work).
  Write spec
  - Convince/coerce a friendly soul in the community to handle
spec for this fiasco while building further functionality.
2017-06-23 19:58:29 -04:00