VOOZH about

URL: https://www.geeksforgeeks.org/ethical-hacking/injection-in-owasp-top-10/

⇱ Injection in OWASP Top 10 - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Injection in OWASP Top 10

Last Updated : 6 Jun, 2026

Injection is a major security risk in the OWASP Top 10. It occurs when untrusted user input is passed to interpreters like SQL databases, operating system shells, LDAP services or browsers without proper validation. Attackers can manipulate queries or commands to access unauthorized data, execute malicious code or compromise systems.

  • Injection occurs when user input is executed as code or commands.
  • Common types include SQL injection, Command Injection, LDAP Injection and Cross-Site Scripting (XSS).
  • Concatenating user input directly into queries is a primary cause.
  • Impacts include data theft, authentication bypass, remote code execution and service disruption.
  • Prevention methods include parameterized queries, input validation and secure coding practices.

Understanding Injection Vulnerabilities

Injection vulnerabilities occur when applications fail to properly separate user-supplied data from executable commands or queries. Attackers exploit this weakness by inserting malicious input that changes the intended behavior of the application.

For example, if a web application directly inserts user input into a SQL query, an attacker may modify the query logic and gain unauthorized access to the database.

Injection attacks target interpreters such as:

  • SQL databases
  • Operating system shells
  • LDAP directories
  • XML parsers
  • Web browsers

Common Causes of Injection Vulnerabilities

1. Lack of Input Validation

Applications often fail to properly validate or sanitize user input before processing it. This allows attackers to inject unexpected or malicious data that can change application behavior.

  • Enables insertion of special characters or commands
  • Can lead to SQL or command manipulation
  • Breaks assumptions about trusted input

2. Dynamic Query Construction

User input is directly concatenated into SQL queries or system commands without separation. This makes it possible for attackers to alter the logic of the original query.

  • Allows query structure manipulation
  • Can bypass authentication checks
  • Increases risk of SQL injection attacks

Vulnerable Example:

SELECT * FROM users WHERE username = 'admin' AND password = '1234';

3. Absence of Parameterized Queries

Developers fail to use prepared statements or parameterized queries when interacting with databases. As a result, the system cannot distinguish between code and user input.

  • User input treated as executable code
  • Increases risk of SQL injection
  • Prevents safe query separation

4. Poor Error Handling

Applications expose detailed error messages from databases or servers to end users. Attackers can use this information to understand system structure.

  • Reveals database schema or query structure
  • Helps in crafting targeted attacks
  • Exposes internal system details

5. Insecure API and Backend Processing

APIs and backend services process user-controlled input without proper validation or filtering. This increases the attack surface for injection vulnerabilities.

  • Accepts untrusted input directly
  • Weak or missing input sanitization
  • Enables injection through API endpoints

Types of Injection Attacks

1. SQL Injection (SQLi)

SQL Injection occurs when attackers manipulate SQL queries by injecting malicious SQL statements through input fields.

Example Payload:

' OR '1'='1

This payload may force the authentication condition to always evaluate as true.

Possible Impact:

  • Unauthorized database access
  • Data theft
  • Authentication bypass
  • Data modification or deletion

2. Command Injection

Command Injection occurs when user input is executed as part of an operating system command.

Vulnerable Command:

ping 127.0.0.1

Malicious Input:

127.0.0.1; cat /etc/passwd

The server may execute both commands, exposing sensitive system files.

Possible Impact:

  • Remote command execution
  • Full server compromise
  • File access and deletion

3. LDAP Injection

LDAP Injection targets applications that use LDAP queries for directory services and authentication. Attackers manipulate LDAP filters to bypass authentication or retrieve unauthorized directory information.

Possible Impact:

  • Unauthorized access
  • Information disclosure
  • Directory manipulation

4. Cross-Site Scripting (XSS)

Cross-Site Scripting occurs when malicious scripts are injected into web pages viewed by other users.

Malicious Input:

<script>alert('Hacked')</script>

When another user loads the page, the script executes in their browser.

Possible Impact:

  • Session hijacking
  • Cookie theft
  • User impersonation
  • Malicious redirects

5. Blind Injection

Blind Injection occurs when applications do not display error messages directly. Attackers infer information by analyzing application behavior, response times, or output differences.

Possible Impact:

  • Database enumeration
  • Information disclosure
  • Stealthy exploitation

Techniques Used to Exploit Injection Vulnerabilities

Attackers typically target input fields, API parameters, HTTP headers, cookies and backend processing systems.

Common Exploitation Techniques

  • Inserting special characters such as ', ", -- and ;
  • Manipulating query logic
  • Appending operating system commands
  • Injecting malicious scripts into web pages
  • Using automated exploitation tools such as SQLMap

Real-World Examples of Injection

Example 1: SQL Injection Login Bypass

An attacker enters the following payload into a login form:

' OR '1'='1

The manipulated query may bypass authentication and grant unauthorized access.

Example 2: Command Injection

An attacker appends additional operating system commands to a vulnerable input field.

127.0.0.1; cat /etc/passwd

This may expose sensitive server files.

Example 3: Stored XSS

An attacker stores a malicious script in a comment field.

<script>alert('Hacked')</script>

The script executes whenever other users access the page.

Impact of Injection

Injection vulnerabilities can cause severe technical and business damage. They impact both system security and organizational operations.

Security Impact

Injection attacks directly compromise the confidentiality, integrity and availability of systems and data.

  • Unauthorized Data Access: Attackers retrieve sensitive records from databases.
  • Authentication Bypass: Login mechanisms are defeated, allowing unauthorized access.
  • Data Modification or Deletion: Critical database records can be altered or wiped.
  • Remote Code Execution: Attackers execute system-level commands on the server.

Business Impact

Beyond technical harm, injection vulnerabilities create serious legal, financial and reputational consequences for organizations.

  • Compliance Violations: Breaches may violate standards such as GDPR and PCI-DSS.
  • Reputation & Financial Loss: Leads to loss of trust, lawsuits and regulatory fines.
  • Service Disruption: Can interrupt operations and affect business continuity.

Prevention of Injection Attacks

Injection attacks can be prevented by following secure coding practices and enforcing strict input handling and access controls.

1. Use Parameterized Queries

Use prepared statements to separate user input from SQL code.

  • Prevents code execution through input
  • Ensures input is treated as data only
  • Reduces SQL injection risk

Example:

SELECT * FROM users WHERE username = ? AND password = ?;

2. Validate and Sanitize Input

Ensure all user input is checked against expected formats using allowlists.

  • Rejects invalid or malicious input
  • Enforces correct data formats
  • Reduces injection opportunities

3. Avoid Dynamic Query Construction

Do not build queries or system commands using direct string concatenation.

  • Prevents query manipulation
  • Eliminates command injection risks
  • Encourages safer design

4. Proper Error Handling

Avoid exposing system or database errors to users.

  • Prevents leakage of system details
  • Use secure server-side logging
  • Display generic error messages

5. Principle of Least Privilege

Give only the minimum required access to users and services.

  • Limits damage from attacks
  • Restricts database and system access
  • Improves overall security

6. Output Encoding

Encode data before displaying it in web pages.

  • Prevents XSS attacks
  • Ensures safe output rendering
  • Protects client-side security

7. Use Web Application Firewalls (WAF)

Deploy WAFs to filter and block malicious traffic.

  • Detects injection patterns
  • Blocks common attack payloads
  • Adds an extra security layer
Comment
Article Tags:
Article Tags: