2

I am new to scapy and I am following some online tutorial, but I am stuck at this problem. I am able to send packets through a wired connection but when I try this with wireless, I face this error. I tried searching google but it was of no help. I hope to find a solution. Thanks in advance.

I am using windows 8.1, python 2.7

>>> p=IP(dst="192.168.1.1")/ICMP()
>>> sr1(p)
Begin emission:
ERROR: --- Error sending packets
Traceback (most recent call last):
  File "c:\Python27\lib\site-packages\scapy\arch\windows\__init__.py", line 374,
 in sndrcv
    pks.send(p)
  File "c:\Python27\lib\site-packages\scapy\arch\pcapdnet.py", line 257, in send

    sx = str(cls()/x)
  File "c:\Python27\lib\site-packages\scapy\packet.py", line 268, in __str__
    return self.build()
  File "c:\Python27\lib\site-packages\scapy\packet.py", line 330, in build
    p = self.do_build()
  File "c:\Python27\lib\site-packages\scapy\packet.py", line 319, in do_build
    pkt = self.self_build()
  File "c:\Python27\lib\site-packages\scapy\packet.py", line 310, in self_build
    p = f.addfield(self, p, val)
  File "c:\Python27\lib\site-packages\scapy\fields.py", line 70, in addfield
    return s+struct.pack(self.fmt, self.i2m(pkt,val))
  File "c:\Python27\lib\site-packages\scapy\layers\l2.py", line 95, in i2m
    return MACField.i2m(self, pkt, self.i2h(pkt, x))
  File "c:\Python27\lib\site-packages\scapy\layers\l2.py", line 89, in i2h
    x = conf.neighbor.resolve(pkt,pkt.payload)
  File "c:\Python27\lib\site-packages\scapy\layers\l2.py", line 38, in resolve
    return self.resolvers[k](l2inst,l3inst)
  File "c:\Python27\lib\site-packages\scapy\layers\inet.py", line 732, in <lambd
a>
    conf.neighbor.register_l3(Ether, IP, lambda l2,l3: getmacbyip(l3.dst))
  File "c:\Python27\lib\site-packages\scapy\arch\windows\__init__.py", line 292,
 in getmacbyip
    ifip = str(pcapdnet.dnet.intf().get(iff)['addr'])
KeyError: 'addr'
INFO: --- Error sending packets
.........................
Received 25 packets, got 0 answers, remaining 1 packets
WARNING: __del__: don't know how to close the file descriptor. Bugs ahead ! Plea
se report this bug.
aaveg
  • 1,864
  • 2
  • 16
  • 15

4 Answers4

3

Slightly late, but:

I ran into the same problem a few months ago, and what worked for me eventually was to tunnel the WiFi through another network interface. It seems that the problem is in the IP obtaining process; Maybe you should try to run as administrator, and set the features of both Python and the Scapy files so that they have full control (right click->Properties->Security).

Do you encounter the same problem while using other methods like send/sr/srp?

FitzChivalry
  • 339
  • 2
  • 19
  • Thanks for the comment. I tried changing the permissions to full control but that did not help. The problem lies in the function getmacbyip(). I changed that function a bit after which it started sending the packet but mac address is not resolved and packet is not delivered. – aaveg May 10 '15 at 17:14
  • srp works? that is a mystery... did you build it as Ether/IP when you used srp? because as far as I'm concerned srp doesn't work with layer 3 protocols. – FitzChivalry May 11 '15 at 18:53
  • I sent this packet to resolve mac address of a system on the network: >>>srp1(Ether(dst=ETHER_BROADCAST)/ARP(op="who-has", pdst="192.168.1.38"),type=ETH_P_ARP,iface="eth0",timeout=2,chainCC=0,nofilter=1). It is really strange that the packet is sent but it does not get a reply in the timeout period. this is why getmacbyip() function also fails – aaveg May 12 '15 at 01:11
  • So just to get it clear: you can send ARP but get no response, but you cannot sent IP at all? – FitzChivalry May 12 '15 at 08:22
  • Yes. Another piece of information if that helps: I tried sending this packet 20-30 times but got a response 2 times. – aaveg May 12 '15 at 11:57
2

I find solution ;}

Just edit c:\Python27\lib\site-packages\scapy\arch\windows__init__.py Like this:

  1. Delete c:\Python27\lib\site-packages\scapy\arch\windows__init__.pyc
  2. Change line get(iff)['addr']) to get(iff)['link_addr'])
lukas kiss
  • 381
  • 2
  • 15
  • I tried that earlier but I get another error which says scapy cannot resolve the mac address of the destination – aaveg May 10 '15 at 16:33
0

In case anybody else has issues with getmacbyip() timing out before it can resolve a MAC, here's a band-aid fix that works:

mac = None
while not mac:
    mac = getmacbyip(ipaddr)

getmacbyip() will return None if it doesn't resolve. This works, but it will still take a few seconds. I wish this wasn't necessary to make it work.

multithr3at3d
  • 510
  • 1
  • 5
  • 14
0

I've update my scapy to the dev version (https://github.com/secdev/scapy/), and then it's working properly.

CyTex
  • 119
  • 1
  • 5