arrow-left

All pages
gitbookPowered by GitBook
1 of 4

Loading...

Loading...

Loading...

Loading...

URL Redirection - Harder

Python - URL Redirection - Harder

hashtag
Running the app on Docker

circle-check

Now that the app is running let's go hacking!

hashtag
Reconnaissance

hashtag
Step 1

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

hashtag
Step 2

Intercepting the traffic generated by the application, we note that the redirection is performed using the following call

That will generate a 302 Redirect response from the server

Exactly like in the previous example (Url. If we look at the code we discover a tiny difference: a blacklist!

If we look at the blacklist definition, we can immediately see that the URL, in order to be valid, must not contain any "." (dot).

hashtag
Step 3

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.

hashtag
Exploitation

Although we cannot explicitly use the dot character, we can find different ways to bypass the blacklist. For example we could use double encoding:

Using the payload above we will be able to successfully redirect a user to any website:

hashtag
Additional sources

$ docker pull blabla1337/owasp-skf-lab:url-redirection-harder
$ docker run -ti -p 127.0.0.1:5000:5000 blabla1337/owasp-skf-lab:url-redirection-harder
http://localhost:5000/newsitearrow-up-right
https://www.owasp.org/index.php/Testing_for_Client_Side_URL_Redirect_(OTG-CLIENT-004)arrow-up-right
GET /redirect?newurl=newsite
landing_page = request.args.get('newurl')
if blacklist(landing_page):
    return render_template("index.html", content = "Sorry, you cannot use \".\" in the redirect")
return redirect(landing_page, 302)
def blacklist(url):
    blacklist = ["."]
    for b in blacklist:
        if url.find(b) != -1:
            return True

    return False
https://www%252egoogle%252ecom

NodeJS - URL Redirection - Harder

hashtag
Running the app on Docker

circle-check

Now that the app is running let's go hacking!

hashtag
Reconnaissance

hashtag
Step 1

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

hashtag
Step 2

Intercepting the traffic generated by the application, we note that the redirection is performed using the following call

That will generate a 302 Redirect response from the server

Exactly like in the previous example (Url. If we look at the code we discover a tiny difference: a blacklist!

If we look at the blacklist definition, we can immediately see that the URL, in order to be valid, must not contain any "." (dot).

hashtag
Step 3

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.

hashtag
Exploitation

Although we cannot explicitly use the dot character, we can find different ways to bypass the blacklist. For example we could use double encoding:

Using the payload above we will be able to successfully redirect a user to any website:

hashtag
Additional sources

$ sudo docker pull blabla1337/owasp-skf-lab:js-url-redirection-harder
$ sudo docker run -ti -p 127.0.0.1:5000:5000 blabla1337/owasp-skf-lab:js-url-redirection-harder
http://localhost:5000/newsitearrow-up-right
https://www.owasp.org/index.php/Testing_for_Client_Side_URL_Redirect_(OTG-CLIENT-004)arrow-up-right
GET /redirect?newurl=newsite
let newurl = req.query.newurl;
  if (blacklist(newurl)) {
    res.render("index.ejs", {
      content: 'Sorry, you cannot use "." in the redirect',
    });
const blacklist = (newurl) => {
  if (newurl.includes(".")) {
    return true;
  }
  return false;
};
https://www%252egoogle%252ecom

Java - URL Redirection - Harder

hashtag
Running the app on Docker

circle-check

Now that the app is running let's go hacking!

hashtag
Reconnaissance

hashtag
Step 1

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

hashtag
Step 2

Intercepting the traffic generated by the application, we note that the redirection is performed using the following call

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!

If we look at the blacklist definition, we can immediately see that the URL, in order to be valid, must not contain any "." (dot).

hashtag
Step 3

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.

hashtag
Exploitation

Although we cannot explicitly use the dot character, we can find different ways to bypass the blacklist. For example we could use double encoding:

Using the payload above we will be able to successfully redirect a user to any website:

hashtag
Additional sources

$ sudo docker pull blabla1337/owasp-skf-lab:java-url-redirection-harder
$ sudo docker run -ti -p 127.0.0.1:5000:5000 blabla1337/owasp-skf-lab:java-url-redirection-harder
http://localhost:5000/newsitearrow-up-right
https://www.owasp.org/index.php/Testing_for_Client_Side_URL_Redirect_(OTG-CLIENT-004)arrow-up-right
GET /redirect?newurl=newsite
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;
	}
private boolean blacklist(String url){
        String[] blacklist = new String[]{"."};
        for(String b: blacklist){
            if(url.indexOf(b) > -1){
                return true;
            }
        }
        return false;
    }
https://www%252egoogle%252ecom