PEN-200 Linux Privilege Escalation Practice Question
You have obtained a low-privileged shell on a Linux server. During enumeration, you discover a file named `backup.sh` in `/opt/scripts` that is owned by root and has permissions `-rwxr-xr-x`. A cron job runs this script every night as root. The directory `/opt/scripts` has permissions `drwxrwxr-x` and is owned by root:developers. Your user is a member of the `developers` group. What is the most reliable way to escalate privileges?
⚠ Common exam trap
The trap here is focusing on the file's permissions and overlooking the directory's write permission, which allows replacing the file entirely.
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
✓
Replace `/opt/scripts/backup.sh` with a malicious script by deleting the original and creating a new file with the same name.
The key vulnerability is that the directory `/opt/scripts` is writable by the `developers` group, of which your user is a member. Although the script file itself is not writable, you can delete it and create a new file with the same name because directory write permission allows file deletion and creation. The cron job will then execute your malicious script as root, granting privilege escalation. This is a common misconfiguration in Linux environments.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use the `sudo` command to edit the script with `sudoedit`.
Why it's wrong here
The scenario does not indicate that your user has any sudo privileges. Attempting to use sudoedit would likely prompt for a password or be denied. Even if sudo were configured, it would not be the most reliable method without evidence of such privileges. The directory write permission already provides a direct path to escalation without needing sudo.
- ✓
Replace `/opt/scripts/backup.sh` with a malicious script by deleting the original and creating a new file with the same name.
Why this is correct
Because the directory `/opt/scripts` is group-writable and you are a member of the `developers` group, you can delete the existing `backup.sh` file and create a new file with the same name. The new file will be owned by your user, but the cron job runs as root and will execute it. This is a classic privilege escalation via writable directory containing a root-executed script. The original file's permissions do not prevent deletion because deletion is controlled by the directory's permissions, not the file's.
- ✗
Add a new cron job that runs a reverse shell as your user.
Why it's wrong here
Adding a new cron job as your user would execute with your user's privileges, not root's. The goal is to escalate to root, so running a reverse shell as your user does not achieve privilege escalation. Additionally, you may not have permission to edit the crontab for other users or system cron directories. This option misunderstands the objective and the mechanics of cron.
- ✗
Modify the contents of `/opt/scripts/backup.sh` to include a reverse shell payload.
Why it's wrong here
The script is owned by root and has permissions `-rwxr-xr-x`, meaning only the owner (root) can write to it. Although the directory is group-writable, the file itself is not writable by the group. Therefore, you cannot directly modify the script's contents. This option is a common misconception because directory write permissions do not automatically grant write access to files within it.
About these practice questions
One of 285 original PEN-200 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official OffSec exam blueprint
This PEN-200 practice question is part of Courseiva's free OffSec 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 PEN-200 exam.