Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
404 if container not found
Browse files Browse the repository at this point in the history
ConnorNelson committed Jun 17, 2024
1 parent 8561f97 commit 2c235d7
Showing 2 changed files with 13 additions and 10 deletions.
14 changes: 9 additions & 5 deletions dojo_plugin/pages/workspace.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import hmac

import docker
from flask import request, Blueprint, render_template, redirect, url_for, abort
from CTFd.models import Users
from CTFd.utils.user import get_current_user, is_admin
@@ -110,11 +111,14 @@ def forward_workspace(service, service_path=""):
abort(404)

if service in ondemand_services:
exec_run(
f"/opt/pwn.college/services.d/{service}",
workspace_user="hacker", user_id=user.id, shell=True,
assert_success=True
)
try:
exec_run(
f"/opt/pwn.college/services.d/{service}",
workspace_user="hacker", user_id=user.id, shell=True,
assert_success=True
)
except docker.errors.NotFound:
abort(404)

elif service.count("~") == 1:
port, user_id = service.split("~", 1)
9 changes: 4 additions & 5 deletions dojo_plugin/utils/workspace.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import shlex

import docker

docker_client = docker.from_env()

def exec_run(cmd, *, shell=False, assert_success=True, workspace_user="root", user_id=None, container=None, **kwargs):

if shell:
cmd = f"""/bin/sh -c \"
{cmd}
\""""

cmd = f'/bin/sh -c {shlex.quote(cmd)}'
if not container:
container = docker_client.containers.get(f"user_{user_id}")
exit_code, output = container.exec_run(cmd, user=workspace_user, **kwargs)

0 comments on commit 2c235d7

Please sign in to comment.