Técnicas de Recolección de Información – Scripting con NMAP
Opciones por linea de comandos para Scripting con NMAP
Se trata de la opción que se utiliza para indicar el script a ejecutar, los otros parámetros que se indican (categoría y expresión) son valores opcionales que pueden o no, ser declarados. Cuando se indica el parámetro all se ejecutan todos los scripts contenidos en el directorio de scripts.
––script-args
Se trata de un conjunto de argumentos que se suministran a los Scripts que admiten parámetros para configurar su ejecución.
––script-help
Enseña ayuda sobre los scripts suministrados por parámetro, se puede indicar una categoría de scripts, un fichero .nse concreto, un directorio de scripts, una expresión o simplemente que enseñe toda la información de todos los scripts.
––script-trace
Se trata de una opción similar a –packet-trace pero funciona a nivel de aplicación en lugar de paquete a paquete. Si esta opción se especifica, toda la comunicación entrante y saliente ejecutada por los scripts es impresa en pantalla
––script-db
Actualiza la base de datos de scripts que
se encuentra localizada en el fichero scripts/script.db de Nmap,
solamente es útil ejecutar esta opción si se ha realizado algún cambio
sobre la estructura de los Scripts como por ejemplo adicionar uno nuevo o
remover uno existente.
-sC
Es equivalente a –script=default simplemente ejecuta un conjunto de script preconfigurados y que se encuentran en la categoría “Default”
Algunos Scripts NMAP:
Ahora es el momento de poner en practica algunas de las opciones anteriormente definidas, a continuación se enseña el uso de algunos scripts Nmap y las opciones de Scripting que ofrece enseñando los resultados sobre una red de privada para pruebas.
1. Ejecutando descubrimiento de Samba o servicios RPC en la maquina objetivo.
>nmap ––script=smb-os-discovery 192.168.1.35
Starting Nmap 5.51 ( http://nmap.org ) at 2011-06-02 12:48 CEST NSE: Script Scanning completed. Nmap scan report for 192.168.1.35 Host is up (0.00029s latency). Not shown: 997 closed ports PORT STATE SERVICE 135/tcp open msrpc 139/tcp open netbios-ssn 445/tcp open microsoft-ds MAC Address: 08:00:27:61:34:29 (Cadmus Computer Systems) Host script results: | smb-os-discovery: | OS: Windows XP (Windows 2000 LAN Manager) | Name: WORKGROUP\ANONYMOUS |_ System time: 2011-06-02 19:48:30 UTC-5 Nmap done: 1 IP address (1 host up) scanned in 1.74 seconds |
2. Ejecutando el script de enumeración de sesiones sobre el servicio SMB
>nmap ––script smb-enum-sessions 192.168.1.35
Starting Nmap 5.51 ( http://nmap.org ) at 2011-06-02 12:54 CEST NSE: Script Scanning completed. Nmap scan report for 192.168.1.35 Host is up (0.00074s latency). Not shown: 997 closed ports PORT STATE SERVICE 135/tcp open msrpc 139/tcp open netbios-ssn 445/tcp open microsoft-ds MAC Address: 08:00:27:61:34:29 (Cadmus Computer Systems) Host script results: | smb-enum-sessions: | Users logged in |_ Active SMB sessions Nmap done: 1 IP address (1 host up) scanned in 1.84 seconds |
3. Verificando si el objetivo tiene alguna vulnerabilidad explotable sobre el servicio remoto de SMB
>nmap ––script smb-check-vulns ––script-args=unsafe=1 192.168.1.35
Starting Nmap 5.51 ( http://nmap.org ) at 2011-06-02 12:56 CEST NSE: Script Scanning completed. Nmap scan report for 192.168.1.35 Host is up (0.00046s latency). Not shown: 997 closed ports PORT STATE SERVICE 135/tcp open msrpc 139/tcp open netbios-ssn 445/tcp open microsoft-ds MAC Address: 08:00:27:61:34:29 (Cadmus Computer Systems) Host script results: | smb-check-vulns: | MS08-067: NOT VULNERABLE | Conficker: Likely CLEAN | |_ SMBv2 DoS (CVE-2009-3103): NOT VULNERABLE Nmap done: 1 IP address (1 host up) scanned in 6.71 seconds |
4. Capturando información relacionada con los headers de un servidor web.
>nmap ––script http-headers http://www.xxxxxx.com
Starting Nmap 5.21 ( http://nmap.org ) at 2011-06-02 13:07 CEST NSE: Script Scanning completed. Nmap scan report for http://www.xxxxxx.com (86.109.162.80) Host is up (0.063s latency). rDNS record for 86.109.162.80: a0019.abansys.com Not shown: 977 closed ports PORT STATE SERVICE 21/tcp open ftp 22/tcp open ssh 25/tcp open smtp 53/tcp open domain 80/tcp open http | http-headers: | Date: Thu, 02 Jun 2011 11:07:25 GMT | Server: Apache/2.0.53 (Fedora) | X-Powered-By: PHP/4.4.4 | Set-Cookie: qtrans_cookie_test=qTranslate+Cookie+Test; path=/; domain=www.xxxxxx.com | X-Pingback: http://www.xxxxxx.com/xmlrpc.php | Connection: close | Content-Type: text/html; charset=UTF-8 | |_ (Request type: HEAD) 106/tcp open pop3pw 110/tcp open pop3 111/tcp open rpcbind 143/tcp open imap 199/tcp open smux 443/tcp open https | http-headers: | Date: Thu, 02 Jun 2011 11:07:25 GMT | Server: Apache/2.0.53 (Fedora) | Last-Modified: Wed, 24 Aug 2005 06:26:41 GMT | ETag: “780189-33f-fee24a40″ | Accept-Ranges: bytes | Content-Length: 831 | Connection: close | Content-Type: text/html | |_ (Request type: HEAD) 465/tcp open smtps 587/tcp open submission 631/tcp open ipp 993/tcp open imaps 995/tcp open pop3s 1720/tcp filtered H.323/Q.931 3306/tcp open mysql 8009/tcp open ajp13 8080/tcp open http-proxy 8443/tcp open https-alt | http-headers: | Date: Thu, 02 Jun 2011 11:07:25 GMT | Server: Apache | Location: https://a0019.abansys.com:8443 | Connection: close | Content-Type: text/html; charset=iso-8859-1 | |_ (Request type: GET) 9080/tcp open unknown 32769/tcp open unknown Nmap done: 1 IP address (1 host up) scanned in 8.28 seconds |
5. Verificando la existencia de Maleware en un objetivo.
>nmap ––script http-malware-host 192.168.1.34
Starting Nmap 5.21 ( http://nmap.org ) at 2011-06-02 13:15 CEST NSE: Script Scanning completed. Nmap scan report for 192.168.1.34 Host is up (0.00058s latency). Not shown: 987 closed ports PORT STATE SERVICE 21/tcp open ftp 80/tcp open http |_http-malware-host: Host appears to be clean 135/tcp open msrpc 139/tcp open netbios-ssn 443/tcp open https |_http-malware-host: Host appears to be clean 445/tcp open microsoft-ds 3306/tcp open mysql 5357/tcp open unknown 49152/tcp open unknown 49153/tcp open unknown 49154/tcp open unknown 49155/tcp open unknown 49156/tcp open unknown MAC Address: 08:00:27:E3:E3:3D (Cadmus Computer Systems) Nmap done: 1 IP address (1 host up) scanned in 2.20 seconds |
6. Escaneo broadcast, ejecutando distintos scripts definidos en Nmap retornando como resultado información útil sobre el segmento de red donde se ejecuta
>nmap -P0 ––script broadcast
Starting Nmap 5.51 ( http://nmap.org ) at 2011-06-30 00:03 CEST Pre-scan script results: | broadcast-upnp-info: | 192.168.1.1 | Server: POSIX, UPnP/1.0, Intel MicroStack/1.0.2126 | Location: http://192.168.1.1:62042/ | 192.168.249.1 | Server: POSIX, UPnP/1.0, Intel MicroStack/1.0.2126 |_ Location: http://192.168.249.1:62042/ | broadcast-dns-service-discovery: | 192.168.1.33 | 9/tcp workstation | Address=192.168.1.33 fe80:0:0:0:5642:49ff:fefa:c10d | 192.168.1.41 | 9/tcp workstation |_ Address=192.168.1.41 fe80:0:0:0:21b:24ff:fec3:4e62 WARNING: No targets were specified, so 0 hosts scanned. Nmap done: 0 IP addresses (0 hosts up) scanned in 40.09 seconds |
7. Ejecución de escaneo utilizando los perfiles de scripts “default” y “safe” indicados en párrafos anteriores.
>nmap ––script default,safe
Starting Nmap 5.51 ( http://nmap.org ) at 2011-06-30 22:04 CEST Stats: 0:00:06 elapsed; 0 hosts completed (0 up), 0 undergoing Script Pre-Scan Pre-scan script results: | broadcast-upnp-info: | 192.168.1.1 | Server: POSIX, UPnP/1.0, Intel MicroStack/1.0.2126 | Location: http://192.168.1.1:62042/ | 192.168.249.1 | Server: POSIX, UPnP/1.0, Intel MicroStack/1.0.2126 |_ Location: http://192.168.249.1:62042/ | broadcast-dns-service-discovery: | 192.168.1.33 | 9/tcp workstation | Address=192.168.1.33 fe80:0:0:0:5642:49ff:fefa:c10d | 192.168.1.41 | 9/tcp workstation |_ Address=192.168.1.41 fe80:0:0:0:21b:24ff:fec3:4e62 WARNING: No targets were specified, so 0 hosts scanned. Nmap done: 0 IP addresses (0 hosts up) scanned in 40.31 seconds |
8. Ejecuta los scripts contenidos en la categoría “default”, ejecuta el script “banner” y los scripts localizados en el directorio /home/adastra”
>nmap ––script default,banner,/home/adastra/ 192.168.1.34
Starting Nmap 5.51 ( http://nmap.org ) at 2011-06-30 22:08 CEST Nmap scan report for 192.168.1.34 Host is up (0.0000030s latency). Not shown: 994 closed ports PORT STATE SERVICE 21/tcp open ftp | banner: 220———- Welcome to Pure-FTPd [privsep] [TLS] ———-\x |_0D\x0A220-You are user number 3 of 50 allowed.\x0D\x0A220-Local time… 22/tcp open ssh |_banner: SSH-2.0-OpenSSH_5.5p1 Debian-6 | ssh-hostkey: 1024 57:91:68:60:9d:1c:18:7e:9f:f2:31:ad:82:9d:34:5f (DSA) |_2048 aa:39:79:ef:31:01:14:91:ae:42:c6:e4:0f:36:96:96 (RSA) 53/tcp open domain 80/tcp open http |_http-title: Site doesn’t have a title (text/html). 111/tcp open rpcbind 443/tcp open https |_http-title: Site doesn’t have a title (text/html). Nmap done: 1 IP address (1 host up) scanned in 10.37 seconds |
9. Ejecutando todos los script que coincidan con la expresión “http-*” el símbolo de “*” tiene el mismo significado que en cualquier sistema UNIX.
>nmap ––script “http-*” 192.168.1.34
Starting Nmap 5.51 ( http://nmap.org ) at 2011-06-30 22:17 CEST Nmap scan report for 192.168.1.34 Host is up (0.0000030s latency). Not shown: 994 closed ports PORT STATE SERVICE 21/tcp open ftp 22/tcp open ssh 53/tcp open domain 80/tcp open http | http-brute: |_ ERROR: No path was specified (see http-brute.path) |_http-methods: GET HEAD POST OPTIONS | http-headers: | Date: Thu, 30 Jun 2011 20:17:02 GMT | Server: Apache/2.2.16 (Debian) | Last-Modified: Fri, 03 Jun 2011 09:32:38 GMT | ETag: “30763-b1-4a4cb6f36ec48″ | Accept-Ranges: bytes | Content-Length: 177 | Vary: Accept-Encoding | Connection: close | Content-Type: text/html | |_ (Request type: HEAD) |_http-malware-host: Host appears to be clean | http-form-brute: |_ ERROR: No uservar was specified (see http-form-brute.uservar) |_http-title: Site doesn’t have a title (text/html). |_http-iis-webdav-vuln: ERROR: This web server is not supported. |_http-date: Thu, 30 Jun 2011 20:17:02 GMT; +1s from local time. | http-enum: | /icons/: Potentially interesting folder w/ directory listing |_ /manual/: Potentially interesting folder | http-domino-enum-passwords: |_ ERROR: No valid credentials were found (see domino-enum-passwords.username and domino-enum-passwords.password) 111/tcp open rpcbind 443/tcp open https | http-brute: |_ ERROR: No path was specified (see http-brute.path) | http-form-brute: |_ ERROR: No uservar was specified (see http-form-brute.uservar) |_http-methods: GET HEAD POST OPTIONS |_http-title: Site doesn’t have a title (text/html). |_http-iis-webdav-vuln: ERROR: This web server is not supported. |_http-date: Thu, 30 Jun 2011 20:17:02 GMT; +1s from local time. |_http-malware-host: Host appears to be clean | http-headers: | Date: Thu, 30 Jun 2011 20:17:02 GMT | Server: Apache/2.2.16 (Debian) | Last-Modified: Fri, 03 Jun 2011 09:32:38 GMT | ETag: “30763-b1-4a4cb6f36ec48″ | Accept-Ranges: bytes | Content-Length: 177 | Vary: Accept-Encoding | Connection: close | Content-Type: text/html | |_ (Request type: HEAD) | http-enum: | /icons/: Potentially interesting folder w/ directory listing |_ /manual/: Potentially interesting folder | http-domino-enum-passwords: |_ ERROR: No valid credentials were found (see domino-enum-passwords.username and domino-enum-passwords.password) Nmap done: 1 IP address (1 host up) scanned in 8.55 seconds |
10. Ejecuta un escaneo utilizando todos los script cargados, excepto aquellos que se encuentran la categoría intrusive anteriormente indicada.
>nmap ––script “not intrusive”
Starting Nmap 5.51 ( http://nmap.org ) at 2011-06-30 22:20 CEST Pre-scan script results: | broadcast-upnp-info: | 192.168.1.1 | Server: POSIX, UPnP/1.0, Intel MicroStack/1.0.2126 | Location: http://192.168.1.1:62042/ | 192.168.249.1 | Server: POSIX, UPnP/1.0, Intel MicroStack/1.0.2126 |_ Location: http://192.168.249.1:62042/ | broadcast-dns-service-discovery: | 192.168.1.33 | 9/tcp workstation | Address=192.168.1.33 fe80:0:0:0:5642:49ff:fefa:c10d | 192.168.1.41 | 9/tcp workstation |_ Address=192.168.1.41 fe80:0:0:0:21b:24ff:fec3:4e62 WARNING: No targets were specified, so 0 hosts scanned. Nmap done: 0 IP addresses (0 hosts up) scanned in 40.19 seconds |
11. Ejecuta los scripts contenidos en las categorías default o en la categoría safe es equivalente a ejecutar –script “default,safe”
>nmap ––script “default or safe”
Starting Nmap 5.51 ( http://nmap.org ) at 2011-06-30 22:24 CEST Pre-scan script results: | broadcast-upnp-info: | 192.168.1.1 | Server: POSIX, UPnP/1.0, Intel MicroStack/1.0.2126 | Location: http://192.168.1.1:62042/ | 192.168.249.1 | Server: POSIX, UPnP/1.0, Intel MicroStack/1.0.2126 |_ Location: http://192.168.249.1:62042/ | broadcast-dns-service-discovery: | 192.168.1.33 | 9/tcp workstation | Address=192.168.1.33 fe80:0:0:0:5642:49ff:fefa:c10d | 192.168.1.41 | 9/tcp workstation |_ Address=192.168.1.41 fe80:0:0:0:21b:24ff:fec3:4e62 WARNING: No targets were specified, so 0 hosts scanned. Nmap done: 0 IP addresses (0 hosts up) scanned in 40.16 seconds |
12. Ejecutando un escaneo utilizando los scripts declarados en la categoría default o safe o intrusive y sin incluir todos los scripts que coincidan con el patrón “http-*”
>nmap ––script “(default or safe or intrusive) and not http-*”
Starting Nmap 5.51 ( http://nmap.org ) at 2011-06-30 22:33 CEST Pre-scan script results: | broadcast-upnp-info: | 192.168.1.1 | Server: POSIX, UPnP/1.0, Intel MicroStack/1.0.2126 | Location: http://192.168.1.1:62042/ | 192.168.249.1 | Server: POSIX, UPnP/1.0, Intel MicroStack/1.0.2126 |_ Location: http://192.168.249.1:62042/ | broadcast-dns-service-discovery: | 192.168.1.33 | 9/tcp workstation |_ Address=192.168.1.33 fe80:0:0:0:5642:49ff:fefa:c10d WARNING: No targets were specified, so 0 hosts scanned. Nmap done: 0 IP addresses (0 hosts up) scanned in 40.24 seconds |
13. Obteniendo información sobre los scripts que cumplen con el patrón “ssh-*”
>nmap ––script-help “ssh-*”
Starting Nmap 5.51 ( http://nmap.org ) at 2011-06-30 22:41 CEST ssh-hostkey Categories: safe default discovery http://nmap.org/nsedoc/scripts/ssh-hostkey.html Shows SSH hostkeys.
Shows the target SSH server’s key fingerprint and (with high enough
verbosity level) the public key itself. It records the discovered host
keys in |
14. Ejecutando un escaneo contra un
servidor SSH utilizando el script ssh-hostkey, este script recibe como
argumento el formato visual de la clave localizada, los valores posibles
son: hex,bubble,visual,full y all
>nmap ––script ssh-hostkey -p22 192.168.1.34 –script-args ssh_hostkey=’hex bubble visual’
Starting Nmap 5.51 ( http://nmap.org ) at 2011-06-30 23:04 CEST Nmap scan report for 192.168.1.34 Host is up (0.000065s latency). PORT STATE SERVICE 22/tcp open ssh | ssh-hostkey: 1024 57:91:68:60:9d:1c:18:7e:9f:f2:31:ad:82:9d:34:5f (DSA) | 1024 xulom-pecym-nybig-rykok-fonal-putad-mydez-fazot-fitop-heget-pexyx (DSA) | | +–[ DSA 1024]—-+ | | +*.+.. | | | o. * .. | | | … . | | | . o o | | | S = = E | | | = * = | | | . + + | | | . | | | | | +—————–+ | | 2048 aa:39:79:ef:31:01:14:91:ae:42:c6:e4:0f:36:96:96 (RSA) | 2048 xekaz-futyl-zelyk-dalik-pysam-ryfes-vofit-reket-zikor-zuruv-saxux (RSA) | | +–[ RSA 2048]—-+ | | ++ | | | . .. | | | + o .. | | | E .. | | | * + . S | | | . o . . | | | . .. o | | | oo. o | | | oo oo | |_+—————–+ Nmap done: 1 IP address (1 host up) scanned in 0.11 seconds |
Finalmente, se aconseja tener instalada la ultima versión de Nmap para poder ejecutar los scripts anteriores (en este caso la versión 5.51) Como se ha mencionado anteriormente, si la instalación de Nmap se ha realizado desde apt-get o dpkg, probablemente la ubicación de todos los scripts se encuentre en /usr/share/nmap/scripts
Gracias a http://thehackerway.com/2011/07/27/tecnicas-de-recoleccion-de-informacion-%E2%80%93-scripting-con-nmap/
Miguel
No hay comentarios.:
Publicar un comentario