kevoreilly / CAPEv2

Malware Configuration And Payload Extraction
https://capesandbox.com/analysis/
Other
1.97k stars 420 forks source link

I changed from REST API to REST API2. but I get the error #495

Closed ai-suzuki closed 3 years ago

ai-suzuki commented 3 years ago

This is open source and friendly with free support!

Prerequisites

Thank you for always answering the question! Thanks to you, I enjoy using cape!

Please answer the following questions yourself before submitting your question.

Expected behavior

I want to use api.(Any version)

Current behavior

I changed from REST API to REST API2. but when I run python3 manage.py drf_create_token ,I get the following error

(venv-cape) root@test-env-cape:/opt/CAPEv2/web# python3 manage.py drf_create_token cape
argument for 's' must be a bytes object
System check identified some issues:

WARNINGS:
account.EmailAddress: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
        HINT: Configure the DEFAULT_AUTO_FIELD setting or the AccountConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
account.EmailConfirmation: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
        HINT: Configure the DEFAULT_AUTO_FIELD setting or the AccountConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
openid.OpenIDNonce: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
        HINT: Configure the DEFAULT_AUTO_FIELD setting or the AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
openid.OpenIDStore: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
        HINT: Configure the DEFAULT_AUTO_FIELD setting or the AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
otp_totp.TOTPDevice: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
        HINT: Configure the DEFAULT_AUTO_FIELD setting or the AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
socialaccount.SocialAccount: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
        HINT: Configure the DEFAULT_AUTO_FIELD setting or the SocialAccountConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
socialaccount.SocialApp: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
        HINT: Configure the DEFAULT_AUTO_FIELD setting or the SocialAccountConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
socialaccount.SocialToken: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
        HINT: Configure the DEFAULT_AUTO_FIELD setting or the SocialAccountConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
users.UserProfile: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
        HINT: Configure the DEFAULT_AUTO_FIELD setting or the UsersConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
CommandError: Cannot create the Token: user cape does not exist
(venv-cape) root@test-env-cape:/opt/CAPEv2/web#

I really want to use api, so I get an error even if I switch back to the REST API ...(It's natural because the support is over)

(venv-cape) root@cape:/opt/CAPEv2/utils# ./api.py --host 0.0.0.0 --port 1337
Traceback (most recent call last):
  File "./api.py", line 32, in <module>
    from lib.cuckoo.common.web_utils import validate_task
  File "/opt/CAPEv2/utils/../lib/cuckoo/common/web_utils.py", line 13, in <module>
    from django.contrib.auth.models import User
  File "/root/venv-cape/lib/python3.8/site-packages/django/contrib/auth/models.py", line 3, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "/root/venv-cape/lib/python3.8/site-packages/django/contrib/auth/base_user.py", line 48, in <module>
    class AbstractBaseUser(models.Model):
  File "/root/venv-cape/lib/python3.8/site-packages/django/db/models/base.py", line 108, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/root/venv-cape/lib/python3.8/site-packages/django/apps/registry.py", line 253, in get_containing_app_config
    self.check_apps_ready()
  File "/root/venv-cape/lib/python3.8/site-packages/django/apps/registry.py", line 135, in check_apps_ready
    settings.INSTALLED_APPS
  File "/root/venv-cape/lib/python3.8/site-packages/django/conf/__init__.py", line 82, in __getattr__
    self._setup(name)
  File "/root/venv-cape/lib/python3.8/site-packages/django/conf/__init__.py", line 63, in _setup
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
(venv-cape) root@cape:/opt/CAPEv2/utils#

Failure information (in case of bug)

(venv-cape) root@test-env-cape:/opt/CAPEv2/web# python3 manage.py drf_create_token cape --traceback
argument for 's' must be a bytes object
System check identified some issues:

WARNINGS:
account.EmailAddress: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
        HINT: Configure the DEFAULT_AUTO_FIELD setting or the AccountConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
account.EmailConfirmation: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
        HINT: Configure the DEFAULT_AUTO_FIELD setting or the AccountConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
openid.OpenIDNonce: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
        HINT: Configure the DEFAULT_AUTO_FIELD setting or the AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
openid.OpenIDStore: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
        HINT: Configure the DEFAULT_AUTO_FIELD setting or the AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
otp_totp.TOTPDevice: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
        HINT: Configure the DEFAULT_AUTO_FIELD setting or the AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
socialaccount.SocialAccount: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
        HINT: Configure the DEFAULT_AUTO_FIELD setting or the SocialAccountConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
socialaccount.SocialApp: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
        HINT: Configure the DEFAULT_AUTO_FIELD setting or the SocialAccountConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
socialaccount.SocialToken: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
        HINT: Configure the DEFAULT_AUTO_FIELD setting or the SocialAccountConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
users.UserProfile: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
        HINT: Configure the DEFAULT_AUTO_FIELD setting or the UsersConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
Traceback (most recent call last):
  File "/root/venv-cape/lib/python3.8/site-packages/rest_framework/authtoken/management/commands/drf_create_token.py", line 38, in handle
    token = self.create_user_token(username, reset_token)
  File "/root/venv-cape/lib/python3.8/site-packages/rest_framework/authtoken/management/commands/drf_create_token.py", line 13, in create_user_token
    user = UserModel._default_manager.get_by_natural_key(username)
  File "/root/venv-cape/lib/python3.8/site-packages/django/contrib/auth/base_user.py", line 45, in get_by_natural_key
    return self.get(**{self.model.USERNAME_FIELD: username})
  File "/root/venv-cape/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/root/venv-cape/lib/python3.8/site-packages/django/db/models/query.py", line 435, in get
    raise self.model.DoesNotExist(
django.contrib.auth.models.DoesNotExist: User matching query does not exist.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/root/venv-cape/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/root/venv-cape/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/root/venv-cape/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/root/venv-cape/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/root/venv-cape/lib/python3.8/site-packages/rest_framework/authtoken/management/commands/drf_create_token.py", line 40, in handle
    raise CommandError(
django.core.management.base.CommandError: Cannot create the Token: user cape does not exist
(venv-cape) root@test-env-cape:/opt/CAPEv2/web#

Procedure to reproduce

  1. pip3 install djangorestframework
  2. cd web/ and python3 manage.py drf_create_token cape
  3. The error occurs

Environment

Host machine: ubuntu 20.04.1 LTS installed Python 3.8.5 git pull, pip3 install -r requirements.txt OK

Failure log

reference Expected behavior

doomedraven commented 3 years ago

hello by parts

ai-suzuki commented 3 years ago

Thank you This os user is exists. Is the user here a user for the Cape app? If so, do you set it with [web_auth] in web.conf? Now,It is set not to use authentication.

doomedraven commented 3 years ago

no you need to become more familiar with difference of server side users and webapps users, that are 2 totally different topics

if you don't use auth you don't need token, and if you enable auth, restart web service and go to /admin/ and create users https://github.com/kevoreilly/CAPEv2/commit/0ac23cafc3b3524d598bcddd42aab89773bdf15f

ai-suzuki commented 3 years ago

Thank you! I was able to use the api with not using auth

doomedraven commented 3 years ago

Cool, if you need auth, just create user in django admin /admin/ and gen token for that user

El vie., 14 may. 2021 11:20, ai-suzuki @.***> escribió:

Thank you! I was able to use the api with not using auth

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/kevoreilly/CAPEv2/issues/495#issuecomment-841124741, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOFH36AJQJMOD42HLSL4JLTNTTONANCNFSM443RLKMQ .