Posted by kiriro
Hi
I’d like to limit frequent dhcp discover from a specific client PC’s mac in thermal runaway. This dhcp client send huge DHCP discover.
I tried to apply “DHCP discover packet” to following rule, It’s famous irule sample used as traditional ddos protection, and I changed $srcip to $mac, for this reason, I want to catch “dchp client mac” inside dhcp relay agent(Source-ip is always same because of same dhcp relay agent).
Then, array as global variable cannot work.
I can catch client mac on dchp discover packet by using this aflex command.
binary scan [UDP::payload 28 6] H12H mac dammy
Could you please advice to this rule?
DDos protection irule =========================================== when RULE_INIT { set ::maxquery 100 set ::holdtime 600 set ::maxarraysize 400 array set ::usertable { } array set ::blacklist { } }
when CLIENT_ACCEPTED { set srcip [IP::remote_addr] set currtime [clock seconds] if { [info exists ::blacklist($srcip)] } { if { $::holdtime > [expr {$currtime - $::blacklist($srcip)}] } { #set ::blacklist($srcip) $currtime #log local0. “BL now [array get ::blacklist]” drop #log local0. “Drop $srcip” return } else { unset ::blacklist($srcip) #log local0. “remove $srcip from blacklist” } } if { [info exists ::usertable(time,$srcip)] and $currtime == $::usertable(time,$srcip) } { incr ::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) drop return } } else { set ::usertable(freq,$srcip) 1 set ::usertable(time,$srcip) $currtime #log local0. “New member <$srcip><$currtime>” } }
when CLIENT_CLOSED { if { [array size ::usertable] > $::maxarraysize } { set usertablelist [array get ::usertable] foreach { x y } $usertablelist { if { $x contains “time,” and $currtime ne $y } { set recip [string trimleft $x “time,”] unset ::usertable(time,$recip) unset ::usertable(freq,$recip) } } } #log local0. “Usertable is now [array get ::usertable]” } =============================================
Best Regards, Kiriro
– A10 NETWORKS CONFIDENTIAL: DO NOT DISTRIBUTE INTERNALLY OR EXTERNALLY