Home PTS: Black-Box Penetration Test 3

PTS: Black-Box Penetration Test 3

This is the 3rd writeup of 3 black-box penetration tests offered in INE’s Penetration Testing Student course that I am currently doing in my journey to obtain the eJPT certification.


You have been engaged in a Black-box Penetration Test ( range). Your goal is to read the flag file on each machine. On some of them, you will be required to exploit a remote code execution vulnerability in order to read the flag.

Initial Enumeration and Exploitation

Fping & Nmap Results

The scenario mentioned that the pentest range is taking place at However, the VPN has connected us to with another machine located at as seen above in the Nmap scan results.

With no open ports on the host, I thought this may be a gateway into the range that we are engaged to do the pentest on. As I combed through previous documentation to recall how to add this route to the routing, it seems that the VPN connection already added that route to our table!

We can perform a typical scan on the assigned range to determine the available targets!

Scenario Scan Results Nmap Results

This target has no open ports but similar to the machine, this may be a gateway to another network. Nmap Results


The details provided by the Nmap scan reveal that port 80 is served by Apache on an Ubuntu OS.

The landing page contains no visible data but the page source contains a comment with what appears to be the output of ifconfig.

Dual Homed Target

This target is dual homed with access to an additional network in the range. If we are able to compromise this machine, there might be an opportunity to pivot through this network and compromise additional systems.

Other than the leaked network interface information in the page source, there is not much else to see here.


A tcpwrapped port means that we are not able to send or receive data with that port. This could be a firewall or an access control list that is blocking us from accesing that port. An attempt to establish a connection with netcat is closed instantly.

For now, we have some information but not much to go off of so let’s continue with the next machine. Nmap Results

The FTP and HTTP services are running on non-standard ports on an Ubuntu OS.


The banner for the ProFTPD service includes a comment to use ftpuser to authenticate. On a hunch, I also used the same for the password which authenticated us to the application. Ftp Flag Location

After successful authentication to the FTP server, the flag is available as a hidden text file along with an additional html folder. Ftp XYZ Directory

It seems that the directory that the FTP daemon is serving could be the same files that the web application is serving. If the ftpuser has write permissions to any of the directories, this would be a vector for remote code execution.

I pulled the index.php and .flag.txt files as the index.html is likely the Apache landing page. We can verify this when we explore the HTTP service.

# .flag.txt
You got the first machine!
# /xyz/index.php


echo "<!-- cmd: " . $_GET["cmd"] . "-->";
echo "<hr />";



The index.php file in the xyz directory executes the ifconfig command which should be displayed on the web page if we browse to that endpoint.


Visting the web application, both of our assumptions are confirmed. The Apache landing page relates to the index.html file and the index.php displays the network interface configuration for this target. Ifconfig

This target is also dual-homed similar to the first one. We can attempt to create a reverse shell connection with a netcat listener on our attacker machine.

Configuring the PHP reverse shell with our tap0 IP address and any port, put the file onto the FTP server 1 . FTP Transfer

Success! Now we can browse to to trigger the reverse shell connection. Reverse Shell

Let’s upgrade this basic shell into a fully interactive TTY shell 2.

Currently, we are the www-data user. In the search for any interesting files, I found a .message data file burrowed in some very lengthy named directories under the elsuser’s home directory. The data was just some binary data with ASCII text thrown in there but it seems this was a rabbit hole to potentially throw us off?

A common step in the privilege escalation vector is to analyze the /etc/passwd file to see the list of system and non-system users. Passwd

There are three additional users that are not root or the service users.

  • elsuser
  • ftpuser
  • test

Without realizing it, I switched to the ftpuser hoping that the credentials from the FTP service were the same. Once we were authenticated, the prompt said root@xubuntu. The whoami command stated that we were root as well even though I logged in as the ftpuser.

The official writeup verified that this is because the uid and gid of the ftpuser is 0 which is the root user. Root

Success regardless! With this target compromised and our privileges escalated, let’s perform some post-exploitation techniques and perform a scan of the targets on the network. We are already aware of 2 targets, (first target) and (this target).

Fortunately for us, this target has nmap installed so we can leverage that to perform a network scan. Nmap Hidden

Looks like there are only two machines on this network which we have already interacted with. There may be other services on the 1st machine that are only accessible through this second network so let’s perform some further enumeration of the 1st machine but on the interface. Nmap

Compared to the original Nmap scan for this target but using the interface, there is an additional SSH service accessible to us. Given the small hint about using ncrack’s minimal.usr password list, we can attempt to brute force the authentication for the root user to the SSH service.

We could attempt to brute force using hydra and the password list by transferring the binary and wordlist onto the compromised machine. This lab, however, is focused on pivoting and this is a good opportunity for us to learn about how to pivot. There are several ways to accomplish this:

  • Metasploit’s autoroute functionality
  • Enable SSH for the ftpuser and enable that for a sock5 proxy
  • Ncat and proxychains 3

We’ll try out the ncat and proxychains method to establish an HTTP proxy. On the compromised machine, configure an HTTP proxy using Ncat on port 3128 with the command ncat -vv --listen 3128 --proxy-type http .

Switching back to the attacker machine, add a line to the end of the /etc/proxychains.conf file with http 3128 . To proxy any command through the proxychains.conf file, prefix that command with proxychains.

At this stage, our goal is to use proxychains to proxy our brute force attempts on the SSH service that is accessible through the network. Proxychains Hydra

Woot! The root user on the 1st target machine has a password of root (terrible password security). But the power of a proxy with proxychains causes pivoting to be incredibly simple.

The last step is to use proxychains to proxy our SSH connection through the compromised machine and grab the remaining flag. Flag

With this flag, we have successfully completed this penetration test.


This pentest was a significantly easier experience than the 2nd that I had so much trouble with. This was definitely focused on the concept of pivoting and accessing additional networks so it may be more difficult in some sense.

I enjoyed this last one and it may have been even more interesting to have a 3rd target in the 2nd network but who knows, that may be the configuration on the eJPT exam.

Either way, this was a fantastic learning opportunity and the only hiccup I had was not understanding why switching to the ftpuser placed me as root but now, I’ll remember to thoroughly analyze the /etc/passwd file and all aspects of it.

This was the last black-box pentest offered by INE as part of their Penetration Testing Student course. Some forums have indicated that the pentest labs are more challenging than the actual certification exam. Out of the three pentests, I think there were 2 or 3 very minor situations that revolved around not fully mapping out an application or service but I think I may be ready for the exam. Hopefully, the next post that I submit is a success post about my exam experience.

Useful Commands

Shell Upgrade

Upgrading your shell into an interactive TTY shell is important so you can switch between users. Without a TTY, you won’t receive the prompt to enter passwords.

Once you have a shell, determine the version of Python and spawn a Bash process.

which python
python{2,3} -c 'import pty; pty.spawn("/bin/bash")'

Background the shell using Ctrl+Z.

In your attacker machine’s terminal, run stty -a and take note of the number of rows and columns.

Run stty raw -echo. At this point, your terminal prompt may be a bit buggy and not display anything. Bring the reverse shell back to the foreground with the fg command. This may not show up in your terminal but have faith that it’s there.

Pressing enter a few times and you should now have an interactive prompt. The last thing to do is to modify the rows and coluns of the reverse shell from what you noted down before.

stty rows <rows> columns <columns>

Nmap Host Discovery

To perform a host discovery scan without port scanning:

nmap -sn


This post is licensed under CC BY 4.0 by the author.