Explore our new Cybersecurity Terms Glossary, explained by our experts.

Sudo is a program on Linux and Unix systems that enables users to run commands with the rights of the superuser. On Linux and Unix systems, a file named sudoers exists under the /etc directory for sudo. This file is sudo’s configuration file. Through configurations made in the sudoers file, users with root rights can execute commands as root or as other users. Figure 1 shows the default sudoers file.
When a command is run with sudo, the system first checks the sudoers file. If that file contains the relevant permissions for the username and the groups the user belongs to, commands can be run with sudo within the granted permissions. Otherwise, the commands cannot be executed. Figure 1.1 shows the permissions assigned to the root user. Figure 1.2 explains the syntax of the permissions assigned to the root user.


When permissions are defined in the sudoers file for a user or a group, the syntax shown in Figure 2 is used. The expressions within the syntax are explained below:
When additions are made to the sudoers file for low-privileged users and user groups, attackers can exploit this situation for privilege escalation. Below, a sample application is provided for privilege escalation via the sudo programme.
When the sudoers file is misconfigured for low-privileged users and groups, this situation may allow attackers to escalate their rights and privileges on Linux and Unix systems. In Figure 2.1, an SSH session was obtained via a user with low privileges.

A rule was also added to the sudoers file for a user named unprivileged. Figure 2.2 shows the reconfigured sudoers file.

According to the rule added for the user named unprivileged: this user can use the sudo programme to run the python tool with root rights on all hosts without entering any password.
The command sudo -l was run on the obtained SSH session and used to identify what the low-privileged user can do via the sudo programme. Figure 2.3 shows the list of sudo permissions defined for the user named unprivileged.

To leverage the functionality of the low-privileged user being able to run python commands with root rights, a Python code that runs the bash application on the operating system can be written. Figure 2.4 shows the code snippet that runs the bash application on the operating system.

In Figure 2.5, the written code snippet was executed using the sudo programme with the python tool, and root access was obtained.

You May Be Interested In These
We use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.