forked from secdev/scapy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanswering_machines.uts
124 lines (100 loc) · 3.48 KB
/
answering_machines.uts
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
% Regression tests for Scapy Answering Machines
# More information at http://www.secdev.org/projects/UTscapy/
############
############
+ Answering Machines
= Generic answering machine mocker
import mock
@mock.patch("scapy.ansmachine.sniff")
def test_am(cls_name, packet_query, check_reply, mock_sniff, **kargs):
def sniff(*args,**kargs):
kargs["prn"](packet_query)
mock_sniff.side_effect = sniff
am = cls_name(**kargs)
am.send_reply = check_reply
am()
= BOOT_am
def check_BOOTP_am_reply(packet):
assert(BOOTP in packet and packet[BOOTP].op == 2)
assert(packet[BOOTP].yiaddr == "192.168.1.128" and packet[BOOTP].giaddr == "192.168.1.1")
test_am(BOOTP_am,
Ether()/IP()/UDP()/BOOTP(op=1),
check_BOOTP_am_reply)
= DHCP_am
def check_DHCP_am_reply(packet):
assert(DHCP in packet and len(packet[DHCP].options))
assert(("domain", "localnet") in packet[DHCP].options)
test_am(DHCP_am,
Ether()/IP()/UDP()/BOOTP(op=1)/DHCP(),
check_DHCP_am_reply)
= ARP_am
def check_ARP_am_reply(packet):
assert(ARP in packet and packet[ARP].psrc == "10.28.7.1")
assert(packet[ARP].hwsrc == "00:01:02:03:04:05")
test_am(ARP_am,
Ether()/ARP(pdst="10.28.7.1"),
check_ARP_am_reply,
IP_addr="10.28.7.1",
ARP_addr="00:01:02:03:04:05")
= DNS_am
def check_DNS_am_reply(packet):
assert(DNS in packet and packet[DNS].ancount == 1)
assert(packet[DNS].an.rdata == "192.168.1.1")
test_am(DNS_am,
IP()/UDP()/DNS(qd=DNSQR(qname="www.secdev.org")),
check_DNS_am_reply)
= DHCPv6_am - Basic Instantiaion
~ osx netaccess
a = DHCPv6_am()
a.usage()
a.parse_options(dns="2001:500::1035", domain="localdomain, local", duid=None,
iface=conf.iface6, advpref=255, sntpservers=None,
sipdomains=None, sipservers=None,
nisdomain=None, nisservers=None,
nispdomain=None, nispservers=None,
bcmcsdomains=None, bcmcsservers=None,
debug=1)
= DHCPv6_am - SOLICIT
~ osx netaccess
req = IPv6(dst="::1")/UDP()/DHCP6(msgtype=1)/DHCP6OptClientId(duid=DUID_LLT())
assert a.is_request(req)
res = a.make_reply(req)
assert not a.is_request(res)
assert res[DHCP6_Advertise]
assert res[DHCP6OptPref].prefval == 255
assert res[DHCP6OptReconfAccept]
a.print_reply(req, res)
= DHCPv6_am - INFO-REQUEST
~ osx netaccess
req = IPv6(dst="::1")/UDP()/DHCP6(msgtype=11)/DHCP6OptClientId(duid=DUID_LLT())
assert a.is_request(req)
res = a.make_reply(req)
assert not a.is_request(res)
assert res[DHCP6_Reply]
assert "local" in res[DHCP6OptDNSDomains].dnsdomains
a.print_reply(req, res)
= DHCPv6_am - REQUEST
~ osx netaccess
req = IPv6(dst="::1")/UDP()/DHCP6(msgtype=3)/DHCP6OptClientId(duid=DUID_LLT())/DHCP6OptServerId(duid=a.duid)
assert a.is_request(req)
res = a.make_reply(req)
assert not a.is_request(res)
assert res[UDP].dport == 546
assert res[DHCP6_Solicit]
a.print_reply(req, res)
= WiFi_am
import mock
@mock.patch("scapy.layers.dot11.sniff")
def test_WiFi_am(packet_query, check_reply, mock_sniff, **kargs):
def sniff(*args,**kargs):
kargs["prn"](packet_query)
mock_sniff.side_effect = sniff
am = WiFi_am(**kargs)
am.send_reply = check_reply
am()
def check_WiFi_am_reply(packet):
assert(isinstance(packet, list) and len(packet) == 2)
assert(TCP in packet[0] and Raw in packet[0] and raw(packet[0][Raw]) == b"5c4pY")
test_WiFi_am(Dot11(FCfield="to-DS")/IP()/TCP()/"Scapy",
check_WiFi_am_reply,
iffrom="scapy0", ifto="scapy1", replace="5c4pY", pattern="Scapy")