Home Cron Jobs - PATH Environment Variable
Post
Cancel

Cron Jobs - PATH Environment Variable

Cron Jobs - PATH Environment Variable

Enumeration

We are going to exploit PATH Environment Variable to escalate our privileges to root. Let’s check the content of a crontab /etc/crontab

linpriv

As you can see, the PATH variable starts with /home/user, which is our current user’s home directory . Since we have write permission to the directory, we can create a file with thesame name as overwrite.sh so that to be executed by the cronjab. This is possible because overwrite.sh script is not configured with it full path and it set to run with root privilege , thereby allowing us to hijack it.

Exploitation

Let’s create a script overwrite.sh with a reverse shell payload and place it in our home directory, so that to be executed automatically by cronjob.

linpriv

We will setup a reverse shell listener and wait for an incoming connection.

linpriv

Well…As you can see, we have obtained a shell with root privilege.

This post is licensed under CC BY 4.0 by the author.