Difference between revisions of "Dnslogger"

From SkullSecurity
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
This is an incredibly simple program, but it also incredibly useful.
==Intro==
Essentially, it logs any DNS request it receives to stdout and responds with
[[dnslogger]] has two primary functions:
'unknown domain' by default. Alternatively, it can be told to respond with
# Print all received DNS requests
a static IP address (IPv4 or IPv6).
# Reply to them with an error or a static ip address (IPv4 or IPv6)


Whenever a DNS request is seen, it prints the request and responds with a
This is obviously very simple, but is also powerful.
NXDOMAIN (that is to say, 'domain not found'). To the source program, there
 
is no evidence that a server even exists or that the request was
==DOWNLOAD==
acknowledged. For example, let's say you're running a dnslogger server on
 
skullseclabs.org. When somebody tries to * ping that domain, it looks like
You can download the source from here: https://github.com/iagox86/nbtool
this:
 
You can download a binary from here, as part of nbtool: https://downloads.skullsecurity.org/
==Usage==
<pre>
<pre>
$ ping www.skullseclabs.org
-h --help
ping: unknown host www.skullseclabs.org
    Help (this page)
</pre>
--test <domain>
   
    Test to see if we are the authoritative nameserver for the given domain.
More than likely, the person will assume that nothing is there and continue
-s --source <address>
on. However, we see the request:
    The local address to bind to. Default: any (0.0.0.0)
<pre>  
-p --port <port>
# ./dnslogger
    The local port to listen on. I don't recommend changing this.
Question 0: www.skullseclabs.org (0x0001 0x0001)
    default: 53
Question 0: www.skullseclabs.org (0x0001 0x0001)
  -A <address>
    The A record to return when a record is requested. Default: NXDOMAIN.
--AAAA <address>
    The AAAA record to return when a record is requested. Default: NXDOMAIN.
--TTL <time>
    The time-to-live value to send back, in seconds. Default: 1 second.
-u --username
    Drop privileges to this user after opening socket (default: 'nobody')
-V --version
    Print the version and exit
</pre>
</pre>


There are many potential uses for dnslogger. Some that come to mind are:
==Printing requests==
Printing DNS requests has a lot of uses. Essentially, it'll tell you if
a program tried to connect to your site, without the program ever
attempting the connection. There are a great number of possible uses for
that:
* Finding open proxies without making an actual connection through it
* Finding open proxies without making an actual connection through it
* Finding open mail relays without sending an email through it
* Finding open mail relays without sending an email through it
* Finding errors in mail-handling code on a site
* Finding shell injection on a Web application without outbound traffic or delays
* Finding shell injection on a Web application without outbound traffic or delays
* Checking if a user visited a certain page
* Checking if a user visited a certain page
 
In addition to simple logging, the ability to set A or AAAA records opens
In every one of those cases, the server will try to look up the domain name
many options:
to perform some action, and fails. For example, to find an open proxy you
can connect to the potential proxy and send it "CONNECT <yourdomain>". If
the proxy server is indeed open, it'll do a lookup on <yourdomain> and
you'll see the request. Then, by default, an error is returned, so the proxy
server gives up on attempting the connection and it's never logged. That's
really the key -- the connection attempt never gets logged.
 
Likewise, shell injection. If you're testing an application for shell
injection, you can send it the payload 'ping <yourdomain>' to run. a
vulnerable server will attempt to ping the domain and perform a DNS lookup.
By default, the DNS lookup will fail, and the server won't perform the ping.
It'll look like this:
<pre>
$ ping www.skullseclabs.org
ping: unknown host www.skullseclabs.org
</pre>
 
dnslogger, however, will have seen the request and we therefore know that
the application is vulnerable. This is far more reliable than the classic
'ping localhost 4 times and see if it takes 3 seconds' approach to finding
shell injection.
 
One final note is discovering Web applications that handle email incorrectly.
A classic vulnerability when sending email, besides shell injection, is
letting the user terminate the email with a "." on its own line, then start
a new email. Something like this:
<pre>
This is my email, hello!
.
mail from: test@test.com
rcpt to: test@<yourdomain>
data
This email won't get sent!
</pre>
 
So the first email was terminated on the second line, with a period. A new
email is composed to test@<yourdomain>. If the application is vulnerable
to this type of attack, it will attempt to look up <yourdomain> so it can
send an email there. We'll see the request, respond with an error, and the
request will never be sent.
 
==Controlling the response==
In addition to logging requests, dnslogger can also respond with arbitrary
A or AAAA records to any incoming request. A long time ago, at work, I used
a Visual Basic program I found somewhere called "FakeDNS" that accomplished
a similar task, but I've since lost it and decided to implement it myself.
Some potential uses of this program are:
* Investigating malware that connects to a remote host
* Redirecting users if you control their DNS server
* Redirecting users if you control their DNS server
* Investigating malware that connects to a remote host
* Redirecting a legitimate program to your own server
* Redirecting a legitimate program to your own server
 
This tool assumes that the authoritative record for a DNS server points to
The first use is actually the one I created this for -- investigating
you. You can check if you do either by running 'dnsxss --test <domain>' or
malware. One of the most common types of malware I'm asked to investigate
by using the 'dnstest' program directly.
at work is a classic downloader, which reaches out to the Internet and
downloads its payload. Almost always, it uses a DNS server to find the
malware. By setting the system's dns to the dnslogger DNS server, all DNS
lookups will be seen (for later investigation), and you can control which
server it tries to connect to to download the files.
 
Another potential use, and somewhat malicious, is, if you control the DHCP
server on a victim's computer, you can point their DNS to a malicious host,
perhaps one running a password-stealer or Metasploit payload, and do what
you want.
 
One final use, which takes me back to the old days of Battle.net programming,
is redirecting a legitimate program with a hardcoded domain. For example,
Battle.net used to default to useast.battle.net, uswest.battle.net, etc.
Although you could change these servers in the registry, another option is
to point your system DNS to dnslogger and let it redirect the requests for
you.
 
==Authoritative DNS server==
Many functions of this tool require you to be the authoritative nameserver
for a domain. This typically costs money, but is fairly cheap and has a lot
of benefits. If you aren't sure whether or not you're the authority, you
can use the --test argument to this program, or you can directly run the
[[dnstest]] program, also included.

Latest revision as of 15:58, 6 October 2014

Intro

dnslogger has two primary functions:

  1. Print all received DNS requests
  2. Reply to them with an error or a static ip address (IPv4 or IPv6)

This is obviously very simple, but is also powerful.

DOWNLOAD

You can download the source from here: https://github.com/iagox86/nbtool

You can download a binary from here, as part of nbtool: https://downloads.skullsecurity.org/

Usage

 -h --help
    Help (this page)
 --test <domain>
    Test to see if we are the authoritative nameserver for the given domain.
 -s --source <address>
    The local address to bind to. Default: any (0.0.0.0)
 -p --port <port>
    The local port to listen on. I don't recommend changing this.
    default: 53
 -A <address>
    The A record to return when a record is requested. Default: NXDOMAIN.
 --AAAA <address>
    The AAAA record to return when a record is requested. Default: NXDOMAIN.
 --TTL <time>
    The time-to-live value to send back, in seconds. Default: 1 second.
 -u --username
    Drop privileges to this user after opening socket (default: 'nobody')
 -V --version
    Print the version and exit

Printing requests

Printing DNS requests has a lot of uses. Essentially, it'll tell you if a program tried to connect to your site, without the program ever attempting the connection. There are a great number of possible uses for that:

  • Finding open proxies without making an actual connection through it
  • Finding open mail relays without sending an email through it
  • Finding errors in mail-handling code on a site
  • Finding shell injection on a Web application without outbound traffic or delays
  • Checking if a user visited a certain page

In every one of those cases, the server will try to look up the domain name to perform some action, and fails. For example, to find an open proxy you can connect to the potential proxy and send it "CONNECT <yourdomain>". If the proxy server is indeed open, it'll do a lookup on <yourdomain> and you'll see the request. Then, by default, an error is returned, so the proxy server gives up on attempting the connection and it's never logged. That's really the key -- the connection attempt never gets logged.

Likewise, shell injection. If you're testing an application for shell injection, you can send it the payload 'ping <yourdomain>' to run. a vulnerable server will attempt to ping the domain and perform a DNS lookup. By default, the DNS lookup will fail, and the server won't perform the ping. It'll look like this:

$ ping www.skullseclabs.org
ping: unknown host www.skullseclabs.org

dnslogger, however, will have seen the request and we therefore know that the application is vulnerable. This is far more reliable than the classic 'ping localhost 4 times and see if it takes 3 seconds' approach to finding shell injection.

One final note is discovering Web applications that handle email incorrectly. A classic vulnerability when sending email, besides shell injection, is letting the user terminate the email with a "." on its own line, then start a new email. Something like this:

This is my email, hello!
.
mail from: test@test.com
rcpt to: test@<yourdomain>
data
This email won't get sent!

So the first email was terminated on the second line, with a period. A new email is composed to test@<yourdomain>. If the application is vulnerable to this type of attack, it will attempt to look up <yourdomain> so it can send an email there. We'll see the request, respond with an error, and the request will never be sent.

Controlling the response

In addition to logging requests, dnslogger can also respond with arbitrary A or AAAA records to any incoming request. A long time ago, at work, I used a Visual Basic program I found somewhere called "FakeDNS" that accomplished a similar task, but I've since lost it and decided to implement it myself. Some potential uses of this program are:

  • Investigating malware that connects to a remote host
  • Redirecting users if you control their DNS server
  • Redirecting a legitimate program to your own server

The first use is actually the one I created this for -- investigating malware. One of the most common types of malware I'm asked to investigate at work is a classic downloader, which reaches out to the Internet and downloads its payload. Almost always, it uses a DNS server to find the malware. By setting the system's dns to the dnslogger DNS server, all DNS lookups will be seen (for later investigation), and you can control which server it tries to connect to to download the files.

Another potential use, and somewhat malicious, is, if you control the DHCP server on a victim's computer, you can point their DNS to a malicious host, perhaps one running a password-stealer or Metasploit payload, and do what you want.

One final use, which takes me back to the old days of Battle.net programming, is redirecting a legitimate program with a hardcoded domain. For example, Battle.net used to default to useast.battle.net, uswest.battle.net, etc. Although you could change these servers in the registry, another option is to point your system DNS to dnslogger and let it redirect the requests for you.

Authoritative DNS server

Many functions of this tool require you to be the authoritative nameserver for a domain. This typically costs money, but is fairly cheap and has a lot of benefits. If you aren't sure whether or not you're the authority, you can use the --test argument to this program, or you can directly run the dnstest program, also included.