###[ UciControlPacket ]###
messageType= 0b001 (Control Command)
packetBoundaryFlag= 0b0: Complete
groupIdentifier= 0b0001 (UWB Session)
reserved0 = 0
opcodeIdentifier= 0b000001 (SESSION_DEINIT_CMD)
reserved1 = 0
payloadLength= 4
###[ SessionDeinitCmd ]###
sessionId = 1
Hi,
I am trying to use the PacketField class to implement a custom packet type.
The code detects the packets properly if I put the fields from CommandPacket
directly into CustomPacket
, but not when I use the PacketField
class.
It just detects the entire data as Raw
rather than CustomPacket
.
Do you know why it does not like to use the PacketField
in the fields?
bind_layers(UDP, CustomPacketHolder)
class CustomPacketHolder(Packet):
fields_desc = [
ShortField("header", 0),
PacketListField("data", [], CustomPacket)
]
class CustomPacket(Packet):
fields_desc = [
BitField("letter", 0, 4),
BitField("checkBits", 0, 12),
PacketField("command", None, CommandPacket)
]
def extract_padding(self, p):
return "", p
class CommandPacket(Packet):
fields_desc = [
BitField("field1", 0, 3),
BitField("field2", 0, 5),
BitField("field3", 0, 1),
BitField("field4", 0, 5),
BitField("field5", 0, 5),
BitField("field5", 0, 1)
]
def extract_padding(self, p):
return "", p
>>> a=sniff(filter='ip host 8.8.8.8', lfilter=lambda x: x.haslayer(DNS), count=2)
if nfs.ACCESS_Call in packet:
and packet[nfs.ACCESS_Call].filehandle
Hello, I am using scapy with a new protocol, which defines one of its operations like this :
For now I defined it like this, which works well for most config packets:
APP_CONF_PARAMS = {
# …
0x06: {
'name': 'DEVICE_MAC_ADDRESS',
'field': XLEShortField("value", default=None)},
0x07: {
'name': 'DST_MAC_ADDRESS',
'field': FieldListField('value', [], XLEShortField("item", default=None), length_from=lambda pkt: (pkt.length))}
# …
}
APP_CONF_PARAM_NAME_BY_ID = {i: data['name'] for i, data in APP_CONF_PARAMS.items()}
APP_CONF_PARAM_FIELD_BY_ID = {i: data['field'] for i, data in APP_CONF_PARAMS.items()}
class AppConfigParameter(PacketWithNoPayload):
fields_desc=[
XByteEnumField("type", None, APP_CONF_PARAM_NAME_BY_ID),
FieldLenField("length", None, fmt="B", length_of="value"),
MultipleTypeField(
# Use a field from APP_CONF_PARAMS if it can be found
[(field, (lambda i: lambda pkt: pkt.type == i)(i)) for i,field in APP_CONF_PARAM_FIELD_BY_ID.items()],
# Handle the parameter as a string if type is unknown
XStrLenField("value", None, length_from=lambda pkt:pkt.length)
)
]
class SessionSetAppConfigCmd(PacketWithNoPayload):
fields_desc=[
FieldLenField("numberOfAppConfiguration", None, fmt='B', count_of="appConfiguration"),
PacketListField("appConfiguration", [], AppConfigParameter,
count_from=lambda pkt: pkt.numberOfAppConfiguration)
]
I have one problem, with a particular config parameter which is used to define the Mac address length.
APP_CONF_PARAMS = {
# …
0x26: {
'name': 'MAC_ADDRESS_MODE',
'field': XByteEnumField("value", default=0x00, enum={
0x00: "MAC address is 2 bytes",
0x01: "MAC address is 8 bytes"})},
# …
}
When it is set to 0x01, mac addresses should be treated as as XLELongField instead of XLEShortField (as shown above).
from scapy.contrib import nfs
which causes all its bindings to execute, or run load_contrib('nfs')
which does the same.from scapy.contrib.nfs import ACCESS_Call
from scapy.contrib.oncrpc import RPC
from scapy.layers.inet import UDP
from scapy.main import load_contrib
from scapy.packet import bind_layers
from scapy.sendrecv import sniff
if __name__ == '__main__':
load_contrib('nfs')
bind_layers(UDP, RPC, sport=2049)
bind_layers(UDP, RPC, dport=2049)
pkts = sniff(offline="nfsv3.pcap")
for packet in pkts:
if ACCESS_Call in packet:
print(packet.show())
Hi, on hypervisors Virtual Machines (e.g. qemu) are usually connected to Virtual Bridges (e.g. Linux Bridge or OVS bridge) through tap devices.
When I try to inject Ethernet frame into tap device with sendp(..., iface=vnet0)
the frame goes to the VM but not to the Bridge.
Has anyone figured out how to send such frames with scapy to the Bridge instead? Basically the goal would be that scapy would allow to imitate VM.
from scapy import *
def live_capture(*args):
iface_list = [['-i', iface] for iface in args]
dumpcap_args = ['dumpcap'] + [arg for sublist in iface_list for arg in sublist] + ['-w', '-']
dumpcap = subprocess.Popen(args=dumpcap_args, stdout=subprocess.PIPE)
capture = sniff(offline=dumpcap.stdout, prn=lambda pkt: pkt.show(), store=0)
return capture
# pass your device names
live_capture('rpcap://[192.168.0.100]:2002/wl1', 'rpcap://[192.168.0.101]:2002/wl1')