SYS-CON MEDIA Authors: Zakia Bouachraoui, Liz McMillan, Yeshim Deniz, Elizabeth White, William Schmarzo

Blog Feed Post

20 Lines or Less #53: Security, Security & more Security

What could you do with your code in 20 Lines or Less? That's the question I ask (sometimes?) every week for the DevCentral community, and every week I go looking to find cool new examples that show just how flexible and powerful iRules can be without getting in over your head.

This week we've got three awesome examples of iRules that are designed to increase your application's security in less than 21 lines of code. Dealing with header size, cache control, and a Microsoft advisory, we get to see a couple of different ways in which iRules can save the day. This isn't a new theme. iRules can be an amazingly powerful security resource in the hands of someone with the security mindset to be aware of what is going on, and the F5/iRules knowledge to craft the solutions necessary to put in place the preventative measures necessary to thwart incoming attacks.

Preventing Overzealous Headers

http://bit.ly/wZHvRC

To work around a recently released bug that allowed attackers to exploit excess parameters in an HTTP request, Aaron whipped up an iRule to count the parameters. User Wizdem had an excellent start, looking through the payload, but Aaron and Jason teamed up to make it more efficient and expanding it to look through the query string as well. If either of these have more than 100 parameters, it drops the request, assuming it to be an attack. Given that most requests shouldn't have anywhere near 100 parameters, that should be a pretty safe assumption, but your mileage may vary, as always. A very slick look at an iRule protecting against a known attack in a short period of time with only a few lines of code. This one looks longer than it is. Take out white space, comments, and log lines and you end up at 20. Honest.

   1: when HTTP_REQUEST {
   2:  
   3:     # Check if the query string contains more than 100 parameters
   4:     if { [llength [split [HTTP::query] &]] > 100 } {
   5:         log local0.alert "Microsoft Security Advisory (2659883)\
   6:             IP Address [IP::client_addr]:[TCP::client_port] requested [HTTP::uri]"
   7:  
   8:         # Drop the request
   9:         drop
  10:         return
  11:     }
  12:     
  13:     # Collect up to 1Mb of POST data
  14:     if { [HTTP::method] equals "POST"}{ 
  15:         set clength 0
  16:     if {[HTTP::header "Content-Length"] ne "" && [HTTP::header "Content-Length"] <= 1048576 && [HTTP::header "Content-Length"] > 0}{ 
  17:            set clength [HTTP::header Content-Length]
  18:         } else { 
  19:             set clength 1048576 
  20:         }
  21:         HTTP::collect $clength
  22:     }
  23: }
  24:  
  25: when HTTP_REQUEST_DATA {
  26:  
  27:     # Check if the collected payload contains more than 100 parameters
  28:     if { [llength [split [HTTP::payload] &]] > 100 } {
  29:         log local0.alert "Microsoft Security Advisory (2659883)\
  30:             IP Address [IP::client_addr]:[TCP::client_port] requested [HTTP::uri]"
  31:  
  32:         # Drop the request
  33:         drop
  34:     }
  35: }

Header Size Restrictions

http://bit.ly/zOI2wZ

Similar yet different, in this snippet the size of each header is inspected to ensure it is not over 1000 characters. While this is not necessarily a malicious attack it was causing problems for the OP in the thread, and Aaron was kind enough to lend an updated version to log the header lengths as they come through, since this thread was brought back up recently. In this incarnation the rule is only logging but it would be trivial to modify it to drop requests as necessary if you experience a particular client attempting to send through egregiously large headers in an attempt to cause problems.

   1: when HTTP_REQUEST {
   2:  
   3:     # Check the total HTTP headers size
   4:     if {[string length [HTTP::request]] > 10000 }{
   5:  
   6:         # Loop through the headers by name
   7:         foreach header {[HTTP::header names]} { 
   8:  
   9:             # Check for a long header value
  10:             if {[string length [HTTP::header value $header]] > 1000 } { 
  11:                 log local0. "Header is long. Header Name: $header,\
  12:                     Length: [string length [HTTP::header value $header]], Value: [HTTP::header value $header]" 
  13:             }
  14:         }
  15:     }
  16: }

No-Cache ... For Real

http://bit.ly/wEiAK3

In this post user Joanna shares the problem she's facing with us

"The problem is that Google Chrome will cache, in the current sessions memory only,  responses which have had the no-cache directive applied.  This means that after a user logs out of an application and walks away,  another user can come up to the computer,  press the back arrow and potentially see private information.  The way round this is to use the no-store directive with a couple of other headers thrown in for good measure. "

That is less than optimal...a browser that refuses to respect no-cache headers for secure pages. I'm not sure in what environments or across which versions this applies, but having a fix readily available is a good thing. Fortunately Joanna was kind enough to provide exactly that. With this simple iRule she was able to more firmly enforce her caching directives and create a more secure application in the process.

   1: when HTTP_RESPONSE {
   2:     # The purpose of this iRule event processing is to force no-store so that browsers will not store this content
   3:     # which would enable users to hit the 'back' button,  even after a logout,  and potentially see customer PII
   4:  
   5:   
   6:     if {[HTTP::header Content-Type] contains "html"} {
   7:         HTTP::header insert Pragma "no-cache"
   8:         HTTP::header insert Expires "Fri, 01 Jan 1990 00:00:00 GMT"
   9:        HTTP::header replace Cache-Control "no-cache,no-store,must-revalidate"
  10:     }
  11: }

There you have it, <= 60 lines of code to help make your iRuling life better, more interesting and in this case more secure, too. More iRules goodness is sure to follow in coming weeks.

#Colin

Read the original blog entry...

More Stories By Colin Walker

Coming from a *Nix Software Engineering background, Colin is no stranger to long hours of coding, testing and deployment. His personal experiences such as on-stage performance and the like have helped to foster the evangelist in him. These days he splits his time between coding, technical writing and evangalism. He can be found on the road to just about anywhere to preach the good word about ADCs, Application Aware networking, Network Side Scripting and geekery in general to anyone that will listen.

Colin currently helps manage and maintain DevCentral (http://devcentral.f5.com). He is also a contributor in many ways, from Articles to Videos to numerous forum posts, to iRules coding and whatever else he can get his hands on that might benefit the community and allow it to continue to grow.

Latest Stories
The digital transformation is real! To adapt, IT professionals need to transform their own skillset to become more multi-dimensional by gaining both depth and breadth of a wide variety of knowledge and competencies. Historically, while IT has been built on a foundation of specialty (or "I" shaped) silos, the DevOps principle of "shifting left" is opening up opportunities for developers, operational staff, security and others to grow their skills portfolio, advance their careers and become "T"-sh...
In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high demand using interactive visualizations and salary indicator tools to maximize earning potential. Manish Dixit is VP of Product and Engineering at Dice. As the leader of the Product, Engineering and Data Sciences team at D...
Despite being the market leader, we recognized the need to transform and reinvent our business at Dynatrace, before someone else disrupted the market. Over the course of three years, we changed everything - our technology, our culture and our brand image. In this session we'll discuss how we navigated through our own innovator's dilemma, and share takeaways from our experience that you can apply to your own organization.
Having been in the web hosting industry since 2002, dhosting has gained a great deal of experience while working on a wide range of projects. This experience has enabled the company to develop our amazing new product, which they are now excited to present! Among dHosting's greatest achievements, they can include the development of their own hosting panel, the building of their fully redundant server system, and the creation of dhHosting's unique product, Dynamic Edge.
Cloud Storage 2.0 has brought many innovations, including the availability of cloud storage services that are less expensive and much faster than previous generations of cloud storage. Cloud Storage 2.0 has also delivered new and faster methods for migrating your premises storage environment to the cloud and the concept of multi-cloud. This session will provide technical details on Cloud Storage 2.0 and the methods used to efficiently migrate from premises-to-cloud storage. This session will als...
DXWorldEXPO LLC announced today that Nutanix has been named "Platinum Sponsor" of CloudEXPO | DevOpsSUMMIT | DXWorldEXPO New York, which will take place November 12-13, 2018 in New York City. Nutanix makes infrastructure invisible, elevating IT to focus on the applications and services that power their business. The Nutanix Enterprise Cloud Platform blends web-scale engineering and consumer-grade design to natively converge server, storage, virtualization and networking into a resilient, softwar...
The Transparent Cloud-computing Consortium (T-Cloud) is a neutral organization for researching new computing models and business opportunities in IoT era. In his session, Ikuo Nakagawa, Co-Founder and Board Member at Transparent Cloud Computing Consortium, will introduce the big change toward the "connected-economy" in the digital age. He'll introduce and describe some leading-edge business cases from his original points of view, and discuss models & strategies in the connected-economy. Nowad...
For far too long technology teams have lived in siloes. Not only physical siloes, but cultural siloes pushed by competing objectives. This includes informational siloes where business users require one set of data and tech teams require different data. DevOps intends to bridge these gaps to make tech driven operations more aligned and efficient.
All in Mobile is a mobile app agency that helps enterprise companies and next generation startups build the future of digital. We offer mobile development and design for smartphones, tablets and wearables. Our projects cover the latest and most innovative technologies - voice assistants, AI, AR/VR and more. We excel at solutions for sports, fintech and retail industries.
NanoVMs is the only production ready unikernel infrastructure solution on the market today. Unikernels prevent server intrusions by isolating applications to one virtual machine with no users, no shells and no way to run other programs on them. Unikernels run faster and are lighter than even docker containers.
The dream is universal: heuristic driven, global business operations without interruption so that nobody has to wake up at 4am to solve a problem. Building upon Nutanix Acropolis software defined storage, virtualization, and networking platform, Mark will demonstrate business lifecycle automation with freedom of choice and consumption models. Hybrid cloud applications and operations are controllable by the Nutanix Prism control plane with Calm automation, which can weave together the following: ...
CloudEXPO | DevOpsSUMMIT | DXWorldEXPO Silicon Valley 2019 will cover all of these tools, with the most comprehensive program and with 222 rockstar speakers throughout our industry presenting 22 Keynotes and General Sessions, 250 Breakout Sessions along 10 Tracks, as well as our signature Power Panels. Our Expo Floor will bring together the leading global 200 companies throughout the world of Cloud Computing, DevOps, IoT, Smart Cities, FinTech, Digital Transformation, and all they entail. As ...
Darktrace is the world's leading AI company for cyber security. Created by mathematicians from the University of Cambridge, Darktrace's Enterprise Immune System is the first non-consumer application of machine learning to work at scale, across all network types, from physical, virtualized, and cloud, through to IoT and industrial control systems. Installed as a self-configuring cyber defense platform, Darktrace continuously learns what is ‘normal' for all devices and users, updating its understa...
Digital Transformation (DX) is a major focus with the introduction of DXWorldEXPO within the program. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throughout enterprises of all sizes. We are offering early bird savings...
Crosscode Panoptics Automated Enterprise Architecture Software. Application Discovery and Dependency Mapping. Automatically generate a powerful enterprise-wide map of your organization's IT assets down to the code level. Enterprise Impact Assessment. Automatically analyze the impact, to every asset in the enterprise down to the code level. Automated IT Governance Software. Create rules and alerts based on code level insights, including security issues, to automate governance. Enterpr...