First make sure java is installed on your host machine. After installation, we go to the folder of the lab we want to practice. "i.e /skf-labs/XSS, /skf-labs/RFI/" and run the following command:
$ ./mvnw spring-boot:run
{% hint style="success" %} Now that the app is running let's go hacking! {% endhint %}
The application shows that there is a new version of the website available somewhere, and a click on the button "Go to new website" will redirect you to it.
If we click on the button we will be redirected on the new page http://localhost:5000/newsite
Intercepting the traffic generated by the application, we note that the redirection is performed using the following call
GET /redirect?newurl=newsite
that will generate a 302 Redirect response from the server
Exactly like in the previous example (KBID-67-Url-redirection). If we look at the code we discover a tiny difference: a blacklist!
public String redirect(@RequestParam(name="newurl", required=true) String newurl, Model model) {
if(blacklist(newurl)){
model.addAttribute("content", "Sorry, you cannot use \".\" in the redirect");
return "index";
}
return "redirect:"+newurl;
}
If we look at the blacklist definition, we can immediately see that the URL, in order to be valid, must not contain any "." (dot).
private boolean blacklist(String url){
String[] blacklist = new String[]{"."};
for(String b: blacklist){
if(url.indexOf(b) > -1){
return true;
}
}
return false;
}
Let's verify the effectiveness of this blacklist. If we try to exploit the unvalidated redirect using an external website, we see that the application blocks us, returning an error in the page.
If we URL encode the dot the application is smart enough to decode it and recognise it in the URL, blocking us again.
Although we cannot explicitly use the dot character, we can find different ways to bypass the blacklist. In example we could use the following techniques:
- double encoding:
https://google%252ecom
- UTF-8 encoding:
https://google.com%E3%80%82.com
- Can you find more?
Using the payload above we will be able to successfully redirect a user to a malicious website
{% embed url="https://owasp.org/www-project-web-security-testing-guide/v41/4-Web_Application_Security_Testing/11-Client_Side_Testing/04-Testing_for_Client_Side_URL_Redirect" %}