After restartting container, python dependencies are missing
Hello,
After restartring running container, fllowing error appears (always):
root@14f3afd5a504:/attack_range# python attack_range.py stop
Traceback (most recent call last):
File "attack_range.py", line 6, in <module>
from modules.aws_controller import AwsController
File "/attack_range/modules/aws_controller.py", line 2, in <module>
import ansible_runner
ModuleNotFoundError: No module named 'ansible_runner'
Trying to fix it reveals more missing deps:
root@14f3afd5a504:/attack_range# pip install ansible_runner
Collecting ansible_runner
Downloading ansible_runner-2.3.1-py3-none-any.whl (78 kB)
|████████████████████████████████| 78 kB 2.6 MB/s
Requirement already satisfied: pyyaml in /usr/lib/python3/dist-packages (from ansible_runner) (5.3.1)
Requirement already satisfied: packaging in /usr/local/lib/python3.8/dist-packages (from ansible_runner) (21.3)
Requirement already satisfied: six in /usr/lib/python3/dist-packages (from ansible_runner) (1.14.0)
Requirement already satisfied: pexpect>=4.5 in /usr/local/lib/python3.8/dist-packages (from ansible_runner) (4.8.0)
Collecting python-daemon
Downloading python_daemon-2.3.2-py3-none-any.whl (34 kB)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /usr/local/lib/python3.8/dist-packages (from packaging->ansible_runner) (3.0.9)
Requirement already satisfied: ptyprocess>=0.5 in /usr/local/lib/python3.8/dist-packages (from pexpect>=4.5->ansible_runner) (0.7.0)
Requirement already satisfied: lockfile>=0.10 in /usr/local/lib/python3.8/dist-packages (from python-daemon->ansible_runner) (0.12.2)
Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (from python-daemon->ansible_runner) (45.2.0)
Requirement already satisfied: docutils in /usr/lib/python3/dist-packages (from python-daemon->ansible_runner) (0.16)
Installing collected packages: python-daemon, ansible-runner
Successfully installed ansible-runner-2.3.1 python-daemon-2.3.2
root@14f3afd5a504:/attack_range# python attack_range.py show
Traceback (most recent call last):
File "attack_range.py", line 6, in <module>
from modules.aws_controller import AwsController
File "/attack_range/modules/aws_controller.py", line 9, in <module>
from python_terraform import Terraform, IsNotFlagged
ModuleNotFoundError: No module named 'python_terraform'
Next step:
root@14f3afd5a504:/attack_range# python attack_range.py show
Traceback (most recent call last):
File "attack_range.py", line 6, in <module>
from modules.aws_controller import AwsController
File "/attack_range/modules/aws_controller.py", line 9, in <module>
from python_terraform import Terraform, IsNotFlagged
ModuleNotFoundError: No module named 'python_terraform'
root@14f3afd5a504:/attack_range# pip install python_terraform
Collecting python_terraform
Downloading python-terraform-0.10.1.tar.gz (8.7 kB)
Building wheels for collected packages: python-terraform
Building wheel for python-terraform (setup.py) ... done
Created wheel for python-terraform: filename=python_terraform-0.10.1-py2.py3-none-any.whl size=6485 sha256=d04b34d6f91cbb7420f8fcf341eba261be81f83af354d8c87bfcc12add33e081
Stored in directory: /root/.cache/pip/wheels/14/fe/eb/ae345d71cd6d0b881dbdb45cd8f0b462d19691591fc4d5adf3
Successfully built python-terraform
Installing collected packages: python-terraform
Successfully installed python-terraform-0.10.1
root@14f3afd5a504:/attack_range#
root@14f3afd5a504:/attack_range#
root@14f3afd5a504:/attack_range# python attack_range.py show
Traceback (most recent call last):
File "attack_range.py", line 6, in <module>
from modules.aws_controller import AwsController
File "/attack_range/modules/aws_controller.py", line 10, in <module>
from modules import aws_service, splunk_sdk
File "/attack_range/modules/aws_service.py", line 2, in <module>
import boto3
ModuleNotFoundError: No module named 'boto3'
Final error that I don't know how to fix:
root@14f3afd5a504:/attack_range# pip install splunklib
Collecting splunklib
Downloading splunklib-1.0.0-py3-none-any.whl (4.6 kB)
Collecting pycrypto
Downloading pycrypto-2.6.1.tar.gz (446 kB)
|████████████████████████████████| 446 kB 1.9 MB/s
Requirement already satisfied: requests in /usr/local/lib/python3.8/dist-packages (from splunklib) (2.28.1)
Requirement already satisfied: charset-normalizer<3,>=2 in /usr/local/lib/python3.8/dist-packages (from requests->splunklib) (2.1.1)
Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python3/dist-packages (from requests->splunklib) (2019.11.28)
Requirement already satisfied: idna<4,>=2.5 in /usr/lib/python3/dist-packages (from requests->splunklib) (2.8)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.8/dist-packages (from requests->splunklib) (1.26.12)
Building wheels for collected packages: pycrypto
Building wheel for pycrypto (setup.py) ... done
Created wheel for pycrypto: filename=pycrypto-2.6.1-cp38-cp38-linux_x86_64.whl size=498476 sha256=55e83251a8faf10e846ba5042ebc5337e4eddc8fe152e33b882ef2b493245410
Stored in directory: /root/.cache/pip/wheels/d0/99/d0/0298ea019d63f1d63a0965b9944b719e875f9bd6ffc6dcf293
Successfully built pycrypto
Installing collected packages: pycrypto, splunklib
Successfully installed pycrypto-2.6.1 splunklib-1.0.0
root@14f3afd5a504:/attack_range# python attack_range.py show
Traceback (most recent call last):
File "attack_range.py", line 6, in <module>
from modules.aws_controller import AwsController
File "/attack_range/modules/aws_controller.py", line 10, in <module>
from modules import aws_service, splunk_sdk
File "/attack_range/modules/splunk_sdk.py", line 4, in <module>
import splunklib.results as results
ModuleNotFoundError: No module named 'splunklib.results'; 'splunklib' is not a package
@pioootrek did you try poetry shell to get back to the virtualenv with all the deps. I t think that might have been the issue here. During install this happens automatically, you might have been kicked out when restarting the instance: https://github.com/splunk/attack_range/blob/develop/docker/docker-entrypoint.sh#L3
Hello @josehelps . You were right. When acivate virtualenv manually, it works and there are no dep errors.
root@14f3afd5a504:/attack_range# python attack_range.py show
Traceback (most recent call last):
File "attack_range.py", line 6, in <module>
from modules.aws_controller import AwsController
File "/attack_range/modules/aws_controller.py", line 10, in <module>
from modules import aws_service, splunk_sdk
File "/attack_range/modules/splunk_sdk.py", line 4, in <module>
import splunklib.results as results
ModuleNotFoundError: No module named 'splunklib.results'; 'splunklib' is not a package
root@14f3afd5a504:/attack_range# poetry shell
Spawning shell within /root/.cache/pypoetry/virtualenvs/attack-range-536x2-W_-py3.8
root@14f3afd5a504:/attack_range# . /root/.cache/pypoetry/virtualenvs/attack-range-536x2-W_-py3.8/bin/activate
(attack-range-py3.8) root@14f3afd5a504:/attack_range# python attack_range.py show
The Vagrant executable cannot be found. Please check if it is in the system path.
starting program loaded for B1 battle droid
||/__'`.
|//()'-.:
|-.||
|o(o)
|||\\ .==._
|||(o)==::'
`|T ""
()
|\
||\
()()
||//
|//
.'=`=.
2022-11-10 18:05:38,130 - INFO - attack_range - [action] > show
Status Virtual Machines
Name Status
----------------------- --------
ar-dfsdf stopped
ar-sfdfsdfsfds stopped
Strange, that in first connection to fresh container, it activates virtualenv automatically.
yeah, it is part of the entrypoint.sh but I am not sure that gets ran during restarts, glad we got to the bottom of it!
Installed Attack Range yesterday (Docker on my MacBook Pro), got things working pretty much as documented - and I decided to stop the container after use. This morning, I started the container again, and ran into this exact issue - so seems there's still a need to run this manually after a restart ...