guardicore / monkey

Infection Monkey - An open-source adversary emulation platform
https://www.guardicore.com/infectionmonkey/
GNU General Public License v3.0
6.63k stars 775 forks source link

TypeError: decoding to str: need a bytes-like object, NoneType found #4267

Closed NCNeo closed 1 month ago

NCNeo commented 1 month ago

Describe the bug

A clear and concise description of what the bug is. when run appllication and make the registration process, get loop register, when see the backend get this error message

2024-07-28 11:46:18,782 - INFO - server_setup.py:189 - _start_island_server() - Using certificate path: /tmp/.mount_InfectZiPKT8/usr/src/monkey_island/cc/server.crt, and key path: /tmp/.mount_InfectZiPKT8/usr/src/monkey_island/cc/server.key. 2024-07-28 11:46:18,782 - INFO - server_setup.py:226 - _log_init_info() - Monkey Island Server is running! 2024-07-28 11:46:18,782 - INFO - server_setup.py:227 - _log_init_info() - version: 2.3.0 2024-07-28 11:46:18,782 - INFO - server_setup.py:234 - _log_web_interface_access_urls() - To access the web interface, navigate to one of the the following URLs using your browser: https://192.168.68.153:5000 2024-07-28 11:46:19,458 - DEBUG - connectionpool.py:473 - _make_request() - https://m15mjynko3.execute-api.us-east-1.amazonaws.com:443 "GET /default?version=2.3.0&deployment=appimage HTTP/1.1" 200 75 2024-07-28 11:46:19,462 - INFO - server_setup.py:249 - _inner() - Version number and deployment type was sent to analytics server. The response is: Deployment: appimage and version: 2.3.0 was sent to the analytics server. 2024-07-28 11:46:20,426 - DEBUG - aws_metadata.py:31 - fetch_aws_instance_metadata() - Failed init of AWSInstance while getting metadata: HTTPConnectionPool(host='169.254.169.254', port=80): Max retries exceeded with url: /latest/meta-data/instance-id (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x7efee55cc690>, 'Connection to 169.254.169.254 timed out. (connect timeout=2)')) 2024-07-28 11:46:22,978 - WARNING - gevent_hub_error_handler.py:25 - call() - gevent caught an exception: ['ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:1006)\n'] 2024-07-28 11:46:24,084 - WARNING - gevent_hub_error_handler.py:25 - call() - gevent caught an exception: ['ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:1006)\n'] 2024-07-28 11:46:24,588 - INFO - pywsgi.py:1226 - write() - 192.168.68.153 - "GET /api/agent-plugins/available/index HTTP/1.1" 401 233 0.001205 2024-07-28 11:46:28,578 - ERROR - app.py:1744 - log_exception() - Exception on /api/register [POST] Traceback (most recent call last): File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/flask/app.py", line 1823, in full_dispatch_request rv = self.dispatch_request() ^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/flask/app.py", line 1799, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(view_args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/flask_restful/init.py", line 489, in wrapper resp = resource(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/flask/views.py", line 107, in view return current_app.ensure_sync(self.dispatch_request)(kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/flask_restful/init.py", line 604, in dispatch_request resp = meth(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/tmp/.mount_InfectZiPKT8/usr/src/monkey_island/cc/services/authentication_service/flask_resources/utils.py", line 41, in decorated_function return func(*args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/tmp/.mount_InfectZiPKT8/usr/src/monkey_island/cc/services/authentication_service/flask_resources/register.py", line 43, in post response: ResponseValue = register() ^^^^^^^^^^ File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/flask_security/decorators.py", line 622, in wrapper return f(args, kwargs) ^^^^^^^^^^^^^^^^^^ File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/flask_security/views.py", line 294, in register if form.validate_on_submit(): ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/flask_wtf/form.py", line 86, in validate_on_submit return self.is_submitted() and self.validate(extra_validators=extra_validators) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/flask_security/forms.py", line 612, in validate if not super().validate(kwargs): ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/wtforms/form.py", line 329, in validate return super().validate(extra) ^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/wtforms/form.py", line 146, in validate if not field.validate(self, extra): ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/wtforms/fields/core.py", line 242, in validate stop_validation = self._run_validation_chain(form, chain) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/wtforms/fields/core.py", line 262, in _run_validation_chain validator(form, self) File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/flask_security/forms.py", line 212, in unique_username form.existing_username_user = _datastore.find_user( ^^^^^^^^^^^^^^^^^^^^^ File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/flask_security/datastore.py", line 898, in find_user obj = self.user_model.objects(**query).first() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/mongoengine/queryset/base.py", line 296, in first result = queryset[0]


  File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/mongoengine/queryset/base.py", line 203, in __getitem__
    queryset._cursor[key],
    ^^^^^^^^^^^^^^^^
  File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/mongoengine/queryset/base.py", line 1681, in _cursor
    self._cursor_obj = self._collection.find(self._query, **self._cursor_args)
                                             ^^^^^^^^^^^
  File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/mongoengine/queryset/base.py", line 1730, in _query
    self._mongo_query = self._query_obj.to_query(self._document)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/mongoengine/queryset/visitor.py", line 91, in to_query
    query = query.accept(QueryCompilerVisitor(document))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/mongoengine/queryset/visitor.py", line 184, in accept
    return visitor.visit_query(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/mongoengine/queryset/visitor.py", line 80, in visit_query
    return transform.query(self.document, **query.query)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/mongoengine/queryset/transform.py", line 124, in query
    value = field.prepare_query_value(op, value)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/site-packages/mongoengine/fields.py", line 171, in prepare_query_value
    value = re.escape(value)
            ^^^^^^^^^^^^^^^^
  File "/tmp/.mount_InfectZiPKT8/opt/python3.11/lib/python3.11/re/__init__.py", line 260, in escape
    pattern = str(pattern, 'latin1')
              ^^^^^^^^^^^^^^^^^^^^^^
TypeError: decoding to str: need a bytes-like object, NoneType found
2024-07-28 11:46:28,604 - INFO - pywsgi.py:1226 - write() - 192.168.68.153 - "POST /api/register HTTP/1.1" 500 163 0.243829

## To Reproduce
Steps to reproduce the behavior:
1. Configure the Monkey with X settings: setup on virtualbox last version, windows 10 last update.
3. Run the monkey on specific machine: intel 11 gen, 16 gb ram, core 4
4. See error
![image](https://github.com/user-attachments/assets/93072177-fdbb-4477-9a80-b2aa9ef4c0b3)

## Expected behavior
A description of what you expected to happen.

## Screenshots
If applicable, add screenshots to help explain your problem.

## Machine version (please complete the following information):
 - OS: Windows or Linux
Windows 10
mssalvatore commented 1 month ago

This looks to be a duplicate of https://github.com/guardicore/monkey/issues/3807. Please make sure your username does not contain any characters other than [A-Za-z0-9].

This is fixed on the develop branch and will make its way to users in the next release.