hi everyone welcome back to another video in the web security academy series in today's video we'll be covering lab number one in the course module titled correspondability with basic origin reflection alright let's get started this website has an insecure course configuration in that it trusts all origins to solve the lab craft some javascript that uses course to retrieve the administrator's api key and upload the code to your exploit server the lab is solved when you successfully submit the administrator's api key so the target goal i've written it over here is to exploit the course misconfiguration
in order to retrieve the administrator's api key so we're targeting an administrator and we're going to use the exploit server in order to send that request to the administrator you can log into your own account using the following credentials and we've got the credentials right over here so let's right click and access the lab and open up burp suite community edition hit okay close next star burp and we'll make this a little bit smaller go to the proxy tab set intercept to off and then click on the http history sub tab next we're gonna set
foxy proxy to send requests to burp so now all the requests that i perform in the browser will be sent to burp first before being sent to the application so we're gonna click on my account and you can see the requests are being intercepted over here seems like i've already logged in so i'm going to log out and log back into the application so click my account and let's log in with the credentials that we were given hit login and here we go so you could see it's making a ton of requests one of them
is the account details request which is an ajax request that retrieves the api key of the user now we're not interested in the api key of our user account we're really interested in the api key of the administrator account so if there is a course misconfiguration in this application and we know that it's using course because it's using one of the course headers access control allow credentials header so the application is definitely making use of the course protocol and what we're really interested in is getting the administrator's api key so we're targeting the administrator user
but before we target that user we need to see if there's a misconfiguration in this application that allows us to exploit a course vulnerability so let's right click hit send to repeater and let's make this a little bit smaller so that we could see both the request and the response hit send and we get a 200 okay message because the application is functioning as expected next what we're going to do is we're going to add the origin header and we're going to add let's say randomwebsite.com and see if the application accepts it now if the
application accepts it that means the application accepts any random origin on the internet to access its data if the application does not accept it or throws an error that means the application only accepts certain domains to access its data and it's usually just the domain of the site or the subdomains of the site so let's hit send and here we go so we get a 200 okay message and if we make this a little bit bigger so if you look over here we've got both headers that are used in the course protocol that we learned
about in the complete guide theory video the first one is the access control allow origin header which specifies the origins that are allowed to access this site in this case it allows arbitrary origins so we had said randomwebsite.com however if you just said so let's say malicious website.com that should work as well because what the application is essentially doing is it's dynamically extracting the origin without checking it and reflecting it back to the user in the access control allow origin header so it essentially allows any site on the internet to access its resources however it
can only access the public resources but you could see over here we've got both headers so we've got the access control allow origin header and the access control allow credentials header which allows credentials to be passed in the request that could be either cookies or authorization headers or certificates but in this case the application makes use of a session cookie so what's going to get passed in the request is session cookies having both headers is very dangerous because what that means is not only can you access public resources from the site but you could also
access private resources and in this case the private resource that we really want to access is the api key of the administrator user so we've confirmed that the application allows an arbitrary origin let's put that in our notes so testing for course misconfigurations the first thing that i usually test is change the origin to an arbitrary value and see if the application accepts it in this case the application accepted it and so we no longer have to move to our next test use case if this one fails so if we go back and we look
at it over here it allowed an arbitrary origin to access the site so let's develop a script that we're going to send to the administrator user and when the user clicks on the site we'll exploit this mis-configuration in order to extract the api key of the user so to do that let's save this first and then let's access the course lab01 html document that i've got over here so first let's initialize the document so html we'll add the body tag and then the script tag the first thing that we're going to do is use the
xml http request object in order to extract data from a web server so we'll initialize it and then we'll initialize the url of the application which is this one over here let's copy that this looks good next we're going to make a gut request so get and we're making the request to the url of the application so the domain of the application plus we're making a request to the account details page okay next we want the script to send the credentials that are stored in that administrator's browser with the request so we're going to make
use of the with credentials property so that looks like this with credentials is equal to true so what this is going to do is it's going to request that the browser send the credentials with the application now if the application does not make use of the access control allow credentials header the request will be denied but in this case it's set to true and so the request is going to go through okay [Music] and we're forgetting our semicolons over here all right next we're going to send the request now once we send the request we
need to be able to extract the response of the request so to do that we're going to add a function so xhr dot on ready state change is equal to this function so when the state changes of the xml http request perform this function over here so if the ready state is equal to done so we'll say xml http request dot done then fetch the response of the request and i keep hitting my caps lock here we go fetch the response of the request so that would be xhr dot response text and we're going to
append that to the string log keys equal to and add that to the response okay this looks good so we did this pretty quickly so i'm going to go over it again essentially what we're doing is we're making a get request to the account details page of the application and we're asking the browser to send any cookies that the browser has stored with the request and then we're sending the request once the request is sent we're fetching the response of the request and adding it to the logs of our malicious server or in this case
our exploit server so what's going to happen is in the logs you'll see this string over here so slash log question mark key is equal to and then you'll see the response of the text all right let's save this and we're gonna go to the exploit server to host the script now this is what you're doing for the academy because the academy has to have a way in order for you to contact the administrator and have the administrator click on your script however if you want to learn how to do this as a proof of
concept on your own stick around to the end of the video so let's copy this put it in the body this looks good click on store exploit and then deliver exploit to victim and then let's view the access log of our exploit server it should have this string over here with the response from the administrator user and you could see it over here so it locked the response of the administrator user's account because what's happening with the exploit server is we're sending this a script to the administrator and we're saying hey click on this link
the administrator clicks on the link and it appears as an empty page however what's happening in the background is this request over here is being made and it's fetching the api key of the administrator so if you go over here you could see where on the administrator's account so the administrator is the one that clicked on the link and you could see over here that's the api key of the administrator so if we copy it and then go back to the exercise and click on submit solution this should be the correct answer and here we
go it says congratulations you solved the lab so essentially we were able to exploit a course misconfiguration that allowed arbitrary origins to access the site in order to obtain the api key of the administrator user if you would like to see a detailed version of the video where we host the script on our own web server check out the video linked on the screen also make sure to check out my course if you're interested in seeing more videos like this one thank you and see you in the next video