Nmap Development mailing list archives

RFC Extend nmap_mass_rdns to support IPv6


From: Gioacchino Mazzurco <gmazzurco89 () gmail com>
Date: Mon, 20 Jul 2015 08:24:56 +0200

This is a request for comment on the work I have done to implement IPv6 
support for nmap_mass_rdns (issue #51), the advantage of this function against 
the one provided by the system is that it can handle multiple requests at 
time, it works by sending all requests and then collecting the responses 
and cache them, instead of doing a request and waiting for a response and then 
do the next request and so no, this should dramatically improve rDNS 
performances in massive scans like `nmap -A 10.0.0-255.1`.

DISCLAIMER: It is possible you feel some sarcasm reading this mail, I hope you 
don't get offended, I don't mean to offend anyone, this is just my way to add 
some fun to code commenting ;)

The whole architecture depends on the cache that was designed around IPv4 so 
first of all I have reimplemented the cache, during this phase I have decided 
to take advantage of C++ features (the code was C++ but written like it was C, 
no class no objects and so on) so class HostElem is the cache element, I am 
saying element and not line because a cache line (class HostCacheLine) can 
contain more then one element to handle elements with same hash, because class 
HostCache is a reverse resolution cache the key is the host IP ( 
sockaddr_storage ) while the value is the name associated to it ( std::string 
).

<key, value> pairs are added with the add method while to get a cached record 
a lookup method is provided, to avoid the cache be overpopulated (this would 
cause bad performance) and HostCache does have aging this is almos invisible 
to the class user and is handled by methods HostCache::{add, prune} and 
HostElem::isTimeToClean

Other then the cache also the DNS requests sending and response parsing parts 
were IPv4 specific I have generalized them creating a simple DNS implementation 
inside the DNS namespace, inside this namespace first of all we encounter a 
series of enums and constants with DNS specific values like the constants offset 
of some DNS packet stuff or the wire number of record type CNAME (it's a bunch 
of lines more then the old implementation but this way you don't get eye 
cancer reading code like `if ((buf[2] & 0xFA) != 0x80)`), after  we do 
encounter the Factory class that provide some DNS low level parsing/writing 
very useful statics method that are used all around the code, so if someone 
discover that integers are not parsed well there is only one place were do we 
have to fix it.

Then there is Record class and his derivatives, they are just used to parse 
the records values from DNS responses, it seems to me those class doesn't need 
to much introduction, but if you want some explanation just ask.

The same goes for Query and Answer classes.

Packet have a little more meat but in the end it's just a representation of a 
DNS packet and delegate most of the parsing work to the classes I have 
introduced before.

As the code i have written is big enough to introduce some bug, my mentor 
suggested to me to write tests too, i have done it and thanks to them i 
discovered some subtle bug that are already fixed in this RFC, moreover my 
mentor have done tests with fuzzing and just one more bug was discovered and 
fixed :)

If you are a git user i do suggest to you to checkout the code directly from 
my sandbox on gitlab

git clone https://gitlab.com/g10h4ck/nmap-gsoc2015.git
git checkout hotfix/51
./configure && make && make dns_check

Otherwise I have also attached the whole ordered patch set, and for the lazier 
there is squashed.diff that is equivalent to all of the patches.

Cheers!

Attachment: 0001-Port-cache-and-etc-hosts-reading-to-ipv6.patch
Description:

Attachment: 0002-Add-human-readeable-DNS-ipv-packets-generation.patch
Description:

Attachment: 0003-Ported-DNS-answers-parsing-to-IPv6.patch
Description:

Attachment: 0004-Move-sockadd_storage-helpers-functions-to-appropriat.patch
Description:

Attachment: 0005-Fixed-error-handling-a-NXDomain-end-resolution-tenta.patch
Description:

Attachment: 0006-Try-to-process-also-truncated-DNS-packets.patch
Description:

Attachment: 0007-Initialize-DNS-request-id-to-random-number.patch
Description:

Attachment: 0008-Split-declarations-to-header.patch
Description:

Attachment: 0009-Add-tests-subdir-and-have-DNS-test-compile-and-run.patch
Description:

Attachment: 0010-Implemented-more-testing-fixed-some-subtle-bug-thank.patch
Description:

Attachment: 0011-Finer-tests-discovered-and-fixed-other-subtle-bug-th.patch
Description:

Attachment: 0012-Fixed-possible-stack-overflow-with-special-crafted-i.patch
Description:

Attachment: 0013-Use-nbase-u8-as-buffer-type.patch
Description:

Attachment: squashed.diff
Description:

_______________________________________________
Sent through the dev mailing list
https://nmap.org/mailman/listinfo/dev
Archived at http://seclists.org/nmap-dev/

Current thread: