Skip to content

Users can start services on other users' machines #984

Description

@Leonabcd123

In the pwncollege_api/v1/workspace endpoint, we get the service and user id from the user:

user_id = request.args.get("user")
password = request.args.get("password")
service = request.args.get("service")

if user_id and not password and not is_admin():
    abort(403)

 user = get_current_user() if not user_id else Users.query.filter_by(id=int(user_id)).first_or_404()

Afterwards, we call start_on_demand_service with that service and user:

if start_on_demand_service(user, service) is False:
    return {"success": False, "active": True, "error": f"Failed to start service {service}"}

In start_on_demand_service, we check whether the service is terminal, code or desktop, and if it is one of them, we start it:

on_demand_services = { "terminal", "code", "desktop"}

def start_on_demand_service(user, service_name):
    if service_name not in on_demand_services:
        return None
    try:
        exec_run(
            f"/run/current-system/sw/bin/timeout -k 10 30 /run/current-system/sw/bin/dojo-{service_name}",
            workspace_user="hacker",
            user_id=user.id,
            assert_success=True,
            log=True,
        )

This allows anyone to start the terminal and code services on another users' machine. Note that we cannot start the desktop service because we verify the user when the service is desktop in the pwncollege_api/v1/workspace endpoint:

if service == "desktop":
    interact_password = container_password(container, "desktop", "interact")
    view_password = container_password(container, "desktop", "view")

    if user_id and password:
        if not hmac.compare_digest(password, interact_password) and not hmac.compare_digest(password, view_password):
            abort(403)
        password = password[:8]
    else:
        password = interact_password[:8]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions