Exploit Development (part 8) Creating a Cyclic Pattern

Video Activity

This lesson focuses on creating a cyclic pattern using the immunity debugger. Participants receive step by step instructions to create a cyclic pattern using the python command. The lesson also discusses operating system DLLs and how they can be used in exploit development.

Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *

Already have an account? Sign In »

14 hours 26 minutes
Video Description

This lesson focuses on creating a cyclic pattern using the immunity debugger. Participants receive step by step instructions to create a cyclic pattern using the python command. The lesson also discusses operating system DLLs and how they can be used in exploit development.

Video Transcription
Okay, so now we need to
figure out which of the 1100 characters are overriding the safe return pointer, and that's causing the progeny, i p.
So what we want to do is create a cyclic pattern, and we're going to do this in immunity, vulgar,
and we do our command down here at this white part of the bottom. But that's kind of small. So I will put them in a note pad first so we can see them a little bit better and we do course need to restart war STP. It's currently crash. Some programs will do this inside of the bugger
that will not always be the case. Some punch up to detach and restart it. But with this one, we can go to debug and then restart Yes,
since it restarted nicely. If you do have any problem with it and make in a few cases, I'm not really sure what it is that does it that give people the same VM and those people don't get the error. But then a couple people do if you do get an error and it says like a noon database for matter unknown user name for a matter
something like that. It will just put up
on alert window that says that if you go into a war FTP folder, there will be
a file FTP demon thought that. And if you do get the error, just delete it before you restart, deletes the database. And if you don't get it, then you don't have to do that. You just restart like we did. But if you do get that error and if we get this error in the later video, then I will.
Sure, deleting it. But
just in case you get it, you just delete that file and everything should be flying.
So those polls, when you re started since he pulls down here so in Click Play
on and
Where did My war of to? Vega
says It's running, but it's not.
There are so, so savory straight again
on hit play.
There you go under the file format or user data, but it's cool enough to see it.
All right, so you have to say OK here and let's delete that FDP demon dot Dad,
you probably won't get this, but luckily for the state of the video, I did, so you can see how to get rid of it. Who? Just delete the dot dat file a few p demon
on DDE.
Now go to restart
and that your research? Fine.
Look. Okay, Click the lightning bolt. So it's running on. We're still attached to it in the d bugger.
So we should be good to go.
All right, now, we need our command. Create our pattern.
We used a Adeline called Mona
on dit is added on to immunity. It's not
in there by the fault just downloaded and add it to Mona. We did that for added two immunity. Rather admitted immunity. And we did that in section one way that are set up.
So we want exclamation point Mona Pattern create will use Mona Fair amount in this class as we do the exploit development, it has command for a lot of useful task that might exploit development a bit easier. So we want to tell it to create a 1100 character patterns were gonna replace that 1100 days
with this pattern
that is going to allow us to
see where our favor turn point over is in just one step instead of him to bring it down into multiple steps like I should do in the previous video Hoes paste that ends a motive pattern. Underscore. Create an 1100.
And since I sat the logs when I was doing the setup, it does love it to see logs War dad Jeff DPD patterned out text. So she logs in the name of program. It's attached to that. Whatever the command is,
if I go to the desktop, not the desktop, that's where everything else is. Sea logs or FTP d and then patterned out text.
There's our secret pattern That's 1 1100 characters long
from the Copy this and go over to my Callie Veum,
and I'm going to use Nan own editors worth to detail that pod.
And I'm just gonna comment out. Buffer equals eight times 1100 without a bee hash and python, and I'll recreate Buffer. You could also get rid of that one entirely, or delete the eight times without the 100 re declare it. But this is nice because we can see each step as we move through. It would be nice
Thio. Remember what we did decide. I'm going to have you do
and exercise where you do it. This yourself. So it'll be nice to have
all the steps. All right, So I'm gonna say buffer equals open quotations and then paste in that 1100 characters of the cyclic pattern.
And don't forget the clothes quotations at the end
I ended up on second line. That's there, but so should light up Green and Nana. All right, So instead of 1100 days now, we're going to still send it 1100 characters on the link should be the same. But now we have our little cyclic pattern. Gonna see how it works. Big A lazy Roby gate, Lily one.
So you get a little b a little see? So you see, it could be pretty long before it has to look around.
So go and say that is the only change we're gonna make. Here was re declaring the buffer variable to be our cyclic pattern so we can
crash it again to make sure we're running over here in immunity. We are indeed running, which we get to G o
so over a Calleigh, let's run it again.
Hit the same output here. So everything as expected here said hi, I'm the war. If you fi
server, please. Did you use your name? Please enter your password. We d'oh or the script is rather come back over here. We have access violation when executing this time not 41 41 41 41 Since we've been send it a long string of A's We sent in our pattern.
Who's dead? We get 30 to 71 41 31 it's here in the I P as well.
We can also see parts of our pattern in E s p e v p N e d I. Those were
covered in age
last time. That was to be expected.
So what we can do? We have a couple options just to see what is in the I p.
We could just do
exclamation point, Mona Pattern, underscore, offset
and then give it 30 to 71
41 31.
And it says that the peace of the pattern is at Position 485. So it's 485 bites into our attacks during.
But remember that
Go back to the CPU view. We also have these registers that have been overwritten with part of the pattern, I mentioned that that might be useful as a place to put our shell code so we can actually just do one step
that will allow us to see all of the places that the pattern shows up in memory. So we can do Mona. Find M S p for the fine medicine flight pattern. This cyclic pattern is part of the medicine for Mark.
You can also use medicine void created directly on Callie. But
I typically used Mona for these sorts of things.
All right, so we could do a motive finding Miss P.
And we do have to crash it with the cyclic pattern in order for this to work. So we do need tohave are cyclic pattern in memory.
But there was it won't find it specifically looking for parts of this pattern in different formats.
Plus do exclamation point. Mona, find MSP
on. It's going to take a little bit here. You'll see it's a searching down at the bottom. It is searching through all of memory for parts of that pattern that will just take a minute to her defense.
So this will give us the location of the I P. But you'll also find
what's in our registers in any other place that happens to be ever written as well.
Let's see what it comes up with. All right, now it's done
so we can take a look again at the output. So we d'oh d'oh!
Sea logs ward as a ppd this one called finding that p So the files are named after
whatever we told it to do.
So here at the top, we have all the loaded models for this one.
So he's already see some windows dll that are loaded
and we also see
war FTP itself should be here somewhere. Cares for Ft. Petey, execute Herbal. It looks like it also has
a dll of its very own.
And she information about them like they're base the size of them with the re based on on that basically just means whether or not they can move. See, one of them is rebased
and things being in the same place every time certainly makes exploits
more stable. I'll be able to use them on other platforms, for instance, are, for the very least on other windows. Ex piece of respect. Three systems.
We generally like to look for things that don't move or don't move very often
and safe at the age. We will look a structured exception handlers or a CH in a later portion of this export development section,
but they're not really relevant now. Noticed that a couple of them do you have a safe as the ages false. That will certainly come into play
address based layout, random ization or SLR that's false for all of them that didn't come in and Windows until Windows Vista.
That said,
isn't a requirement that you use SLR on your programs. And certainly legacy programs like this wouldn't have it enabled. So SLR address Space layout organization is another thing that makes things move. Anything that does have SLR enabled on an operating system that support it with Mr later than it would
when you re boot
all of those. Deal of all those programs will be loaded at a different face and memory to continue with exploit development, you'll see ways to bypass SLR
is certainly relevant these days,
but again, with this example on anything we're going to do in this class, we won't see that taken. Exploit development class. I'm sure that that will be covered. Certainly covered in mind, Frau, it's not relevant. Likewise, no execution.
We don't have to worry about that here. So that execution prevention basically again is a way to stop exploits from working. So I was like, We're executing code off the stack. Why are you executing code off the stack?
You shouldn't be executing off the stack. The *** just supposed to be like local information. It shouldn't be executing. So someone got the bright idea. Well, let's just marked sections of memory that aren't supposed to be executed as not execute herbal. And then people can't just put their show cause they're on Execute it. So
again, if you take exploit development class, I'm sure you'll spend
office time looking at different ways to bypass no execution. But we don't have to worry about it here. We don't have
backs on, and it also says, Are they
operating system? He yells. And that's true of everything that is not worth U P itself or any of its deal l. So operating system deals are probably going to change among service facts or could even change just among a few updates,
and certainly among different Windows versions, they're probably going to change, not necessarily or they're going to change. There are
so instances of deals don't change that often. And in my experience in this VCR key is a good operating system DLL that you can use. It doesn't change very much in the history of Windows, whereas something like User 30 to our system 32 does have a lot of changes. Bayer
a lot more going on.
So if I have to use an operating system deal, I usually go for the n S v c r t dot dll. But just for this basic example, really, any of the operating system deals will work just fine. We're working with the specific platform, but we would like
as exploit developers to make our exploits is universal is possible. And so my first thing is to try and go for four. If CPD itself or any of its deals. And if not, then it's easy. Artie, if it's there,
uh, we'll see that a bit later on.
All right, then the actual meat of funding Miss p, the program
looking for our pattern.
So it found quite a few parts of the pattern. But in particular I'm interested in the registers at this point,
So e i p again it found it off. That is 485. It did find those other three registers s, P e T, I and EVP all contained part of the pattern as well. So he s P is it off that 493 on afterwards? It has the length of 607 bites. So if we
put our shell code in E. S P, we have 607 bites for shell code. More space.
I mean, we can use more advanced shell code. Certainly helpful.
S t e d. I is at 749 and its length is 351. So not nearly as long. There EVP that 400 or 581 and his link is 519. So everybody has almost as much basis e s P
castles are. We could probably use EVP just fine, but let's go ahead and grab the SP. It does have the longest length on as well. See the make Something interesting happened that I think is worth seeing, particularly if you're going to continue an exploit development. So I will choose E S P. That's where we're going to put our shell code
too. It's offset is 493 that has linked 607 almost gotten. Copy this out.
find a Miss p and entitled is what I want. So just copy this for reference. So often is 493 and links is 607. And also just put the I P Is it offset
485. So we found that with finding this p as well as with the pattern underscore off that Just find the ivy.
So that means our favor turn point or ever right is going to be 485 bites in
and then it looks like so
safe Return phoners four bites. So that'll get us to offset. 489. But then e s P is it 493. So if we remember our picture from the beginning of exploit development, it said that are saved return pointer was right on top of E S P.
So why are we four bites off? That's kind of confusing. Well, sometimes the picture is not completely exact. What's happening here is that calling convention. There's different calling conventions of different compilers that you use different platforms. They have
different ways of dealing with things. There's certainly no hard and fast rules that this has to be done this way.
So basically the arguments. So there's one for bite argument between
E. I. P is over right on E S. P. So there's four extra bites that basically get stripped off when our whatever function we called return. So there's just four extra bites there,
so nothing to worry about. It just makes our picture a little bit inexact in this case. But this is gonna be taking care of automatically. We don't have to worry about ripping off extra arguments or anything when it compiles. It takes care of all that automatically. We just need to know. Yes, p that 493 d I. T. Is at 485
so we'll just take that into account more rebuild
our attacks during the next thing we need to do, of course, is verify that this is all true. As you become more familiar with exploit development, you may skip that part, but I encourage you to always verify everything because as soon as you stop, at least in my experience, that's when you start making mistakes and we'd rather catch to them. Now
we're down the line when everything just stopped working and you can't figure out why.
Up Next