Nmap aracını port scan amaçlı kullanabileceğimiz gibi, gelişmiş özelliklerini kullanıp pentest amaçlı da kullanabiliriz.Port tarama aracı olarak Fyodor tarafından geliştirilmeye başlanılan nmap günümüzde zaafiyet bulma ve exploit etme özellikleri ile kendisini aşmış durumda :) Hackerlar ve pentestçilerin olmazsa olmaz araçlarından biridir.Bu yazımda nmap'in NSE(nmap script engine) özelliği üzerinde duracağım ve canlı bir örnek ile konuyu ele alacağım.
Ubuntu sistem üzerinde /usr/local/share/nmap/ yolunda nmap dosyalarına erişebilirsiniz:
root@pamuksekeri-pc:/usr/local/share/nmap# ls -lh
total 5.5M
-rw-r--r-- 1 root root 10K 2012-01-08 19:02 nmap.dtd
-rw-r--r-- 1 root root 386K 2012-01-08 19:02 nmap-mac-prefixes
-rw-r--r-- 1 root root 3.1M 2012-01-08 19:02 nmap-os-db
-rw-r--r-- 1 root root 9.8K 2012-01-08 19:02 nmap-payloads
-rw-r--r-- 1 root root 6.2K 2012-01-08 19:02 nmap-protocols
-rw-r--r-- 1 root root 49K 2012-01-08 19:02 nmap-rpc
-rw-r--r-- 1 root root 1.3M 2012-01-08 19:02 nmap-service-probes
-rw-r--r-- 1 root root 608K 2012-01-08 19:02 nmap-services
-rw-r--r-- 1 root root 32K 2012-01-08 19:02 nmap.xsl
drwxr-xr-x 3 root root 4.0K 2012-03-18 08:21 nselib
-rw-r--r-- 1 root root 41K 2012-01-08 19:02 nse_main.lua
drwxr-xr-x 2 root root 20K 2012-03-28 15:33 scripts
-rw-r--r-- 1 root root 1.4K 2012-03-29 20:45 test_nmap_results.xml
NSE kulandığı script'ler ise scripts dizini altında;
root@pamuksekeri-pc:/usr/local/share/nmap/scripts# ls -l | more
total 2412
-rw-r--r-- 1 root root 8222 2012-01-08 19:02 address-info.nse
-rw-r--r-- 1 root root 2872 2012-01-08 19:02 afp-brute.nse
-rw-r--r-- 1 root root 5617 2012-01-08 19:02 afp-ls.nse
-rw-r--r-- 1 root root 6842 2012-01-08 19:02 afp-path-vuln.nse
-rw-r--r-- 1 root root 5387 2012-01-08 19:02 afp-serverinfo.nse
-rw-r--r-- 1 root root 2470 2012-01-08 19:02 afp-showmount.nse
-rw-r--r-- 1 root root 1727 2012-01-08 19:02 amqp-info.nse
-rw-r--r-- 1 root root 15025 2012-01-08 19:02 asn-query.nse
-rw-r--r-- 1 root root 1962 2012-01-08 19:02 auth-owners.nse
-rw-r--r-- 1 root root 831 2012-01-08 19:02 auth-spoof.nse
-rw-r--r-- 1 root root 8942 2012-01-08 19:02 backorifice-brute.nse
-rw-r--r-- 1 root root 9558 2012-01-08 19:02 backorifice-info.nse
-rw-r--r-- 1 root root 5445 2012-01-08 19:02 banner.nse
-rw-r--r-- 1 root root 1632 2012-01-08 19:02 bitcoin-getaddr.nse
-rw-r--r-- 1 root root 1532 2012-01-08 19:02 bitcoin-info.nse
-rw-r--r-- 1 root root 3656 2012-01-08 19:02 bitcoinrpc-info.nse
-rw-r--r-- 1 root root 3619 2012-01-08 19:02 bittorrent-discovery.nse
-rw-r--r-- 1 root root 2892 2012-01-08 19:02 broadcast-avahi-dos.nse
-rw-r--r-- 1 root root 2283 2012-01-08 19:02 broadcast-db2-discover.nse
-rw-r--r-- 1 root root 6122 2012-01-08 19:02 broadcast-dhcp-discover.nse
-rw-r--r-- 1 root root 1468 2012-01-08 19:02 broadcast-dns-service-discovery.nse
-rw-r--r-- 1 root root 3403 2012-01-08 19:02 broadcast-dropbox-listener.nse
Ubuntu sistem üzerinde /usr/local/share/nmap/ yolunda nmap dosyalarına erişebilirsiniz:
root@pamuksekeri-pc:/usr/local/share/nmap# ls -lh
total 5.5M
-rw-r--r-- 1 root root 10K 2012-01-08 19:02 nmap.dtd
-rw-r--r-- 1 root root 386K 2012-01-08 19:02 nmap-mac-prefixes
-rw-r--r-- 1 root root 3.1M 2012-01-08 19:02 nmap-os-db
-rw-r--r-- 1 root root 9.8K 2012-01-08 19:02 nmap-payloads
-rw-r--r-- 1 root root 6.2K 2012-01-08 19:02 nmap-protocols
-rw-r--r-- 1 root root 49K 2012-01-08 19:02 nmap-rpc
-rw-r--r-- 1 root root 1.3M 2012-01-08 19:02 nmap-service-probes
-rw-r--r-- 1 root root 608K 2012-01-08 19:02 nmap-services
-rw-r--r-- 1 root root 32K 2012-01-08 19:02 nmap.xsl
drwxr-xr-x 3 root root 4.0K 2012-03-18 08:21 nselib
-rw-r--r-- 1 root root 41K 2012-01-08 19:02 nse_main.lua
drwxr-xr-x 2 root root 20K 2012-03-28 15:33 scripts
-rw-r--r-- 1 root root 1.4K 2012-03-29 20:45 test_nmap_results.xml
NSE kulandığı script'ler ise scripts dizini altında;
root@pamuksekeri-pc:/usr/local/share/nmap/scripts# ls -l | more
total 2412
-rw-r--r-- 1 root root 8222 2012-01-08 19:02 address-info.nse
-rw-r--r-- 1 root root 2872 2012-01-08 19:02 afp-brute.nse
-rw-r--r-- 1 root root 5617 2012-01-08 19:02 afp-ls.nse
-rw-r--r-- 1 root root 6842 2012-01-08 19:02 afp-path-vuln.nse
-rw-r--r-- 1 root root 5387 2012-01-08 19:02 afp-serverinfo.nse
-rw-r--r-- 1 root root 2470 2012-01-08 19:02 afp-showmount.nse
-rw-r--r-- 1 root root 1727 2012-01-08 19:02 amqp-info.nse
-rw-r--r-- 1 root root 15025 2012-01-08 19:02 asn-query.nse
-rw-r--r-- 1 root root 1962 2012-01-08 19:02 auth-owners.nse
-rw-r--r-- 1 root root 831 2012-01-08 19:02 auth-spoof.nse
-rw-r--r-- 1 root root 8942 2012-01-08 19:02 backorifice-brute.nse
-rw-r--r-- 1 root root 9558 2012-01-08 19:02 backorifice-info.nse
-rw-r--r-- 1 root root 5445 2012-01-08 19:02 banner.nse
-rw-r--r-- 1 root root 1632 2012-01-08 19:02 bitcoin-getaddr.nse
-rw-r--r-- 1 root root 1532 2012-01-08 19:02 bitcoin-info.nse
-rw-r--r-- 1 root root 3656 2012-01-08 19:02 bitcoinrpc-info.nse
-rw-r--r-- 1 root root 3619 2012-01-08 19:02 bittorrent-discovery.nse
-rw-r--r-- 1 root root 2892 2012-01-08 19:02 broadcast-avahi-dos.nse
-rw-r--r-- 1 root root 2283 2012-01-08 19:02 broadcast-db2-discover.nse
-rw-r--r-- 1 root root 6122 2012-01-08 19:02 broadcast-dhcp-discover.nse
-rw-r--r-- 1 root root 1468 2012-01-08 19:02 broadcast-dns-service-discovery.nse
-rw-r--r-- 1 root root 3403 2012-01-08 19:02 broadcast-dropbox-listener.nse
böyle devam edip gidiyor.Script pool'unu update etmek için nmap --script-update komutunu verebilirsiniz.NSE ile sistemler üzerinde bulunan açık portlara uygun scriptleri çalıştırarak varsa zaafiyet bunları bulabilir ve exploit edebilirsiniz.
Nmap scriptlerinin ihtiyaç duyduğu datalara ise /usr/local/share/nmap/nselib/data dizini altından erişilebilir.Örneğin login bruteforce yaparken kullanacağı username,password veya subdomain bruteforce için kullanılacak kelimeler bu dizin altında bulunur.Bunları isteğinize göre güncelleyip kullanabilirsiniz.
root@pamuksekeri-pc:/usr/local/share/nmap/nselib/data# ls -lh
total 620K
-rw-r--r-- 1 root root 5.8K 2012-01-08 19:02 favicon-db
-rw-r--r-- 1 root root 4.0K 2012-01-08 19:02 http-default-accounts-fingerprints.lua
-rw-r--r-- 1 root root 125K 2012-01-08 19:02 http-fingerprints.lua
-rw-r--r-- 1 root root 8.7K 2012-01-08 19:02 http-folders.txt
-rw-r--r-- 1 root root 9.3K 2012-01-08 19:02 mysql-cis.audit
-rw-r--r-- 1 root root 8.2K 2012-01-08 19:02 oracle-default-accounts.lst
-rw-r--r-- 1 root root 5.8K 2012-01-08 19:02 oracle-sids
-rw-r--r-- 1 root root 14K 2012-01-08 19:02 packetdecoders.lua
-rw-r--r-- 1 root root 46K 2012-01-08 19:02 passwords.lst
drwxr-xr-x 2 root root 4.0K 2012-03-18 08:21 psexec
-rw-r--r-- 1 root root 1.1K 2012-01-08 19:02 rtsp-urls.txt
-rw-r--r-- 1 root root 7.3K 2012-01-08 19:02 snmpcommunities.lst
-rw-r--r-- 1 root root 1.8K 2012-01-08 19:02 ssl-ciphers
-rw-r--r-- 1 root root 82K 2012-01-08 19:02 ssl-fingerprints
-rw-r--r-- 1 root root 1.7K 2012-03-29 20:39 test_nmap_results.xml
-rw-r--r-- 1 root root 1.5K 2012-01-08 19:02 tftplist.txt
-rw-r--r-- 1 root root 82 2012-03-29 19:51 usernames.lst
-rw-r--r-- 1 root root 253K 2012-01-08 19:02 wp-plugins.lst
Örnek olarak aşağıda snmp-brute.nse scriptinin kullandığı snmp community string değerlerini görebilirsiniz:
root@pamuksekeri-pc:/usr/local/share/nmap/nselib/data# more snmpcommunities.lst
public
private
snmpd
mngt
cisco
admin
Ftp portu açık olan bir uzak sunucu için, bu port üzerindeki zaafiyetleri bulup exploit eden tüm NSE scriptlerini çalıştırıp sonuçlarını bir xml dosyasına istenilen style'de yazan nmap komutu şu şekilde:
root@pamuksekeri-pc:/usr/local/share/nmap# nmap 10.10.10.10 -p 21 -sV -PN -n -vv --open --reason --script-trace --script "ftp*" -oX test-nmap-results.xml --stylesheet=nmap.xsl
Starting Nmap 5.61TEST4 ( http://nmap.org ) at 2012-03-29 23:12 EEST
NSE: Loaded 21 scripts for scanning.
NSE: Script Pre-scanning.
NSE: Starting runlevel 1 (of 1) scan.
Initiating SYN Stealth Scan at 23:12
Scanning 10.10.10.10 [1 port]
Discovered open port 21/tcp on 10.10.10.10
Completed SYN Stealth Scan at 23:12, 0.06s elapsed (1 total ports)
Initiating Service scan at 23:12
Scanning 1 service on 10.10.10.10
Completed Service scan at 23:12, 0.09s elapsed (1 service on 1 host)
NSE: Script scanning 10.10.10.10.
NSE: Starting runlevel 1 (of 1) scan.
Initiating NSE at 23:12
NSOCK (0.3400s) TCP connection requested to 10.10.10.10:21 (IOD #1) EID 8
NSOCK (0.3410s) TCP connection requested to 10.10.10.10:21 (IOD #2) EID 16
NSOCK (0.3410s) TCP connection requested to 10.10.10.10:21 (IOD #3) EID 24
NSOCK (0.3430s) TCP connection requested to 10.10.10.10:21 (IOD #4) EID 32
NSOCK (0.3430s) TCP connection requested to 10.10.10.10:21 (IOD #5) EID 40
NSOCK (0.3430s) TCP connection requested to 10.10.10.10:21 (IOD #6) EID 48
NSOCK (0.3970s) Callback: CONNECT SUCCESS for EID 8 [10.10.10.10:21]
NSE: TCP 192.168.1.51:38441 > 10.10.10.10:21 | CONNECT
NSOCK (0.3980s) Callback: CONNECT SUCCESS for EID 16 [10.10.10.10:21]
NSE: TCP 192.168.1.51:38442 > 10.10.10.10:21 | CONNECT
NSOCK (0.4010s) Callback: CONNECT SUCCESS for EID 24 [10.10.10.10:21]
NSE: TCP 192.168.1.51:38443 > 10.10.10.10:21 | CONNECT
NSOCK (0.4020s) Callback: CONNECT SUCCESS for EID 32 [10.10.10.10:21]
NSE: TCP 192.168.1.51:38444 > 10.10.10.10:21 | CONNECT
...
...
...
NSE: TCP 192.168.1.51:38502 > 10.10.10.10:21 | CLOSE
Completed NSE at 23:15, 46.28s elapsed
Nmap scan report for 10.10.10.10
Host is up, received user-set (0.029s latency).
Scanned at 2012-03-29 23:14:14 EEST for 46s
PORT STATE SERVICE REASON VERSION
21/tcp open ftp syn-ack ProFTPD
| ftp-brute:
|_ test: test
Service Info: OS: Unix
NSE: Script Post-scanning.
NSE: Starting runlevel 1 (of 1) scan.
Read data files from: /usr/local/bin/../share/nmap
Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 46.66 seconds
Raw packets sent: 1 (44B) | Rcvd: 1 (44B)
Tüm ftp scriptlerini çalıştırdığımız için, bu scriptlerden ftp-brute.nse scripti görüldügü gibi ftp sunucu üzerinde k.adı:test ve şifre:test ile erişim yapılabildiğini buldu.
Burada denenen tüm ftp scriptleri şunlardır:
root@pamuksekeri-pc:~# ls -lh /usr/local/share/nmap/scripts/ | grep ftp | cut -d " " -f8
ftp-anon.nse
ftp-bounce.nse
ftp-brute.nse
ftp-libopie.nse
ftp-proftpd-backdoor.nse
ftp-vsftpd-backdoor.nse
ftp-vuln-cve2010-4221.nse
tftp-enum.nse
Şimdi de sonuçlarımızı kaydettiğimiz xml dosyamıza bakalım.
Burada denenen tüm ftp scriptleri şunlardır:
root@pamuksekeri-pc:~# ls -lh /usr/local/share/nmap/scripts/ | grep ftp | cut -d " " -f8
ftp-anon.nse
ftp-bounce.nse
ftp-brute.nse
ftp-libopie.nse
ftp-proftpd-backdoor.nse
ftp-vsftpd-backdoor.nse
ftp-vuln-cve2010-4221.nse
tftp-enum.nse
Şimdi de sonuçlarımızı kaydettiğimiz xml dosyamıza bakalım.
Bu komut koşturulurken dikkat edilmesi gereken şey bu komutta kullanılan nmap.xsl dosyası ile komutun çalıştırıldığı dizin aynı olması gerekir aksi durumda dosyanın tam yolunu belirtmeniz gerekecektir.
Nmap ile ilgili geçmiş yazılara Pentest amaçlı network scanning , port scanning teknikleri , Pentest çalımalarında hedef OS tespiti ulaşabilirsiniz.

Yazı için teşekkürler. Nmap NSE konusundaki bilgi eskilikliğimi görmüş oldum. Yararlı oldu.
YanıtlaSilteşekkürler yorumunuz için..faydalı olmuşsa ne mutlu bize.
YanıtlaSil