secdev / scapy

Scapy: the Python-based interactive packet manipulation program & library.
https://scapy.net
GNU General Public License v2.0
10.67k stars 2.02k forks source link

ICMPExtensionMPLS #3018

Closed ghost closed 3 years ago

ghost commented 3 years ago

Hey found something kind of cool that I was hoping to try but I can't figure out what's going on with it or how it was intended to be used, the only docs I could find was this generated list of method signatures:

https://scapy.readthedocs.io/en/latest/_modules/scapy/contrib/icmp_extensions.html#ICMPExtensionHeader

In [90]: send(IP(dst="142.250.209.14")/ICMP()/ICMPExtensionHeader(version = 2)/ICMPExtensionMPLS(classnum = 1, classtype = 1))                              
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-90-400b6ecaea8e> in <module>
----> 1 send(IP(dst="142.250.209.14")/ICMP()/ICMPExtensionHeader(version = 2)/ICMPExtensionMPLS(classnum = 1, classtype = 1))

~/.local/lib/python3.6/site-packages/scapy-2.4.4.dev221-py3.6.egg/scapy/sendrecv.py in send(x, iface, *args, **kargs)
    355         x,
    356         lambda iface: iface.l3socket(), iface=iface,
--> 357         *args, **kargs
    358     )
    359 

~/.local/lib/python3.6/site-packages/scapy-2.4.4.dev221-py3.6.egg/scapy/sendrecv.py in _send(x, _func, inter, loop, iface, count, verbose, realtime, return_packets, socket, **kargs)                                                                                                                                   
    328     results = __gen_send(socket, x, inter=inter, loop=loop,
    329                          count=count, verbose=verbose,
--> 330                          realtime=realtime, return_packets=return_packets)
    331     if need_closing:
    332         socket.close()

~/.local/lib/python3.6/site-packages/scapy-2.4.4.dev221-py3.6.egg/scapy/sendrecv.py in __gen_send(s, x, inter, loop, count, verbose, realtime, return_packets, *args, **kargs)                                                                                                                                          
    302                     else:
    303                         dt0 = ct - float(p.time)
--> 304                 s.send(p)
    305                 if return_packets:
    306                     sent_packets.append(p)

~/.local/lib/python3.6/site-packages/scapy-2.4.4.dev221-py3.6.egg/scapy/arch/linux.py in send(self, x)
    569                     type_x, self.LL)
    570             self.LL = type_x
--> 571         sx = raw(ll(x))
    572         x.sent_time = time.time()
    573         try:

~/.local/lib/python3.6/site-packages/scapy-2.4.4.dev221-py3.6.egg/scapy/compat.py in raw(x)
    243         This function is and will always be cross-version compatible
    244         """
--> 245         return bytes(x)
    246 
    247     def bytes_encode(x):

~/.local/lib/python3.6/site-packages/scapy-2.4.4.dev221-py3.6.egg/scapy/packet.py in __bytes__(self)
    569     def __bytes__(self):
    570         # type: () -> bytes
--> 571         return self.build()
    572 
    573     def __div__(self, other):

~/.local/lib/python3.6/site-packages/scapy-2.4.4.dev221-py3.6.egg/scapy/packet.py in build(self)
    700         :return: string of the packet with the payload
    701         """
--> 702         p = self.do_build()
    703         p += self.build_padding()
    704         p = self.build_done(p)

~/.local/lib/python3.6/site-packages/scapy-2.4.4.dev221-py3.6.egg/scapy/packet.py in do_build(self)
    683         for t in self.post_transforms:
    684             pkt = t(pkt)
--> 685         pay = self.do_build_payload()
    686         if self.raw_packet_cache is None:
    687             return self.post_build(pkt, pay)

~/.local/lib/python3.6/site-packages/scapy-2.4.4.dev221-py3.6.egg/scapy/packet.py in do_build_payload(self)
    669         :return: a string of payload layer
    670         """
--> 671         return self.payload.do_build()
    672 
    673     def do_build(self):

~/.local/lib/python3.6/site-packages/scapy-2.4.4.dev221-py3.6.egg/scapy/packet.py in do_build(self)
    683         for t in self.post_transforms:
    684             pkt = t(pkt)
--> 685         pay = self.do_build_payload()
    686         if self.raw_packet_cache is None:
    687             return self.post_build(pkt, pay)

~/.local/lib/python3.6/site-packages/scapy-2.4.4.dev221-py3.6.egg/scapy/packet.py in do_build_payload(self)
    669         :return: a string of payload layer
    670         """
--> 671         return self.payload.do_build()
    672 
    673     def do_build(self):

~/.local/lib/python3.6/site-packages/scapy-2.4.4.dev221-py3.6.egg/scapy/packet.py in do_build(self)
    683         for t in self.post_transforms:
    684             pkt = t(pkt)
--> 685         pay = self.do_build_payload()
    686         if self.raw_packet_cache is None:
    687             return self.post_build(pkt, pay)

~/.local/lib/python3.6/site-packages/scapy-2.4.4.dev221-py3.6.egg/scapy/packet.py in do_build_payload(self)
    669         :return: a string of payload layer
    670         """
--> 671         return self.payload.do_build()
    672 
    673     def do_build(self):

~/.local/lib/python3.6/site-packages/scapy-2.4.4.dev221-py3.6.egg/scapy/packet.py in do_build(self)
    685         pay = self.do_build_payload()
    686         if self.raw_packet_cache is None:
--> 687             return self.post_build(pkt, pay)
    688         else:
    689             return pkt + pay

~/.local/lib/python3.6/site-packages/scapy-2.4.4.dev221-py3.6.egg/scapy/contrib/icmp_extensions.py in post_build(self, p, pay)
     56         if self.chksum is None:
     57             ck = checksum(p)
---> 58             p = p[:2] + chr(ck >> 8) + chr(ck & 0xff) + p[4:]
     59         return p + pay
     60 

TypeError: can't concat str to bytes

Hit a similar snag with this one too if you care to unwind it and see whats wrong with it (unrelated):

sudo python3 -c 'import emoji as e; import random as r; from scapy.all import *; import itertools; RT = RadioTap(); D11B = Dot11Beacon(); beacon_send = (lambda e, mac, intf: sendp(RT/Dot11(type=0, subtype=8, addr1="ff:ff:ff:ff:ff:ff", addr2=mac, addr3=mac)/D11B/Dot11Elt(ID="SSID", info=e, len=len(e) ), inter=0, iface=intf, loop=0) ); [ sys.stdout.write("{}\n".format(x)) and beacon_send("".join(r.sample(e.UNICODE_EMOJI.keys(), 8) ), x, "wlan0" ) for x in itertools.cycle( [str(x) for x in [RandMAC()] * 20 ] ) ]'

I haven't had much luck with scapy to tell you the truth, but it looks cool I like that operator overloading / factory pattern sort of thing. scapy looks really complete but I wonder how much of it actually works now unfortunately. I wish that help() on objects would give a common, terse usage example, that way I'd have a little confidence that somebody actually knew that it worked the way it was supposed to, as opposed to tracking things down all over the internet.

guedou commented 3 years ago

I fixed the MPLS extension issue.

Could you open another issue with the second problem and provide a simple reproducer? It will be really helpful to fill the issue template.

ghost commented 3 years ago

Sure I can do that, I'll leave this ticket open since the pull request is awaiting review still --

EDIT: actually I don't really know how you would do that because it does technically appear to be working, https://gist.github.com/philoctetes409bc/05c8f6cf2479d0daf57e9a43b74a7f0b but I have no way of checking at the moment, but if I remember right I expected to see these appear in "Available networks" of various wireless devices and I may just be doing this incorrectly or it may not even be possible the way I'm trying to do it. If you have a means to test you're more than welcome to.