Contribute Open Script

[BRCD_OS_111] Passive Cookie Persistence

by Yasir_Liaqatullah on ‎01-20-2012 02:30 PM (26 Views)

Area

Content inspection

Traffic

HTTP

Description

            This script analyzes enables the ADX to persist on a cookie inserted by a real-server. The ADX analyzes the response and if it finds a pre-defined cookie, ServerID, it creates a session for this flow. The ADX also analyzes the requests coming-in and if it finds the same cookie, the value is extracted and hashed. This has is then used to find a corresponding sessions and the new request is sent to the same server. Thus, once a cookie is inserted by the real server, all subsequent requests having the same cookie will continue to go the same real server.

Performance Estimate

            Contact us for our detailed reporting

               or

            Report your own performance estimate

Required Backend configuration

            No special configuration is required

Events and API Used

Events

API

HTTP_REQUEST

OS_HTTP_REQUEST::cookie

OS_SLB::smileytongue:ersist

HTTP_RESPONSE

OS_HTTP_RESPONSE::cookie

Script source code

use OS_SLB;

use OS_HTTP_REQUEST;

use OS_HTTP_RESPONSE;

#############################################

#

# HTTP REQUEST EVENTS

#

#############################################

sub HTTP_REQUEST {

        #my $serverName = "NULL";

       # Get the Cookie from the request

       my $MyCookieValue =   OS_HTTP_REQUEST::cookie("ServerID");

       #print "\n\n\n **** my cookie is: $MyCookieValue\n";

        if ( defined $MyCookieValue ) {

             # forward to server based on   passive cookie persistence

              OS_SLB::smileytongue:ersist("passive-persist","$MyCookieValue");

        } else {

              OS_SLB::forward(10);

        }

}

sub HTTP_RESPONSE {

          $mySetCookieHeader =   OS_HTTP_RESPONSE::header("Set-Cookie");

          #print "\n\n\n %%% my set   cookie is: $mySetCookie\n";

          # Analyze response. If response has a set-cookie header, and with

          # a cookie name of ServerID, then create a persist session with

          # this information

          if ( $mySetCookieHeader =~   m/.*ServerID=(\d+).*/ ) {

               $CookieValue = $1;

               #print "\n\n\n %%% my Cookie   Value is: $CookieValue\n";

                 OS_SLB::smileytongue:assive_persist("add","$CookieValue");

          }

}

Comments
by noc32 on ‎02-06-2013 08:04 AM

Hello,

I understand this is for the sake of example, but wouldn't it be more efficient to use

OS_HTTP_RESPONSE::cookie instead of searching the headers with a regex ?

Cheers,

Clément Hermann