Injeção SQL

Segurança

Definição

Um ataque de injeção de código que insere instruções SQL maliciosas nos campos de entrada de aplicativos para manipular ou extrair dados de um banco de dados backend. Prevenido por consultas parametrizadas e validação de entrada.

How SQL Injection Works

SQL Injection (SQLi) occurs when user-supplied input is concatenated directly into a database query without sanitization. An attacker inserts SQL metacharacters — quotes, comment sequences, boolean operators — to alter query logic. A simple ' OR '1'='1 can bypass a login form; a UNION SELECT attack can dump entire database tables; a ;DROP TABLE can destroy data.

Attack Variants

Type Technique Visibility
In-band Results returned in HTTP response High
Blind boolean Infer data from true/false responses Low
Time-based blind Infer data from response delay Low
Out-of-band Exfiltrate via DNSDomain Name System. The hierarchical, distributed naming system that translates human-readable domain names (e.g., example.com) into IP addresses (e.g., 93.184.216.34). Often called the "phonebook of the internet." or HTTP callbacks Stealthy

Out-of-band SQLi is particularly dangerous because it bypasses WAFWeb Application Firewall. A security layer that filters, monitors, and blocks HTTP/HTTPS traffic to and from a web application, protecting against attacks like SQL injection, XSS, and CSRF at the application layer. rules that look only at HTTP responses — the data leaves through a secondary channel like DNS.

Prevention

The only reliable fix is parameterized queries (prepared statements) — the database driver handles escaping, making injection structurally impossible. Complementary controls include:

XSSCross-Site Scripting. A web vulnerability that allows attackers to inject malicious scripts into web pages viewed by other users. XSS can steal session cookies, redirect users, or deface websites; mitigated by output encoding and CSP headers. often co-occurs with SQLi in vulnerable applications — fixing one class of injection improves overall security posture.

Termos relacionados

Mais em Segurança