Tuesday, November 17, 2015

Splunk app for Stream for passive DNS monitoring

This is a killer app.

Forget everything I said in my last blog article.

Drop Splunk App for Stream into your system, put a stream forwarder on (or between) your DNS server, and look at the pretty pictures.


(snip of the full page, there's also tables on domains and so forth)

For added value, the app appears to be CIM compliant, so you can use e.g. PCAP Analyzer and Splunk DBIR App with the feed as well.

I'll dive into this some more later on with examples on using it for analytics, e.g. checking for zeus infection and so forth.

Sunday, August 02, 2015

Passive DNS monitoring with dnsmasq, rsyslog and Splunk

Passive DNS monitoring with dnsmasq, rsyslog and Splunk

There's not too many articles about this out on the internet, so I thought I'd give it a go.  Configuration is based on a Raspberry Pi running Raspbian (Jessie) and Splunk 6.2.4.

What is passive DNS monitoring?

It's the practice of recording DNS query replies on your network.  It's a small bit of information which can help diagnose network issues, and of course identify potentially compromised hosts through either overt detection (think: x837fnv9ebfj38390nf78d7.evil-domain.ru) or baseline anomalies.

About the tools

  • dnsmasq – a home network's best friend – caching DNS, DHCP & tftp server
  • rsyslog – a system logging daemon with powerful features.  Default syslogd in Debian.
  • splunk – commercial log analysis platform, free for up to 500Mb/day intake


dnsmasq setup


Just enable the log-queries option to your existing setup and you're good to go.
$ echo "log-queries" > /etc/dnsmasq.d/log-queries
$ service dnsmasq restart

rsyslog setup

Observe that dnsmasq logs DNS queries now into /var/log/daemon.log.  The two lines we're most interested in contain the texts "query" and "reply", so lets snarf them in rsyslog.  We'll add a little context to keep it real.

$ cat /etc/rsyslog.d/00-dnsmasq-splunk.conf
if $programname == 'dnsmasq' and ($msg contains ' query[' or $msg contains ' reply ') then @splunkserver:5141


Obviously substitute the IP of your real splunk index node for splunkserver above.  Why IP?  Because rsyslog doing a DNS lookup inserts a log entry in the DNS log which rsyslog parses, does a DNS lookup, which inserts an entry in the log which rsyslog parses, does a DNS lookup, which inserts an entry in the log which rsyslog parses, does a DNS lookup, which inserts ...

splunk setup

We'll be doing multiple things in Splunk, so lets take it one step at a time.

intake

Splunk now has to have a syslog listener on port 5141.  Navigate to Settings -> Data Inputs and add a new UDP listener.  (you could also go TCP, use @@splunkserver:5141 in rsyslog, and shake hands all around).  You'll accept messages from raspberrypi (restrict to host) and set the source type to linux_messages_syslog.  As per best practice log it into its own index (e.g. 'dns') with a source name override of 'dns' too.

You can pull up the search app now and test that you're seeing events matching e.g. "index=dns" &/or "source=dns"

Field Extractions

There's four main important data elements in the dnsmasq logs:

  • dns_query_clientip - ^.+query\[.+\s(?P.+)$
  • dns_query_hostname - ^(?:[^\]\n]*\]){2}\s+(?P[^ ]+)
  • dns_reply_hostname - ^[^\]\n]*\]:\s+\w+\s+(?P[^ ]+)
  • dns_reply_ip - ^.+reply.+\s(?P.+)$


You can easily make these in Splunk 6.2.4 by clicking on "Extract New Fields" in the field list on the left side.  You can cut/paste the above regexps in by choosing "I prefer to write the regular expression myself", or have fun like I did by poking around with the mouse then fixing it up later.

Data model

To make things easier, we can create a data model for the DNS information which automagically extracts the fields we like.  You'll probably like the date information and the four fields we created above.

dashboard

You can now create a custom dashboard to let you easily interrogate DNS traffic.  Start with a Pivot on the data model, and play around with the stats and charting as you wish.  Edit panels and add inputs for the time and the extracted data fields.  Create some visualisations.

Interesting info for analysis:
  • TLD.  Create a search macro dns_tld defined as:  index=dns | rex field=dns_hostname "(?P[A-Za-z0-9]+\.[A-Za-z]+)$" | transaction dns_hostname startswith="query" 
  • Top queried domains.  Try: `dns_tld` | top 25 domain
  • Anomalies.  Try: `dns_tld`| anomalies field=dns_hostname | sort - unexpectedness

Saturday, May 09, 2015

Don't use systemd

Upgraded to jessie.  On reboot;

* primary network interface is not configured.  This caused total network outage as this system is the DHCP server for the network.  Root cause = systemd.  It messed up the network config.

* Full GUI loads at boot.  RPi was set to be headless, but systemd pulled in dependencies requiring all of X11 (probably for the hideously awful systemd-ui app, the most user-unfriendly thing I've used.  And I've used Microsoft Windows.)

* systemd-logind is broken by default, there's no login consoles.

* load is constantly over 1.5 because of this:

top - 15:21:53 up 4 days,  2:12,  2 users,  load average: 1.58, 1.58, 1.50
Tasks: 127 total,   2 running, 125 sleeping,   0 stopped,   0 zombie
%Cpu(s): 10.4 us, 14.2 sy,  0.0 ni, 75.2 id,  0.0 wa,  0.0 hi,  0.3 si,  0.0 st
KiB Mem:    949408 total,   711404 used,   238004 free,    88224 buffers
KiB Swap:  1918972 total,        0 used,  1918972 free.   247176 cached Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
    1 root      20   0    6416   4972   2748 R  77.6  0.5   4493:41 systemd


Hovers between 77 and 90% CPU utilisation.  There's absolutely NOTHING logged as to why.

* shutdown is broken because systemd refuses to shut the system down until one of its broken components responds - which it doesn't in 7 hours of waiting.  Only solution is hard poweroff.


Whoever decided this should be the default init in Debian needs to be taken out to pasture and shot thrice.