Extracting information in DNS Records with Unsniff and Ruby

There was a question in the Wireshark Q&A site that prompted this post. A user wanted to pull out IP Addresses but only from the “Answer Records” section of DNS.  All the information in Authority or Additional records section were to be ignored. The picture below describes what he was trying to accomplish with tshark.

Types of scripting

The problem is TShark does not actually expose an object model to a scripting language. The user gets the values of the fields “dns.qry.name” and “dns.resp.addr” which are tagged fields using the display filter format. Without doubt, this is a powerful capability of TShark but extending this to support adhoc scripting requirements is difficult. The solution is to dump the entire packet as text and parse if offline – a difficult ask.

How would you accomplish this with a scriptable object model ?

Unsniff Network Analyzer exposes an object model to scripting languages like Ruby and VBScript. So you can put together a quick script to walk down the protocol try which ever way you want. Lets do this example in Ruby.

Once you get hold of the packets you want, you use the same field names in the GUI to navigate the protocol tree. The key pieces in the above ruby code are :

  • Import the pcap file

  • Iterate over all packets and only work on QUERY Response. The same string is shown in the user interface, so it is easy to remember this string.

  • Find the “Answer Records” section in the “DNS” layer and process each record

Running this

If you run the above script

You get something like this

 

Add Unsniff to your toolkit

The beauty of Unsniff is you can script higher layer objects the same way using the UserObjects model. For example you can save all Images matching a certain name or size or whatever. Check out the samples here

  • Download Unsniff Network Analyzer for free here

Author: Vivek Rajagopalan

Vivek Rajagopalan is the a lead developer for Trisul Network Analytics. Prior products were Unsniff Network Analyzer and Unbrowse SNMP. Loves working with packets , very high speed networks, and helping track down the bad guys on the internet.