sniff(filter='icmp', iface=['eth0', 'eth1'], prn=lambda x: x.show())
iface_b = create_string_buffer(network_name(iface).encode("utf8"))
AttributeError: 'list' object has no attribute 'encode'
Hello everyone! Just a quick question regarding https://github.com/secdev/scapy/blob/dcd54d59c94b83632b74e268e8b14026cbcd67c8/scapy/contrib/http2.py#L2672
parse_txt_hdrs' type hints clearly state that this metod has a string as input, but the first thing that it does is embed the string in a BytesIO object, which requires bytes as an input, is this a leftover from a previous version of the code or rather a typo? Thanks in advance
Is there a trick to insert one bye in front of Packet?
Conceptually this kind of operation is needed. I am developing a trick to resolve the 'max_val' thing I mentioned above.new_packet = b'\x02' + old_packet
I tried this way. It seems working
new_packet = Packet(max_val.to_bytes(1, 'big') + raw(old_packet))
I found a strange thing in packet print.
It seems there are extra backslashes. I am not sure which one is correct.
Packet type is
IP / TCP 47.1.1.1:42219 > 47.1.1.5:ssh PA / Raw
Raw after TCP in Old Version (Released version, my old log record)
###[ Raw ]###
load = '\x0f*E\x12\x83^\x86\xfca\xa9....
Raw after TCP in New Version (GIT version)
###[ Raw ]###
load = '\x0f*E\x12\\x83^\\x86\\xfca\\xa9....
packet[Raw].load
lfilter
instead?
scapy -H
I see many warnings like /usr/lib/python3.10/site-packages/prompt_toolkit/renderer.py:514: DeprecationWarning: The explicit passing of coroutine objects to asyncio.wait() is deprecated since Python 3.8, and scheduled for removal in Python 3.11.
, is there any way to suppress those info?
I've got pcap for 30 seconds (91MB, 519k packets) and its dissect takes forever (~100 sec).
Tried disable most payload_guess
for Ether
/ IP
/ TCP
/ UDP
but got very minor (~5%) speed up.
Is there any way to speed up packets dissect, as I actually only need TCP
/ UDP
fields and not underlying layers?
Found similar issue secdev/scapy#2055 from 2019, but best answer was switch to other libraries.
Profiling shows most time at field access:
147.559 MainThread <thread>:12524
└─ 147.558 <module> <stdin>:1
└─ 147.558 <listcomp> <stdin>:1
└─ 147.076 __call__ scapy\base_classes.py:370
└─ 144.964 __init__ scapy\packet.py:129
├─ 134.626 dissect scapy\packet.py:998
│ ├─ 126.404 do_dissect_payload scapy\packet.py:972
│ │ ├─ 115.127 __call__ scapy\base_classes.py:370
│ │ │ └─ 114.058 __init__ scapy\packet.py:129
│ │ │ ├─ 101.785 dissect scapy\packet.py:998
│ │ │ │ ├─ 65.001 do_dissect_payload scapy\packet.py:972
│ │ │ │ │ ├─ 54.295 __call__ scapy\base_classes.py:370
│ │ │ │ │ │ └─ 53.096 __init__ scapy\packet.py:129
│ │ │ │ │ │ ├─ 40.858 dissect scapy\packet.py:998
│ │ │ │ │ │ │ ├─ 29.573 do_dissect scapy\packet.py:952
│ │ │ │ │ │ │ │ ├─ 10.320 getfield scapy\fields.py:2200
│ │ │ │ │ │ │ │ │ ├─ 5.328 m2i scapy\fields.py:2922
│ │ │ │ │ │ │ │ │ │ └─ 4.508 _fixup_val scapy\fields.py:2906
│ │ │ │ │ │ │ │ │ │ └─ 4.073 __init__ scapy\fields.py:2711
│ │ │ │ │ │ │ │ │ │ └─ 3.156 __setattr__ scapy\fields.py:2825
│ │ │ │ │ │ │ │ │ │ └─ 3.110 [self]
│ │ │ │ │ │ │ │ │ └─ 4.221 [self]
│ │ │ │ │ │ │ │ ├─ 5.086 [self]
│ │ │ │ │ │ │ │ ├─ 4.822 getfield scapy\layers\inet.py:367
│ │ │ │ │ │ │ │ │ └─ 3.282 m2i scapy\layers\inet.py:376
│ │ │ │ │ │ │ │ │ └─ 2.178 [self]
│ │ │ │ │ │ │ │ ├─ 4.564 getfield scapy\fields.py:245
│ │ │ │ │ │ │ │ │ └─ 2.903 [self]
│ │ │ │ │ │ │ │ └─ 3.500 do_copy scapy\fields.py:258
│ │ │ │ │ │ │ │ └─ 1.989 copy scapy\fields.py:2839
│ │ │ │ │ │ │ │ └─ 1.721 __init__ scapy\fields.py:2711
│ │ │ │ │ │ │ └─ 10.373 do_dissect_payload scapy\packet.py:972
│ │ │ │ │ │ │ ├─ 5.279 __call__ scapy\base_classes.py:370
│ │ │ │ │ │ │ │ └─ 4.892 __init__ scapy\packet.py:1878
│ │ │ │ │ │ │ │ └─ 4.563 __init__ scapy\packet.py:129
│ │ │ │ │ │ │ └─ 4.348 guess_payload_class scapy\packet.py:1011
│ │ │ │ │ │ │ └─ 1.795 [self]
│ │ │ │ │ │ ├─ 4.619 [self]
│ │ │ │ │ │ ├─ 2.740 __setattr__ scapy\packet.py:456
│ │ │ │ │ │ ├─ 2.138 __call__ scapy\base_classes.py:370
│ │ │ │ │ │ │ └─ 1.531 [self]
│ │ │ │ │ │ └─ 2.020 init_fields scapy\packet.py:224
│ │ │ │ │ │ └─ 1.582 do_init_cached_fields scapy\packet.py:251
# Measurement Request Header 1
ByteField("element_id1", 0),
ByteField("length1", 0),
ByteField("token1", 0),
ByteField("request_mode1", 0),
ByteEnumField("measurement_type1", 0, measurement_type),
# LCI Request
ByteEnumField("LCI_Location_Subject", 0, location_subject),
# Measurement Request Header 2
ByteField("element_id2", 0),
ByteField("length2", 0),
ByteField("token2", 0),
ByteField("request_mode2", 0),
ByteEnumField("measurement_type1", 0, measurement_type),
# Location Civic Request Field
ByteEnumField("Civic_Location_Subject", 0, location_subject),
ByteEnumField("Civic_Location_Type", 0, civic_location_type),
ByteEnumField(
"Location_Service_Interval_Units", 0, civic_location_interval_units
),```
Hey I'm thinking of using scapy inside of python module's but I'm really put off that I can't import it efficiently
import scapy.all as scapy
really just doesn't cut it because there is zero autocompletion within an ide like pycharm. I tried doing something more targeted like.
from scapy.compat import raw
from scapy.layers.dns import DNS
from scapy.layers.inet import UDP, IP, in4_chksum
But when I do this I get hit with circular import errors. Is there something I'm missing?
assert 0 == rsp.payload.status # Ok but I would like to compare it the the defined enum value
assert "STATUS_OK" == rsp.payload.status # Which cannot be done like this
def field2str(pkt, field_name):
field, val = pkt.getfield_and_val(field_name)
return field.i2repr(pkt, val)
assert "STATUS_OK" == field2str(rsp.payload, 'status') # Can be done like this, but looks too verbose to me