File: nmap.uts

package info (click to toggle)
scapy 2.6.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,956 kB
  • sloc: python: 163,618; sh: 90; makefile: 11
file content (96 lines) | stat: -rw-r--r-- 1,887 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
% Regression tests for Scapy Nmap module

~ nmap

############
############
+ Basic Nmap OS fingerprints tests

= Module loading
load_module('nmap')

= Test functions

d = nmap_udppacket_sig(IP()/UDP(), IP(raw(IP()/ICMP(type=3, code=2)/IPerror()/UDPerror())))
assert len(d) == 9

d = nmap_tcppacket_sig(IP()/TCP())
assert len(d) == 5

= Fetch database
~ netaccess

try:
    from urllib.request import urlopen
except ImportError:
    from urllib2 import urlopen

filename = 'nmap-os-fingerprints' + str(RandString(6))

def _test():
    with open(filename, 'wb') as fd:
        fd.write(urlopen('https://raw.githubusercontent.com/nmap/nmap/9efe1892/nmap-os-fingerprints').read())

retry_test(_test)

conf.nmap_base = filename

= Database loading
~ netaccess

print(conf.nmap_kdb.base, conf.nmap_kdb.filename, len(conf.nmap_kdb.get_base()))
assert len(conf.nmap_kdb.get_base()) > 100

= fingerprint test: www.secdev.org
~ netaccess needs_root
with no_debug_dissector():
    score, fprint = nmap_fp('www.secdev.org')

print(score, fprint)
assert score > 0.5
assert fprint

= fingerprint test: gateway
~ netaccess needs_root
with no_debug_dissector():
    score, fprint = nmap_fp(conf.route.route('0.0.0.0')[2])

print(score, fprint)
assert score > 0.5
assert fprint

= fingerprint test: to text
~  netaccess needs_root

import re as re_

with no_debug_dissector():
    a = nmap_sig("www.secdev.org", 80, 81)

a
for x in nmap_sig2txt(a).split("\n"):
    assert re_.match(r"\w{2,4}\(.*\)", x)

= nmap_udppacket_sig test: www.google.com
~ netaccess needs_root

with no_debug_dissector():
    a = nmap_sig("www.google.com", ucport=80)

assert len(a) > 3
assert len(a["PU"]) > 0

+ Nmap errors triggering

= Nmap base not available

conf.nmap_kdb.filename = "invalid"
conf.nmap_kdb.reload()
assert conf.nmap_kdb.filename == None

= Clear temp files
try:
    os.remove(filename)
except:
    pass