Page cover

πŸ‘€Stealth - TryHackMe Walkthrough / Writeup

Shortest Path to Admin, AV Bypass using msfvenom and meterpreter and more.

Room Link
Be like a stealth bomber

Table of Contents


Recon

Using nmap scan, for initial recon. I will spare you the delay of looking for open ports :)

Ok, now as you can see a lot of open ports, but we will only focus on the 8080 port as that is the only way for initial access, unless you found something else.

Visiting the http://target:8080 presents us with the following page.

file upload section

Since this is a windows server, we will upload a powershell file that will execute and download a web shell for us in C:\xampp\htdocs

You may choose any web shell, that you may like, my personal favorite is p0wny Shell.

download the file in your current directory

Create a powershell script that will download the shell to htdocs directory.

Before we deliver it, start the server

Now upload our getShell.ps1 file! and wait for it to fetch our shell.php

wait for it to execute

Once done you can check the web shell at http://targetip:8080/shell.php

access the shell

Weaponization

As you can see we have a local account access, now we can create a reverse shell payload, an encoded payload to avoid AV detection. But why, we already have a web shell? because....

Use the following command to generate a msfvenom payload. If you are using your own choice of encoder make sure it is x64.

Notice the encoder I am using with -e x64/zutto_dekiru

You may generate the commands from revshells.com, but make sure you are using encoders. This generates a rev.exe file for us. Before we deliver it to target, start the msfconsole listener.


Delivery

Once we are all done with the setup, use the web shell to deliver the payload and execute it to get the shell.

execute the shell

And you should receive the connection in no time.

meterpreter session

You may check the uid first, check if its evader or not.

Then check what kind of privileges you have. Execute getprivs

getprivs

Now if you notice carefully, we have a SeImpersonatePrivilege option which is enabled for us.


Exploitation ( Automatic )

I will divide the exploitation part, into 2 categories, one is automated with msfconsole and other one is manually exploiting the system.

Let's get started. The first is very simple, just execute : getsystem

And you should have admin access.

getsystem

Theory on why this one worked in the first place

I think since we are using an encoded agent, this avoids detection by AV, the payload might not be touching the disk at all but running in memory, to avoid getting flagged.

Exploitation ( Manual Method )

Once you have a web shell, enumerate the box to check if there is a .NET SDK compiler for us or not.

.NET Compiler

The next prerequisite is to check if you have SeImpersonatePrivilege enabled or not. use the following command.

SeImpersonatePrivilege

Ok now for the final showdown, we don't need a reverse shell, we will compile an exploit, locally on the system, and also another C sharp file that will execute the registry query to dump SAM/SYSTEM hive.

First lets download the exploit code on our machine.

download the exploit code from here

Create another program like backup.cs, use the code below.

Now upload both of the code on our target system using the web shell.

upload the files

Now finally compile them using the following commands.

Once done, execute them like following.

exploit

If you see backup successful, then all is well.

check for the bak files

If you see the bak files being generated, lets get them.

Dump the hashes

Get the hash

Now use Evil-Winrm to access the box as admin, via pass the hash technique

Evil-WinRm

Get User Flag

Get User Flag

The user flag is encoded in base64. Use the following command to decode.

it will give you a link to an endpoint which contains a message to get the flag
the message, hints us to remove the log files in uploads directory

Remove the following log file

log file location

And then reload the endpoint again, to get the flag!

User Flag

Get Admin Flag

Get Admin Flag

Theory on why the manual method works

Few years ago, I wrote a simple c program to print hello world, I thought to myself, how can I publish it and share it with others. So I compiled it on my windows machine, and executed it. It worked without any issues. But as soon as I ran it on a different computer or even a VM. Defender/UAC kicked in and flagged it as malicious as it did not have any valid digital certificate. Imagine a simple hello world getting flagged by the AV.

It was not the same with a java program, I wrote a simple hello world, created a jar file, and executed on different machine, it worked without any issues. Since it ran via Java, a trusted binary it did not have any issues.

So in this room, when we are compiling an actual exploit and defender does not find it suspicious, because it thinks the user is not mad to break the system. Same with the backup.cs file as well. But if you compile the program without signing it with a valid digital certificate it might get flagged on a different machine. Even if its running a Windows 10 Home Edition. Now if you think there might be a different reason, please feel free to share with me.

Credits to my friends for helping me research on this room

1st Person

For giving me the idea of compiling the exploit

Check out 0xb0b's writeup : https://0xb0b.gitbook.io/writeups/tryhackme/2023/stealth

2nd Person

for giving me the idea of exploitation via metasploit

Thank you for reading my article ❀️ Happy Hunting 😎, feel free to connect with me on Linkedin

Last updated

Was this helpful?