Forum Discussion

zak_thompson_86's avatar
zak_thompson_86
Icon for Nimbostratus rankNimbostratus
May 11, 2007

Brute Force Blocking script

hi guys, new to the forum we just picked up a 6800 since our old D25 couldn't handle capacity, Anywho we needed a better way to block brute force attacks.

So in CodeShare I found the DNS Flood prevention script.. well we turned it into a brute-force attack/reject script.

when RULE_INIT {
  set ::maxquery 50
  set ::holdtime 600
  set ::bantime 3600
  array set ::usertable { }
  array set ::blacklist { }
}
when HTTP_RESPONSE {
if { [HTTP::status] equals "401" } {
set currtime [clock second]
set srcip [IP::client_addr]
if { [ info exists ::blacklist($srcip) ] } { 
} else {
if { [ info exists ::usertable(freq,$srcip)] } {
incr ::usertable(freq,$srcip)
log local0.  "$srcip^$::usertable(firsthit,$srcip)^$::usertable(freq,$srcip)"
} else {
set ::usertable(freq,$srcip) 1
set ::usertable(time,$srcip) $currtime
set ::usertable(firsthit,$srcip) $currtime
}
}
} else { return } 
}
when HTTP_REQUEST {
set srcip [IP::client_addr]
set currtime [clock second]
if { [ info exists ::blacklist($srcip) ] } {
    
if { $::bantime > [expr ${currtime} - $::blacklist($srcip) ] } {
drop
     log local0.  "drop $srcip"
return    
} else {
unset ::blacklist($srcip)
log local0. "remove $srcip from blacklist"
}
}
if { [ info exists ::usertable(freq,$srcip)] } {
if { $::usertable(freq,$srcip) > $::maxquery } {
log local0. "new blacklist member <$srcip> with $::usertable(freq,$srcip) times"
set ::blacklist($srcip) $currtime
unset ::usertable(freq,$srcip)
unset ::usertable(time,$srcip)
unset ::usertable(firsthit,$srcip)
drop
return
}
}
}

Anything you guys could see as improvements/leaks etc? Cheers!

4 Replies

  • working like a charm! Though we disabled it while we debug/test some performance profiles for throughput, it was blocking a couple hundred ips a day, and these guys were on a 300 threshold in 5 minutes.
  • Hi everybody,

     

     

    sorry kicking up this old topic.

     

    But I want to use this script, but instead of using the http status as trigger I want to use a certain string in the response page that should start the 'count'... Which event,command... I could use best for this?

     

    Thanks...

     

  • You need to collect the data in

     

     

    "when HTTP_RESPONSE...." event

     

     

    using HTTP::collect method

     

     

    then search for your trigger string in "when HTTP_RESPONSE_DATA" event using HTTP::payload

     

     

     

    ---

     

    Sam