blob: 13ca7d27dcdbbe12dc25fb4e30c2d45a79b9554e [file] [log] [blame]
Guillaume Valadon35f97ef2016-12-02 08:07:09 +01001% Regression tests for Scapy BPF mode
2
3# More informations at http://www.secdev.org/projects/UTscapy/
4
5
6############
7############
8+ Addresses manipulation functions
9
10= Get the packet IPv4 address configured on conf.iface
11
12get_if_raw_addr(conf.iface)
13
14
15= Get the packed MAC address of conf.iface
16
17get_if_raw_hwaddr(conf.iface)
18
19= Get the packed MAC address of LOOPBACK_NAME
20
21get_if_raw_hwaddr(LOOPBACK_NAME) == (ARPHDR_LOOPBACK, '\x00'*6)
22
23
24############
25############
26+ BPF related functions
27
28= Get a BPF handler
29~ needs_root
30
31from scapy.arch.bpf.supersocket import get_dev_bpf
32fd, _ = get_dev_bpf()
33
34= Attach a BPF filter
35~ needs_root
36
37from scapy.arch.bpf.supersocket import attach_filter
38attach_filter(fd, conf.iface, "arp or icmp")
39
40
41= Get network interfaces list
42
43iflist = get_if_list()
44len(iflist) > 0
45
46
47= Get working network interfaces
48~ needs_root
49
50from scapy.arch.bpf.core import get_working_ifaces
51ifworking = get_working_ifaces()
52len(ifworking)
53
54from scapy.arch.bpf.core import get_working_if
55len(ifworking) and get_working_if() == ifworking[0][0]
56
57
58= Misc functions
59~ needs_root
60
61from scapy.arch.bpf.supersocket import isBPFSocket, bpf_select
62isBPFSocket(L2bpfListenSocket()) and isBPFSocket(L2bpfSocket()) and isBPFSocket(L3bpfSocket())
63
64l = bpf_select([L2bpfSocket()])
65l = bpf_select([L2bpfSocket(), sys.stdin.fileno()])
66
67
68############
69############
70+ BPF sockets
71
72= L2bpfListenSocket - initialization variants
73~ needs_root
74
75L2bpfListenSocket()
76L2bpfListenSocket(iface=conf.iface)
77L2bpfListenSocket(promisc=True)
78L2bpfListenSocket(filter="icmp")
79L2bpfListenSocket(iface=conf.iface, promisc=True, filter="icmp")
80
81
82= L2bpfListenSocket - set_*()
83~ needs_root
84
85s = L2bpfListenSocket()
86s.set_promisc(0)
87s.set_nonblock(1)
88s.set_promisc(0)
89s.close()
90
91s = L2bpfListenSocket()
92s.set_nonblock(set_flag=False)
93s.set_nonblock(set_flag=True)
94s.set_nonblock(set_flag=False)
95s.close()
96
97
98= L2bpfListenSocket - get_*()
99~ needs_root
100
101s = L2bpfListenSocket()
102blen = s.get_blen()
103blen > 0 and type(blen) == int
104s.close()
105
106s = L2bpfListenSocket()
107stats = s.get_stats()
108len(stats) == 2 and type(stats) == tuple
109s.close()
110
111
112= L2bpfListenSocket - other methods
113~ needs_root
114
115s = L2bpfListenSocket()
116type(s.fileno()) == int
117s.close()
118
119s = L2bpfListenSocket()
120guessed = s.guess_cls()
121issubclass(guessed, Packet)
122s.close()
123
124
125= L2bpfSocket - nonblock_recv()
126~ needs_root
127
128s = L2bpfSocket()
129s.nonblock_recv()
130s.close()
131
132
133= L*bpfSocket - send()
134~ needs_root
135
136s = L2bpfSocket()
137s.send(Ether()/IP(dst="8.8.8.8")/ICMP())
138
139s = L3bpfSocket()
140s.send(IP(dst="8.8.8.8")/ICMP())
141
142s = L3bpfSocket()
143s.assigned_interface = LOOPBACK_NAME
144s.send(IP(dst="8.8.8.8")/ICMP())