| http://www.devx.com | Printed from http://www.devx.com/security/Article/20678/1954 |
|
Banish Security Blunders with an Error-prevention Process
Traditionally, application security is an afterthoughtwe build our apps and try to poke holes in them later. Why not take potential security breaches into account from the very beginning? The Automated Error Prevention Methodology provides a framework you can use to integrate security concerns into your app development right from the start.
by
Dr. Adam Kolawa
|
|
ecurity can be a complex and often overwhelming issue. To ensure application security, not only must you prevent hackers from entering the system, but you need code in place that safeguards security should those preventive measures fail. There is no room for error. You can anticipate and prevent hundreds of security vulnerabilities, but if you overlook just one vulnerability, a hacker can wreak total havoc on your system.
These are the three most commonly exploited internal software weaknesses:
A New Security Supplement
Introduction to AEP These are its five main principles:
For more details about the AEP Methodology, including a blueprint for how to apply its five key principles to your own development group, see the AEP section of the Parasoft Website.
|
| Security Problem #1: SQL Injection Vulnerabilities One security breach opens when SQL statements are dynamically created as software executes. If a hacker is able to pass fixed inputs into the SQL statement, the inputs can become part of the SQL statement. This technique can be used to gain access to privileged data, login to password-protected areas without a proper login, remove database tables, add new entries to the database, or even login to an application with administrator privileges. The traditional attempt to avoid this problem is to validate all user inputs, but there is a way to prevent these attacks altogether.
Typically, this best practice implemented as a two-stage process. In the first stage, you build and parse your SQL statements with variables in place of the expected user inputs. Next, before the statement is passed to the database, replace your variables with the user inputs. Make sure that your user inputs are never parsed as the actual SQL statementthis renders even malicious user inputs ineffective. For instance, in Java, a secure way to build SQL statements is to construct all queries with PreparedStatement instead of Statement and/or to use parameterized stored procedures. Parameterized stored procedures are compiled before user input is added, making it impossible for a hacker to modify the actual SQL statement. When PreparedStatement is used, most JDBC drivers will prepare a statement with the server, and then supply the parameters separately. In either case, after the initial parsing, there is a clear distinction between the SQL statement and the variable. The variables are encapsulated and special characters within them are automatically escaped in a manner suited to the target database. Consequently, it is impossible for a hacker to pass malicious input and have it treated as if it were the actual SQL statement— which is necessary if the hacker is going to succeed with SQL injection attacks.
Even if you use PreparedStatement, you still need to pay attention to the way in which you build arguments. All parameters should be inserted through the appropriate JDBC calls. If you concatenate the SQL sentence and omit the JDBC calls, then an attempted SQL injection could be parsed as SQL, and the hacker could succeed.
Implementing SQL Injection Best Practices For instance, for Java applications, you would enforce the AEP coding standard and analyze the code that is responsible for forming the SQL statements, and then verify that if you build SQL for JDBC, you always use PreparedStatement. You could also verify whether all available PreparedStatements are built properly (with all parameters inserted through appropriate JDBC calls, rather than string concatenation). Moreover, to determine whether SQL statements are being built in the recommended two-step process, you could watch database calls as the application is being tested and determine if statements are always being constructed in a safe manner.
|
| Security Problem #2: Buffer Overflow Vulnerabilities Buffer overflows are a standard problem that affect C/C++ applications all too often. Buffer overflow attacks occur when a hacker manages to pass an input through all the program's built-in defenses and write to the buffer. It is only possible when the hacker is able to find and exploit a memory corruption bug in the application. For example, assume that your C++ application has an array or a memory chunk on the stack, and a memory issue makes it possible to write beyond the size of the array or memory chunk, and overwrite the return address of the function. The hacker can exploit this weakness so that the function returns to a hacker-designated function, or so that the function executes a hacker-designated operation. In fact, some recently-discovered buffer overflows in major operating systems give hackers license to perform a variety of malicious actions, such as causing the system to fail, installing programs, viewing, changing, and deleting data, modifying any part of the system, and creating accounts with full privileges.
Developers traditionally try to handle buffer overflow exploits by limiting the size of the input or by verifying the input. However, it's easy to miss cases if you have no procedure for identifying all the inputs which need to be checked. To actually remove the opportunity for these attacks, you need ensure that memory corruption bugs do not occur in the released or deployed version of your software.
Implementing Buffer Overflow Best Practices
|
| Security Problem #3: Uncaught Runtime Exception Vulnerabilities It is true that languages such as Java and .NET (managed C/C++) do not have a problem with buffer overflows. However, these languages suffer from a different problem that is just as serious: uncaught runtime exceptions. Typical checked exceptions provide a relatively easy way to transfer flow and keep a program running when exceptional situations occur. However, unchecked runtime exceptions— exceptions that are automatically thrown by the runtime system when a program violates the language syntax/semantics— are usually an indication of software bugs. They typically stem from problems related to arithmetic, pointers, and indexing, and can occur at any point in a program. If these exceptions surface in the field, the resulting unexpected flow transfer and potential thread termination could lead to instability, unexpected results, or even crashes or security breaches. For example, a very simple NullPointerException in login code could allow a hacker to completely bypass the login procedure.
The only real way to prevent uncaught runtime exception security vulnerabilities is to identify all possible uncaught runtime exceptions early in the development lifecycle, then examine and modify the code to ensure that it does not provide any opportunities for hackers.
Implementing Uncaught Runtime Exception Best Practices
The Key to Success
Dr. Adam Kolawa is the Chairman/CEO of Parasoft, which he cofounded with a group of fellow CalTech graduate students in 1987. Kolawa's years of experience with various software development processes has resulted in his unique insight into the high-tech industry and the ability to successfully identify technology trends. He can be reached at ak@parasoft.com.
|
| DevX is a division of Jupitermedia Corporation © Copyright 2007 Jupitermedia Corporation. All Rights Reserved. Legal Notices |