tags:

views:

321

answers:

6

I have a site running Classic-ASP and on the login page I would like to delay the response to a failed login attempt (by like 10 seconds) to help prevent brute force attacks on accounts.

Quick google searches show some hacks using SQL server queries that seem hack-tastic.

Is there a good way to do this in classic asp?

+1  A: 

There is no simple way to do so in pure ASP.
Either SQL WAITFOR, or create simple ActiveX component in VB (or anything) that sleeps.
Note that this will increase load on the server. Sleeping requests keep memory and connections consumed for nothing.

Dercsár
A: 

There is the Response.Buffer option that you can use to tell it to delay returning the response until the page has completed processing, so you could perhaps combine that with some kind of timeout in the script, but it would not be especially elegant especially as VBScript doesn't really offer you a way of asking threads to sleep so you can end up thrashing the CPU.

Maybe better to use a server-side session and javascript on the client, so the client delays the request and the server will only send the response after the expected delay is over. That should provide some server-side safeguards and be useable for users who aren't trying to mess around with your system...

glenatron
+1  A: 

There is another approach, but keep in mind the aforementioned caveats about unessecarily consumed resources. Here is an approach though

Sub DelayResponse(numberOfseconds)
 Dim WshShell
 Set WshShell=Server.CreateObject("WScript.Shell")
 WshShell.Run "waitfor /T " & numberOfSecond & "SignalThatWontHappen", , True
End Sub

Asa Yeamans
+1  A: 

There is the WScript.Sleep method for general purpose VBScript, however, this won't work in the context of ASP.

There are a number of other mechanisms you can use to achieve this, however, they're all effectively "workarounds" as there's no built-in way to cleanly cause an ASP page (running VBScript) to pause itself.

See here:

How do I make my ASP page pause or 'sleep'?

To specifically answer your question of:

Is there a good way to do this in classic asp?

No. There's no good way to do this, and there's only the "hack-tastic" hacks that can be used, however they bring with them all sorts of side-effects and caveats. (See the last part of the "How do I make my ASP page pause or 'sleep'?" link for a specific memory eating, page faulting nasty side-effect.)

CraigTP
+4  A: 

I am not going to answer your specific question, as many have already done so, but there are far better ways of preventing brute force attacks.

For instance:

  1. Why not lock a specific session or IP address out after say 5 (being generous here) failed login attempts? You could lock it out for say 10 minutes. You could even write a "401 Unauthorized" HTTP status and then simply end the response with Response.End.
  2. In a similar fashion, but not even linked to failed logins, you could block requests for the login page more than X times in Y seconds for a specific IP, UserAgent and other client features - ensuring kind of a 'unique' client.
  3. Ignore IP address (it is easily spoofed and can be a proxy server IP), and simply detect the automation of the login attempt. X number of failed logins within Y seconds for a specific username/email address, block it for that username for a set period of time, and end the response.

Just saying there are other options than putting unnecessary load on your server by locking some resources and waiting.

Obviously, doing this at the hardware layer - firewalls etc. would be the preferred option.

Wim Hollebrandse
There are certainly other approaches, the problem with IP based blocking is that often users at large corporations will appear to be coming from the same IP, so an IP based block might affect more people than desired. And source IP can simply be faked, rendering this method inert.
Bert Lamb
Yes, I am aware of that Bert, proxies and all that, and it can even be spoofed. However, brute force attacks tend to also use a specific username, for which they attempt logins, so X login attempts for user 'Admin' within Y seconds, just tell them to take a hike. Regardless of IP or anything. It's the repeated login attempts for the same username in a timespan that is clearly an automated web request, that identifies this. Modified my answer to reflect some of this.
Wim Hollebrandse
+1, Good Answer, although I'd use strong terms to disuade the delay response solution. A brute force attempt using a fresh session each time can be performed with many parallel requests hence such an attack can effectively become an unintended DOS attack.
AnthonyWJones
+1  A: 

Other approach to avoid brute force attacks without using IP restrictions is to offer a captcha after the second fail attempt for the same user. This is the way Google do it.

This is how Google does it

Eduardo Molteni