Skip to content

Commit 820dcec

Browse files
Merge branch 'master' into master
2 parents 226062f + eafe48f commit 820dcec

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/pwncore/config.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import os
2+
import bcrypt
23
from dataclasses import dataclass
4+
import warnings
5+
from passlib.hash import bcrypt_sha256
36

47
"""
58
Sample messages:
@@ -42,6 +45,8 @@
4245
"users_not_found": 24,
4346
}
4447

48+
admin_hash_value = os.environ.get("PWNCORE_ADMIN_HASH", bcrypt_sha256.hash('pwncore'))
49+
using_default_admin = os.environ.get("PWNCORE_ADMIN_HASH") is None
4550

4651
@dataclass
4752
class Config:
@@ -58,15 +63,15 @@ class Config:
5863
staticfs_url: str
5964
staticfs_data_dir: str
6065
staticfs_jwt_secret: str
61-
66+
admin_hash: str
6267

6368
config = Config(
64-
development=True,
69+
development=False,
6570
# db_url="sqlite://:memory:",
6671
db_url=os.environ.get("DATABASE_URL", "sqlite://:memory:"),
67-
docker_url=None, # None for default system docker
72+
# docker_url=None, # None for default system docker
6873
# Or set it to an arbitrary URL for testing without Docker
69-
# docker_url="http://google.com",
74+
docker_url="http://google.com",
7075
flag="C0D",
7176
max_containers_per_team=3,
7277
jwt_secret="mysecret",
@@ -77,4 +82,9 @@ class Config:
7782
staticfs_url="http://localhost:8080",
7883
staticfs_data_dir=os.environ.get("STATIC_DATA_DIR", "/data"),
7984
staticfs_jwt_secret="PyMioVKFXHymQd+n7q5geOsT6fSYh3gDVw3GqilW+5U="
85+
admin_hash=admin_hash_value,
8086
)
87+
88+
# Warn in production if env not loaded
89+
if not config.development and using_default_admin:
90+
warnings.warn("Default admin hash being used in production!", RuntimeWarning)

src/pwncore/routes/admin.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from datetime import date
33

44
from fastapi import APIRouter, Request, Response
5-
from passlib.hash import bcrypt
5+
from passlib.hash import bcrypt, bcrypt_sha256
66
from tortoise.transactions import atomic, in_transaction
77

88
import pwncore.containerASD as containerASD
@@ -29,7 +29,6 @@
2929
if config.development:
3030
logging.basicConfig(level=logging.INFO)
3131

32-
ADMIN_HASH = "$2b$12$USIGDWgl8WSgSoGauDTKE.ZAKyInaJn84fsZ.ARA6FmntIZeNCTUq"
3332
NAMES = [
3433
"Mimas",
3534
"Enceladus",
@@ -57,7 +56,7 @@ async def _del_cont(id: str):
5756
async def calculate_team_coins(
5857
response: Response, req: Request
5958
): # Inefficient, anyways will be used only once
60-
if not bcrypt.verify((await req.body()).strip(), ADMIN_HASH):
59+
if not bcrypt_sha256.verify((await req.body()).strip(), config.admin_hash): # Use config.admin_hash
6160
response.status_code = 401
6261
return
6362
async with in_transaction():
@@ -88,7 +87,7 @@ async def calculate_team_coins(
8887
async def init_db(
8988
response: Response, req: Request
9089
): # Inefficient, anyways will be used only once
91-
if not bcrypt.verify((await req.body()).strip(), ADMIN_HASH):
90+
if not bcrypt_sha256.verify((await req.body()).strip(), config.admin_hash):
9291
response.status_code = 401
9392
return
9493
await Problem.create(

0 commit comments

Comments
 (0)