so we're going to take a look at a reflected cross-site scripting attack and it will be taking advantage of a vulnerable search input so let's take a look at the lab so we have a Blog style page and we have the option to search the blog and one of the very first things we like to do when searching for cross-site scripting attack vectors is to input an arbitrary string and just see where it presents itself on the page so let's search for a string let's pop open the dev tools and let's search for that arbitrary string in the Dom we've got two matches the first is inside that H1 tag it's unlikely we're going to be able to do anything with that so let's have a look at the second appearance of our arbitrary string so we have an input field type equals text placeholder equals search The Blog name equals search value equals Zen shell so thinking about the context here our search term is appearing inside the value attribute of that input element so the question is can we break out of that value attribute and create a new attribute for example something like an on Mouse over event and then we can pop up a JavaScript alert when that event occurs so the way that we're going to break out of that is by ending with a double quote so hopefully we are outside of that value attribute now but still inside the input tags so let's see if we can create a new attribute it's going to be an on mouseover event and when that event occurs I. E when the user's cursor is over the element in question we want to call the JavaScript alert function so let's search for that you can see the URL at the top of the page is updated because all of this information is contained with inside the query string so we have that search parameter and the value is the URL encoded version of our search string now you can see straight away we get congratulations you solve the lab Echo to the page notice what happens if we Mouse over that search box we get the alert just as a little bit of post analysis let's see if we can check out that element fact it's very difficult to right click on the element directly because it obviously triggers the alert so looking in the Dom here we have this form we have our input element picking up where we left off we have value equals Zen shell and then we have the on Mouse over attribute now you probably realize that the end result of this is going to be a trailing double quote which we can actually see there in the Dom this doesn't look like it's valed HTML but the Dom is fairly intelligent and can times still understand what is intended by a certain element even if it doesn't quite match up to correct syntax so that doesn't look like it's correct syntax to me but you can still see that the rest of the element itself is working just fine now you might wonder how were we able to do this it doesn't seem like we should be able to just break out of an attribute with inside an element and it's not a vulnerability with HTML or even a vulnerability with the Dom it's just a vulnerability with the way that this particular Blog has been coded by the developer and we have to be very careful when writing to the Dom this is often done with something like javascript's document. write method and all it does is take a string it's very easy to inject into the Dom if the developer is just taking our string and appending it to the string that's being past the document.
write method so there's obviously no handling of our string beforehand maybe stripping it of certain special characters before it's then passed into something like the document. write method of course we don't know exactly what's happening on the back end but we do know something is being mishandled by the developer for this vulnerability to arise and it's usually to do with not properly sanitizing a string that's passed to the back end by the user so really what should happen is as soon as the script at the back end see is that we've tried to pass in a double quote it strips that from the output before it passes it to the document.