Courseiva

CCNA Linux Privilege Escalation Questions

18 questions · Linux Privilege Escalation topic · All types, answers revealed

1
MCQmedium

Why is it often effective to check for 'Capabilities' on Linux binaries when SUID is not present?

A.Capabilities are automatically granted to all users on a system.
B.They allow a binary to perform privileged operations without full root UID.
C.Capabilities only work on binaries that have the SUID bit set.
D.They enable the user to bypass the sudo password prompt.
AnswerB

Capabilities break down root privileges into smaller units. If a binary is granted the 'CAP_DAC_OVERRIDE' capability, for example, it can bypass file permission checks even if the binary itself isn't running as root. This allows for privilege escalation by leveraging the binary's authorized, high-level permissions.

Why this answer

Linux capabilities allow for fine-grained control over privileged operations, such as network raw socket access or file modification, without requiring the full root user. If a binary has excessive capabilities assigned, it can be abused to perform privileged actions. This is a subtle but powerful alternative to SUID that is frequently overlooked during security assessments, making it a valuable path for privilege escalation when traditional SUID targets are unavailable.

Exam trap

Students often ignore binaries lacking the SUID bit entirely, assuming they are secure, and completely overlook alternative mechanisms like Linux capabilities during enumeration.

2
MCQmedium

During post-exploitation on a Linux target, you discover a binary with the SUID bit set owned by root. Running 'strings' on the binary reveals it calls 'system("ps")' without specifying an absolute path. Which of the following techniques is most likely to allow you to escalate privileges by exploiting this behavior?

A.Overwrite the /bin/ps binary with a malicious script, then run the SUID binary.
B.Modify the binary to replace system("ps") with system("/bin/sh"), then run it.
C.Use LD_PRELOAD to inject a shared library that hijacks the system() call.
D.Create a malicious 'ps' executable in a directory earlier in the PATH, then run the SUID binary.
AnswerD

The binary uses system("ps"), which invokes the shell to run the command. If the PATH environment variable includes a writable directory before /bin, you can place a malicious 'ps' there. When the SUID binary runs, it will execute your 'ps' as root, granting escalation. This is a classic PATH hijacking attack.

Why this answer

The SUID binary calls system("ps") without an absolute path, meaning it relies on the PATH environment variable to locate the ps command. If an attacker can prepend a writable directory to PATH and place a malicious ps script there, the SUID binary will execute it with root privileges. This is a classic PATH hijacking privilege escalation.

Exam trap

The trap here is assuming that LD_PRELOAD or binary modification is needed, while overlooking the simpler PATH hijacking due to the relative command invocation.

3
MCQmedium

Which Linux kernel feature, if misconfigured or outdated, allows an unprivileged user to gain root access by exploiting a vulnerability in the handling of user namespaces?

A.AppArmor profile confinement
B.Unprivileged user namespace clone functionality
C.Shared memory segment access via IPC
D.Extended file attributes (xattr)
AnswerB

The 'unshare' or 'clone' syscalls allow creating new namespaces without root. Exploits often target how the kernel handles these namespaces to escalate privileges. Because these features are often exposed to all users, they serve as a critical vector for local privilege escalation attacks on outdated kernels.

Why this answer

User namespaces allow unprivileged processes to behave as root within a confined environment. Vulnerabilities in how the kernel manages these namespaces, such as improper capability checks, can be exploited to gain full root access on the host system. This highlights the importance of kernel patching and minimizing the attack surface by disabling unnecessary namespace features on production servers to prevent escapes.

Exam trap

Candidates often confuse user namespace features with standard file permissions or misconfigured SUID binaries, looking in the wrong places for kernel-level escalation vectors.

4
MCQhard

When performing a kernel exploit for privilege escalation, what is the most significant risk to the stability of the target system?

A.The system will automatically log the attacker's IP address.
B.The system might experience a kernel panic, causing a complete crash.
C.The exploit will permanently delete all data on the disk.
D.The system firewall will automatically block the user account.
AnswerB

Because kernel exploits manipulate sensitive memory structures and CPU instructions, any mistake or unexpected state will trigger a kernel panic. This results in an immediate and total system crash, which is a major risk when attempting privilege escalation on live systems that need to remain operational.

Why this answer

Kernel exploits operate at the lowest level of the operating system. If the exploit code contains errors or interacts incorrectly with kernel memory structures, it can lead to a kernel panic, crashing the entire system. This is a significant operational risk, as it results in downtime and potentially triggers alerts that lead to discovery, emphasizing the need for caution and testing exploits in isolated environments before deployment on production targets.

Exam trap

Candidates often fear being 'caught' by an IDS/IPS. While that is a risk, the immediate, most significant technical risk of a kernel exploit is crashing the target machine entirely.

5
MCQmedium

A penetration tester discovers that the current user can write to a script located in /opt/backup/ that is executed every minute by a cron job running as root. The script has permissions `-rwxr-xr-x 1 root root`. What is the MOST reliable way to escalate privileges?

A.Use the `at` command to schedule a script that modifies the cron job.
B.Change the script's permissions to 777 and then execute it manually.
C.Create a symbolic link to /etc/passwd in the same directory and modify the script to write to it.
D.Modify the script to add a reverse shell command, then wait for the cron job to execute.
AnswerD

This is correct. Since the script is writable by the current user and executed by root via cron, modifying it to include a reverse shell or a command that creates a SUID binary will execute with root privileges. Waiting for the next cron interval triggers the escalation.

Why this answer

Because the script is writable and executed by root, an attacker can insert arbitrary commands that run with root privileges. Modifying the script to spawn a reverse shell or create a SUID backdoor is the most direct and reliable method. The cron job will execute the modified script as root, granting escalation.

Exam trap

The trap here is overcomplicating the attack with symlinks or permission changes when the script is already directly writable and executed by root.

6
MCQmedium

During a Linux privilege escalation assessment, you obtain a low-privileged shell as user 'student'. You run 'id' and see the user belongs to the 'docker' group. Which command will most reliably escalate to root on this host?

A.newgrp docker
B.unshare -Ur
C.docker run -v /:/mnt --rm -it alpine chroot /mnt sh
D.sudo -u root /bin/bash
AnswerC

Members of the docker group can control the Docker daemon, effectively giving root-level access to the host. This command starts a container, mounts the host's root filesystem at /mnt inside the container, and then uses chroot to change the root to /mnt, spawning a shell with root privileges on the host's filesystem. This is a classic and reliable privilege escalation technique when docker group membership is present.

Why this answer

Docker group membership allows a user to interact with the Docker daemon, which runs as root. By mounting the host root filesystem into a container and chrooting into it, an attacker can effectively gain root-level access to the host. This technique is well-known and reliable, as it leverages the daemon's privileges to bypass filesystem permissions.

The other commands either require existing sudo rights, only change group context, or create isolated namespaces without host root privileges.

Exam trap

The trap here is assuming that docker group membership only allows managing containers, when in fact it provides a direct path to host root via filesystem mounts.

7
MCQhard

Refer to the exhibit. The 'find' binary has the SUID bit set. How can you leverage this to gain a root shell?

A.find . -exec /bin/sh -p \;
B.find . -name "*" -delete
C.find . -exec chmod 777 /etc/shadow \;
D.find / -user web -exec ls -l {}
AnswerA

Using the -exec flag with /bin/sh allows you to spawn a shell. The -p flag is essential for 'sh' to maintain the SUID privilege level instead of dropping it to the user's real UID. This command effectively drops you into a root shell because 'find' is executing as root.

Why this answer

The 'find' command includes an '-exec' flag that allows executing arbitrary commands on the files it locates. When an SUID-bit 'find' binary is used with the '-exec' flag, the command spawned by '-exec' will also run with the SUID owner's privileges. This is a well-documented technique for privilege escalation, demonstrating why SUID binaries must be audited to ensure they do not offer functionality that can be abused for command execution.

Exam trap

Candidates frequently omit the critical '-p' flag when spawning a shell via SUID binaries, causing the shell to drop privileges and preventing root access.

8
MCQeasy

Which file is essential for auditing to determine which users have been granted sudo privileges?

A./etc/passwd
B./etc/sudoers
C./etc/shadow
D./etc/group
AnswerB

The /etc/sudoers file is the definitive source for sudo permissions. It lists all users and groups that have been granted sudo rights and specifies the exact scope of those rights. This file is the primary target for auditing privilege assignments on any Linux system.

Why this answer

The /etc/sudoers file is the configuration file that controls sudo access. It defines exactly which users or groups can execute commands with elevated privileges and under what conditions. Auditing this file is the standard way to identify misconfigurations that could allow a low-privileged user to gain root access.

Understanding its syntax is vital for any security professional to accurately identify and remediate potential privilege escalation paths in a Linux environment.

Exam trap

Candidates often waste time looking into generic system logs or password files instead of targeting the definitive configuration file that dictates sudo access policies.

9
MCQeasy

While enumerating a Linux host, you notice that the `passwd` command has the SUID bit set and is owned by root. You recall that SUID binaries run with the privileges of the file owner. Which of the following is the most direct way to leverage this to gain root access?

A.Run `passwd` and change the root password.
B.The SUID bit on `passwd` is standard and does not by itself allow privilege escalation.
C.Use the SUID bit to read the `/etc/shadow` file and crack the root hash.
D.Exploit a vulnerability in the `passwd` binary to execute arbitrary code.
AnswerB

The `passwd` command is commonly SUID root by default on many Linux distributions to allow users to change their own passwords by writing to `/etc/shadow`. This is a legitimate, expected configuration and does not constitute a vulnerability. Without an additional flaw or misconfiguration, the SUID bit on passwd cannot be leveraged for privilege escalation. Recognizing standard SUID binaries is crucial to avoid false positives during enumeration.

Why this answer

The SUID bit on `/usr/bin/passwd` is a standard, secure configuration present on most Linux systems. It allows unprivileged users to change their own passwords by temporarily elevating privileges to write to `/etc/shadow`. This is not a vulnerability; the binary enforces strict access controls.

Therefore, it does not provide a direct path to root. Testers should focus on non-standard SUID binaries or misconfigurations rather than expected ones.

Exam trap

The trap here is assuming that any SUID root binary is exploitable, when in fact many are standard and secure by design.

10
MCQeasy

Refer to the exhibit. Given the sudo privileges, which command will successfully spawn a root shell?

A.sudo /usr/bin/vim -c ':!/bin/sh'
B.sudo /usr/bin/vim /etc/shadow
C.sudo /usr/bin/vim --version
D.sudo /usr/bin/vim -u NONE
AnswerA

The -c command flag executes a command immediately upon vim startup. By invoking :!/bin/sh, the user forces vim to spawn a system shell. Because vim is running with sudo privileges, the spawned shell inherits root permissions, effectively escalating the user's access level to the highest possible on the system.

Why this answer

The exhibit shows that the user can run 'vim' as root without a password. Since vim has a built-in shell execution feature, an attacker can escape the editor to a root-privileged command prompt. This is a classic example of misconfigured sudo rights, where allowing full access to a versatile utility that supports command execution effectively grants the user complete control over the system.

Exam trap

Candidates often try to execute vim normally or forget the critical syntax required to pass commands via flags, failing to utilize the built-in escape sequences needed to spawn a root shell.

11
MCQmedium

You find that a binary relies on a relative path to execute a secondary script. If you cannot modify the PATH variable, what is the best alternative to exploit this configuration?

A.Modify the binary's ELF header to change the search path.
B.Create the expected directory structure in a location you control and execute the binary from there.
C.Use the 'ptrace' system call to attach to the binary and change its execution flow.
D.Inject environment variables like 'LD_LIBRARY_PATH' to overwrite the binary's functionality.
AnswerB

If the binary expects to find a script in a relative path like './scripts/run.sh', you can create a directory named 'scripts' in your current location and place a malicious 'run.sh' inside. When the binary runs, it will find and execute your script, inheriting the binary's SUID privileges.

Why this answer

If PATH modification is not possible, you can utilize symlinks or directory traversal to manipulate the binary's search logic. By creating a directory structure that mimics the expected relative path, you can place a malicious executable where the binary expects the legitimate one. This is effective because it exploits the binary's reliance on current working directory context, bypassing strict system-wide path settings entirely.

Exam trap

Test-takers frequently assume they can simply modify the system PATH variable even when they lack the necessary administrative write permissions, leading them down a dead end.

12
MCQhard

You have a low-privileged shell on a Linux host. You discover a cron job that runs every minute as root and executes a script located at /opt/backup/backup.sh. The script is world-writable. However, you also notice that the directory /opt/backup is owned by root and has permissions 755. Which of the following is the MOST reliable way to escalate privileges?

A.Replace the backup.sh script with a symbolic link to a file you control.
B.Modify the script to add a new user with UID 0 to /etc/passwd.
C.Use the `crontab` command to edit the root user's crontab and add a new job.
D.Overwrite the backup.sh script with a reverse shell payload.
AnswerD

The script is world-writable, meaning any user can modify its contents. Since the cron job runs as root, overwriting the script with a payload that creates a SUID root shell or connects back to your listener will execute with root privileges. The directory permissions do not prevent modifying the file's contents because the file itself is world-writable. This is a direct and reliable escalation.

Why this answer

The script is world-writable, so you can modify its contents directly. Because the cron job executes it as root, any commands you insert will run with root privileges. A reverse shell payload is a common and effective method.

The directory permissions prevent replacing the file or creating symlinks, but do not prevent editing the file's contents. Therefore, overwriting the script is the most reliable approach.

Exam trap

The trap here is focusing on the directory permissions and assuming you cannot modify the script, when in fact the file itself is writable and that is sufficient to inject commands.

13
MCQhard

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?

A.Use the `sudo` command to edit the script with `sudoedit`.
B.Replace `/opt/scripts/backup.sh` with a malicious script by deleting the original and creating a new file with the same name.
C.Add a new cron job that runs a reverse shell as your user.
D.Modify the contents of `/opt/scripts/backup.sh` to include a reverse shell payload.
AnswerB

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.

Why this answer

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.

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.

14
MCQmedium

Which command is most useful for identifying processes that are running as root, which might be potential targets for privilege escalation?

A.ps aux | grep root
B.ls -l /proc
C.netstat -tulnp
D.cat /etc/passwd | grep root
AnswerA

The 'ps aux' command lists every process on the system, and 'grep root' filters that list to show only those owned by the root user. This is the fastest way to identify all high-privilege services, which are the most valuable targets for your privilege escalation attempts.

Why this answer

The 'ps' command is essential for process enumeration. By using specific flags like 'aux', you can display all processes running on the system, including their owner. Identifying services owned by root allows you to focus your efforts on finding vulnerabilities in those specific processes.

This is a fundamental enumeration step, as privilege escalation often involves finding a misconfigured or vulnerable service that is already running with the target privileges.

Exam trap

Candidates often forget specific filtering flags or confuse process enumeration commands, attempting to use tools that do not display the file owners or trying to inspect user-level processes instead of focusing on root-owned services.

15
MCQmedium

During a Linux privilege escalation assessment, you discover that the current user can run `/usr/bin/find` via sudo without a password. You execute `sudo find /home -exec /bin/bash \;`. What is the outcome?

A.A root shell is spawned because find's -exec runs the command as the invoking user, not root.
B.The command fails because find does not allow -exec to run shell commands.
C.A root shell is spawned only if the current user is a member of the sudo group.
D.A root shell is spawned because sudo runs find as root, and -exec executes /bin/bash with root privileges.
AnswerD

This is correct. When sudo executes find as root, the find process runs with an effective UID of 0. The -exec action forks and executes /bin/bash as a child of find, inheriting root privileges. Thus, an interactive root shell is obtained. This is a classic GTFOBins technique for privilege escalation.

Why this answer

When a user is allowed to run find with sudo, they can leverage the -exec action to execute arbitrary commands as root. Because the entire find process runs with root privileges, any command spawned by -exec inherits those privileges. This allows an attacker to spawn a root shell, achieving privilege escalation.

Exam trap

The trap here is assuming that -exec drops privileges or runs commands as the original user, when in fact it inherits the effective UID of the find process.

16
MCQeasy

You identify a cron job running as root that executes a script located in a writable directory. What is the most reliable way to escalate privileges in this scenario?

A.Modify the /etc/shadow file directly.
B.Append a reverse shell command to the writable script.
C.Restart the crond service to force execution.
D.Change the ownership of the script using chmod.
AnswerB

Appending a reverse shell payload to a script executed by a root cron job ensures the shell executes with root authority. This is a standard privilege escalation technique because cron jobs typically run with the permissions of the user who owns them, which is root in this specific scenario.

Why this answer

When a cron job runs as root, any script it executes also runs with root privileges. If the script is writeable by a low-privileged user, it can be modified to include a reverse shell. This is a common misconfiguration that highlights the importance of checking file permissions and cron job schedules during the post-exploitation phase of a penetration test or a professional security assessment.

Exam trap

Candidates often attempt to replace the entire script file, which may trigger file integrity monitors. Appending the command is often stealthier and sufficient to gain the reverse shell.

17
MCQeasy

When reviewing 'sudo -l' output, what does the 'NOPASSWD' tag signify for the listed command?

A.The user is automatically added to the root group.
B.The command can be run as root without entering a password.
C.The command is not logged by the system administrator.
D.The command will run in a sandbox for security.
AnswerB

NOPASSWD specifically bypasses the sudo password prompt for the defined command. This allows the user to execute the command with the elevated privileges defined in the sudoers file instantly. This is a primary target during privilege escalation, as it simplifies the path to root significantly.

Why this answer

The 'NOPASSWD' tag indicates that the user can execute the specified command with sudo privileges without being prompted for their own password. This is a critical misconfiguration, as it removes the authentication barrier for privilege escalation. In an attack scenario, it allows for immediate, automated execution of commands as root, which is significantly more dangerous than configurations that still require a user to authenticate via their password.

Exam trap

Candidates often confuse NOPASSWD with a general sudo privilege. The trap is failing to realize that this specific tag bypasses the password prompt entirely, allowing for immediate execution of commands.

18
MCQmedium

You have gained a low-privileged shell on a Linux system and discovered a binary with the SUID bit set. The binary executes a system call to 'cat' without specifying an absolute path. How can you leverage this to escalate privileges?

A.Overwrite the SUID binary's source code in /usr/src to include a reverse shell.
B.Use 'chmod' to grant everyone execute permissions on the SUID binary to trigger a buffer overflow.
C.Prepend a directory containing a malicious 'cat' script to the PATH variable and run the binary.
D.Modify the /etc/ld.so.preload file to inject a malicious library into the SUID binary's execution flow.
AnswerC

By creating a script named 'cat' in a directory like /tmp and setting the PATH variable to start with that directory, the system executes your script instead of the legitimate binary. Because the parent program is SUID root, your malicious script runs with root privileges, granting a shell.

Why this answer

By manipulating the PATH environment variable, you can point the system to a malicious 'cat' executable created in a writable directory. When the SUID binary runs, it executes your script with the permissions of the file owner rather than yours. This technique exploits the insecure execution of external commands, a common vulnerability in improperly coded SUID binaries that allows for arbitrary command execution under an elevated security context.

Exam trap

Candidates often assume the binary is vulnerable because it is SUID, forgetting that they must actually manipulate the environment to redirect the binary's execution to their own malicious code.

Ready to test yourself?

Try a timed practice session using only Linux Privilege Escalation questions.