Задача Задача №3621804
А
А
That looks like a time-based blind SQL injection payload, not a legitimate query.
What it is doing (at a high level):
- It uses PostgreSQL’s pg_sleep(15) to introduce a 15-second delay if the injected clause evaluates to true.
- The fragment "402=(SELECT 402 FROM PG_SLEEP(15))" will cause the database to sleep for 15 seconds and then return true, which helps an attacker infer information based on timing.
- The "555-1" and the "OR" inject into a WHERE-like clause, and the trailing “--” comments out the rest of the original query to avoid syntax errors.
Defensive takeaways for exam prep:
- This demonstrates a classic SQL injection vulnerability and a time-based blind approach.
How to defend (safe code practices):
- Use parameterized/prepared statements so user input is never treated as executable SQL.
- Example (conceptual):
- SELECT * FROM users WHERE id = ? (bind the user input as a parameter)
- Example (conceptual):
- Validate and sanitize inputs, and enforce strict types (e.g., numeric IDs should be validated to be integers).
- Avoid building SQL by concatenating user input into strings.
- Use an ORM or query builder that automatically uses parameter binding.
- Apply least-privilege principle for the application’s database user (no unnecessary rights; restrict to needed operations).
- Implement input length checks and whitelisting where appropriate.
- Monitor and log unusual queries (e.g., usage of pg_sleep, long delays) and consider a WAF or query-pattern detection.
- If possible, disable or restrict dangerous functions (e.g., pg_sleep) for non-admin roles, though this may not be feasible in all setups.
If you want, I can give you a safe exam-style question and a model answer, or show how to rewrite a vulnerable example into a secure one in a specific language.
