TryHackMe! PickleRick - BYPASSING Blacklists

Futurescience
40 followers
4 Video Views·Nov 5, 2022
Hello everyone my name is Jon Hammond and in this video I want to showcase the Pickle Rick CTF
from tryhackme.com. So I'll hop on over to my screen and we'll get to the good stuff.
This is the Pickle Rick room that says a Rick and Morty CTF help Rick turn back into a human.
I've joined the room here and we can start to roll through. I'm gonna go ahead and deploy the
machine, deploy the virtual machine on this task and explore the web application. So I will fire
up a terminal here so I can move into the tryhackme directory there and I will sudo open vpn
Jon Hammond YT because that is the account that I'm using for this one. This is a free room so
I believe anyone even if you're not a subscriber should be able to access it. Let me make a
directory for YT Pickle Rick. Pickle Rick. All right there we go. Pickle Rick and let's get a
readme file going just so we can have a space to take notes, throw stuff in and I'll also go ahead
and make a nmap directory so I can nmap the box. I will attack sc, tack on nmap initial and let's
grab the IP address now that that should be spun up. Let me go ahead and ping this box. Yep okay
looks like he's good. Fire up that nmap scan. While that's going we can start to build out our
notes. I'll export the IP address so we can save that as a variable for the future. Let's do task
one. Let's actually make a spot for nmap results because I just kind of throw stuff in even though
I already have specific files. Might as well. Looks like there are only three questions in
this room. What is the first ingredient that Rick needs? Okay. Second and final. That's it.
So we're just trying to find pieces of the puzzle here. There we go and let's see what we got. So
ssh is open. 80 is open on the web page. Okay and it says Rick is super cool. Looks like that's it.
Okay let me copy that export command so I can work with that. I'll do the same down here
and because I know that 80 is running I will fire up a little Nekto scanner and I'll t that results
to nekto.log. He can go and let's go check some things out. We can poke around. We could try and
That would be a little lame because we don't exactly know where we're going yet. So let's
just grab the IP address and go interact with the website. It says help Morty. I need your help. I've
turned myself into a pickle again and this time I can't change back. I need my password. I don't
know what it was. Help Morty help. So there's not a whole lot going on on this page. Let's go check
it out. View the source here. It looks like we have this image. We might be able to download
this image and maybe check it in case there are any strings in there or things that they
might be trying to hide from us. But I do see this giant gaping HTML comment says note to self
remember the username. Username equals Rick Rules. Okay so now we have a little bit of an
inclination where maybe we could go with this if you wanted to use Hydra and like brute force this
Rick Rules username with some passwords to try and beat up SSH. Maybe potentially log in. For
other enumeration we could be running Go Buster or we could be running Neato as we're doing. So
now that I mentioned Go Buster let's actually go ahead and slap that in. Get some enumeration
going in the background. So I will use Go Buster and it needs a URL. So our IP address. We'll use
the word list op rock you. I think my face is in the way. No we don't we don't want to use rock
you because we're not cracking passwords. We will use the directory listing that would come with
Durr Buster. And I'm actually going to specify TACX to specify some file extensions that I might
want to look for. I'll look for PHP. I'll look for S.H. text CGI. I like to use S.H. and CGI in case
there's any like shell shock stuff or some of the things that might be running. Obviously HTML J.S.S.
excuse me J.S. for JavaScript C.S.S. maybe Python files too. Just may as well. And the
found index at H.T.M.L. That's good. That's where we already are. Let's go check out that robots
text because I saw that Nikto said robots text was retrieved but it does not contain any disallow
entries which is strange. Let's go check out our robots text. And it says Wubba lubba dub dub.
So perfect. Let's save that in our notes. And we also have that thing as well. Maybe that
might be something. It's probably there for a reason. Right. Our other Go Buster scan found
a login dot PHP. OK. So assets portal dot PHP. It looks like that has a status 302. So we might
not be able to access that just yet. But it seems to exist. So let's hop on to go check those out.
I'll go to portal dot PHP. Oh looks like we need to log in first. So it redirected me to log in.
Log in has this image and a username and log. So the only pieces of information that we have
thus far are this username Rick Rules and whatever this string is. Wubba lubba dub dub.
Obviously the Rick and Rorty reference but maybe that's a password. We could try to log in. OK.
Looks like it logged in. No I don't want to add that to the last pass. Thank you.
So seemingly command panel. We execute a command. What else is in here? Only the real Rick can view
this page. Potions. Creatures. Bethaclona. OK. So we can't do anything with that. Seemingly.
Let's go poke around at this command panel and let our other things run in the background.
So I will run LS. OK. Looks like I have some interesting files here. Super secret pickle
and greed dot text. Let's see what that is. I cat that out please. No. Command disabled to
make it hard for future pickle Rick. What? OK. What else do we have here? CD. That's its clue.
I can't cat out. Can I just not cat out something that is a text file? All right. OK. I can't
seem to run command. Well what can I run? Um. DIR work? Yep. I can head clue dot text.
That's also disabled. Well that's annoying. OK. Please stop losing my page when I hit the
base button or the back button. So we know we seemingly can't run cat. And I bumped around
this for a little bit of time. I was like what can I do to read files? I like to use map file
as one technique but since that seemingly doesn't work in our case we could echo something the
output of clue dot text. Maybe. Can we run echo? That doesn't seem to work for me. How about
I can't run cat while read line do echo line while read not. What am I doing while read line
do echo that read in from clue dot text. Does that work? Oh OK. Excellent. It does. So that works.
One other technique that I thought of using was using grep and grep capital R is really nice
because it can work recursively. So this is going to be a mess. I'm going to get the results of
every file in the actual file system or we can actually just try grep on that clue dot text
and match anything match any characters that work grep clue dot text period. Or is it pattern first
grep period and then clue dot text as the file name. Yeah that's OK. So grep the pattern you're
looking for and I'm using a period for the regular expression anything. And I'm also going to be
using that file name. We could use that grep tech are in search for the anything and that will
return all of the files in this folder which looks a little messy. But if we go check out the
source code we can probably make sense of it because it thankfully will showcase the lines
that we're reading. So this will actually let us see the source code as well because we're just
catting out not really but using grep or using that while read technique to read a file. I like
the while read technique because those are all built ins while is a built in read is a built in
echo is a built in. So that technique might be useful in other situations even more than this.
But it looks like we can see that PHP code. So we found robots that text found our denied page
found the index. Oh and also found the login page. That's kind of cool. OK. So it's verifying
the credentials that we found. What else do we have. OK. Super secret ingredient number one
is Mr. Meesee care. Cool. Look around the file system for the other ingredients. That's our clue.
We can navigate move stuff around. But oh this is a portal page and that will check with the
contains function. If we have some string inside of another string some of the commands here. OK.
So it looks like we have a blacklist in place for commands that we can run or can't run cat head
more tail nano Vim and V.I. That's not a lot. That's not a lot of commands that actually gives
us a lot of options. Right. So we also have some base 64 string. What is this. Let's try this.
Let's make me to go away. For those of you that have already completed this room you might already
know what this is. And I'm just going to showcase it because for completeness sake and being
thorough. But it looks like it's nested base 64 like recursive base 64. So I keep adding on a base
64 tag D over and over and over again. And you're seeing the output base 64. It's also seeing some
other missteps. But I will base 64 tag D repeatedly repeatedly repeatedly until I get the answer
rabbit hole which is a little mean. I spent all that time and we wasted it. OK. So that's it.
There's no real results to get from that. But we know we have command execution. We know we have
a blacklist for commands that we can't work with. We've found our way to mitigate not being able to
run cat. We can still read files with that while read line technique and we can use grep. So now
we want to probably leverage this more so we can actually move around the file system in a sane
way not just through this stupid web interface. So let's try and get a reverse shell. Let's see
if we have net cat. I think that's a fine option. We use net cat tech H maybe doesn't seem to run
net cat tech tech version. I don't seem to get any command output from that. So maybe that's not
actually there. Oh cat is in that name. So that's just going to yell at it. And I keep hitting the
back button. So what could we do to get a reverse shell. We could try to use Python. I'm just going
to verify that we actually have Python working whether or not Python 2 or Python 3. So if I
print out which is regular Python doesn't work for me I could specify Python 3 and that looks
like it does get some some output for me. So what we could do is we could use the pen test monkey
reverse shell cheat sheet and we could just modify hey the Python one liner that we have to go ahead
and give us a shell by using not just Python as a command but Python 3 if I add that in there.
So I am going to need to I guess modify this to get our IP address. So I do actually need that
terminal. What is my current IP address show 10 0 8 9 1 12 weird oddball and let's use a port
9 9 9 or quad 9 and let's use Python 3. So let's close that shell out and get back to a regular
shell and let's net cat LNVP quad 9 and now we can go try and go execute that command because we
know that Python 3 should work for us. So if I execute looks like that's not responding it's
probably executing it and we have a shell. Excellent. Okay so this is kind of a crappy
shell just as we normally do when we run like netcat reverse shells we don't have our tab
autocomplete or up and down command history or left and right arrow keys so it's very very
frustrating and we could accidentally control c. So I've showcased in other videos the stabilized
shell technique using Python taxi pty and creating it with stty raw minus echo and exporting the term
environment variable. So I actually do that with my poor man's pen test project. If you haven't
seen that I it might come in handy poor man's pen test that's in my github. It's just using
gwake to send some keys that could automate the process of your interaction on a web shell or on
a reversing shell and even upload and download files etc etc. So I'm going to actually use gwake
and I will run my stabilized shell 3 script because if I actually check out what that is
stabilized shell 3. Let's go ahead and sub all that so you can see what that source code looks
like. I just use Python 3 to run the pty and make my terminal in raw mode and turn off echo so I get
a stable shell. It's just an automated way so I don't have to type it and mistype it all the time
that I do and we know that it's going to be using Python 3 because we just tested in Python as a
command itself doesn't really seem to be on the box. So let's go ahead and do that let's go ahead
and run stabilize shell which is in my prompt so I don't need the dot slash stabilize shell 3 and
okay now we have a stable dub dub dub data. This is also handy because we could actually use some
of the other upload file functionalities so I don't have netcat. Do I actually have netcat?
Did it just not want to work for me? Yeah it does. Whatever. Okay so let's go ahead and use some of
the functionality that we have built out to upload linps and then I'll go ahead and put it in dev.shm
kind of a hidden directory so if I wanted to do my enumeration I don't have to deal with
creating the socket or netcatting things and doing it it just kind of finding my IP address
and all that crap it'll just get linps or whatever file I really wanted to on the box as fast as I
can. Pretty helpful for king of the hill stuff as well. Scrolling through this we found some
interesting information dub dub dub data may run the following command everything as sudo without
a password so we could just as easily sudo bash and be root and that's it that okay now we've
owned the box we've owned that machine so uh what else are we going to be looking for well in the
home directory of root looks like we found our third ingredient that's that let's go ahead and
I guess go submit that nothing to stop us oh and I never added the Mr. Meeseek here
is that right yeah cool what else do we have here what else could we find for that second argument
uh looks like he's in rick maybe second ingredients yeah cat that out one jerry tier
and just like that we finished the room and own that box so to recap just some command injection
to the web page some robots.txt to find stuff some durbuster with php extensions to find our login
the command injection didn't allow us to run common commands like cat because it had a blacklist going
we can still evade that my built-in technique that I really like is a wow read line um echo
things out and redirect into it that is helpful because even in a command shell where you don't
have grep that would work because those are all built-in commands we use grep to work because
we can read out all the files nice and easily find the source code know that blacklist and
then we were able to determine okay what can we use in this machine to get a reverse shell
python python 3 in this case just need to add that 3 there because python still on the box
but not the just flat regular python command use python 3 get a reverse shell I like to use my
poor man's pen test project because it just automates a lot of things um we actually have
the python 3 reversal in there so I could just slap that in it and stabilizing the shell and
uploading lind p's and doing the reconnaissance that maybe we wouldn't have done naturally but
okay if I were dubbed up to data I could just simply sudo attack l and know that so that's
something maybe we could do manually we should do manually but lind p's will take care of that so
okay that's that video that's pickle rick that that's the try hack me room kind of kind of fun
kind of simple kind of good but uh I hope you guys enjoyed if you did like this video please
do press that like button hit the subscribe button hit the comment button and then type
things in and hit the enter button so you enter a comment uh love to see you guys on discord server
love to see you on patreon paypal twitter facebook linkedin all of the things have a great day bye
