chu@antisec:~/htb$

← ../ writeups

chu@antisec:~/htb$ cat spectra.md

Spectra - HackTheBox - WriteUp

image
spectra — machine card on hackthebox

chu@antisec:~/htb$ cat tools.txt

Tools used:

● nmap
PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 8.1 (protocol 2.0)
| ssh-hostkey:
|_  4096 52:47:de:5c:37:4f:29:0e:8e:1d:88:6e:f9:23:4d:5a (RSA)
80/tcp   open  http    nginx 1.17.4
| http-methods:
|_  Supported Methods: GET HEAD
|_http-server-header: nginx/1.17.4
|_http-title: Site doesn't have a title (text/html).
3306/tcp open  mysql   MySQL (unauthorized)
|_ssl-cert: ERROR: Script execution failed (use -d to debug)
|_ssl-date: ERROR: Script execution failed (use -d to debug)
|_sslv2: ERROR: Script execution failed (use -d to debug)
|_tls-alpn: ERROR: Script execution failed (use -d to debug)
|_tls-nextprotoneg: ERROR: Script execution failed (use -d to debug)
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.91%E=4%D=2/27%OT=22%CT=1%CU=35715%PV=Y%DS=2%DC=T%G=Y%TM=603AA18
OS:D%P=x86_64-pc-linux-gnu)SEQ(SP=100%GCD=1%ISR=107%TI=Z%CI=Z%II=I%TS=A)OPS
OS:(O1=M54DST11NW7%O2=M54DST11NW7%O3=M54DNNT11NW7%O4=M54DST11NW7%O5=M54DST1
OS:1NW7%O6=M54DST11)WIN(W1=FE88%W2=FE88%W3=FE88%W4=FE88%W5=FE88%W6=FE88)ECN
OS:(R=Y%DF=Y%T=40%W=FAF0%O=M54DNNSNW7%CC=Y%Q=)T1(R=Y%DF=Y%T=40%S=O%A=S+%F=A
OS:S%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T5(R
OS:=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F
OS:=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)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%CD
OS:=S)

After our nmap scan, we can see an HTTP service running on our target.

Image
nmap — scan results

Accessing it, we come across this page:

Image
landing — two links on the page

The first link takes us to the /main/ directory, which is running a WordPress 5.4.2 site

Image
/main/ — wordpress is up

On the second link, we get an error saying the database connection failed:

Image
testing — db connection error

But if we try to list the directory:

Image
listing — directory listed

One of these files stands out, wp-config.php.save, but if we try to read it:

Image
wp-config.php.save — rendered, nothing useful

At this point we use the old trick of viewing the page source:

Image
view-source — credentials in the source

And there we go, credentials :D~

● creds
define( 'DB_NAME', 'dev' );
define( 'DB_USER', 'devtest' );
define( 'DB_PASSWORD', 'devteam01' );
define( 'DB_HOST', 'localhost' );

If we try to use them on the WordPress login page, we notice the credentials don't work...

Image
wp-login — credential denied

Digging further into the WordPress site, we can see the username is 'administrator'

Image
post — author administrator

So let's try logging in with the credentials administrator:devteam01 aaand b00m, we're in ~

Image
wp-admin — wordpress dashboard

Now let's use metasploit to get a reverse connection to the machine, for that we'll use the exploit:

Image
searchsploit — wp exploit in msf
● exploit
exploit/unix/webapps/wp_admin_shell_upload

We set the options:

Image
options — user and password set

Double-checking before running it:

Image
check — options checked

Then we run our exploit and land our access:

Image
meterpreter — session opened

After that, we generate an RSA key on our machine to upgrade our access:

Image
ssh-keygen — key for nginx
● cmd
ssh-keygen

In meterpreter, we drop to a shell and write our RSA key to /home/nginx/.ssh/authorized_keys to step up our shell.

Image
authorized_keys — nginx key written

After writing it, we connect over SSH.

Image
ssh — login as nginx
● cmd
ssh nginx@spectra.htb -i nginx

Now that we have an interactive shell, we start mapping the system... After a while, a file called autologin.conf.orig in the /opt directory catches our eye...

Image
/opt — autologin.conf.orig

Inside that file we can see it points to a file called passwd in the /etc/autologin folder, so let's go take a look

Image
passwd — password in autologin

That gives us another password... let's test it Tried it with the chronos user, no luck — but with the user katie... :D

Image
katie — ssh login

Now that we have our first flag, let's move on to privilege escalation

Image
user flag — first flag

We can run /sbin/initctl as root

Image
sudo -l — initctl allowed

We can look at the scripts that are already there and try to reuse one of them

Image
initctl list — available scripts

Inside the scripts folder, we have write permission on some files:

Image
/etc/init — writable .conf files

Let's look at the contents of test.conf and figure out where we can use it to escalate privileges.

Image
test.conf — runs a node script

We can see it runs NodeJS, so let's build a Node payload, in my case I used the node reverse shell from Payload All The Things We write it to the /tmp directory as chu.js ( /tmp/chu.js )

Image
chu.js — node payload in /tmp

Now let's head back to our initctl and try to run the test.conf script

Image
initctl start — test.conf is up

We open our pre-set port on our machine and wait for the connection:

Image
root — shell received on the listener

we are r00t

if i helped you, add + respect at my profile :D

My references: