1 % Regression tests for Scapy Nmap module 2 3 ~ nmap 4 5 ############ 6 ############ 7 + Basic Nmap OS fingerprints tests 8 9 = Module loading 10 load_module('nmap') 11 12 = Test functions 13 14 d = nmap_udppacket_sig(IP()/UDP(), IP(raw(IP()/ICMP(type=3, code=2)/IPerror()/UDPerror()))) 15 assert len(d) == 9 16 17 d = nmap_tcppacket_sig(IP()/TCP()) 18 assert len(d) == 5 19 20 = Fetch database 21 from __future__ import print_function 22 try: 23 from urllib.request import urlopen 24 except ImportError: 25 from urllib2 import urlopen 26 27 for i in range(10): 28 try: 29 open('nmap-os-fingerprints', 'wb').write(urlopen('https://raw.githubusercontent.com/nmap/nmap/9efe1892/nmap-os-fingerprints').read()) 30 break 31 except: 32 pass 33 34 conf.nmap_base = 'nmap-os-fingerprints' 35 36 = Database loading 37 assert len(nmap_kdb.get_base()) > 100 38 39 = fingerprint test: www.secdev.org 40 ~ netaccess 41 score, fprint = nmap_fp('www.secdev.org') 42 print(score, fprint) 43 assert score > 0.5 44 assert fprint 45 46 = fingerprint test: gateway 47 ~ netaccess 48 score, fprint = nmap_fp(conf.route.route('0.0.0.0')[2]) 49 print(score, fprint) 50 assert score > 0.5 51 assert fprint 52 53 = fingerprint test: to text 54 ~ netaccess 55 56 import re as re_ 57 58 a = nmap_sig("www.secdev.org", 80, 81) 59 a 60 for x in nmap_sig2txt(a).split("\n"): 61 assert re_.match(r"\w{2,4}\(.*\)", x) 62 63 = nmap_udppacket_sig test: www.google.com 64 ~ netaccess 65 66 a = nmap_sig("www.google.com", ucport=80) 67 assert len(a) > 3 68 assert len(a["PU"]) > 0 69 70 + Nmap errors triggering 71 72 = Nmap base not available 73 74 nmap_kdb.filename = "invalid" 75 nmap_kdb.reload() 76 assert nmap_kdb.filename == None 77 78 = Clear temp files 79 try: 80 os.remove('nmap-os-fingerprints') 81 except: 82 pass 83 84