1% Tests for portmap module 2############ 3############ 4+ Packet Creation Tests 5 6= Create subpackets 7Map_Entry() 8 9= Create Portmap Packets 10NULL_Call() 11NULL_Reply() 12DUMP_Call() 13DUMP_Reply() 14GETPORT_Call() 15GETPORT_Reply() 16 17+ Test Layer bindings 18 19= RPC Layer Bindings for Portmap calls 20from scapy.contrib.oncrpc import * 21pkt = RPC()/RPC_Call()/NULL_Call() 22assert (pkt.mtype, pkt.program, pkt.pversion, pkt.procedure) == (0, 100000, 2, 0) 23pkt = RPC()/RPC_Call()/GETPORT_Call() 24assert (pkt.mtype, pkt.program, pkt.pversion, pkt.procedure) == (0, 100000, 2, 3) 25pkt = RPC()/RPC_Call()/DUMP_Call() 26assert (pkt.mtype, pkt.program, pkt.pversion, pkt.procedure) == (0, 100000, 2, 4) 27 28= RPC Layer Bindings for Portmap replies 29from scapy.contrib.oncrpc import * 30pkt = RPC()/RPC_Reply()/NULL_Reply() 31assert pkt.mtype == 1 32pkt = RPC()/RPC_Reply()/GETPORT_Reply() 33assert pkt.mtype == 1 34pkt = RPC()/RPC_Reply()/DUMP_Reply() 35assert pkt.mtype == 1 36 37+ Test Built Packets vs Raw Strings 38 39= Portmap calls vs Raw Strings 40pkt = GETPORT_Call( 41 prog=100003, 42 vers=3, 43 prot=6, 44 port=0 45) 46assert bytes(pkt) == b'\x00\x01\x86\xa3\x00\x00\x00\x03\x00\x00\x00\x06\x00\x00\x00\x00' 47 48= Portmap replies vs Raw Strings 49pkt = GETPORT_Reply( 50 port=2049 51) 52assert bytes(pkt) == b'\x00\x00\x08\x01' 53 54pkt = DUMP_Reply(value_follows=1, 55 mappings=[Map_Entry(prog=1, vers=2, prot=3, port=4, value_follows=1), 56 Map_Entry(prog=5, vers=6, prot=7, port=8, value_follows=0), 57 ] 58 ) 59assert bytes(pkt) == b'\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x05\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\x00' 60