hardMultiple ChoiceObjective-mapped
PT0-002 Practice Question: A penetration tester has gained low-privilege…
A penetration tester has gained low-privilege shell access on a Linux server. The tester runs `sudo -l` and sees the following entry: `(root) NOPASSWD: /usr/bin/python3 /opt/scripts/*.py` The `/opt/scripts/` directory is owned by the tester's current user. Which technique is most effective for escalating privileges to root?
⚠ Common exam trap
Many candidates think symbolic links or overwriting system files are viable, but the key is that the sudo rule specifically executes Python scripts from a writable directory, making a crafted script the simplest and most direct escalation path.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Write a malicious Python script to /opt/scripts/ that spawns a root shell
The tester's user owns `/opt/scripts/` and can write arbitrary files there. The sudo rule allows executing any `.py` file in that directory as root without a password. By writing a Python script that calls `os.setuid(0); os.system('/bin/bash')` or similar, the tester can spawn a root shell, directly leveraging the misconfigured sudoers entry.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Create a symbolic link from a Python script to a system file like /etc/shadow
Why it's wrong here
This fails because the sudo rule executes Python scripts, not arbitrary files. A symlink pointing to /etc/shadow would cause the Python interpreter to attempt to read the shadow file as source code, resulting in a SyntaxError since it contains colon-delimited account data, not valid Python. Even if the file were readable, Python wouldn't execute it as a shell, and the symlink path might fall outside the /opt/scripts/ directory allowed by the sudoers rule.
- ✓
Write a malicious Python script to /opt/scripts/ that spawns a root shell
Why this is correct
Since the user owns /opt/scripts, they can create a Python script that imports os and calls os.system('/bin/bash') or launches a reverse shell with socket and subprocess modules. When the script is run via the configured sudo rule, it executes with root privileges because sudo preserves the target user's (root) permissions. This is a classic and reliable privilege escalation when a sudoers entry permits executing scripts from a user-writable directory without disabling the associated commands.
- ✗
Exploit a kernel vulnerability to overwrite the sudo binary
Why it's wrong here
This approach is unnecessary and risky because kernel exploits require a specific vulnerable kernel version and may crash the system or hang, which can kill the session. Overwriting /usr/bin/sudo would also require write access to a root-owned system binary directory, which the low-privilege user does not have. Since a direct sudo rule exists to run Python scripts as root, exploiting the kernel or modifying sudo adds complexity, violates the principle of least resistance, and can alert defenders or leave the system unstable.
- ✗
Overwrite an existing Python script in /usr/bin/ with a malicious payload
Why it's wrong here
This attempt fails for two reasons: the user almost certainly lacks write permission to /usr/bin/, as that directory is owned by root and typically read-only for non-privileged users, so the overwrite would be denied. Even if the overwrite succeeded, the sudoers rule in question is scoped specifically to /opt/scripts/, not /usr/bin/, so running the modified script with sudo would not be permitted. Additionally, sudo would not execute an arbitrary binary/script from /usr/bin under this rule, making the entire effort futile.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PT0-003 question from scratch — 185 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PT0-003 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PT0-003 exam.