How to get source of request in Asp?

Asked

Viewed 323 times

2

I need to do a certain action with a page that is in classic Asp.

What I need is get the origin of the request which is made on that page and depending on what the origin, I do something related to that request.

For example, if the request comes from the page itself on Asp, I let the flow run normally. But if the request has another origin(Postman and Burp suite do it) then I would treat the situation differently.

The intention is to take care of system security.

How can I capture the origin of this request on Asp?

2 answers

5


HTTP_REFERER does not guarantee any safety, it is very easy to overwrite and defraud the origin since it is a header.

The best to do in question to ensure the origin of the form could be using the reCAPTCHA

Also experiment techniques such as protection anti-CSRF (CSRF means Cross-Site Request Forgery), is not 100% efficient, but works better than HTTP_REFERER, an example of Soen (I just don’t know if md5 is really something necessary)

I think it would be something like:

  • All pages who receive a request or have a Form or an Ajax must (you can put in a global or a function):

    Function GetGUID()
    
        GetGUID = CreateObject("Scriptlet.TypeLib").GUID
    
    End Function
    
    Dim token
    
    ' Só atualiza o valor da sessão se não vier de um POST
    ' com `<input name=csrftoken>`
    If Request.Form("csrftoken") = "" Then
        token = md5(GetGUID())
        Session("token")=token
        Session("token_time")=Time()
    End If
    
  • On the page that receives the POST/request should have this:

    If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
        ' Compara o Form com a sessão
        If Request.Form("csrftoken") = Session("token") Then
            ' Executa o seu código aqui !!!
        End If
    End If
    
  • In the form you should also add the Session("token")

    <form method="post" action="pagina.asp">
        <input type="text" name="foo" placeholder="Exemplo">
        <input type="submit" value="submit">
        <input type="hidden" value="<%= Session("token") %>" name="csrftoken">
    </form>
    

It has been a long time since I work with classic Asp, if you have any typing error are free to fix them

How to Fool Referer and Origin

With Postman or Wget it is easy to fool the site, see just play it on the terminal (be for Linux, although it is possible to install on Windows):

wget 
--user-agent="Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0"
--header="Host: seusite.com"
--header="Origin: http://seusite.com"
--header="Referer: http://seusite.com/pasta/formulario.asp" 
--header="Connection: keep-alive"
--header="Accept-Language: en-US,en;q=0.5"
--post-data="campo1=foo&campo2=bar"
http://seusite.com/pasta/pagina.asp

Okay, I’ve tricked your system.

0

I believe what you need is referer = Request.ServerVariables ("HTTP_REFERER"), follows a link with all the options of Servervariables.

Just stating that the HTTP_REFERER does not work in all cases, if it comes from a redirect for example, it does not take this value.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.