on 19-Aug-2021 13:10
Well hello, there, community! If you don't follow the DevCentral Connects show, you should check us out, we're live every Thursday at 12:30 pacific. On today's show, we blitzed through some iRules fundamentals and introduced the following challenge.
Little Jimmy Packets has been captured while skiing at Keystone, Colorado by Bad Actor Bob, who has created several malicious clones of him and placed them around the globe, one each in Brazil, Australia, Egypt, and Germany, and Canada. Bad Actor Bob has also infected all other visitors from the numeric land of 172.16.2.0/23. The fine people of Celestial City are waiting for Jimmy Packets arrival, but you need to make sure that the gatekeeper, Mr BIG-IP, only allows the real Jimmy Packets in! Can you help?
Mr BIG-IP doesn’t have any idea how to differentiate the clones from the real thing. You need to equip him by uploading an iRule to his inspection engine to make sure he accurately carries out his duties as the gatekeeper of Celestial City.
I like to start with a sketch or drawing before I code to make sure I have the high level stuff worked out. Note that all the details of the challenge are not represented here.
There are many approaches you could take to this, but I tried to keep it fairly simple. I'll share the code first, then make some comments afterward.
when RULE_INIT { set static::countries [list AU BR CA DE EG] } when CLIENT_ACCEPTED { if { [IP::addr [IP::client_addr] equals 172.16.2.0/23] } { set numland_responder 1 } if { [active_members easy_street] >= 1 } { set ezstreet 1 } } when HTTP_REQUEST { # Shown here for purposes of the challenge, but welcome_wagon would be default # pool welcome_wagon if { [HTTP::host] ne "celestial-city.devcentral.test" } { set dom_responder 1 set subdomain [string range [HTTP::host] 0 [expr {[string first ".devcentral.test" [HTTP::host]] - 1 }]] } if { [string tolower [HTTP::header User-Agent]] contains "jimmy-packets"} { if { [lsearch -exact $static::countries [whereis [IP::client_addr] country]] != -1 } { set clone_responder 1 } if { [info exists ezstreet]} { pool easy_street } } # Response Handlers if { [info exists dom_responder] } { log local0. "Unauthorized: Wrong subdomain from [IP::client_addr]: $subdomain" HTTP::respond 401 content "You used the wrong domain, so you get NOTHING! YOU LOSE! GOOD DAY SIR!" } elseif { [info exists clone_responder] } { log local0. "Unauthorized: Clone from [whereis [IP::client_addr] country], IP: [IP::client_addr], UA: [HTTP::header User-Agent]" HTTP::respond 401 content "You are a clone and thus not welcome here. Take it up with Bad Actor Bob." } elseif { [info exists numland_responder] } { log local0. "Unauthorized: IP [IP::client_addr] matches numeric land infection zone" HTTP::respond 401 content "You are infected and thus not welcome here. Take it up with Bad Actor Bob." } }
I'm super rusty! I wrote the bones of this iRule before connecting to the BIG-IP and I can't tell you how many syntax errors I had. Use it or lose it, right? Ok, working through my solution...