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

Add admin hash config and warning #79

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

Conversation

lqSky7
Copy link

@lqSky7 lqSky7 commented Feb 22, 2025

No description provided.

Comment on lines 3 to 9
import warnings
from dotenv import load_dotenv

# Put .env in root of pwncore
dotenv_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), ".env")
if not load_dotenv(dotenv_path):
warnings.warn(f".env file not loaded from {dotenv_path}", RuntimeWarning)
Copy link
Contributor

Choose a reason for hiding this comment

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

db_url=os.environ.get("DATABASE_URL", "sqlite://:memory:"),

Load like this.

Copy link
Contributor

Choose a reason for hiding this comment

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

The rest is not needed.

Comment on lines 52 to 58
raw_admin_hash = os.environ.get("PWNCORE_ADMIN_HASH")
if (raw_admin_hash is None):
admin_hash_value = "$2b$12$BjtKkihGhQlOZuLD/KrmuOP27mJ04ldXyzBgtbrNzD9JoPN/DKN1u"
using_default_admin = True
else:
admin_hash_value = raw_admin_hash
using_default_admin = False
Copy link
Contributor

Choose a reason for hiding this comment

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

Add the default value directly in the get function call

Copy link
Contributor

Choose a reason for hiding this comment

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

for the default one put the password as pwncore and hash it.

Comment on lines 47 to 53
raw_admin_hash = os.environ.get("PWNCORE_ADMIN_HASH", "sqlite://:memory:")
if raw_admin_hash is None:
admin_hash_value = "$2b$12$ZA/l9O96A34QQOlUD48LkesLukw4IAMDih1oV8l.GoEa7TewfeOP2"
using_default_admin = True
else:
admin_hash_value = raw_admin_hash
using_default_admin = False
Copy link
Contributor

Choose a reason for hiding this comment

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

Recheck this. It is wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

import admin_hash directly. No need for raw_admin_hash or admin_hash_value

Copy link
Author

Choose a reason for hiding this comment

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

i don't understand os.environ.get("PWNCORE_ADMIN_HASH", "sqlite://:memory:")

second argument of environ.get is what the variable will default to if .env is not found right?

should i do it like this?

admin_hash_value = os.environ.get("PWNCORE_ADMIN_HASH", None)
if admin_hash_value is None:
    admin_hash_value = "$2b$12$ZA/l9O96A34QQOlUD48LkesLukw4IAMDih1oV8l.GoEa7TewfeOP2"
    using_default_admin = True

@@ -1,5 +1,7 @@
import os
from dataclasses import dataclass
import warnings
from dotenv import load_dotenv
Copy link
Contributor

Choose a reason for hiding this comment

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

Not accessed. Remove this.

Copy link
Author

Choose a reason for hiding this comment

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

warning is being used, should i just do a print statement instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

warnings is fine. dotenv is not required.

Copy link
Contributor

@KreativeThinker KreativeThinker left a comment

Choose a reason for hiding this comment

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

In case bcrypt was installed, remove that.

@@ -1,5 +1,7 @@
import os
import bcrypt
Copy link
Contributor

Choose a reason for hiding this comment

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

use passlib.hash > bcrypt instead.

@@ -42,6 +44,8 @@
"users_not_found": 24,
}

admin_hash_value = os.environ.get("PWNCORE_ADMIN_HASH", bcrypt.hashpw('pwncore'.encode(), bcrypt.gensalt()).decode())
Copy link
Contributor

Choose a reason for hiding this comment

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

bcrypt.hashpw('pwncore'.encode(), bcrypt.gensalt()).decode() > bcrypt.hash("pwncore")

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