UNDERSTANDING OWASP TOP 10 SERIES

By Venkatesh Sundar, Chief Technology Officer, Indusface

sql_injection

Open Source Web Application Consortium releases its list of top 10 web vulnerabilities, every three years. Second time in a row, Injection flaws like SQL and LADP, have managed to keep their top position secure and have emerged as the worst web vulnerability. Injection flaws, such as SQL, OS, and LDAP injection occur when untrusted data is sent to an interpreter as part of a command or query. The attacker’s hostile data can trick the interpreter into executing unintended commands or accessing data without proper authorization.

Threat Agents Application Specific Consider anyone who can send untrusted data to the system, including external users, internal users, and administrators.
Attack Vectors Exploitability EASY Attacker sends simple text-based attacks that exploit the syntax of the targeted interpreter. Almost any source of data can be an injection vector, including internal sources
Security Weakness Prevalence COMMON Injection flaws occur when an application sends untrusted data to an interpreter.Injection flaws are very prevalent, particularly in legacy code, often found in:

  • SQL queries
  • LDAP queries
  • XPath queries
  • OS commands
  • Program arguments, etc.

Injection flaws are easy to discover when examining code, but more difficult via testing. Scanners and fuzzers can help attackers find them.

Detectability AVERAGE
Technical Impacts Impact SEVERE Injection can result in data loss or corruption, lack of accountability, or denial of access. Injection can sometimes lead to complete host takeover.
Business Impacts Application / Business Specific Consider the business value of the affected data and the platform running the interpreter. All data could be stolen, modified, or deleted. Could your reputation be harmed?
Source: OWASP

Following example will explain an injection attack scenario:

For www.vulnerable-bank.com, imagine a typical username and password login page. Let’s take an attacking example and how it works scenario.

Normal Scenario: username = author and password = author123

SQL Query:

SELECT * FROM AUTH_TABLE WHERE user =‘author’ and passw = ‘author123’

Attacking Scenario: username = author and password = ‘ or ‘1’=’1

SQL Query:

SELECT * FROM AUTH_TABLE WHERE user =‘author’ and passw = ‘ ‘ or ‘1’=’1’

The above line says, password equals to null or 1=1 (which is universal truth), so the attacker modifies logical AND to logical OR.

The best way to find out if an application is vulnerable to injection is to verify that all use of interpreters clearly separates untrusted data from the command or query. For SQL calls, this means using bind variables in all prepared statements and stored procedures, and avoiding dynamic queries.

Checking the code is a fast and accurate way to see if the application uses interpreters safely. Code analysis tools can help a security analyst find the use of interpreters and trace the data flow through the application. Manual penetration testers can confirm these issues by crafting exploits that confirm the vulnerability.

Automated dynamic scanning which exercises the application may provide insight into whether some exploitable injection problems exist. Scanners cannot always reach interpreters and can have difficulty detecting whether an attack was successful.

How to prevent injections like SQL:

 

Preventing injection requires keeping untrusted data separate from commands and queries.

  1. The preferred option is to use a safe API which avoids the use of the interpreter entirely or provides a parameterized interface. Beware of APIs, such as stored procedures, that appear parameterized, but may still allow injection under the hood.
  2. If a parameterized API is not available, you should carefully escape special characters using the specific escape syntax for that interpreter. OWASP’s ESAPI has some of these escaping routines.
  3. Positive or “whitelist” input validation with appropriate canonicalization also helps protect against injection, but is not a complete defense as many applications require special characters in their input. OWASP’s ESAPI has an extensible library of white list input validation routines.

Here are some recommended best practices to prevent injection exploits:

  1. Make white box testing and secure code review an integral part of the development cycle.
  2. Manual penetration testing should be part of the QA cycle.
  3. Automated along with periodic manual checks should be part of the operations process after deployment to keep up with new vulnerabilities and the automated scanning can help perform basic security sanity checks. It is very common to have injection issues introduced even with minor code changes as such changes may not be subjected to a fully fledged security review process in the development cycle.
  4. In situations where fixing the code of detected vulnerabilities cannot be done in a timely manner a WAF can be used for virtual patching after deployment
Founder & Chief Marketing Officer, Indusface

Venky has played multiple roles within Indusface for the past 6 years. Prior to this, as the CTO @indusface, Venky built the product/service offering and technology team from scratch, and grew it from ideation to getting initial customers with a proven/validated business model poised for scale. Before joining Indusface, Venky had 10+ years of experience in security industry and had held various mgmt/leadership roles in Product Development, Professional Services and Sales @Entrust.