This site is the archived OWASP Foundation Wiki and is no longer accepting Account Requests.
To view the new OWASP Foundation website, please visit https://owasp.org
Difference between revisions of "Top 10-2017 A1-Injection"
m (T.Gigler moved page Top 10 2017-A1-Injection to Top 10-2017 A1-Injection: OWASP Top 10-2017 Release) |
m (Editorial changes (fixed line feeds)) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{Top_10_2013:TopTemplate | {{Top_10_2013:TopTemplate | ||
− | |usenext= | + | |useprev=2017PrevLink |
+ | |prev={{Top_10:LanguageFile|text=top10|year=2017|language=en}} | ||
+ | |usenext=2017NextLink | ||
|next=A2-{{Top_10_2010:ByTheNumbers | |next=A2-{{Top_10_2010:ByTheNumbers | ||
− | + | |2 | |
− | + | |year=2017 | |
− | + | |language=en | |
− | + | }} | |
− | |||
|year=2017 | |year=2017 | ||
|language=en | |language=en | ||
}} | }} | ||
− | + | <!--- 2017 Injection ---> | |
{{Top_10_2010:SummaryTableHeaderBeginTemplate|year=2017|language=en}} | {{Top_10_2010:SummaryTableHeaderBeginTemplate|year=2017|language=en}} | ||
− | {{Top_10:SummaryTableTemplate|exploitability= | + | {{Top_10-2017:SummaryTableTemplate|exploitability=3 |prevalence=2 |detectability=3 |impact=3 |year=2017|language=en}} |
{{Top_10_2010:SummaryTableHeaderEndTemplate|year=2017}} | {{Top_10_2010:SummaryTableHeaderEndTemplate|year=2017}} | ||
− | + | <td colspan=2 {{Template:Top_10_2010:SummaryTableRowStyleTemplate|year=2017}}> | |
− | + | <!--- Threat Agent: ---> | |
− | < | + | Almost any source of data can be an injection vector, environment variables, parameters, external and internal web services, and all types of users. <u>[[Injection_Flaws|Injection flaws]]</u> occur when an attacker can send hostile data to an interpreter. </td> |
− | + | <td colspan=2 {{Template:Top_10_2010:SummaryTableRowStyleTemplate|year=2017}}> | |
− | + | <!--- Security Weakness: ---> | |
− | </td> | + | Injection flaws are very prevalent, particularly in legacy code. Injection vulnerabilities are often found in SQL, LDAP, XPath, or NoSQL queries, OS commands, XML parsers, SMTP headers, expression languages, and ORM queries.<br/>Injection flaws are easy to discover when examining code. Scanners and fuzzers can help attackers find injection flaws. </td> |
− | + | <td colspan=2 {{Template:Top_10_2010:SummaryTableRowStyleTemplate|year=2017}}> | |
− | + | <!--- Impacts: ---> | |
− | </td> | + | Injection can result in data loss, corruption, or disclosure to unauthorized parties, loss of accountability, or denial of access. Injection can sometimes lead to complete host takeover.<br/>The business impact depends on the needs of the application and data.</td> |
− | |||
− | |||
− | |||
− | </ | ||
− | |||
− | |||
− | </td> | ||
{{Top_10_2010:SummaryTableEndTemplate|year=2017}} | {{Top_10_2010:SummaryTableEndTemplate|year=2017}} | ||
− | {{Top_10:SubsectionTableBeginTemplate|type=main}} {{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection= | + | {{Top_10:SubsectionTableBeginTemplate|type=main}} |
− | + | {{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=isTheApplicationVulnerable|position=firstLeft|year=2017|language=en}} | |
− | + | An application is vulnerable to attack when: | |
− | + | * User-supplied data is not validated, filtered, or sanitized by the application. | |
− | + | * Dynamic queries or non-parameterized calls without context-aware escaping are used directly in the interpreter. | |
− | + | * Hostile data is used within object-relational mapping (ORM) search parameters to extract additional, sensitive records. | |
− | + | * Hostile data is directly used or concatenated, such that the SQL or command contains both structure and hostile data in dynamic queries, commands, or stored procedures. | |
− | + | * Some of the more common injections are SQL, NoSQL, OS command, Object Relational Mapping (ORM), LDAP, and Expression Language (EL) or Object Graph Navigation Library (OGNL) injection. The concept is identical among all interpreters. Source code review is the best method of detecting if applications are vulnerable to injections, closely followed by thorough automated testing of all parameters, headers, URL, cookies, JSON, SOAP, and XML data inputs. Organizations can include static source (<u>[[Source_Code_Analysis_Tools|SAST]]</u>) and dynamic application test (<u>[[:Category:Vulnerability_Scanning_Tools|DAST]]</u>) tools into the CI/CD pipeline to identify newly introduced injection flaws prior to production deployment. | |
− | |||
− | {{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection= | + | {{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=howToPrevent|position=right|year=2017|language=en}} |
− | < | + | Preventing injection requires keeping data separate from commands and queries. |
+ | * The preferred option is to use a safe API, which avoids the use of the interpreter entirely or provides a parameterized interface, or migrate to use Object Relational Mapping Tools (ORMs).<br/><b>Note</b>: Even when parameterized, stored procedures can still introduce SQL injection if PL/SQL or T-SQL concatenates queries and data, or executes hostile data with EXECUTE IMMEDIATE or exec(). | ||
+ | * Use positive or "whitelist" server-side input validation. This is not a complete defense as many applications require special characters, such as text areas or APIs for mobile applications. | ||
+ | * For any residual dynamic queries, escape special characters using the specific escape syntax for that interpreter.<br/><b>Note</b>: SQL structure such as table names, column names, and so on cannot be escaped, and thus user-supplied structure names are dangerous. This is a common issue in report-writing software. | ||
+ | * Use LIMIT and other SQL controls within queries to prevent mass disclosure of records in case of SQL injection. | ||
+ | {{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=exampleAttackScenarios|position=left|year=2017|language=en}} | ||
+ | <b>Scenario #1</b>: An application uses untrusted data in the construction of the following <span style="color:red;"><b><u>vulnerable</u></b></span> SQL call: | ||
{{Top_10_2010:ExampleBeginTemplate|year=2017}}<b><span style="color:red;"> | {{Top_10_2010:ExampleBeginTemplate|year=2017}}<b><span style="color:red;"> | ||
String query = "SELECT * FROM accounts WHERE custID='" + request.getParameter("id") + "'"; | String query = "SELECT * FROM accounts WHERE custID='" + request.getParameter("id") + "'"; | ||
− | |||
</span></b>{{Top_10_2010:ExampleEndTemplate}} | </span></b>{{Top_10_2010:ExampleEndTemplate}} | ||
− | + | <b>Scenario #2</b>: Similarly, an application’s blind trust in frameworks may result in queries that are still vulnerable, (e.g. Hibernate Query Language (HQL)): | |
− | < | ||
{{Top_10_2010:ExampleBeginTemplate|year=2017}}<b><span style="color:red;"> | {{Top_10_2010:ExampleBeginTemplate|year=2017}}<b><span style="color:red;"> | ||
Query HQLQuery = session.createQuery("FROM accounts | Query HQLQuery = session.createQuery("FROM accounts | ||
WHERE custID='" + request.getParameter("id") + "'");''' | WHERE custID='" + request.getParameter("id") + "'");''' | ||
− | |||
</span></b>{{Top_10_2010:ExampleEndTemplate}} | </span></b>{{Top_10_2010:ExampleEndTemplate}} | ||
− | In both cases, the attacker modifies the ‘id’ parameter value in | + | In both cases, the attacker modifies the ‘id’ parameter value in their browser to send: <span style="color:red;"><b>' or '1'='1</b></span>. For example: |
− | |||
{{Top_10_2010:ExampleBeginTemplate|year=2017}}<b><span style="color:red;"><nowiki> | {{Top_10_2010:ExampleBeginTemplate|year=2017}}<b><span style="color:red;"><nowiki> | ||
http://example.com/app/accountView?id=' or '1'='1 | http://example.com/app/accountView?id=' or '1'='1 | ||
</nowiki></span></b>{{Top_10_2010:ExampleEndTemplate}} | </nowiki></span></b>{{Top_10_2010:ExampleEndTemplate}} | ||
− | This changes the meaning of both queries to return all the records from the accounts table. | + | This changes the meaning of both queries to return all the records from the accounts table. More dangerous attacks could modify or delete data, or even invoke stored procedures. |
− | {{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=references|position=right | + | {{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=references|position=right|year=2017|language=en}} |
− | {{Top_10_2010:SubSubsectionOWASPReferencesTemplate}} | + | {{Top_10_2010:SubSubsectionOWASPReferencesTemplate|year=2017|language=en}} |
− | * <u>[[ | + | * <u>[[OWASP_Proactive_Controls#2:_Parameterize_Queries|OWASP Proactive Controls: Parameterize Queries]]</u> |
− | * <u>[[ | + | * <u>[[ASVS_V5_Input_validation_and_output_encoding|OWASP ASVS: V5 Input Validation and Encoding]]</u> |
− | * <u>[[ | + | * <u>[[Testing_for_SQL_Injection_(OTG-INPVAL-005)|OWASP Testing Guide: SQL Injection]]</u>, <u>[[Testing_for_Command_Injection_(OTG-INPVAL-013)|Command Injection]]</u>, <u>[[Testing_for_ORM_Injection_(OTG-INPVAL-007)|ORM injection]]</u> |
− | * <u>[[ | + | * <u>[[Injection_Prevention_Cheat_Sheet|OWASP Cheat Sheet: Injection Prevention]]</u> |
− | * <u>[[ | + | * <u>[[SQL_Injection_Prevention_Cheat_Sheet|OWASP Cheat Sheet: SQL Injection Prevention]]</u> |
+ | * <u>[[Injection_Prevention_Cheat_Sheet_in_Java|OWASP Cheat Sheet: Injection Prevention in Java]]</u> | ||
+ | * <u>[[Query_Parameterization_Cheat_Sheet|OWASP Cheat Sheet: Query Parameterization]]</u> | ||
+ | * <u>[[OWASP_Automated_Threats_to_Web_Applications|OWASP Automated Threats to Web Applications – OAT-014]]</u> | ||
− | {{Top_10_2010:SubSubsectionExternalReferencesTemplate}} | + | {{Top_10_2010:SubSubsectionExternalReferencesTemplate|year=2017|language=en}} |
− | * <u>[ | + | * <u>[https://cwe.mitre.org/data/definitions/77.html CWE-77: Command Injection]</u> |
− | * <u>[ | + | * <u>[https://cwe.mitre.org/data/definitions/89.html CWE-89: SQL Injection]</u> |
− | * <u>[ | + | * <u>[https://cwe.mitre.org/data/definitions/564.html CWE-564: Hibernate Injection]</u> |
− | * <u>[ | + | * <u>[https://cwe.mitre.org/data/definitions/917.html CWE-917: Expression Language Injection]</u> |
− | * <u>[ | + | * <u>[https://portswigger.net/kb/issues/00101080_serversidetemplateinjection PortSwigger: Server-side template injection]</u> |
{{Top_10_2013:BottomAdvancedTemplate | {{Top_10_2013:BottomAdvancedTemplate | ||
− | |type={{ | + | |type=box |
− | |usenext= | + | |useprev=2017PrevLink |
+ | |prev={{Top_10:LanguageFile|text=top10|year=2017|language=en}} | ||
+ | |usenext=2017NextLink | ||
|next=A2-{{Top_10_2010:ByTheNumbers | |next=A2-{{Top_10_2010:ByTheNumbers | ||
− | + | |2 | |
− | + | |year=2017 | |
− | + | |language=en | |
− | + | }} | |
− | |||
|year=2017 | |year=2017 | ||
|language=en | |language=en | ||
}} | }} | ||
+ | |||
+ | <!-- [[Category:OWASP Top Ten Project]] --> |
Latest revision as of 16:26, 1 January 2018
Threat Agents / Attack Vectors | Security Weakness | Impacts | |||
---|---|---|---|---|---|
App Specific | Exploitability: 3 |
Prevalence: 2 |
Detectability: 3 |
Technical: 3 |
Business ? |
Almost any source of data can be an injection vector, environment variables, parameters, external and internal web services, and all types of users. Injection flaws occur when an attacker can send hostile data to an interpreter. |
Injection flaws are very prevalent, particularly in legacy code. Injection vulnerabilities are often found in SQL, LDAP, XPath, or NoSQL queries, OS commands, XML parsers, SMTP headers, expression languages, and ORM queries. Injection flaws are easy to discover when examining code. Scanners and fuzzers can help attackers find injection flaws. |
Injection can result in data loss, corruption, or disclosure to unauthorized parties, loss of accountability, or denial of access. Injection can sometimes lead to complete host takeover. The business impact depends on the needs of the application and data. |
Is the Application Vulnerable?
An application is vulnerable to attack when:
|
How to Prevent
Preventing injection requires keeping data separate from commands and queries.
|
Example Attack Scenarios
Scenario #1: An application uses untrusted data in the construction of the following vulnerable SQL call: String query = "SELECT * FROM accounts WHERE custID='" + request.getParameter("id") + "'"; Scenario #2: Similarly, an application’s blind trust in frameworks may result in queries that are still vulnerable, (e.g. Hibernate Query Language (HQL)): Query HQLQuery = session.createQuery("FROM accounts WHERE custID='" + request.getParameter("id") + "'"); In both cases, the attacker modifies the ‘id’ parameter value in their browser to send: ' or '1'='1. For example:
http://example.com/app/accountView?id=' or '1'='1
This changes the meaning of both queries to return all the records from the accounts table. More dangerous attacks could modify or delete data, or even invoke stored procedures. |
References
OWASP
External |