Existen algunas herramientas que nos permiten detectar cuando un servidor DNS se encuentra mal configurado y permite realizar consultas AXFR a servicios externos de forma pública, también conocido como Enumeración DNS, en una entrada anterior se ha utilizado DIG sobre un servidor DNS para la enumeración de sub-dominios y zonas, en este caso, se utilizará Fierce2, DNSMap y MetaSploit Framework

Fierce2

Se trata de una herramienta que viene incluida en Backtrack, sin embargo, es fácilmente instalada en cualquier otra maquina con GNU/Linux.

En primer lugar es necesario obtener el código fuente del repositorio de Fierce:

svn co https://svn.assembla.com/svn/fierce/fierce2/trunk/ fierce2/

Posteriormente es necesario ejecutar el fichero install.sh

>chmod 755 install.sh
>./install.sh

Una vez instalado, las opciones disponibles son:

>fierce
fierce 2.0beta-r406 ( http://trac.assembla.com/fierce )Usage: perl fierce {target options} [OPTIONS]TARGET OPTIONS:-dns [dns name(s) or file] The domain(s) you would like scanned.

Single domain, Multiple domains (Comma seperated)

Also, supports file input (one domain per line)

-range [111.222.333.1-100] Scan an internal IP range (must be combined with

-dnsservers). Note, that this does not support a pattern

and will simply output anything it finds.

Singe range, Multiple ranges (Comma separated)

Also, supports file input (one range per line)

GENERAL OPTIONS:

-format [type] Output format [txt || xml || html || all]

-output [file] Output file

-template [dir] Template Directory

-arin [«query»] ARIN Query (default uses domain, without extension)

-prefix [prefix file|URL] Prefix file or URL for bruteforce attack

-maxbruteforce [int] Max number concatted onto prefix (default 5)

-maxlookups [int] Max number hostname lookups (default 10)

-tld [file|URL] TLD file or URL for bruteforce

-subdomain [file|URL] Subdomain file or URL for subdomains bruteforce

-dnsservers [dns server or file]

Use particular DNS server(s) for hostname lookups.

(Single domain, Multiple domains (Comma seperated)

or File list(one domain per line) )

-ztstop Stop scan if Zone Transfer works

-wildcstop Don’t perform bruteforcing if a Wildcard is found

-all Perform every test.

-only [option(s)] Only perform (comma seperated)

-no [option(s)] Do not perform (comma seperated)

arin ARIN lookup

zt Zone Transfer

wildc Check for Wild Card

prebf Prefix Brute Force

subbf Subdomain Brute Force (default off)

tldbf TLD Brute Force (default off)

vhost Vhost Hosts (default off)

findmx Find MX Records

whois Whois Lookup

hlookups Hostname Lookups

nearby Find Nearby Hosts

-threads [int] Number of threads (default 5 threads)

-port [int] Port to use for testing

-delay [int] Number of seconds to delay (default 3 secs)

-tcptimeout [int] Specify a different TCP timeout (default 10 secs)

-udptimeout [int] Specify a different UDP timeout (default 5 secs)

-search [comma seperated] Search list based on the PTR names when performing lookups.

-traverse [int] Number of IPs to search at once betwen 0 and 255 (default 10)

-wide Scan the entire class C after finding any matching

hostnames in that class C.

-debug Debug option

-verbose Verbose option

-h -help This help screen.

-v -version Output the version number.

EXAMPLES:

perl fierce -dns example.com -prefix hosts.txt

perl fierce -dns example.com -prefix http://mywebsite.com/prefix.txt -wide

Type ‘man fierce’ for more information

Ahora se puede comenzar a utilizar fierce contra un servidor DNS mal configurado o vulnerable:

>./fierce -dns jdaanial.hostdns.com -prefix hosts.txt -ztstop
Fierce 2.0beta-r406 ( http://trac.assembla.com/fierce )

Starting Fierce Scan at Thu Jun 9 23:34:45 2011Args: -dns jdaanial.hostdns.com -ztstop 1 -prefix hosts.txt

Scanning domain jdaanial.hostdns.com at Thu Jun 9 23:34:45 2011 …

jdaanial.hostdns.com – 85.24.128.101

Nameservers for jdaanial.hostdns.com:

ARIN lookup «jdaanial»:

Zone Transfer:

Wildcards:

Prefix Bruteforce:

85.24.128.101 0.jdaanial.hostdns.com

MX records:

Whois Lookups:

NetRange 85.0.0.0 – 85.255.255.255

NetHandle NET-85-0-0-0-1

Hostname Lookups:

jdaanial.hostdns.com 85.24.128.101

Nearby IPs:

Ending domain scan at Thu Jun 9 23:34:45 2011

Elapsed time 18 seconds

Ending Fierce Scan

End Time: Thu Jun 9 23:35:03 2011

Total Elapsed Time: 18 seconds

Como puede apreciarse el intento “Zone Transfer” no ha dado ningún resultado, lo que quiere decir que no ha sido exitoso, no obstante, el proceso de fuerza bruta para recuperar subdominios ha sido exitosa, esto principalmente gracias a que el fichero de prefijos que viene incluido en Fierce es bastante completo.

NOTA: En el caso anterior, el servidor DNS se ha creado en www.zoneedit.com que permite la creación de servidores DNS de forma gratuita (con algunas restricciones) sin embargo, es útil para realizar pruebas.

Ahora, contra uno que tiene mas subdominios configurados:

>./fierce -dns linux.lan -prefix hosts.txt -ztstop
Fierce 2.0beta-r406 ( http://trac.assembla.com/fierce )

Starting Fierce Scan at Thu Jun 9 23:37:57 2011Args: -dns linux.lan -ztstop 1 -prefix hosts.txt

Scanning domain linux.lan at Thu Jun 9 23:37:57 2011 …

linux.lan – undefined

Nameservers for linux.lan:

ns1.linux.lan 192.168.1.33

ARIN lookup «linux»:

Zone Transfer:

ns1.linux.lan Success!

linux.lan. 38400 IN SOA ns1.linux.lan. admin.linux.lan. (

2006081401 ; Serial

28800 ; Refresh

3600 ; Retry

604800 ; Expire

38400 ) ; Minimum TTL

linux.lan. 38400 IN MX 10 mail.linux.lan.

linux.lan. 38400 IN NS ns1.linux.lan.

IN.linux.lan. 38400 IN NS http://www.tunnel.linux.lan.

mail.linux.lan. 38400 IN A 192.168.1.33

mail.linux.lan. 38400 IN MX 10 mail.linux.lan.

ns1.linux.lan. 38400 IN A 192.168.1.33

sshdns.ns1.linux.lan. 38400 IN A 192.168.1.33

http://www.tunnel.linux.lan. 38400 IN A 192.168.1.33

http://www.linux.lan. 38400 IN A 192.168.1.33

Ending domain scan at Thu Jun 9 23:37:57 2011

Elapsed time 1 seconds

Ending Fierce Scan

End Time: Thu Jun 9 23:37:58 2011

Total Elapsed Time: 1 seconds

Como se puede apreciar, contra este servidor DNS si se ha conseguido realizar una transferencia de zona, lo que indica que el servidor DNS no se encuentra correctamente configurado contra DNS Enumeration, por otro lado, dado que se ha especificado la opción -ztstop el proceso terminará automáticamente, dado que el intento “Zone Transfer” ha sido exitoso, por esta razón no se ha llevado a cabo el proceso de fuerza bruta contra sub-dominios.

La diferencia entre esta herramienta y el comando estándar DIG con la opción “-t AXFR” es que Fierce intentará recolectar toda la información posible sobre el servidor DNS sin que sea necesario conocer alguno de los nameservers del dominio.

DNSMap

Se trata de una herramienta que esta diseñada principalmente para pentesters durante el proceso de recolección de información, tiene características bastante similares a Fierce2, en especial con lo relacionado al mecanismo de “Fuerza Bruta” contra sub-dominios, el cual es bastante útil cuando un intento por “transferir la zona” (Zone Transfer) no ha tenido el efecto esperado.

Para instalar esta herramienta se debe descargar, descomprimir, compilar e instalar todo desde el código que se encuentra disponible en: http://code.google.com/p/dnsmap/ para esto se realiza el procedimiento estándar en GNU/Linux utilizando el comando make para compilar y make install para instalar.

Una vez instalado, las opciones disponibles son:

./dnsmap
dnsmap 0.30 – DNS Network Mapper by pagvac (gnucitizen.org)

usage: dnsmap <target-domain> [options]

options:

-w <wordlist-file>

-r <regular-results-file>

-c <csv-results-file>

-d <delay-millisecs>

-i <ips-to-ignore> (useful if you’re obtaining false positives)

e.g.:

dnsmap target-domain.foo

dnsmap target-domain.foo -w yourwordlist.txt -r /tmp/domainbf_results.txt

dnsmap target-fomain.foo -r /tmp/ -d 3000

dnsmap target-fomain.foo -r ./domainbf_results.txt

Su uso mas simple, es el siguiente

./dnsmap linux.lan
dnsmap 0.30 – DNS Network Mapper by pagvac (gnucitizen.org)

[+] searching (sub)domains for linux.lan using built-in wordlist

[+] using maximum random delay of 10 millisecond(s) between requests

mail.linux.lan

IP address #1: 192.168.1.33

ns1.linux.lan

IP address #1: 192.168.1.33

http://www.linux.lan

IP address #1: 192.168.1.33

[+] 3 (sub)domains and 3 IP address(es) found

[+] completion time: 6 second(s)

Por otra parte al igual que con Fierce2, puede establecerse un diccionario para realizar fuerza bruta contra sub-dominios, ademas de especificar un fichero para almacenar los resultados, por ejemplo:

./dnsmap linux.lan -w /opt/DNS/fierce2/hosts.txt -r results.txt
dnsmap 0.30 – DNS Network Mapper by pagvac (gnucitizen.org)

[+] searching (sub)domains for linux.lan using /opt/DNS/fierce2/hosts.txt

[+] using maximum random delay of 10 millisecond(s) between requests

mail.linux.lan

IP address #1: 192.168.1.33

ns1.linux.lan

IP address #1: 192.168.1.33

http://www.linux.lan

IP address #1: 192.168.1.33

[+] 3 (sub)domains and 3 IP address(es) found

[+] regular-format results can be found on results.txt

[+] completion time: 8 second(s)

>cat results.txt

mail.linux.lan

IP address #1: 192.168.1.33

ns1.linux.lan

IP address #1: 192.168.1.33

http://www.linux.lan

IP address #1: 192.168.1.33

MetaSploit FrameWork DNS Enumeration

Con MetaSploit también se encuentra disponible un modulo para ejecutar enumeración DNS, utilizando un enfoque similar al que se sigue con herramientas como Fierce2 o DNSMap, Sin embargo, va un poco mas allá, dado que incluye una variedad de opciones más completa, permitiendo verificar si un dominio tiene AXFR habilitado, Ataque de Fuerza Bruta, enumeración de Records DNS, como es costumbre, su uso es realmente sencillo:

msf > use auxiliary/gather/dns_enum
msf auxiliary(dns_enum) > show options

Module options (auxiliary/gather/dns_enum):

Name Current Setting Required Description

—- ————— ——– ———–

DOMAIN yes The target domain name

ENUM_AXFR true yes Initiate a zone Transfer against each NS record

ENUM_BRT false yes Brute force subdomains and hostnames via wordlist

ENUM_IP6 false yes Brute force hosts with IPv6 AAAA records

ENUM_RVL false yes Reverse lookup a range of IP addresses

ENUM_SRV true yes Enumerate the most common SRV records

ENUM_STD true yes Enumerate standard record types (A,MX,NS,TXT and SOA)

ENUM_TLD false yes Perform a top-level domain expansion by replacing TLD and testing against IANA TLD list

IPRANGE no The target address range or CIDR identifier

NS no Specify the nameserver to use for queries, otherwise use the system DNS

STOP_WLDCRD false yes Stops Brute Force Enumeration if wildcard resolution is detected

WORDLIST /opt/metasploit3/msf3/data/wordlists/namelist.txt no Wordlist file for domain name brute force.

Existen algunas propiedades requeridas para establecer opciones del escaneo DNS, como se puede apreciar, el modulo es bastante completo e incluye una gran cantidad de opciones para administrar la ejecución del modulo, las mas interesantes son:

ENUM_AXFR Verifica si el dominio tiene habilitado Zone Transfer
ENUM_BRT Fuerza Bruta con Diccionario.
ENUM_RVL Reverse Lookup de un rango de direcciones
ENUM_STD Enumeración de tipos de Registros Estándar.

Estableciendo algunas de las propiedades y ejecutando el modulo se obtienen los siguientes resultados:

msf auxiliary(dns_enum) > set DOMAIN google.com
DOMAIN => google.com

msf auxiliary(dns_enum) > show options

Module options (auxiliary/gather/dns_enum):

Name Current Setting Required Description

—- ————— ——– ———–

DOMAIN google.com yes The target domain name

ENUM_AXFR true yes Initiate a zone Transfer against each NS record

ENUM_BRT false yes Brute force subdomains and hostnames via wordlist

ENUM_IP6 false yes Brute force hosts with IPv6 AAAA records

ENUM_RVL false yes Reverse lookup a range of IP addresses

ENUM_SRV true yes Enumerate the most common SRV records

ENUM_STD true yes Enumerate standard record types (A,MX,NS,TXT and SOA)

ENUM_TLD false yes Perform a top-level domain expansion by replacing TLD and testing against IANA TLD list

IPRANGE no The target address range or CIDR identifier

NS no Specify the nameserver to use for queries, otherwise use the system DNS

STOP_WLDCRD false yes Stops Brute Force Enumeration if wildcard resolution is detected

WORDLIST /opt/metasploit3/msf3/data/wordlists/namelist.txt no Wordlist file for domain name brute force.

msf auxiliary(dns_enum) > run

[*] Setting DNS Server to google.com NS: 216.239.32.10

[*] Retrieving General DNS Records

[*] Domain: google.com IP Address: 74.125.230.144 Record: A

[*] Domain: google.com IP Address: 74.125.230.146 Record: A

[*] Domain: google.com IP Address: 74.125.230.147 Record: A

[*] Domain: google.com IP Address: 74.125.230.145 Record: A

[*] Domain: google.com IP Address: 74.125.230.148 Record: A

[*] Start of Authority: ns1.google.com. IP Address: 216.239.32.10 Record: SOA

[*] Name Server: ns2.google.com. IP Address: 216.239.34.10 Record: NS

[*] Name Server: ns4.google.com. IP Address: 216.239.38.10 Record: NS

[*] Name Server: ns1.google.com. IP Address: 216.239.32.10 Record: NS

[*] Name Server: ns3.google.com. IP Address: 216.239.36.10 Record: NS

[*] Name: alt1.aspmx.l.google.com. Preference: 20 Record: MX

[*] Name: alt3.aspmx.l.google.com. Preference: 40 Record: MX

[*] Name: alt4.aspmx.l.google.com. Preference: 50 Record: MX

[*] Name: alt2.aspmx.l.google.com. Preference: 30 Record: MX

[*] Name: aspmx.l.google.com. Preference: 10 Record: MX

[*] Text: v=spf1 include:_netblocks.google.com ip4:216.73.93.70/31 ip4:216.73.93.72/31 ~all , TXT

[*] Auxiliary module execution completed

Se han podido encontrar Los NameServer del dominio, las direcciones IP (Registros A) del dominio, al igual que los registros SOA, TXT y MX.

Este modulo también registra todos los resultados relevantes en base de datos (en el caso de que se haya establecido una conexión previamente) para consultar la información almacenada se ejecuta el comando db_notes.

msf auxiliary(dns_enum) > db_notes
[*] Time: Sat Jun 11 10:53:57 UTC 2011 Note: host=209.85.229.147 service=dns type=DNS_ENUM data=»209.85.229.147,google.com,A»[*] Time: Sat Jun 11 10:53:57 UTC 2011 Note: host=209.85.229.104 service=dns type=DNS_ENUM data=»209.85.229.104,google.com,A»[*] Time: Sat Jun 11 10:53:57 UTC 2011 Note: host=209.85.229.99 service=dns type=DNS_ENUM data=»209.85.229.99,google.com,A»[*] Time: Sat Jun 11 10:53:58 UTC 2011 Note: host=216.239.38.10 service=dns type=DNS_ENUM data=»216.239.38.10,ns4.google.com.,NS»

[*] Time: Sat Jun 11 10:53:58 UTC 2011 Note: host=216.239.36.10 service=dns type=DNS_ENUM data=»216.239.36.10,ns3.google.com.,NS»

[*] Time: Sat Jun 11 10:53:58 UTC 2011 Note: host=216.239.34.10 service=dns type=DNS_ENUM data=»216.239.34.10,ns2.google.com.,NS»

[*] Time: Sat Jun 11 10:53:58 UTC 2011 Note: host=216.239.32.10 service=dns type=DNS_ENUM data=»v=spf1 include:_netblocks.google.com ip4:216.73.93.70/31 ip4:216.73.93.72/31 ~all ,TXT»

Por otro lado se puede realizar una prueba de transferencia de zona para determinar si esta característica esta habilitada en el servidor DNS objetivo.

msf auxiliary(dns_enum) > set DOMAIN hostdns.com
DOMAIN => hostdns.com

msf auxiliary(dns_enum) > run

[*] This Domain has Wildcards Enabled!!

[*] Wildcard IP for 1618.hostdns.com is: 85.24.128.101

[*] Setting DNS Server to hostdns.com NS: 93.188.0.20

[*] Performing Zone Transfer against all nameservers in hostdns.com

[*] Testing Nameserver: ns1.loopia.se.

AXFR query, switching to TCP

[-] Zone Transfer Failed

[*] Testing Nameserver: ns2.loopia.se.

AXFR query, switching to TCP

[-] Zone Transfer Failed

[*] Auxiliary module execution completed