phaethon/kamene

Powershell ExecutionPolicy Problem

Closed this issue · 1 comments

OS: Windows 10
Python 3.5.1

When running from scapy.all import *, a ValueError exception is thrown.
Here is a sample output:

WARNING: Windows support for scapy3k is currently in testing. Sniffing/sending/receiving packets should be working with WinPcap d
river and Powershell. Create issues at https://github.com/phaethon/scapy
Traceback (most recent call last):
  File ".\arper.py", line 1, in <module>
    from scapy.all import *
  File "C:\ProgramData\chocolatey\lib\python3\tools\lib\site-packages\scapy\all.py", line 16, in <module>
    from .arch import *
  File "C:\ProgramData\chocolatey\lib\python3\tools\lib\site-packages\scapy\arch\__init__.py", line 88, in <module>
    from .windows import *
  File "C:\ProgramData\chocolatey\lib\python3\tools\lib\site-packages\scapy\arch\windows\__init__.py", line 200, in <module>
    ifaces.load_from_powershell()
  File "C:\ProgramData\chocolatey\lib\python3\tools\lib\site-packages\scapy\arch\windows\__init__.py", line 151, in load_from_pow
ershell
    for i in get_windows_if_list():
  File "C:\ProgramData\chocolatey\lib\python3\tools\lib\site-packages\scapy\arch\windows\__init__.py", line 87, in get_windows_if
_list
    name, value = [ j.strip() for j in i.split(':') ]
ValueError: too many values to unpack (expected 2)

This occurred because in scapy\arch\windows\__init__.py line 78, where the powershell is started an error message saying that the profile could not be loaded due to ExecutionPolicy is shown before the output of Get-NetAdapter. Here is an example of that message:

. : File C:\Users\USERNAME\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 cannot be loaded because running
scripts is disabled on this system. For more information, see about_Execution_Policies at
http://go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:3
+ . 'C:\Users\iluxo\Documents\WindowsPowerShell\Microsoft.PowerShell_pr ...
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

A simple solution would be to pass an additional -NoProfile option when starting the powershell subprocess. This is probably a better way of doing it anyways, since if that flag is not passed, the poweshell will first load the profile and only then run the Get-NetAdapter command, which takes some extra time.

I will submit a pull request in little bit.