Okay now use in our script we're able to see the requests and the responses and we're even able to see
the plain text of the hastier melt code of the pages that the person is loading.
And as expected we can see that the Steimle code is being sent in the load field of the roll layer of
each response packet.
Now we know that the load is just a string and basically use in python we can replace any part of the
string or inject more string or more text inside the string.
So you literally only limited by your knowledge of hash DML and Javascript with what you can do with
this.
Now what I want to do in this example is inject a job or script code that will only show an alert on
screen saying test just to make sure that what I'm doing is correct and that it's working.
And then in the next lecture we're going to inject more useful javascript codes.
Now Javascript is a client side programming language which basically means that this language gets executed
on the browser itself not on the server.
So it's similar to hasty M-L but hate mail is a markup language whereas Javascript is a programming
language allowing us to do so much more than hashed him out.
So the script that will show the alert that I want to use is basically just alert and then I'm going
to put the alert text which is test and that's it.
That's the whole script so alert is a function in javascript that will display a message to the user
and the message that I want to display is called test.
Now if you want to run a javascript code in a hasty M-L page you have to wrap this with a script tag.
So you have to say script before it and that the end of that you have to do slash script.
Ok now that's perfect and all we want to do now is put this text somewhere and our web page in here.
Now you can put it anywhere you want so you can literally place this slash div with another slash div
followed by the script or what.
What is much better is to look for the last tag of the page which is a tag that should exist in every
single page.
So if I just right click this and view the page source you can see that the page ads with a slash body.
Now this is usually the last tag of the page that indicates this is the end of the body of the page.
There is only one of this.
Unlike other types that you might see they repeat.
And if you try to inject stuff after it then you'll end up with injecting your code multiple times in
the page.
So the body tag is a really good tag to use as an anchor when injecting stuff on the page.
It's also a good idea to inject your javascript in here so that the page gets loaded first and then
your javascript code gets executed so that it won't delay the page and the user will not get suspicious
because if you inject your code for example here at the head at the start of the page then if your code
takes some time to execute the page will not load until your code is executed or loaded.
Whereas when we put it at the bottom it'll get loaded at the bottom.
And even if there is an error which you with your code it won't really affect the way that the website
looks because we're putting it at the end.
So what I want to do is I want to replace any occurrence of the slash body with another slash body followed
by my script to do this.
We're going to use replace method that can be invoked on any string in Python so you can see that the
Hasyim old code is literally coming up in the load as a string.
And since this is a string we can use any methods that can be used on Python strings and therefore we
can use the dot replace method.
So basically what I'm going to say in my response so we know that the responses come in here.
I'm going to remove the print statement here.
And I'm going to say the modified load is equal to K.P. pocket and we want to access the role here so
we're going to do is K.P. thraw and when accessed load field cause this is the field that contains the
hash DML code and for all of this I want to do dot replace.
So I want to invoke a python method that is called The replace and this method basically allows me to
replace a certain string with another string.
So the first input to this argument is this ring that I want to replace.
And what I want to replace is every time I want Python to see a slash body tag.
Which is the last time that I just showed you I wanted to be replaced with my javascript code.
So it's this code in here I'm going to copy it.
And then we're going to append this slash body.
So basically what we're saying is I want you to first of all read the load field of the rollator of
every packet.
I want you to look for Slash but you and I want you to replace that with my javascript code.
Followed by Slash buddy now you can use this replace function on any string.
It doesn't have to be a load field of a packet.
Like I said everything that I show is generic.
So this method can be invoked or on any string and it'll allow you to replace a certain substring with
another substring.
And based on what we are able to see in here you'll see that you'll be able to replace images download
links javascript codes or anything that is loaded in the hastier mail page in here.
Now let's go back to our example and now our modified load contains the load that has our script.
So now all we have to do is literally do what we were doing in here.
So we're going to say our new pocket is equal to set payloads or invoking the set payload function and
we're going to give with this K.P. packet.
And we wanted to set this out with the modified load.
And finally we want to set the payload of the packet to the string of the new packet and that's it we're
done.
So let's save this go down.
Control-C this run our code again.
I'm just going to close everything and remove my history first.
And then I'm going to go to being dot com.
And as you can see as soon as the page loads we are getting an alert or a message saying test.
So this means that our javascript code that we injected is getting executed on the target page.
So that's perfect.
Now as you can see this is not really a very useful javascript code but in the next lecture I'm going
to show you a more useful javascript code that you could run that that'll allow you to do so many cool
things on the target.
But basically for now this is the end of the lecture.
You can use what I showed you so far to replace any part in any hasty M-L page.
So it doesn't have to be inject in javascript.
You can replace the links you can replace the images.
And like I said you're only limited by your knowledge of javascript and hemol also the methods that
I showed you so far so the normal replace method that can be invoked on strings and the read not so
method that replaces substring in a bigger string used in projects you can use them on any string.
It doesn't have to be a load field of a packet.
You can use these methods on any string in any scenario that you might find yourself in.