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

sudo causes errors on complex shell based tests #120

Open
rc-GeorgeAllen opened this issue Jun 27, 2022 · 3 comments
Open

sudo causes errors on complex shell based tests #120

rc-GeorgeAllen opened this issue Jun 27, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@rc-GeorgeAllen
Copy link

https://github.com/swimlane/atomic-operator/blob/a5dd297c106e9cf699d8dcff4d21223cdf41d6e2/atomic_operator/execution/localrunner.py#L39

causes errors when the {command} is a script containing a function, eg:
https://github.com/redcanaryco/atomic-red-team/blob/96f7ca5f9bfdd1c1c07b7e4629be0543d3bb709f/atomics/T1003.008/T1003.008.yaml#L71-L74

This could be fixed by wrapping the command with bash -c and/or escaping:

import shlex
# ...
                command = f'sudo bash -c {shlex.quote(command)}'
@fxploit
Copy link

fxploit commented Jun 28, 2022

Thank you for telling me the cause.

However, like the guide, I declared the shlex package and revised the 'localrunner.py' 39 line like
command = f'sudo bash -c {shlex.quote(command)}'

However, the same error occurs. So what do you think about entering 'sudo bash -c' in the command part of the 'yaml' file as another way?

Traceback (most recent call last):
  File "/usr/local/bin/atomic-operator", line 33, in <module>
    sys.exit(load_entry_point('atomic-operator==0.8.5', 'console_scripts', 'atomic-operator')())
  File "/usr/local/bin/atomic-operator", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/local/lib/python3.10/dist-packages/atomic_operator-0.8.5-py3.10.egg/atomic_operator/__init__.py", line 1, in <module>
    from .atomic_operator import AtomicOperator
  File "/usr/local/lib/python3.10/dist-packages/atomic_operator-0.8.5-py3.10.egg/atomic_operator/atomic_operator.py", line 13, in <module>
    from .execution import (
  File "/usr/local/lib/python3.10/dist-packages/atomic_operator-0.8.5-py3.10.egg/atomic_operator/execution/__init__.py", line 1, in <module>
    from .awsrunner import AWSRunner
  File "/usr/local/lib/python3.10/dist-packages/atomic_operator-0.8.5-py3.10.egg/atomic_operator/execution/awsrunner.py", line 3, in <module>
    from .base import ExecutionBase
ModuleNotFoundError: No module named 'atomic_operator.execution.base'

@rc-GeorgeAllen
Copy link
Author

swimlane/atomic-operator#55 regarding ModuleNotFoundError: No module named 'atomic_operator.execution.base' is a separate issue. This issue is specific to bash sub-shell errors from the tests themselves.

@MSAdministrator
Copy link
Collaborator

@rc-GeorgeAllen hey you - just saw this one actually lol.

@MSAdministrator MSAdministrator added the bug Something isn't working label Feb 13, 2023
@MSAdministrator MSAdministrator transferred this issue from swimlane/atomic-operator Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants