decalage2 / ViperMonkey

A VBA parser and emulation engine to analyze malicious macros.
1.05k stars 186 forks source link

Install fails on Windows 10 with PyPy 2.7 and ViperMonkey Feb 2021 #106

Closed decalage2 closed 3 years ago

decalage2 commented 3 years ago

Describe the bug Installing the latest ViperMonkey (Feb 2021) on Windows 10 with PyPy 2.7 fails due to dependencies such as cryptography, which need to be compiled.

To Reproduce Steps to reproduce the behavior:

  1. Follow the install instructions for PyPy 2.7 on Windows
  2. Error when running pypy -m pip install -U -r requirements.txt

Expected behavior The install should work flawlessly on Windows with PyPy, without needing the Microsoft VC++ compiler installed. Problematic dependencies should be optional to avoid this issue.

Screenshots

Collecting cryptography>=2.3
  Downloading cryptography-3.3.2.tar.gz (539 kB)
     |################################| 539 kB 517 kB/s
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... error
  ERROR: Command errored out with exit status 1:
   command: 'c:\...\pypy.exe' 'c:\...\site-packages\pip' install --ignore-installed --no-user --prefix 'c:\...\temp\pip-build-env-9gbixk\normal' --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'cffi>=1.12'
[...]
      DistutilsPlatformError: Microsoft Visual C++ 14.2 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/
      ----------------------------------------
  ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  ----------------------------------------

Desktop (please complete the following information):

Additional context Actually the error comes from oletools, which requires msoffcrypto-tool, which in turns requires cryptography. So a solution may be to have msoffcrypto-tool optional for oletools. Related issue: https://github.com/decalage2/oletools/issues/473

decalage2 commented 3 years ago

Workaround: I managed to install oletools 0.54.1 (last version without msoffcrypto-tool) by running pypy -m pip install oletools==0.54.1. But then the install fails again on regex, which also requires the Visual C++ compiler. Need to check if regex can be made optional for ViperMonkey.

decalage2 commented 3 years ago

I found a way to fix this with a conditional dependency in setup.py and requirements.txt: regex will only be installed if the platform is not PyPy or not Windows (which is the same as not(PyPy and Windows)):

regex; platform_python_implementation!="PyPy" or platform_system!="Windows"

Also oletools has been fixed the same way to avoid installing msoffcrypto-tool (see https://github.com/decalage2/oletools/issues/473). So once oletools 0.56.1 is on PyPI, we can change ViperMonkey to require oletools>=0.56.1 instead of ==0.54.1.