louisabraham / LaBot

Bot Dofus 2 en Python 3
MIT License
79 stars 37 forks source link

Scapy3 Windows #5

Closed MrErne closed 6 years ago

MrErne commented 6 years ago

Soucis avec Scapy sur Windows

Log:

E:\DEV\Emulation\Conda>activate dofus_conda

(dofus_conda) E:\DEV\Emulation\Conda>python -m labot.sniffer.main --debug 15:50:09.484 WARNING: MainThread - error.warning(): Winpcap is installed over Npcap. Will use Winpcap (see 'Winpcap/Npcap conflicts' in scapy's docs)

15:50:11.682 WARNING: MainThread - error.warning(): Error building scapy IPv6 routing table : invalid literal for int() with base 10: ''

15:50:11.684 WARNING: MainThread - error.warning(): No route found for IPv6 destination :: (no default route?)

15:50:12.539 DEBUG: MainThread - main.(): Starting sniffer on live interface

15:50:12.540 DEBUG: MainThread - ui.init(): Initializing UI...

15:50:12.540 DEBUG: MainThread - ui.init(): Initializing sniffer UI with capture file None and start function <function launch_in_thread at 0x00000132B5175EA0>

15:50:12.541 DEBUG: MainThread - ui.init(): Initializing Message Table

15:50:12.541 DEBUG: MainThread - ui.init(): Finished initializing UI.

15:50:12.541 DEBUG: MainThread - ui.async_start(): Starting sniffer asynchronously...

15:50:12.542 DEBUG: MainThread - selector_events.init(): Using selector: SelectSelector

15:50:12.543 DEBUG: Thread-2 - ui.loop_in_thread(): Starting loop: <_WindowsSelectorEventLoop running=False closed=False debug=False> in thread

15:50:12.543 DEBUG: MainThread - ui.async_start(): Started sniffer in thread: <Thread(Thread-2, started 5768)>

[I:wdom.server] Start server on localhost:8888 [I:wdom.server._tornado] connected [W:wdom.server._tornado] 200 GET / (::1) 15.92ms [W:wdom.server._tornado] 304 GET /_static/js/wdom.js (::1) 104.03ms [I:wdom.server._tornado] 101 GET /wdom_ws (::1) [I:wdom.server._tornado] WebSocket OPEN [W:wdom.server._tornado] 404 GET /favicon.ico (::1) 21.04ms 15:50:16.721 DEBUG: Thread-2 - network.launch_in_thread(): Launching sniffer in thread...

15:50:16.723 DEBUG: Thread-3 - network.sniff(): Setting up sniffer...

15:50:16.723 DEBUG: Thread-2 - network.launch_in_thread(): Started sniffer in new thread

15:50:16.729 DEBUG: Thread-3 - network.sniff(): Started Sniffing

15:50:16.730 ERROR: Thread-3 - pcapdnet.fileno(): Cannot get selectable PCAP fd on Windows

15:50:16.730 DEBUG: Thread-3 - network.sniff(): Stopped sniffing.

Exception in thread Thread-3: Traceback (most recent call last): File "D:\Users\MrErne\Miniconda3\envs\dofus_conda\lib\threading.py", line 916, in _bootstrap_inner self.run() File "D:\Users\MrErne\Miniconda3\envs\dofus_conda\lib\threading.py", line 864, in run self._target(*self._args, **self._kwargs) File "E:\DEV\Emulation\Conda\labot\sniffer\network.py", line 136, in _sniff prn=lambda p: on_receive(p, action), File "E:\DEV\Emulation\Conda\labot\sniffer\network.py", line 56, in sniff sel = select([s], [], [], refresh) OSError: [WinError 10038] Une opération a été tentée sur autre chose qu’un socket

Et voici le code de scapy qui doit surement bloquer:

def fileno(self): if sys.platform.startswith("win"): log_loading.error("Cannot get selectable PCAP fd on Windows") return 0 return pcap_get_selectable_fd(self.pcap)

louisabraham commented 6 years ago

Can you type

import scapy
scapy.VERSION

In a repl?

MrErne commented 6 years ago
(dofus_conda) C:\Users\MrErne>python
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import scapy
>>> scapy.VERSION
'2.4.0'
louisabraham commented 6 years ago

What about

import scapy3k

?

MrErne commented 6 years ago
(dofus_conda) C:\Users\MrErne>pip install scapy3k
Collecting scapy3k
  Could not find a version that satisfies the requirement scapy3k (from versions: )
No matching distribution found for scapy3k

(dofus_conda) C:\Users\MrErne>python
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import scapy3k
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'scapy3k'
>>>
louisabraham commented 6 years ago

If you install scapy-python3 (the package for scapy3k), does the sniffer work?

MrErne commented 6 years ago
(dofus_conda) E:\DEV\Emulation\Conda>python -m labot.sniffer.main --debug
WARNING: No route found for IPv6 destination :: (no default route?). This affects only IPv6
16:25:13.787 WARNING: MainThread - utils.warning(): No route found for IPv6 destination :: (no default route?). This affects only IPv6

16:25:14.290 DEBUG: MainThread - main.<module>(): Starting sniffer on live interface

16:25:14.291 DEBUG: MainThread - ui.init(): Initializing UI...

16:25:14.292 DEBUG: MainThread - ui.__init__(): Initializing sniffer UI with capture file None and start function <function launch_in_thread at 0x000001FB226C0598>

16:25:14.295 DEBUG: MainThread - ui.__init__(): Initializing Message Table

16:25:14.295 DEBUG: MainThread - ui.init(): Finished initializing UI.

16:25:14.296 DEBUG: MainThread - ui.async_start(): Starting sniffer asynchronously...

16:25:14.296 DEBUG: MainThread - selector_events.__init__(): Using selector: SelectSelector

16:25:14.298 DEBUG: Thread-3 - ui.loop_in_thread(): Starting loop: `<_WindowsSelectorEventLoop running=False closed=False debug=False>` in thread

16:25:14.298 DEBUG: MainThread - ui.async_start(): Started sniffer in thread: <Thread(Thread-3, started 14412)>

[I:wdom.server] Start server on localhost:8888
[I:wdom.server._tornado] connected
[I:wdom.server._tornado] 200 GET / (::1)
[W:wdom.server._tornado] 304 GET /_static/js/wdom.js (::1) 99.62ms
[I:wdom.server._tornado] 101 GET /wdom_ws (::1)
[I:wdom.server._tornado] WebSocket OPEN
16:25:24.838 DEBUG: Thread-3 - network.launch_in_thread(): Launching sniffer in thread...

16:25:24.839 DEBUG: Thread-4 - network.sniff(): Setting up sniffer...

16:25:24.839 DEBUG: Thread-3 - network.launch_in_thread(): Started sniffer in new thread

16:25:24.840 DEBUG: Thread-4 - network.sniff(): Started Sniffing

<L2pcapListenSocket: read packets at layer 2 using libpcap>
16:25:24.840 DEBUG: Thread-4 - network.sniff(): Stopped sniffing.

Exception in thread Thread-4:
Traceback (most recent call last):
  File "D:\Users\MrErne\Miniconda3\envs\dofus_conda\lib\threading.py", line 916, in _bootstrap_inner
    self.run()
  File "D:\Users\MrErne\Miniconda3\envs\dofus_conda\lib\threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "E:\DEV\Emulation\Conda\labot\sniffer\network.py", line 137, in _sniff
    prn=lambda p: on_receive(p, action),
  File "E:\DEV\Emulation\Conda\labot\sniffer\network.py", line 57, in sniff
    sel = select([s], [], [], refresh)
  File "D:\Users\MrErne\Miniconda3\envs\dofus_conda\lib\site-packages\scapy\supersocket.py", line 38, in fileno
    return self.ins.fileno()
  File "D:\Users\MrErne\Miniconda3\envs\dofus_conda\lib\site-packages\scapy\arch\pcapdnet.py", line 232, in fileno
    error("Cannot get selectable PCAP fd on Windows")
NameError: name 'error' is not defined
louisabraham commented 6 years ago

OK so basically there is a problem in both scapy3k (kamene) and normal scapy (the first one that was used).

The problem is caused by my use of select on the ListenSocket which is not supported by Windows.

I adapted the function sniff in sendrecv.py from kamene (scapy3k). I just looked at its equivalent in scapy, and it seems they have another system to replace select: https://github.com/secdev/scapy/blob/master/scapy/sendrecv.py#L877

It seems they just read and ignore the error on windows, so I'll adapt what they do (with a sleep).

I will also delete the scapy3k imports now that this name is deprecated and scapy works well on Python 3.

louisabraham commented 6 years ago

Tell me if it is fixed (forgot that r'fix #[0-9]+' triggers github)

MrErne commented 6 years ago

Sacpy Fix on Windows 👍