Welcome!

You will be redirected in 30 seconds or close now.

ColdFusion Authors: Yakov Fain, Jeremy Geelan, Maureen O'Gara, Nancy Y. Nee, Tad Anderson

Related Topics: ColdFusion

ColdFusion: Article

Defeating DoS Attacks

Defeating DoS Attacks

A denial-of-service (DoS) attack is an attempt by a single person or a group of people to disrupt an online service. It is designed to bring the server and network to its knees by flooding it with useless traffic. A DoS attack is the most common type of Internet attack and can be launched against your site at any time with relative ease. This can affect you by eating up your bandwidth and server resources to service these bogus requests while leaving no resources to fill legitimate requests.

So how do you know if you're being attacked? There are many variations of DoS attacks, and some are more difficult to catch than others. Some programs, such as the Apache Web server, have rearchitected their software to protect against this sort of attack. The method described here will allow you to catch and automatically defeat DoS attacks against your applications, regardless of the Web server used.

All you'll need to add to your database is a single table to keep track of active sessions (see Listing 1). You can decide whether to implement this on an application level or across the entire server, and decide which database makes sense for doing this tracking. Although there is a slight performance hit to enable this feature, you'll gain other relevant information on current site usage such as how many users are online, what page they're currently viewing, and how many total pages they've retrieved during the session.

Some may feel that we're creating a set of data for tracking sessions in a database that could just as well be created using ColdFusion's client variables. We'll discuss that alternative briefly in the conclusion.

We only need to make a couple of changes to our application to enable our DoS checking. First, in your application.cfm, we'll add code to check if a session already exists in our database. If it does, we'll update the lasthit timestamp as well as the last page and total pages viewed; otherwise we'll add a new record for this session (see Listing 2). We use a combination of CFID and CFTOKEN instead of URLTOKEN to keep things compatible with earlier versions of ColdFusion.

Now we have all of the current sessions for our site within a database. We'll take advantage of ColdFusion's built-in session management to help us detect attacks. Normally, ColdFusion will generate a new CFID and CFTOKEN for each individual browser that it encounters. Since many DoS attacks use an automated program and not a browser, ColdFusion ends up generating a new CFID and CFTOKEN for each request. Now we need a way to check for this.

We set up a scheduled script to run every 5 minutes and monitor our session table (you can modify the interval if necessary). Our check script (see Listing 3) first deletes any sessions from our database that are older than our specified session length (as defined in a CFAPPLICATION tag, which though not shown here, is 60 minutes in this case). We then count how many distinct URLTOKENs we have for each IP address. You should note that it is perfectly valid to have multiple sessions for a single IP if your users are sharing an Internet connection or going through a proxy server. Therefore, we'll set our threshold high enough (50) so that regular usage of the site will not be affected. You can modify this threshold as you see fit to make the check more or less sensitive. Finally, we create a list of any offending IP addresses and save this to an application variable.

You may wonder about locking the last line, assigning the application.DoS variable. While in CF5 it's always best to lock any reference to persisted variables, and in CFMX it's wise to do so to avoid "race conditions" when multiple users or sessions run code at the same time. In this case, however, this is a task that will be run only by the CF scheduler and then only once at a time.

The last thing you'll need to do in order to protect your site is to add some code at the top of your application.cfm to stop offending requests dead in their tracks (see Listing 4). Although we can't ignore these requests completely (as they've already made it through to our application), we can halt them right away so that we do not waste processing power or bandwidth.

We mentioned earlier that this process of tracking and analyzing sessions, while it has value beyond just this task, is partly already done for us if we enable CLIENTMANAGEMENT="yes" in our CFAPPLICATION tag. ColdFusion will then automatically write to a repository a set of fixed client variables similar to those we've set up (CFID, CFTOKEN, HitCount, LastVisit, TimeCreated, and URLToken). It will then update these values for each client that visits your application.

There are a couple of problems with using this data. First, CF doesn't automatically write the IP address for the visitor. You could easily add that one value by adding to your application.cfm the single line:

<CFSET client.ipaddress=cgi.remote_addr>

But even then, in order to process the data, you need to manage it in the location and format in which CF creates it. It writes these data either to a database or the registry, depending on the setting of the associated CLIENTSTORAGE attri-bute. If CLIENTSTORAGE="registry", or if it's not specified at all, CF will write these variables to the registry. CLIENTSTORAGE can also point to a database.

The problem is that the database approach creates tables (Cdata and CGLobal) and columns that are not easily parsed for our purposes. And while we could write CFREGISTRY tags to extract the data from the registry, it is challenging to then convert that to query-like data to be analyzed as we have. (If you want to explore it, the client data is written to the registry in HKEY_LOCAL_MACHINE\SOFTWARE\ Macromedia\ColdFusion\CurrentVersion\Clients).

DoS attacks are on the rise and growing exponentially each year. You need to protect yourself, or at least be aware of the damage that a DoS attack can do. If you have a Web page with 200K of graphics and data, calling that six or seven times a second will consume a full T1 of bandwidth. Hopefully most of you will only need this tag to keep track of users currently on your site, but for those having attack problems, this method will provide a self-correcting way to insulate your site from trouble.

More Stories By Joe Danziger

Joe Danziger is a senior web applications developer with Multimax, Inc., a provider of Enterprise IT Services and Solutions supporting the critical missions of the Air Force, Army, Navy, and other Department of Defense components. He is certified as an Advanced Macromedia ColdFusion MX Developer, and also maintains the Building Blocks site (www.ajaxcf.com) dedicated to AJAX and ColdFusion, as well as DJ Central (www.djcentral.com), a Website serving DJs and the electronic dance music industry.

Comments (2)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


IoT & Smart Cities Stories
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...
IoT is rapidly becoming mainstream as more and more investments are made into the platforms and technology. As this movement continues to expand and gain momentum it creates a massive wall of noise that can be difficult to sift through. Unfortunately, this inevitably makes IoT less approachable for people to get started with and can hamper efforts to integrate this key technology into your own portfolio. There are so many connected products already in place today with many hundreds more on the h...
The standardization of container runtimes and images has sparked the creation of an almost overwhelming number of new open source projects that build on and otherwise work with these specifications. Of course, there's Kubernetes, which orchestrates and manages collections of containers. It was one of the first and best-known examples of projects that make containers truly useful for production use. However, more recently, the container ecosystem has truly exploded. A service mesh like Istio addr...
Digital Transformation: Preparing Cloud & IoT Security for the Age of Artificial Intelligence. As automation and artificial intelligence (AI) power solution development and delivery, many businesses need to build backend cloud capabilities. Well-poised organizations, marketing smart devices with AI and BlockChain capabilities prepare to refine compliance and regulatory capabilities in 2018. Volumes of health, financial, technical and privacy data, along with tightening compliance requirements by...
Charles Araujo is an industry analyst, internationally recognized authority on the Digital Enterprise and author of The Quantum Age of IT: Why Everything You Know About IT is About to Change. As Principal Analyst with Intellyx, he writes, speaks and advises organizations on how to navigate through this time of disruption. He is also the founder of The Institute for Digital Transformation and a sought after keynote speaker. He has been a regular contributor to both InformationWeek and CIO Insight...
Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settlement products to hedge funds and investment banks. After, he co-founded a revenue cycle management company where he learned about Bitcoin and eventually Ethereal. Andrew's role at ConsenSys Enterprise is a mul...
To Really Work for Enterprises, MultiCloud Adoption Requires Far Better and Inclusive Cloud Monitoring and Cost Management … But How? Overwhelmingly, even as enterprises have adopted cloud computing and are expanding to multi-cloud computing, IT leaders remain concerned about how to monitor, manage and control costs across hybrid and multi-cloud deployments. It’s clear that traditional IT monitoring and management approaches, designed after all for on-premises data centers, are falling short in ...
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...
Dynatrace is an application performance management software company with products for the information technology departments and digital business owners of medium and large businesses. Building the Future of Monitoring with Artificial Intelligence. Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more busine...