phaethon / kamene

Network packet and pcap file crafting/sniffing/manipulation/visualization security tool. Originally forked from scapy in 2015 and providing python3 compatibility since then.
GNU General Public License v2.0
868 stars 192 forks source link

subprocess.TimeoutExpired #47

Open ghost opened 8 years ago

ghost commented 8 years ago

When I run from scapy.all import *, I get the following output:

WARNING: Windows support for scapy3k is currently in testing. Sniffing/sending/receiving packets     should be working with WinPcap driver and Powershell. Create issues at     https://github.com/phaethon/scapy
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    from scapy.all import *
  File "C:\Python34\lib\site-packages\scapy\all.py", line 16, in <module>
    from .arch import *
  File "C:\Python34\lib\site-packages\scapy\arch\__init__.py", line 88, in <module>
    from .windows import *
  File "C:\Python34\lib\site-packages\scapy\arch\windows\__init__.py", line 23, in <module>
    from scapy.arch import pcapdnet
  File "C:\Python34\lib\site-packages\scapy\arch\pcapdnet.py", line 32, in <module>
    from .winpcapy import *
  File "C:\Python34\lib\site-packages\scapy\arch\winpcapy.py", line 26, in <module>
    _lib=CDLL('wpcap.dll')
  File "C:\Python34\lib\ctypes\__init__.py", line 351, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

What's wrong?

phaethon commented 8 years ago

You need WinPcap driver to be installed.

ghost commented 8 years ago

OK. However, I just installed WinPcap and tried running this:

import scapy.all

def arp_display(pkt):
  if pkt[ARP].op == 1: #who-has (request)
    if pkt[ARP].psrc == '0.0.0.0': # ARP Probe
      print("ARP Probe from: " + pkt[ARP].hwsrc)

print(scapy.all.sniff(prn=arp_display, filter="arp", store=0, count=10))

and I got this error:

WARNING: Windows support for scapy3k is currently in testing. Sniffing/sending/receiving packets should be working with WinPcap driver and Powershell. Create issues at https://github.com/phaethon/scapy
WARNING: No match between your pcap and windows network interfaces found. You probably won't be able to send packets. Deactivating unneeded interfaces and restarting Scapy might help.Check your winpcap and powershell installation, and access rights.
WARNING: No route found for IPv6 destination :: (no default route?). This affects only IPv6
Traceback (most recent call last):
  File "C:\Python34\find_macaddress.py", line 8, in <module>
    print(scapy.all.sniff(prn=arp_display, filter="arp", store=0, count=10))
  File "C:\Python34\scapy\arch\windows\__init__.py", line 448, in sniff
    s = L2socket(type=ETH_P_ALL, *arg, **karg)
  File "C:\Python34\scapy\arch\pcapdnet.py", line 266, in __init__
    self.ins = open_pcap(iface, 1600, self.promisc, 100)
  File "C:\Python34\scapy\arch\windows\__init__.py", line 224, in <lambda>
    pcapdnet.open_pcap = lambda iface,*args,**kargs:  _orig_open_pcap(pcap_name(iface),*args,**kargs)
  File "C:\Python34\scapy\arch\pcapdnet.py", line 251, in <lambda>
    open_pcap = lambda *args,**kargs: _PcapWrapper_pypcap(*args,**kargs)
  File "C:\Python34\scapy\arch\pcapdnet.py", line 215, in __init__
    self.iface = create_string_buffer(device.encode('ascii'))
AttributeError: 'NoneType' object has no attribute 'encode'
phaethon commented 8 years ago

This is a different error situation. Which version of Windows do you use? It should be working with Windows 8 and above, but Windows 7 and below are currently not directly supported for sniffing/crafting.

ghost commented 8 years ago

I just upgraded to windows 10... let me check....

ghost commented 8 years ago

Huh? First try, this is what I got:

WARNING: Windows support for scapy3k is currently in testing. Sniffing/sending/receiving packets should be working with WinPcap driver and Powershell. Create issues at https://github.com/phaethon/scapy Traceback (most recent call last): File "C:\Python34\find_macaddress.py", line 1, in import scapy.all File "C:\Python34\scapy\all.py", line 16, in from .arch import File "C:\Python34\scapy\archinit.py", line 88, in from .windows import File "C:\Python34\scapy\arch\windowsinit.py", line 200, in ifaces.load_from_powershell() File "C:\Python34\scapy\arch\windowsinit.py", line 151, in load_from_powershell for i in get_windows_if_list(): File "C:\Python34\scapy\arch\windowsinit.py", line 79, in get_windows_if_list stdout, stdin = ps.communicate(timeout = 10) File "C:\Python34\lib\subprocess.py", line 960, in communicate stdout, stderr = self._communicate(input, endtime, timeout) File "C:\Python34\lib\subprocess.py", line 1216, in _communicate raise TimeoutExpired(self.args, orig_timeout) subprocess.TimeoutExpired: Command '['powershell', 'Get-NetAdapter', '|', 'select Name, InterfaceIndex, InterfaceDescription, InterfaceGuid, MacAddress', '|', 'fl']' timed out after 10 seconds

I'm running it again.

ghost commented 8 years ago

Same error!

phaethon commented 8 years ago

Can you open powershell and execute the command from there? Get-NetAdapter | select Name, InterfaceIndex, InterfaceDescription, InterfaceGuid, MacAddress | fl

ghost commented 8 years ago

Actually, I reimported scapy.all, I got something saying I can't import scapy.arch.pcapdnet:

WARNING: Windows support for scapy3k is currently in testing. Sniffing/sending/receiving packets should be working with WinPcap driver and Powershell. Create issues at https://github.com/phaethon/scapy
Traceback (most recent call last):
  File "<pyshell#25>", line 1, in <module>
    import scapy.all
  File "C:\Python34\scapy\all.py", line 16, in <module>
    from .arch import *
  File "C:\Python34\scapy\arch\__init__.py", line 88, in <module>
    from .windows import *
  File "C:\Python34\scapy\arch\windows\__init__.py", line 23, in <module>
    from scapy.arch import pcapdnet
ImportError: cannot import name 'pcapdnet'
ghost commented 8 years ago

I'm running it in Windows PowerShell... this was the output...

Microsoft Windows [Version 10.0.10586]
(c) 2015 Microsoft Corporation. All rights reserved.

C:\Users\******>powershell
Windows PowerShell
Copyright (C) 2015 Microsoft Corporation. All rights reserved.

PS C:\Users\******> Get-NetAdapter | select Name, InterfaceIndex, InterfaceDescription, InterfaceGuid, MacAddress | fl

Name                        : Local Area Connection
InterfaceIndex           : 7
InterfaceDescription : Realtek PCIe FE Family Controller
InterfaceGuid            : {3F66385A-8F2B-46F1-8F45-39163AD3C9C4}
MacAddress             : 2C-27-D7-43-3F-03

PS C:\Users\******>
phaethon commented 8 years ago

Powershell output seems to be fine. You can try with longer timeout. I have no idea why 10 seconds is not enough to get the result from Powershell call from python. Did you make a clean reinstall of python and scapy after upgrade to Windows 10? If you did not change scapy configuration files then getting new import exception could be caused by some upgrade issues.

fedorch commented 8 years ago

I have some idea about timeout: If I try to run scapy from console with administrative rights then PowerShell calls works fine. If I try to run scapy from console without administrative rights then PowerShell calls ask me to press 'Y' to confirm action. If I try to run scapy from IDE (PyCharm) no matter it is running with or without administrative rights then I receive timeout message whithout any confirmation asks.

phaethon commented 8 years ago

In 1) you can use it then, right? 2) this explains timeout. Have not tested scapy without administrative rights, and probably have to add to documentation that it should be executed with admin rights. 3) Apparently, IDE is affecting normal library loading execution environment. Likely PyCharm specific issue, I will not investigate myself.

fedorch commented 8 years ago

In 1) you can use it then, right?

No. PowerShell calls works whithout problems but they don't return corresponding information (Windows 7)

I just suggested why @qlstudio can have a timeout.

ghost commented 8 years ago

Python's wierd... sniff() doesn't work but from scapy.all import * does. I'm reinstalling Python and Scapy....

ghost commented 8 years ago

I reinstalled Python, same error

Ax3l0to commented 8 years ago

I have an error: WARNING: Windows support for scapy3k is currently in testing. Sniffing/sending/receiving packets should be working with WinPcap driver and Powershell. Create issues at https://github.com/phaethon/scapy WARNING: No route found for IPv6 destination :: (no default route?). This affects only IPv6 Traceback (most recent call last): File "C:/Users/axel.ch/Desktop/python bluetooth/wifiPrint.py", line 9, in <module> sniff(prn=wifiPrint) File "C:\Users\axel.ch\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\windows\__init__.py", line 445, in sniff s = L2socket(type=ETH_P_ALL, *arg, **karg) File "C:\Users\axel.ch\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\pcapdnet.py", line 265, in __init__ self.ins = open_pcap(iface, 1600, self.promisc, 100) File "C:\Users\axel.ch\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\windows\__init__.py", line 222, in <lambda> pcapdnet.open_pcap = lambda iface,*args,**kargs: _orig_open_pcap(pcap_name(iface),*args,**kargs) File "C:\Users\axel.ch\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\pcapdnet.py", line 250, in <lambda> open_pcap = lambda *args,**kargs: _PcapWrapper_pypcap(*args,**kargs) File "C:\Users\axel.ch\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\pcapdnet.py", line 214, in __init__ self.iface = create_string_buffer(device.encode('ascii')) AttributeError: 'NoneType' object has no attribute 'encode'

Can you help me, please

phaethon commented 8 years ago

@stinng is this related to the original issue? If it is not, create new issue or choose another one, which is related. Please, give your OS, OS version, version of libpcap installed, conf.route output.

ghost commented 8 years ago

I have that issue, too.

Ax3l0to commented 8 years ago

It is related because this issue happened just after the original issue. Moreover this issue is already at the top of this webpage. I have windows 10. What is libpcap? I don't think that I have libpcap on my computer.

phaethon commented 8 years ago

http://www.winpcap.org/ has to be installed for scapy to run.

Ax3l0to commented 8 years ago

I have Winpcap 4.1.3 on my computer. This issue happened after the installation of Winpcap.

ghost commented 8 years ago

Me too.

phaethon commented 8 years ago

Check out with latest commit if the issue is fixed. If it is not fixed, please, add Windows version, and output from show_interfaces()

jklahn commented 8 years ago

I've found some references for the "Get-NetAdapter" error stating that the Get-NetAdapter cmdlet is only available on Windows 8+ and Server 2012+. I was receiving this error on a Windows Server 2008 machine, so this would make sense. If this is the case, I'd recommend @phaethon added which versions of Windows are supported in the ReadMe.md for clarification.

phaethon commented 8 years ago

@jklahn scapy3k used to be working only on Windows 8+, but, currently, it works on Windows 7, too. Which specific error are you referring to?

ghost commented 8 years ago
Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:38:48) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import scapy.all
Traceback (most recent call last):
  File "C:\Users\DARREN\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\__init__.py", line 25, in <module>
    import networkx as nx
ImportError: No module named 'networkx'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import scapy.all
  File "C:\Users\DARREN\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\all.py", line 16, in <module>
    from .arch import *
  File "C:\Users\DARREN\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\__init__.py", line 28, in <module>
    log_loading.degub("Can't import networkx. Not criticial, but won't be able to draw network graphs.")
AttributeError: 'Logger' object has no attribute 'degub'
>>> 

I'm pretty sure you meant "debug".

phaethon commented 8 years ago

Sure I meant :)

ghost commented 8 years ago

I still have this error

Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:38:48) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import scapy.all
Traceback (most recent call last):
  File "C:\Users\DARREN\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\__init__.py", line 25, in <module>
    import networkx as nx
ImportError: No module named 'networkx'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import scapy.all
  File "C:\Users\DARREN\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\all.py", line 16, in <module>
    from .arch import *
  File "C:\Users\DARREN\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\__init__.py", line 28, in <module>
    log_loading.degub("Can't import networkx. Not criticial, but won't be able to draw network graphs.")
AttributeError: 'Logger' object has no attribute 'degub'
>>> import scapy.all
WARNING: No match between your pcap and windows network interfaces found. You probably won't be able to send packets. Deactivating unneeded interfaces and restarting Scapy might help.Check your winpcap and powershell installation, and access rights.
WARNING: No route found for IPv6 destination :: (no default route?). This affects only IPv6
>>> 
========== RESTART: C:/Users/DARREN/AppData/Local/Programs/Python/Python35-32/arper.py ==========
WARNING: No match between your pcap and windows network interfaces found. You probably won't be able to send packets. Deactivating unneeded interfaces and restarting Scapy might help.Check your winpcap and powershell installation, and access rights.
WARNING: No route found for IPv6 destination :: (no default route?). This affects only IPv6
Traceback (most recent call last):
  File "C:/Users/DARREN/AppData/Local/Programs/Python/Python35-32/arper.py", line 8, in <module>
    print(scapy.all.sniff(prn=arp_display, filter="arp", store=0, count=30))
  File "C:\Users\DARREN\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\windows\__init__.py", line 452, in sniff
    s = L2socket(type=ETH_P_ALL, *arg, **karg)
  File "C:\Users\DARREN\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\pcapdnet.py", line 266, in __init__
    self.ins = open_pcap(iface, 1600, self.promisc, 100)
  File "C:\Users\DARREN\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\windows\__init__.py", line 226, in <lambda>
    pcapdnet.open_pcap = lambda iface,*args,**kargs: _orig_open_pcap(pcap_name(iface),*args,**kargs)
  File "C:\Users\DARREN\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\pcapdnet.py", line 251, in <lambda>
    open_pcap = lambda *args,**kargs: _PcapWrapper_pypcap(*args,**kargs)
  File "C:\Users\DARREN\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\pcapdnet.py", line 215, in __init__
    self.iface = create_string_buffer(device.encode('ascii'))
AttributeError: 'NoneType' object has no attribute 'encode'
>>> 
ghost commented 8 years ago

arper.py

import scapy.all

def arp_display(pkt):
  if pkt[ARP].op == 1: #who-has (request)
    if pkt[ARP].psrc == '0.0.0.0': # ARP Probe
      print("ARP Probe from: " + pkt[ARP].hwsrc)

print(scapy.all.sniff(prn=arp_display, filter="arp", store=0, count=30))

call from show_interfaces

>>> show_interfaces()
INDEX  IFACE                                IP               MAC
>>> 
phaethon commented 8 years ago

Add, please, get_if_list() output, and conf.iface value. I have a Windows 7 machine with freshly installed scapy from git and WinPcap. And it works, so this is not a generic Windows 7 problem, but related to your configuration. You can try reinstalling WinPcap. Did you check "Start winpcap driver at boot" option when you installed WinPcap?

Ax3l0to commented 8 years ago

I have windows 10 and the latest version of Winpcap.(I check "Start winpcap driver at boot")

>>> show_interfaces()
INDEX  IFACE                                IP               MAC
2      Broadcom NetLink (TM) Gigabit Ethernet  192.168.1.116    0C:54:A5:4F:F0:87
0      Qualcomm Atheros AR5BWB222 Wireless Network Adapter  192.168.1.80     34:23:87:AF:5C:03
>>> get_if_list()
['\\Device\\NPF_{3A0FFBED-3A79-498F-9841-FC3F08C77049}', '\\Device\\NPF_{8D4125AD-8233-4383-BC35-9DED0AA02201}', '\\Device\\NPF_{18F22F5F-D347-4562-BA5C-EDC74DC02317}', '\\Device\\NPF_{04366867-5D5F-4F30-A32A-EBEFA6A1421F}']
>>> conf.iface
'mon0'
phaethon commented 8 years ago

@stinng you still have the same error as mentioned before even with the latest git version?

Ax3l0to commented 8 years ago

I still have the same error

netzeng commented 7 years ago

When I run from scapy.all import *, I get the following output:

from scapy.all import Traceback (most recent call last): File "", line 1, in File "C:\Python34\lib\site-packages\scapy\all.py", line 16, in from .arch import File "C:\Python34\lib\site-packages\scapy\arch__init.py", line 95, in from .windows import * File "C:\Python34\lib\site-packages\scapy\arch\windows__init.py", line 200, in <modul e> ifaces.load_from_powershell() File "C:\Python34\lib\site-packages\scapy\arch\windows\init__.py", line 151, in load_f rom_powershell for i in get_windows_if_list(): File "C:\Python34\lib\site-packages\scapy\arch\windows\init__.py", line 86, in get_win dows_if_list name, value = [ j.strip() for j in i.split(':') ] ValueError: too many values to unpack (expected 2)

How to this problem?

liagnliang commented 7 years ago

I've had the same question ,You can try installing WMF

phaethon commented 7 years ago

The was a change in windows code few commits ago. Can you check using latest git version if it has solved the issue?

esmeeeee commented 7 years ago

I had the same issue: WARNING: No match between your pcap and windows network interfaces found etc Solved it by running as administrator