secdev / scapy

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

WARNING: Could not get the source MAC: invalid literal for int() with base 16 when parsing IP address #3235

Closed aboelkassem closed 2 years ago

aboelkassem commented 3 years ago

Brief description

I'm trying to use scapy.arping() to create packets with ARP message to IP addresses, but when I passing the correct IP Address e.g 192.168.1.0/24 it gives me the following warning message and didn't send packets for local IP addresses

Begin emission:
WARNING: Could not get the source MAC: invalid literal for int() with base 16: ''
WARNING: Could not get the source MAC: invalid literal for int() with base 16: ''
WARNING: more Could not get the source MAC: invalid literal for int() with base 16: ''
Finished sending 256 packets.
*
Received 1 packets, got 1 answers, remaining 255 packets

Environment

Update

Using Scapy version 2.4.4 worked for me, so hoping to fix this problem in the latest version

gpotter2 commented 3 years ago

Hi, could you please share a snippet that reproduces the issue exactly? Thanks

aboelkassem commented 3 years ago

How to reproduce

Actual result

>>> arping('192.168.1.0/24')
Begin emission:
WARNING: Could not get the source MAC: invalid literal for int() with base 16: ''
WARNING: Could not get the source MAC: invalid literal for int() with base 16: ''
WARNING: more Could not get the source MAC: invalid literal for int() with base 16: ''
Finished sending 256 packets.
*
Received 1 packets, got 1 answers, remaining 255 packets
  <CorrectMACAdress> unknown 192.168.1.2
(<ARPing: TCP:0 UDP:0 ICMP:0 Other:1>, <Unanswered: TCP:0 UDP:0 ICMP:0 Other:255>)

Expected result Using scapy version 2.4.4 solved the problem for me and sending a packet message for more than one device without getting these WARNING messages

gpotter2 commented 3 years ago

Did you retry using the current github version?

aboelkassem commented 3 years ago

yea, I just cloning the current Github version to reproduce this

gpotter2 commented 3 years ago

Interesting. Could you show the results of the following (feel free to censor the IPs, but we need to make sure the IPs/MACs are well-formed):

aboelkassem commented 3 years ago

of course, but I see everything is normal, you can try it yourself but the result was

>>> conf.route
Network          Netmask          Gateway      Iface                                       Output IP      Metric
0.0.0.0          0.0.0.0          192.168.1.1  VMware Virtual Ethernet Adapter for VMnet1  CorrectIP      291
0.0.0.0          0.0.0.0          192.168.1.1  Realtek PCIe FE Family Controller           CorrectIP      35
0.0.0.0          0.0.0.0          192.168.1.1  Qualcomm QCA9377 802.11ac Wireless Adapter  CorrectIP      55
CorrectIP        255.255.255.0    0.0.0.0      VMware Virtual Ethernet Adapter for VMnet1  CorrectIP      291
CorrectIP        255.255.255.0    0.0.0.0      Realtek PCIe FE Family Controller           CorrectIP      291
CorrectIP        255.255.255.0    0.0.0.0      Qualcomm QCA9377 802.11ac Wireless Adapter  CorrectIP      311
CorrectIP        255.255.255.255  0.0.0.0      VMware Virtual Ethernet Adapter for VMnet1  CorrectIP      291
CorrectIP        255.255.255.255  0.0.0.0      VMware Virtual Ethernet Adapter for VMnet1  CorrectIP      291
CorrectIP        255.255.255.255  0.0.0.0      Realtek PCIe FE Family Controller           CorrectIP      291
CorrectIP        255.255.255.255  0.0.0.0      Qualcomm QCA9377 802.11ac Wireless Adapter  CorrectIP      311
CorrectIP        255.255.255.255  0.0.0.0      Qualcomm QCA9377 802.11ac Wireless Adapter  CorrectIP      311
CorrectIP        255.255.255.255  0.0.0.0      Realtek PCIe FE Family Controller           CorrectIP      291
CorrectIP        255.255.255.0    0.0.0.0      VMware Virtual Ethernet Adapter for VMnet8  CorrectIP      291
CorrectIP        255.255.255.255  0.0.0.0      VMware Virtual Ethernet Adapter for VMnet8  CorrectIP      291
CorrectIP        255.255.255.255  0.0.0.0      VMware Virtual Ethernet Adapter for VMnet8  CorrectIP      291
CorrectIP        240.0.0.0        0.0.0.0      VMware Virtual Ethernet Adapter for VMnet1  CorrectIP      291
CorrectIP        240.0.0.0        0.0.0.0      VMware Virtual Ethernet Adapter for VMnet8  CorrectIP      291
CorrectIP        240.0.0.0        0.0.0.0      Realtek PCIe FE Family Controller           CorrectIP      291
CorrectIP        240.0.0.0        0.0.0.0      Qualcomm QCA9377 802.11ac Wireless Adapter  CorrectIP      311
CorrectIP        240.0.0.0        0.0.0.0      Microsoft Wi-Fi Direct Virtual Adapter #5   CorrectIP      281
255.255.255.255  255.255.255.255  0.0.0.0      VMware Virtual Ethernet Adapter for VMnet1  CorrectIP      291
255.255.255.255  255.255.255.255  0.0.0.0      VMware Virtual Ethernet Adapter for VMnet8  CorrectIP      291
255.255.255.255  255.255.255.255  0.0.0.0      Realtek PCIe FE Family Controller           CorrectIP      291
255.255.255.255  255.255.255.255  0.0.0.0      Qualcomm QCA9377 802.11ac Wireless Adapter  CorrectIP      311
255.255.255.255  255.255.255.255  0.0.0.0      Microsoft Wi-Fi Direct Virtual Adapter #5   CorrectIP      281

>>> conf.route.route('192.168.1.0/24')
('\\Device\\NPF_{.....}', 'CorrectIP', '0.0.0.0')

>>> conf.ifaces
INFO: Table cropped to fit the terminal (conf.auto_crop_tables==True)
Source   Index  Name                               MAC                IPv4           IPv6
libpcap  11     Qualcomm QCA9377 802.11ac Wirele_  CorrectMAC      CorrectIP        CorrectIPv6
libpcap  14     Microsoft Wi-Fi Direct Virtual A_  CorrectMAC      CorrectIP        CorrectIPv6
libpcap  15     Realtek PCIe FE Family Controller  CorrectMAC      CorrectIP        CorrectIPv6  
libpcap  3      VMware Virtual Ethernet Adapter _  CorrectMAC      CorrectIP        CorrectIPv6 
libpcap  6      VMware Virtual Ethernet Adapter _  CorrectMAC      CorrectIP        CorrectIPv6
apalom commented 3 years ago

I'm getting the same error when I attempt to get the MAC of my own machine from a python script. .

From the command line Ether().src returns my MAC address. But, if I attempt to run Ether().src from a python script, I get WARNING: Could not get the source MAC: invalid literal for int() with base 16: '' and an empty MAC of 00:00:00:00:00:00.

Environment

gpotter2 commented 3 years ago

Are you sure you're running the same version of scapy in script and on the CLI? You can check scapy.__version__

p-l- commented 3 years ago

Could you add the following line, in scapy/utils.py, after def mac2str(mac)::

    log_runtime.info("MAC in mac2str: %r", mac)

So that it reads:

def mac2str(mac):
    # type: (str) -> bytes
    log_runtime.info("MAC in mac2str: %r", mac)
    return b"".join(chb(int(x, 16)) for x in plain_str(mac).split(':'))

And then run your test again (Ether().src), and report the output here?

aboelkassem commented 3 years ago

Could you add the following line, in scapy/utils.py, after def mac2str(mac)::

    log_runtime.info("MAC in mac2str: %r", mac)

So that it reads:

def mac2str(mac):
    # type: (str) -> bytes
    log_runtime.info("MAC in mac2str: %r", mac)
    return b"".join(chb(int(x, 16)) for x in plain_str(mac).split(':'))

And then run your test again (Ether().src), and report the output here?

Thanks for your reply, the output which I get when I try to test Ether().src was:

>>> Ether().src
INFO: MAC in mac2str: 'xx:xx:xx:xx:xx:xx'
'xx:xx:xx:xx:xx:xx'

and its correct, but when I try arping('192.168.1.0/24') to send packages as broadcast still getting this warning message

>>> arping('192.168.1.0/24')
Begin emission:
INFO: MAC in mac2str: 'ff:ff:ff:ff:ff:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: 'ff:ff:ff:ff:ff:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: 'ff:ff:ff:ff:ff:ff'
INFO: MAC in mac2str: ''
WARNING: Could not get the source MAC: invalid literal for int() with base 16: ''
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: ''
WARNING: Could not get the source MAC: invalid literal for int() with base 16: ''
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: 'ff:ff:ff:ff:ff:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: 'ff:ff:ff:ff:ff:ff'
INFO: MAC in mac2str: ''
WARNING: more Could not get the source MAC: invalid literal for int() with base 16: ''
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: ''
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: 'ff:ff:ff:ff:ff:ff'
INFO: MAC in mac2str: ''
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: ''
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: 'ff:ff:ff:ff:ff:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: 'ff:ff:ff:ff:ff:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: 'ff:ff:ff:ff:ff:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: 'ff:ff:ff:ff:ff:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: 'ff:ff:ff:ff:ff:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: 'ff:ff:ff:ff:ff:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: 'ff:ff:ff:ff:ff:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: 'ff:ff:ff:ff:ff:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: 'ff:ff:ff:ff:ff:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: 'ff:ff:ff:ff:ff:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: 'ff:ff:ff:ff:ff:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: 'ff:ff:ff:ff:ff:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: '00:00:00:00:00:00'
INFO: MAC in mac2str: 'ff:ff:ff:ff:ff:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
INFO: MAC in mac2str: 'aa:bb:cc:dd:ee:ff'
.........continue printing the same Info messages as above
p-l- commented 3 years ago

Ok this part is interesting:

INFO: MAC in mac2str: ''
WARNING: Could not get the source MAC: invalid literal for int() with base 16: ''

Sometimes, mac2str() is called with an empty string (as I suspected). I have no idea why, but that's a start.

michaliskon commented 3 years ago

I have the same issue.

Scapy version: 2.4.5
Python version: 3.9.5
Operating System: Windows 10
gpotter2 commented 3 years ago

I can't replicate. The routes must be wrong somehow, please provide them entirely.

Could you make sure you're using the github version and provide the output of

a = Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst="192.168.1.0/24")  # change here
for x in a:
     z = Ether(raw(x))
     print(z.sprintf("%Ether.src% -> %Ether.dst%: %ARP.hwsrc% -> %ARP.hwdst%"))
gpotter2 commented 2 years ago

Closing for inactivity.