Skip to content

Commit 746a28d

Browse files
committed
Updated Sudo and Program directories
Program directories configured for /root/tickets, and /root/scripts for running of program. alias and sudo set for sysadmin user.
1 parent d2fc56c commit 746a28d

3 files changed

Lines changed: 52 additions & 17 deletions

File tree

docker/setup/setup-sysadmin-user.sh

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,20 @@ echo "[+] Creating user: $USERNAME"
1010
if id "$USERNAME" >/dev/null 2>&1; then
1111
echo "[i] User $USERNAME already exists"
1212
else
13-
# Detect Debian-based distros (has /etc/debian_version)
13+
# Detect Debian-based distros
1414
if [ -f /etc/debian_version ]; then
1515
echo "[+] Detected Debian-based system — using adduser"
16-
# --disabled-password: user can't log in via password
17-
# --gecos "": skip interactive prompts
18-
# --home: specify home directory
19-
# --shell: specify default shell
2016
adduser --disabled-password --gecos "" --home "$USER_HOME" --shell /bin/bash "$USERNAME"
2117
else
2218
echo "[+] Using useradd for non-Debian system"
23-
# -m: create home
24-
# -d: set home path
25-
# -s: set shell
2619
useradd -m -d "$USER_HOME" -s /bin/bash "$USERNAME"
2720
fi
2821
fi
2922

3023
echo "[+] Create sysadmin HOME directory and set permissions"
3124
# Ensure home directory exists and is owned by the user
3225
mkdir -p "$USER_HOME"
33-
chown -R "$USERNAME" "$USER_HOME" || true
26+
chown -R "$USERNAME:$USERNAME" "$USER_HOME" || true
3427

3528
# Ensure .bashrc exists
3629
if [[ ! -f "$USER_HOME/.bashrc" ]]; then
@@ -39,13 +32,18 @@ fi
3932

4033
# Add alias for the sysadmin user
4134
if ! grep -q "alias sysadmin-sim" "$USER_HOME/.bashrc"; then
42-
echo "alias sysadmin-sim='bash /bin/sysadmin-sim/sysadmin-sim-config.sh'" >> "$USER_HOME/.bashrc"
35+
echo "alias sysadmin-sim='sudo /bin/sysadmin-sim/sysadmin-sim-config.sh'" >> "$USER_HOME/.bashrc"
4336
echo "[+] Added sysadmin-sim alias to $USER_HOME/.bashrc"
4437
fi
4538

46-
echo "[+] Disabling sudo and restricting privilege escalation tools"
39+
# Add the sysadmin user to sudoers securely
40+
if ! grep -q "$USERNAME" /etc/sudoers.d/sysadmin-sim 2>/dev/null; then
41+
echo "$USERNAME ALL=(ALL) NOPASSWD: /bin/sysadmin-sim/sysadmin-sim-config.sh" > /etc/sudoers.d/sysadmin-sim
42+
chmod 440 /etc/sudoers.d/sysadmin-sim
43+
echo "[+] Configured sudo access for $USERNAME"
44+
fi
4745

48-
# Create /etc/sudoers.d if missing and restrict sudo usage for sysadmin
46+
echo "[+] Disabling sudo and restricting privilege escalation tools"
4947
if command -v sudo >/dev/null 2>&1; then
5048
mkdir -p /etc/sudoers.d
5149
echo "$USERNAME ALL=(ALL) NOPASSWD: /bin/false" > /etc/sudoers.d/disable-sudo
@@ -60,9 +58,5 @@ for binary in /usr/bin/su /usr/bin/pkexec; do
6058
fi
6159
done
6260

63-
# Lock root account if passwd and shadow file are available
64-
if command -v passwd >/dev/null 2>&1 && [ -f /etc/shadow ]; then
65-
passwd -l root || true
66-
fi
67-
6861
echo "[+] Setup complete for user: $USERNAME"
62+

docker/ubuntu/Dockerfile.ubuntu

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ RUN apt-get update && \
2727
COPY docker/setup/setup-sysadmin-user.sh /tmp/setup-sysadmin-user.sh
2828
RUN chmod +x /tmp/setup-sysadmin-user.sh && /tmp/setup-sysadmin-user.sh && rm /tmp/setup-sysadmin-user.sh
2929

30+
# Set sudo NOPASSWD for the sysadmin user to access the simulator
31+
RUN echo "sysadmin ALL=(ALL) NOPASSWD: /bin/sysadmin-sim/sysadmin-sim-config.sh" >> /etc/sudoers
32+
3033
# SSH banner files
3134
COPY docker/setup/login-banner.player.txt /tmp/login-banner.player.txt
3235
COPY docker/setup/login-banner.admin.txt /tmp/login-banner.admin.txt
@@ -43,6 +46,19 @@ RUN mkdir -p /bin/sysadmin-sim
4346
COPY src/scripts/sysadmin-sim-config.sh /bin/sysadmin-sim/sysadmin-sim-config.sh
4447
RUN chmod +x /root/sysadmin-sim-config.sh
4548

49+
# Create directories for scripts and tickets
50+
RUN mkdir -p /bin/sysadmin-sim /etc/.sysadmin-sim /root/tickets /root/scripts
51+
52+
# Copy the main simulator script
53+
COPY src/scripts/sysadmin-sim-config.sh /bin/sysadmin-sim/sysadmin-sim-config.sh
54+
RUN chmod +x /bin/sysadmin-sim/sysadmin-sim-config.sh
55+
56+
# Copy ticket files and scripts
57+
COPY src/tickets/ /root/tickets/
58+
COPY src/scripts/ /root/scripts/
59+
RUN chmod -R 700 /root/tickets /root/scripts
60+
61+
4662
# Set up Entrypoint
4763
COPY docker/setup/entrypoint.sh /usr/local/bin/entrypoint.sh
4864
RUN chmod +x /usr/local/bin/entrypoint.sh

src/tickets/ticket-018.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
id: ticket-018
2+
title: "Adjust process priority with nice"
3+
difficulty: medium
4+
description: |
5+
A script has been running with a low priority, causing it to be preempted by other processes.
6+
Adjust the priority of the process named 'slowtask' to a nice value of 5.
7+
objectives:
8+
- Use the `nice` command to set the priority of 'slowtask' to 5
9+
exam_objectives:
10+
- exam: "Linux+"
11+
version: "XK0-005"
12+
domain: "1"
13+
objective_id: "1.1"
14+
description: "Manage files and directories using command-line utilities"
15+
tools:
16+
- nice
17+
- ps
18+
tags: [process, priority, system]
19+
setup_script: "/bin/sysadmin-sim/ticketsticket-018-setup.sh"
20+
strikedown_script: "/bin/sysadmin-sim/ticket-018-strikedown.sh"
21+
check_script: "/bin/sysadmin-sim/ticket-018-check.sh"
22+
compatible_distributions: [ubuntu, debian, fedora, rocky, alpine]
23+
architecture: [amd64, arm64]
24+
flag: LINUX{a9cb52f8c68e24307e88b88173890393}
25+

0 commit comments

Comments
 (0)