Задача Задача №3621743
А
А
It looks like a time-based SQL injection payload for PostgreSQL.
What the snippet is doing (at a high level):
- It’s designed to be injected into a vulnerable SQL query, appending something like: OR 885=(SELECT 885 FROM PG_SLEEP(15))--
- The inner part calls the pg_sleep(15) function, which pauses the database work for 15 seconds.
- The SELECT 885 FROM pg_sleep(15) (or similar) makes the query take 15 seconds to complete; the comparison 885 = 885 is true, so the injected condition evaluates to true after the delay.
- The trailing -- comments out the rest of the original query, so the attacker can bypass the intended logic.
Key concepts:
- Time-based blind SQL injection: you infer information by observing delays rather than by getting data directly back in the result set.
- PG_SLEEP is a PostgreSQL function used to induce a delay; attackers sometimes wrap it in a SELECT to fit into an injected boolean expression.
Defensive takeaways (how to protect and detect):
- Use parameterized queries and prepared statements; never concatenate user input into SQL.
- Apply input validation and allowlists (white-list allowed values).
- Use least-privilege database accounts; avoid granting the app account permissions to execute dangerous functions (like sleep) if not needed.
- Enable proper error handling and avoid leaking error messages or query details to users.
- Consider a database-side defense: set a reasonable statement_timeout (e.g., 5–10 seconds) so long-running queries are automatically terminated.
- Use a web application firewall or query/procedure monitoring to detect anomalous patterns (e.g., unusual delays, repeated boolean-like injections).
- If you must test vulnerabilities, do so only in a controlled lab with explicit permission.
If this is for an exam, the expected takeaway is:
- Recognize this as a time-based blind SQL injection attempt in PostgreSQL.
- Identify the use of pg_sleep to induce a detectable delay and the technique of using a tautology (885=885) to force evaluation after the delay.
- Be able to discuss proper mitigations and safe testing practices.