Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing bug executing setup.sh script in python venv #2475

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ByteSnipers
Copy link
Contributor

Fixing issue when running setup.sh in venv

steps to reproduce

  1. go to the MobSF folder
  2. execute command "python -m venv venv"
  3. execute command "source ./venv/bin/activate"
  4. run setup.sh

console output:
.......
[notice] To update, run: pip install --upgrade pip ERROR: Can not perform a '--user' install. User site-packages are not visible in this virtualenv. [INSTALL] Installing Requirements
........

Solution:

after adding a check for pip location not in /usr/lib/python the script works without any errors

Describe the Pull Request

DESCRIBE THE DETAILS OF PULL REQUEST HERE

Checklist for PR

  • Run MobSF unit tests and lint tox -e lint,test
  • Tested Working on Linux, Mac, Windows, and Docker
  • Add unit test for any new Web API (Refer: StaticAnalyzer/tests.py)
  • Make sure tests are passing on your PR MobSF tests

Additional Comments (if any)

DESCRIBE HERE

Fixing issue when running setup.sh in venv


steps to reproduce
-------------------------------
1) go to the MobSF folder
2) execute command "python -m venv venv"
3) execute command "source ./venv/bin/activate"
4) run setup.sh

console output:
.......
[notice] To update, run: pip install --upgrade pip
ERROR: Can not perform a '--user' install. User site-packages are not visible in this virtualenv.
[INSTALL] Installing Requirements
........


Solution:
---------------
after adding a check for pip location not in /usr/lib/python the script works without any errors
@ajinabraham
Copy link
Member

You do not have to create a venv explicitly, running setup.sh will automatically create a venv with poetry

@ByteSnipers
Copy link
Contributor Author

ByteSnipers commented Dec 18, 2024

Poetry may create a virtual environment, but it also can fails, in this case poetry will try to install the package locally.
https://python-poetry.org/docs/managing-environments/

my current operating system does not support --user flag for python installation. The execution of setup.sh script fails.

the only option to run the script to create venv using "python -m venv venv". It is a clean built in python functionality which works perfectly.

@ajinabraham
Copy link
Member

my current operating system does not support --user flag for python installation. The execution of setup.sh script fails.

Are you observing any errors when running setup.sh script outside the venv?
The docs and updating mobsf instructions are done with the assumption that poetry manages the virtualenv.
For non-standard environments, we recommend using the docker image instead.

@ByteSnipers
Copy link
Contributor Author

ByteSnipers commented Dec 18, 2024

yes, the MobSF stop working with script deployment setup.sh und run.sh on famous penetration testing distribution blackarch.

I'm supporting MobSF als part of the MPT (Mobile Penetration Toolkit) and MobSF 4.1.3 stoped working on blackarch. I'm trying to have a clear separation on supported tools, without a need to use additional tools like docker.

that is why I put the time in development patch on running setup.sh on venv. So far the only check is whether the script is running on MacOS ( $unamestr == 'Darwin' ) and the additional check for venv was added ("$pip_location" != "/usr/lib/python"*)

please check the following command: python -m pip -V
PIP on linux host => pip 24.3.1 from /usr/lib/python3.12/site-packages/pip (python 3.12)
pip in vevn => pip 24.2 from /home//path/to/venv_folder/venv/lib/python3.12/site-packages/pip (python 3.12)

you have to check "/usr/lib/python" presence in the string
if [[ $unamestr == 'Darwin' || "$pip_location" != "/usr/lib/python"* ]]; then

This modification should not have any side side effects and only allows run the script properly in venv as well

@ajinabraham
Copy link
Member

Let me test this across our OS suite and get back.

# Check and upgrade pip
if python3 -m pip -V &>/dev/null; then
# Pip Check and Upgrade
python3 -m pip -V
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be replaced with pip_location ?

@ByteSnipers
Copy link
Contributor Author

my current operating system does not support --user flag for python installation. The execution of setup.sh script fails.

Are you observing any errors when running setup.sh script outside the venv? The docs and updating mobsf instructions are done with the assumption that poetry manages the virtualenv. For non-standard environments, we recommend using the docker image instead.

Thanks for clarification. You are right, I removed venv and use setup.sh with poetry. Just released an new MPT version which fix the issue.

Could you create a new release which include this patch?
#2477

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants