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
After years of investments and acquisitions, CloudBlue was created with the goal of building the world's only hyperscale digital platform with an increasingly infinite ecosystem and proven go-to-market services. The result? An unmatched platform that helps customers streamline cloud operations, save time and money, and revolutionize their businesses overnight. Today, the platform operates in more than 45 countries and powers more than 200 of the world's largest cloud marketplaces, managing mo...
BMC has unmatched experience in IT management, supporting 92 of the Forbes Global 100, and earning recognition as an ITSM Gartner Magic Quadrant Leader for five years running. Our solutions offer speed, agility, and efficiency to tackle business challenges in the areas of service management, automation, operations, and the mainframe.
The platform combines the strengths of Singtel's extensive, intelligent network capabilities with Microsoft's cloud expertise to create a unique solution that sets new standards for IoT applications," said Mr Diomedes Kastanis, Head of IoT at Singtel. "Our solution provides speed, transparency and flexibility, paving the way for a more pervasive use of IoT to accelerate enterprises' digitalisation efforts. AI-powered intelligent connectivity over Microsoft Azure will be the fastest connected pat...
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. 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 throug...
Apptio fuels digital business transformation. Technology leaders use Apptio's machine learning to analyze and plan their technology spend so they can invest in products that increase the speed of business and deliver innovation. With Apptio, they translate raw costs, utilization, and billing data into business-centric views that help their organization optimize spending, plan strategically, and drive digital strategy that funds growth of the business. Technology leaders can gather instant recomm...
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. 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 throug...
As you know, enterprise IT conversation over the past year have often centered upon the open-source Kubernetes container orchestration system. In fact, Kubernetes has emerged as the key technology -- and even primary platform -- of cloud migrations for a wide variety of organizations. Kubernetes is critical to forward-looking enterprises that continue to push their IT infrastructures toward maximum functionality, scalability, and flexibility. As they do so, IT professionals are also embr...
CloudEXPO has been the M&A capital for Cloud companies for more than a decade with memorable acquisition news stories which came out of CloudEXPO expo floor. DevOpsSUMMIT New York faculty member Greg Bledsoe shared his views on IBM's Red Hat acquisition live from NASDAQ floor. Acquisition news was announced during CloudEXPO New York which took place November 12-13, 2019 in New York City.
In an age of borderless networks, security for the cloud and security for the corporate network can no longer be separated. Security teams are now presented with the challenge of monitoring and controlling access to these cloud environments, at the same time that developers quickly spin up new cloud instances and executives push forwards new initiatives. The vulnerabilities created by migration to the cloud, such as misconfigurations and compromised credentials, require that security teams t...
The graph represents a network of 1,329 Twitter users whose recent tweets contained "#DevOps", or who were replied to or mentioned in those tweets, taken from a data set limited to a maximum of 18,000 tweets. The network was obtained from Twitter on Thursday, 10 January 2019 at 23:50 UTC. The tweets in the network were tweeted over the 7-hour, 6-minute period from Thursday, 10 January 2019 at 16:29 UTC to Thursday, 10 January 2019 at 23:36 UTC. Additional tweets that were mentioned in this...