Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to protect a web server FROM a reverse proxy server

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.

like image 984
Twisted Whisper Avatar asked Oct 10 '10 06:10

Twisted Whisper


People also ask

How do I stop reverse proxy?

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.

How secure is reverse proxy?

Are reverse proxies really secure? Adding a welcome layer of security, a reverse proxy is effective in protecting systems against web vulnerabilities. The reverse proxy sits between external clients and your internal services, preventing anyone from directly accessing your network.

Is a webserver a reverse proxy?

A web server listens for HTTP requests and reacts to them by sending back an HTTP response. A reverse proxy is a web server which determines what response to make by also implementing an HTTP client. Client A makes an HTTP request to the reverse proxy. The reverse proxy makes an HTTP request to Server B.


2 Answers

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.

like image 138
jmz Avatar answered Sep 21 '22 15:09

jmz


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.

like image 26
Twisted Whisper Avatar answered Sep 18 '22 15:09

Twisted Whisper