views:

336

answers:

8

I have a website "www.website.com".

Recently I found out that somebody has set up a reverse proxy with an almost identical url "www.website1.com" in front of my website.

I'm concerned of those users who came to my website through that reverse proxy. Their username and passwords might be logged when they login.

Is there a way for me to have my web server refuse reverse proxy?

For example, I've set up a reverse proxy using squid with the url "www.fakestackoverflow.com" in front of "www.stackoverflow.com". So whenever I type "www.fakestackoverflow.com" in my web browser address bar, I'll be redirected to "www.stackoverflow.com" by the reverse proxy. Then I notice the url in my address bar changed to "www.stackoverflow.com" indicating that I'm no longer going through the reverse proxy.

"www.stackoverflow.com" must've detected that I came to the website from another url and then redirected me to the website through the actual url.

How do I do something like that in ASP.NET web application?

Also asked on server fault.

A: 

The simplest way would probably be to put some Javascript code on your page that examines window.location to see if the top level domain (TLD) matches what you expect, and if not, replaces it with your correct domain (causing the browser to reload to the proper site instead).

Amber
Javascript runs on the client and can be easily disabled. Having said that, this solution does not *protect* the web server at all.
Josh Stodola
@Amber ~ @Josh Stodola is correct. (-1)
drachenstern
+7  A: 

First, use JavaScript to sniff document.location.href and match it against your domain:

var MyHostName =  "www.mydomain.com";
if (0 == document.location.href.indexOf("https://")) 
{
    MyHostName = "https://" + MyHostName + "/";
    if (0 != document.location.href.indexOf(MyHostName)) {
        var new_location = document.location.href.replace(/https:\/\/[^\/]+\//, MyHostName);

        if(new_location != document.location.href)
            document.location.replace(new_location);
    }
}
else
{
    MyHostName = "http://" + MyHostName + "/";
    if (0 != document.location.href.indexOf(MyHostName)) {
        var new_location = document.location.href.replace(/http:\/\/[^\/]+\//, MyHostName);

        if(new_location != document.location.href)
            document.location.replace(new_location);
    }
}

Second: write a init script to all your ASP pages to check if the remote user IP address matches the address of the reverse proxy. If it matches, redirect to a tinyurl link which redirects back to your real domain. Use tinyurl or other redirection service to counter reverse proxy's url rewriting.

Third: write a scheduled task to do a DNS lookup on the fake domain, and update a configuration file which your init script in step 2 uses. Note: Do not do a DNS lookup in your ASP because DNS lookups can stall for 5 seconds. This opens a door for DOS against your site. Also, don't block solely based on IP address because it's easy to relocate.

Edit: If you're considered of the proxy operator stealing user passwords and usernames, you should log all users who are served to the proxy's IP address, and disable their accounts. Then send email to them explaining that they have been victims of a phishing attack via a misspelled domain name, and request them to change their passwords.

jmz
@jmz +1 Well nice code and I think its working, but if some have place a custom reverse proxy to steal some password then its going to remove probably most of the javascript to avoid this when its send the page.
Aristos
@Aristos: One solution against such an attack would be to create the login form with JavaScript. Also, serving the login page from a HTTPS connection would alert most technically savvy users. Also you could alert against malicious sites like Last.fm does (https://www.last.fm/login)
jmz
I think it is a fair idea to block the ip, until a stronger defense is forthcoming. It is usually easier to block them than change them.
strainer
I recommend serving porn when the reverse proxy IP is detected.
usr
@jmz ~ See comment below from Josh Stodola, and above from Aristos ... javascript is not a cure for server based problems. Do you do only javascript based validation too? (-1)
drachenstern
@drachenstern: You missed point 2 and 3 in my text.
jmz
@jmz ~ Any requirement based on javascript is invalid. I could as easily parse the html on the wire and strip that block or similar blocks of code, as soon as I found out what you were doing. Then you and I would be engaged in a lockstep battle. What would you do to stop me then?
drachenstern
A: 

There's very little you can do to prevent this without causing legitimate proxies (translation, google cache, etc..) from failing. If you don't care if people use such services, then simply set your web app to always redirect if the base url is not correct.

There are some steps you can take if you are aware of the proxies, and can find out their IP addresses, but that can change and you would have to stay on top of it. @jmz's answer is quite good in that regard.

Mystere Man
I wonder how stackoverflow.com is doing it. changing the correct url in the browser's address bar and it doesn't cause google translate to fail too.
Twisted Whisper
A: 

I have come with an idea, and I think a solution.

First of all you do not need all page to be overwrite because this way you block other proxies, and other services (like google automatic translate).

So let say that you won to be absolute sure about the login page.

So what you do, when a user gets on login.aspx page you make a redirect with the full path of your site again to login.aspx.

if(Not all ready redirect on header / or on parametres from url)
  Responce.Redirect("https://www.mysite.com/login.aspx");

This way I do not think that transparent proxy can change the get header and change it.

Also you can log any proxy, and or big requests from some ips and check it. When you found a Fishing site like the one you say you can also report it.

http://www.antiphishing.org/report_phishing.html
https://submit.symantec.com/antifraud/phish.cgi
http://www.google.com/safebrowsing/report_phish/

Aristos
then how do i know if the page has already been redirected? how would this work "if(Not all ready redirect on header)"? use session, cookies?
Twisted Whisper
@Twisted Well I am still think that. One way is to have a middle page. I have middle pages on many actions that do the work and then redirect to the result page. Other is to read the headers.
Aristos
A: 

After days of searching and experimenting, I think I've found an explanation to my question. In my question, I used stackoverflow.com as an example but now I'm going to use whatismyipaddress.com as my example since both exhibit the same behaviour in the sense of url rewriting plus whatismyipaddress.com is able to tell my ip address.

First, in order to reproduce the behaviour, I visited whatismyipaddress.com and got my ip address, say 111.111.111.111. Then I visited www.whatismyipaddress.com (note the additional www. as its prefix) and the url in my browser's address bar changed back to whatismyipaddress.com discarding the prefix. After reading comments from Josh Stodola, it strucked me to prove this point.

Next, I set up a reverse proxy with the url www.myreverseproxy.com and ip address 222.222.222.222 and I have it performed the two scenarios below:

  1. I have the reverse proxy points to whatismyipaddress.com (without the prefix **www.). Then typed www.myreverseproxy.com in my browser's address bar. The reverse proxy then relayed me to whatismyipaddress.com and the url in my address bar didn't change (still showing www.myreverseproxy.com). I further confirmed this by checking the ip address on the webpage which showed 222.222.222.222 (which is the ip address of the reverse proxy). This means that I'm still viewing the webpage through the reverse proxy and not directly connected to whatismyipaddress.com.

  2. Then I have the reverse proxy points to www.whatismyipaddress.com (with the prefix wwww. this time). I visited www.myreverseproxy.com and this time the url in my address bar changed from www.myreverseproxy.com to whatismyipaddress.com. The webpage showed my ip address as 111.111.111.111 (which is the real ip address of my pc). This means that I'm no longer viewing the webpage through the reverse proxy and redirected straight to whatismyipaddress.com.

I think this is some kind of url rewriting trick which Josh Stodola has pointed out. I think I'm gonna read more on this. As to how to protect a server from reverse proxy, the best bet is to use SSL. Encrypted information passing through a proxy will be of no use since it can't be read in plain sight thus preventing eavesdropping and man-in-the-middle attack which what reverse proxy exactly is.

Safeguarding with javascript though can be seen trivial since javascript can be stripped off easily by a reverse proxy and also prevent other online services like google translate from accessing your website.

Twisted Whisper
@twisted I have lost you :) can you give an example in code ? :)
Aristos
i don't have codes for this. it's about using your web browser visiting whatismyipaddress.com and www.whatismyipaddress.com with and without reverse proxy. Basically, perform 4 steps as follow: 1) visit whatismyipaddress.com without reverse proxy. 2) visit www.whatismyipaddress.com without proxy. 3) visit whatismyipaddress.com through a reverse proxy. 4) visit www.whatismyipaddress.com through a reverse proxy. before and after every step, pay close attention to the url in your web browser's address bar and also your ip address.
Twisted Whisper
@Twisted Still I can not think how to make all this working in real pages.
Aristos
Ssl will not protect you. ssl is a point to point security feature. This means that the asl will be decrypted at the reverse proxy. Then the rp can provide it's own ssl very for the spoofed domain if it wants or it can use plain http.
Mike
@Mike very good point.
Aristos
+1  A: 

If you were to do Authentication over SSL using https://, you can bypass the proxy in most cases.

You can also look for the X-Forwarded-For header in the incoming request and match it against the suspicious proxy.

Shoan
Trouble is, this only works if the proxy is not bespoke/malicious. If it's a custom proxy that's malicious, it's unlikely to follow best practice!
Paul Russell
A: 

Maybe create a black-list of URLs and compare requests with Response.Referer if the website is on that list then kill the request or do a redirection of your own.

The black-list is obviously something you would have to manually update.

Monkieboy
The Referer is the most easy to overwrite and change.
Aristos
I was clearly unaware that it was easy to achieve, thanks for pointing that out.
Monkieboy
+1  A: 

As I see it, your fundamental issue here is that whatever application layer defence measures you put in place to mitigate this attack can be worked around by the attacker, assuming this really is a malicious attack made by a competent adversary.

In my view, you should definitely be using HTTPS, which in principle would allow the user to confirm for sure whether they're talking to the right server, but this relies on the user knowing to check for this. Some browsers these days display extra information in the URL bar about which legal entity owns the SSL certificate, which would help, as it's unlikely an attacker would be able to persuade a legitimate certificate authority to issue a certificate in your name.

Some of the other comments here said that HTTPS can be intercepted by intermediate proxy servers, which is not actually true. With HTTPS, the client issues a CONNECT request to the proxy server, which tunnels all future traffic direct to the origin server, without being able to read any of it. If we assume that this proxy server is entirely bespoke and malicious, then it can terminate the SSL session and intercept the traffic, but it can only do that with its own SSL certificate, not with yours. This certificate will either be self signed (in which case clients will get lots of warning messages) or a genuine certificate issued by a certificate authority, in which case it'll have the wrong legal entity name, and you should be able to go back to the certificate authority, have the cert revoked and potentially ask the police to take action against the owner of the certificate, if you have reasonable suspicion that they are phishing.

The other thing I can think of which would mitigate this threat to some extent would be to implement one-time password functionality, either using a hardware/software token or using (my personal favorite) an SMS sent to the user's phone when they log in. This wouldn't prevent the attacker getting access to the session once, but should prevent them being able to log in in future. You could further protect the users by requiring another one time password before allowing them to see/edit particularly sensitive details.

Paul Russell