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