06:00 UTC Charta Aetatis Cyberpunk

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

HackTheBox - DevHub

In the wiki DevHubJupyter NotebookMCP Jam Also namedUbuntu
Transcript 3303 words · auto-generated captions

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

What's going on YouTube? This is IPSAC and today we're doing DevHub which is definitely on the easier side of Medium. It starts out finding a vulnerable version of MCP Jam and we can just use a CVE to get a shell and from here we discovered the Jupyter notebook is listening on the local host and running a process listing leaks the token used to authenticate against Jupyter notebooks. So we just set up a port forward connect to Jupiter and we can run a command to get a shell. As this user, we can read a custom web server that has a simple way just to read SSH keys as long as we can figure out how to authenticate to the server, which is somewhat straightforward. So, with all that being said, let's just jump in. As always, we're going to start off with an end map. So, - SC for default scripts SV enumerate versions- reason to give us things like the TTL OA output all formats in the end map directory and call it devub. And then the IP address of 1012967.227.

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 being 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 engine X also running on Ubuntu. And it is redirecting us to devhub.htb. So let's go ahead and add this to our host file. So pseudo vets host. Then we can add 1012967227 and devhub.htb. So, let's take a look at this page because there's really not much else for us to scan. So, we can do http devhub.htb and we get a page. So, we have mcp inspector. It says it's listening on port 6274.

We don't see this open because our end map only scanned the top 1,00 ports. We could test this single port. So, nc-zv. I'm just going to type devub.hb because I forgot the IP. And we see it's connected. So, we know this port is active. We have the analytics dashboard which is a jupitter-based analytics environment that is running on local host port quad 8 and they have some type of git server that is in maintenance mode. Doesn't look like we have much else here. We could see what this is built in before we go over to the MCP. And this looks like a static page. I don't see like any PHP or anything indicating there's a framework in play.

Uh we could just try like index and we get a44 not found from engineext.html. html and we get a page. So we could try running something in the background like a go buster or something like that, but I just want to take a look at port 6274.

So let's go ahead and make a request. So 6274 and we see it is mcp jam. Now we had just covered mcp jam in a previous video like two weeks ago I want to say. We even see the mcpjam version. If we click on settings is 142. If I go to IPSC.rocks rocks. We type mcp jam. We

can see that is the cobalt video where we actually find 142 and go into the um

CVE. Now, I would recommend watching this video if you want to look more in depth there. I'm going to just glance over this because we literally just did this. So, let's go over to Google.

And I just like Google over duck.go because it seems to give me better results. I don't know exactly why. And I probably should have typed google.com instead of googling Google or duck duck going Google whatever. But let's see 142 rcce github. And let's see we have a exploit here. There is one over there as well. So I'm just going to take a look here and copy this cve or the GitHub link. Get clone. Paste this. And let's see exactly how this exploit works. So V.

Oh man, this is horrible. Um, let's change the target to devhub.htb. Was it 6274? I want to say uh let's see

what port is this 6274. I was correct. Um, attacker IP 101014. Uh, what am I? 171. Attacker port, we'll do 901. And what

we're going to do is send a request to devhub.ht. ht on 6274 let's fix http and all we have to send is this and it gets rce again check out the codeboard video if you want more um in-depth explanation um oddly enough we're doing NC and I normally don't use this because there's two versions of netcat there's like netcat traditional netcatopbsd and maybe there's three maybe there's like a ncat for end mapap and only one of them has the dash e I forget exactly which one it is. But normally when you ship it with busy box that has the dash e flag. So that's why that works. But you could always just do command bash and then - c and um the standard reverse

shell. So let's just see if this works. If it doesn't work, then we'll be replacing that exploit with our traditional reverse shell. Right? So nclvnp 90001. Let's go ahead and execute

this exploit. And there we go. We have a well a connection back. We don't see a shell. If I do pwd, we see we have um connections. And that is why I always do the V for my netcat. I don't really say that too much, but I know like years ago when I was doing like OCP and I was like in the labs, I was running these exploits. I was like, I'm I'm not getting a shell. I don't know what's happening. When really I did get a shell. It just doesn't say that um you have a connection if you don't do the -v. So if you ever wonder why I always do verburst on netcat, um that is why.

I've been burned up by that plenty of times where I run this um exploit, it gives me the shell, doesn't say anything. I just assumed it didn't work and then I type something like ls or something and then I get a prompt back or maybe I type like oh I don't even get standard error back. Um but yeah, so we have a shell here. Let's go ahead and upgrade this TTY. So Python 3- C import

pty pty spawn bin bash. Then we'll do that sdty raw

minus echo foreground enter enter. And I'm going to do export term is equal to xterm which lets me clear the screen. Awesome. So let's see what do we have here. Well the mcp-dev user instead of like dubdubdub data or something like that. Um I'm just going to quickly gp um everything that ends in sh on pass wd. that covers most shells like uh bash, dash, uh zsh

um a lot of shells end at sh for shell. Uh we have mcpdev analyst and root. So

I'm just going to go over and switch to ssh because that is a more reliable shell. And if I screw something up, I can easily get back. So let's do make dur.sh. We'll do sh key genen-

tedd25519. The file name, I'm just going to call it IP. And we have.pub. That ED25519

just made this a much smaller key. If I used RSA, then it may span multiple lines. Is a bit more of a pain to work with. I like doing the ED25519. So, let's do echo authorized authorized keys. Sage mod this to 600. I

don't think we have to, but it always sucks when you drop an SSH key and it's the wrong permission. You don't know why it's not working. So, out of habit, I always just change it once I um drop it. So, we'll do ship mcpdev devhub.htb. And there we go. We get in. So, I'm just going to go ahead and close that pane. And let's see what do we have. Um I always like doing a psef forest first. If I knew mcp dev's password, I may be trying like a pseudo-l. But if I type that, um we get that right. So,

let's take a look at the PS output and see what we have. Scrolling all the way down. Wow, there's a lot of scuzzy interfaces. But let's see where do we start getting into after the machine booted. So, right now we have the analyst user that is running Jupyter M bin Python 3. And then

it looks like it is going to be running a Jupyter notebook. The local host um for the like bind interface or the network interface port quad 8, no browser um notebooks. We have a server

app token. So this should let us log in if we connect to that. And then nothing else really. What else do we have though? So we have the MCP dev. This is how we got our shell. Um then on root,

which is a little bit odd. So, root is running a Python interpreter out of Jupyter N and it's running this Python script. So, before we go ahead and look at Jupyter notebooks, I want to see if I can see this server.py. So, let's do a cat on this and we get permission denied. Um, let's do lsla on the directory. And we can see the analyst user can read this. So, um, we can't

even get into home analyst. So, the first step is getting a shell as analyst. Um, as I showed, the analyst user was running Jupyter Notebook. Um, we could just quickly switch to port 8888, but before I do that, just in case we didn't see this and somehow we leaked this server app token elsewhere, um, I've done it before by like their centralized logging somewhere. You have access to Splunk. You can look at the like various things in process and you see the sensitive token and use it kind of as a lateral movement step, right? Um in that case uh this would have to be listening on 0.0.0.0.

But um let's just pretend we know the server app token but not the port. So what I do is SSLnt. We see there are two things quad 8 and 5000. I'd look at 127001 quad 8 and then 5000. And we see there

is a difference between the two. We have tornado server and work zug. Now, I'm guessing this is going to be Flask because most Flask things say work. Um, this is probably going to be the um Jupyter notebook, of course. Well, we know it is. If we went back to the homepage, it does tell us Jupiter's listening here, right? So, there's a lot of ways we know this, but nowadays, if I ever have a question, I go to handy dandy Claude. Um, let's see. Did I typo

that? Nope. There we go. Uh, keying password. There we go. And then all I'd say is um what is the default server

header in Jupiter notebook? Right?

And I'm asking this I could just say I have these two um responses. Which one is Jupyter Notebook? But if I give it these two options, it may hallucinate and just pick one. I like just um not telling it everything and seeing what it says, right? So it says tornado server is going to be Jupyter notebook. So, we know port quad 8 is Jupiter. So, let's go ahead and forward this port to a box. So, the first thing you type on a line is squiggly c. You go into

this um sh console and I can do the

-l888 127001888. And what that's going to do is listen on port quad on my local host, send it through this SS8 session, and go out the other end on this. So if I now go to 127001 port quad 8, we should hit

Jupyter notebook and it says token authentication is enabled. So let's go ahead and grab um that token.

So let's go and copy this.

We'll paste the token here and get access to Jupyter notebooks. Now if you've never used Jupyter Notebook before, it is a really nice tool. um giving attackers access to it is very bad because it's just like rce by feature. But essentially you can create these like live notebooks I guess you call them. Um it essentially you could put documentation around a script. So right here they're saying the internal data analysis for dev hub metrics and they're actually not doing anything here which is kind of silly. Um you click this little run button it would run the script. So if I did like print hello like this, it does this. And what I normally use this for is I would have a bunch of just incident response type of things where I document like golden ticket here, things to look for and then there'd be playbooks here where you click play and then would query Splunk and show you the data. So you have like documentation and then a script here. It kind of saves people from like copy and pasting from a browser back to their terminal and all that type of stuff. So, it is really handy to have these live notebooks that can just run code, but very dangerous.

Um, we don't even have to write a Python reverse shell because if we just go to launcher, we could click terminal and boom, we're analyst at devhub.htb. So, let's go in. SSH will first make. SSH and then v authorized keys. And you

guessed it, let's go ahead and get our key. So, catip.pub, pub. We will copy this and we will paste that in chmod 600. So

we can get out of this web browser terminal. Um analyst at devhub.htv.

There we go. And I'm just going to close that browser. I'll leave page. There we go. Awesome. So now the analyst user um they could go into the opt what was it um not mcpjam

this ops mcp. So it is running the server. If we look at server um we see debug is false. If debug was true a lot of times flask will just auto uh it does what's called hot reloading. So when this script gets modified it just reruns it and starts it over. It's really handy when you're developing things and like you want to try to center a div. You can just keep like writing in Vim until you get all the spaces correct so it's centered and you don't have to keep like restarting the server because Flask is monitoring the file to do a hot reload. So what I'm going to do real quick, I'm just going to say os.system and we'll say touchdevshm poned.

This probably isn't going to work, but what this is going to do is if this server.py Pi ever gets restarted, I'll know because there'll be a pony file in dev shm, which becomes very handy because um I don't have to run like py or other things on this box. We could also just throw the yolo and try to reboot it because if it reboots, it probably starts the server up when it boots up and we get a shell if we had malicious Python code there. Unfortunately, um nothing here happens. So, let's go ahead and take a look at server.py. Um, we could also probably because if we looked at this real quick, hold on. Um, it is running the Python 3 out of the home analyst Jupyter N. So, we could also just poison the Python environment, replace the interpreter, put a library, something like that. Right? So, there's a lot of ways we could just backdoor this server.py. But, let's see if we can just exploit it. So, looking at it, it is just Flask. Uh, we have a API key here. Uh, can I just copy this easily?

Is that going to go on my clipboard? It did. Awesome. So, curl, it's probably going to be some type of header. I don't know exactly what it is yet, but I'm just setting up the curl quest to test it. It's probably like authorization bearer or something like that, right? Uh, we have some visible tools, hidden tools. Uh, here we go. We want to send the X API key. So, let's copy this.

Go back here. Send it. And this listened on localhost 5000. Um, we can say tools list. There we go.

And if I give it a invalid key and just get rid of the O, unauthorized. So now we have validated. We can authenticate to this server. Let's see what we have. So route. This is all just a static text. Static text. I'm surprised not even running up time. It's just 14 days, 3 hours, 22 minutes. Uh, that's unauthenticated. Let's see. unauthenticated val uh static text again. So, we can't really exploit any of these services because it's just responding with hard-coded text. It's not doing anything that could be potentially dangerous because it responds with a string. We have ops debug mode and that's going to list hidden tools. We have an ops admin dump and what that's going to do is let

us run SSH keys. So, let's go ahead and try this. So, we need tool name. How is it doing? Tool name.

Go up. Tool name.

Oh, come on. Uh, data get name.

So, let's go ahead and say d-json

name. Do that.

Uh, JSON is unknown.

Okay. So, let's just do the dash d method not allowed. Um, we have to say,

oh wait, this is tools list. We want to do tools call

supported media type. Let's do -h content type application JSON. So, the

d-JSON is going to do essentially what the dash d except automatically set the content type as well. Um, confirmation required. Set confirm is equal to true. So, let's go ahead and set confirm

to true. Invalid. That didn't do it. One zero. Okay. How do we do this?

Confirmation required.

Let's see. If not, confirm.

args get confirm. Oh, t what's args.

Let's see

args arguments.

So, we did a tool name that's

data.getame and this is all JSON. So, we got to create a probably dictionary for arguments is my guess. So let's go and say name is that and we can say

arguments

um like this colon squiggly brackets.

Uh let's do one one is it can be true. We could also just type true as well. Um

so let's see invalid target. So, we just need comma target

then what is it? SSH keys and we get a

key. Uh, let's see. JQ dot uh jq is not installed. So, let's

just go ahead and copy this.

Echo this jq dot. We'll do dash r for raw. Uh, I don't like those dash slashns. Let's just do um what if I print f on this. There we go.

So, the print f would just um when it reads the back slashn, it just puts the line break. So, we got this key. So, let's do vroo root. I'm just going to guess this is root's key. chod uh 600 root sh-irdehub.htb

HTB. Um, specify the key. And there we go. We got in. And that is going to be the box. Um, really simple box. Hope you guys enjoyed it. Take care and I will 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 537 sources the paper read this month. Text and HTML, one-click unsubscribe, free.

How often
Your desks