Neosify - Buy, Stake & Earn Crypto
Neosify - Buy, Stake & Earn Crypto
Neosify - Buy, Stake & Earn Crypto
Black Box

Black Box Pentest: INE eJPT Practice Lab 3

By 7R!XxSec | 7RiXxSec | 28 Nov 2021


 

Special Thanks to:

INE            Legacyy

 

Introduction

 

Hello Friends! Welcome back; today we have been contracted by INE to perform an assessment of their network. As INE desired a blackbox test, 7R!XxSec was provided with very little information going in. The engagement letter stated as follows:

You have been engaged in a Black-box Penetration Test (172.16.37.0/24 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”

And as such, we entered into the engagement with the following assumptions:

  • There are multiple machines on the network
  • Full control is not the aim, success is the capturing of the flag

 

Attack Narrative

 

Beginning with a network scan, we discovered two machines with attack surfaces.

9772f222bcc919ea92e9ea89070893833a68a4404360ab277796895a5c360cf8.png

1e6e1e947ce38480dcc4224eccca2012d9de21b693a9e2a5febc2f6424844f0b.png

 

Let's grab a port scan from 220

 

8d158bc516da95ac60d487a6ae644e67fd9d0334248839983775bfdca57f8d95.png

 

Okay, a webserver and a port which is blocking our attempts to identify it, although its numerical designation would suggest it is a SQL server. Heading out to the website we find nothing, but a source code check reveals some useful network information which indicates that this machine is dual-homed, meaning there is an internal network we do not yet have visibility on.

 

579f8a7f59c483ed1e666b26490f2e2083c14d1ba397af6fe524e3f0d037fe66.png

 

Dirsearching on the root reveals a subdirectory, but access to it is forbidden.

 

a9fdd711de08c30194244f7cdb62663c8ba7a3cfe2141705b7b068ed844b229e.png

 

Some Searchsploiting reveals that there is a potential Optionsbleed vulnerability to attack the Apache service with, but a Metasploit Optionsbleed Scanner reveals that the conditions for this exploit are not in place. Seems like we are at a dead end on this machine. Let’s go take a peek at the other machine we found in our host scan.

 

13547f0da4faaf0115bf5e974450042db0ad8b01d39cf2815683dc2df95cdcea.png

 

Looks like we have a second webserver, and also an FTP server! I love a good exposed FTP server ./fistpump but let’s take a look at the website first.

Nothing on the index page, but a Dirsearch reveals an exposed subdirectory, which itself reveals what appears to be an ifconfig command being executed.

 

2668aaf42e1764b66ddc7da01cce6884c7b97c39d46e2005a23fad32cd1780ac.png

8fdcdaf35eda302a6a004aa9930b00e941d668962f14280845a0c44d2c88c067.png

Other than this there is not much else to play with here, let’s go back and check out that FTP server.

Immediate win here: after a couple oblivious attempts, the message finally becomes clear, the FTP banner gives both the username and password to access this service.

 

35569a862b95288d26fd1b4f33249cd8d25b8fb00ab2e818e4f8b6a681ce932b.png

644c00b5e5d987f808b13df07b4457295656b4b1d60c046d1b8e3df3b1983211.png

 

Some light enumeration reveals a delicious secret, the PHP index page for the machine’s webserver is being served via this FTP server. Furthermore, we have full 777 access to the directory containing this file.

 

071c1da0b15ddea76c848f2167ca847c887c5ec2081d80c7de370c01c5c59b81.png

9105c364492a7fc2088d760e1b51dd9a9e70e5b57da62a1ca86ee084c29366c9.png

 

This is very good for us if it is what we think it is. Let’s run a quick test to make sure it is. We’ll copy this index.php file, replace the command it calls, replace the FTP version with our version, and go call the webpage to see if it calls our new command.

 

ce584d564150483e67a5656bb78cca31b2ec5661386bc7656c972c9118f898bb.png

6837097a1d57f293a75191c0166ea5768da55adfe4a1da5f10e954d8d4ff9284.png

faa2af00d8c2cc5fd33e9620cdcee98ddf0eecd7834c8300be5169e66b4aeade.png

42eb5df6c07e0e80cdf9d8f2c4ae94e78fe937162f28e445c235d3cc077eb0f4.png

6f1494af0637afd0f71ab92525bc3be47c9a732dc13a4f3dfae299c17814f271.png

 

Alright! Rock on dudes! Let’s bust into this thing! We can find a PHP Reverse Shell here which we will customize to our environment, call it index.php, insert in place on the FTP server, and then catch the webpage refresh with a NetCat listener!

 

09ceb508595e8e9fcd2df5668f6c8baf53b4b068c1b6b9d4da09ade4db578e09.png

 

It is a fairly trash shell, but I discovered a super cool and convenient shell upgrade thanks to ropnop’s blog, here.

 

f2b4c411b6982304911b05f1d31d81dc4e8b819dc5740f75fd70bfb16a364ca5.png

 

Initial enumeration uncovers a very obviously interesting directory structure in elsuser’s profile:

 

53a53138736910e943729b97506b19610bd34badbad3be1b960806e3480d0421.png

 

A few nested directories down we can see there is a file called ‘.message’,

 

8f56dfeaeb7e58dfea6f583938024c6f86f206799b1a03f77144ba9e4f87a994.png

 

which we can assume has something to do with this exploit.

Moving along, let’s snag root, it is a very simple kernel exploit that can be found here and all we did was download it, compile it, move it onto the machine in the tmp directory and call the script.

 

ee8e9b1a16d04fed40006c8eaa2de8e6668a8daa91377f98191a047d00234709.png

 

With that root access, we can grab the flag in a hidden file among ftpuser’s directory

 

48f5d6ae57d15edd1a4fbb8bd1cf611dd1d414e6488f480e3e429a08db713c01.png

 

which happens to not contain anything? Weird? A little more digging turns up an actual flag in /var/www

 

d30bb5843e0bfb5bd4e546bd20faab36c8cf83fcd232415a0dda9470dfa5174c.png

 

Further leveraging our administrative access we can see the bash history now, and among it:

 

9bacd0b2237da7b73b0b4b155c49fd5e98d407f27d293f5c27b5124d1c9192df.png

 

What we see here is the developer setting up and testing the environment.. He/she was wanting to make sure that nmap could reach this internal network on these specific ports, so it would be convenient to assume that we can just copy paste this Nmap command rather than scanning everything. Scanning everything would still be best practice, but in this particular environment I would feel safe going with the assumption. Conveniently, also, the developer did not uninstall Nmap, so we can use the present installation rather than the static copy we happened to bring over with our toolset. So using the developer’s command with the developer’s tool we discover the following:

 

c9f9821cde972b7eff6990c9b219666dec13520b9f69187dcd784b37cb94d03a.png

 

Before we make a move here, let’s talk exfiltration quickly. This machine is setup beautifully for exfil, and there are multiple methods of retrieving whatever data we harvest in a very simple way. Cast ‘mkdir loot’ wherever you like, harvest data and pipe it into this directory. Whenever you’re ready, simply move the directory into /var/www/html/xyz; now hop back onto the attack machine and either pull this dir down via the FTP server or else through the web browser:

 

5a6104f74d9684ed73dd77ee8328fa16932a38e8c27551a504307a77907c22e7.png

579b49872ac2c053f14cbe7d40e65c22cd7192bf9c1723288bf6a35f5523f377.png

 

The object shown in the picture is some FTP source code that may be more interesting if we were more stuck than we are, but as we have rooted this box this is fairly irrelevant at this point.

Now, a quick aside. This is a prime example of the frustration and redundancy of hacking... Perhaps moreso learning to hacking than hacking itself... Regardless, when reading the instructions for this engagement it clearly described an internal network, and also suggested that a pivot would be required. When running through here I decided to trust those instructions, and I wallowed in the mud for literally a week of trying to pivot into a deeper set of machines. Now it’s not that there isn’t an internal network, and it not that a pivot can’t be used, so it’s not exactly like they lied about it all. The only thing is that my expectations of a pivot is that there would be more machines.. And I thought I had found them! I will also point out that this is as much due to my lack of experience as it is due to my higher expectations coming in, but I went for a week (a couple hours a day) bouncing back and forth between four machines, wondering just #wtf was going on here, because I was finding my own relics in novel machines, and some had strikingly similar directory structures to others, and most of the time I was ‘ip a’ing between every command because I was so confused which box I was even in anymore! Now this week of ./flailing was not pointless, it taught me a great deal of lessons to add to my repertoire of initial enumeration, and I will now more readily be able to identify a similar situation in the future. To share a bit of my mental process I’ll share a few pictures here before I explain and we perform the final few commands for this network.

I had been visually mapping the network from the first scan, and it looked like:

 

fbe78e2b323f540669105241a217f9cb2473cd3f25a1684c18005331fc13f644.png

 

Then the internal network was discovered

 

000755dd30abf43e4ec4a1509e43783adc1e6d29ec37bb79b3bc633bf58ddbc3.png

 

Then more internal network

 

0183069d1a07413105e3e8fb8c52c01f3e0aeebd978e7b7c44a792b52fdd6ecc.png

 

and this is where the roadblock occured. I spent six days sitting on 172.16.34.234, trying to pivot onto 172.16.50.224. I tried a Metasploit pivot, a Chisel pivot, a browser proxy pivot, an Sshuttle pivot (though spent most of my time trying to load static SSH services onto the machine ./sigh), and then a Metasploit pivot again! Something just wasn’t quite right. So after six days of this frustration I pivoted my attention to the other discovered internal box, got into it, and was even more confused!

 

666fb7ca9656f2a7143f2db4e3e897777f51da00c16dc159ddd73c97181f64a6.png

812e0a97fe63c38f013abf3d7b6b7e30961ae4a956764f0aa1f7e2e05b385bfd.png

 

#blessings to Legacyy here because although the real answer was not as advanced as his thoughts, his thoughts nonetheless were the first indication I’d had in a week that I may not be a complete bumbling moron.

It was shortly after this exchange that I discovered the true truth:

 

ac21a2c915faeafb8517403ea9399be3773957f2e8d09feca6a8757c6e04a5d2.png

 

Both external boxes were dual-homed to the internal network, and that’s all there was here. So in a classic 7R!XxSec moment I realized that the six days I spent trying to hop from 172.16.37.234 onto 172.16.50.224 was actually six days of me trying to log into a box from a position of already being root on itself.

 

3fee66e35bd6eaadbe5d0eb4a35cb90312b9270db58dbe302905a3442f2adc4f.png

 

End aside.

So here we are, sitting in the dual-homed ‘machine one’ and looking to get into the dual-homed ‘machine two’, of which the external facing IP was a brick-wall of a website (this is the very first machine we enumerated), but of which we now have access to through its internal side. Now pay close attention, because this exploit is about to get pretty wild:

 

7fc3b049440e880ae51c1a438a00e098c5932d62193bc2f1a2c3bd9370d9b270.png

d7e4a4616906947534574e9cc19592059bd4218073b62efc4474a368f9f72089.png

a2559c49a52acbaf584bf45a54d754c1a4819fbc523f33c0fe02af949eb97a58.png

08b0fbfcba5ca8044512c42d41b052c51ebdbd9435c22c0f6202df3312d3b968.png

 

Blam! Nailed it! Great work team! That is that in this network. After hitting here, still under the assumption that there were additional machines which were purely internal I did run some scans to check it out, but nothing came up, so #straightWins.

Thanks for hanging out with me today, and I look forward to our next adventure together!

 

 

Happy Hacking,

 

 

7R!Xx

How do you rate this article?

1


7R!XxSec
7R!XxSec

Storyteller, Entrepreneur, Lover, Hater, APT ...


7RiXxSec
7RiXxSec

Write-ups related to my learning journey through the field of Offensive Security and related topics. Likely will be mostly CTF write-ups, but I would also like to get into doing conceptual write-ups on different topics I am learning about as my adventure progresses.

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.