Задача Задача №3620414
А
А
That input looks like a time-based SQL injection payload intended for PostgreSQL.
What it’s trying to do (high level):
- Injects into a numeric or ID field with something like: 555-1 OR [condition] -- that is, it tries to alter the query’s logic so the WHERE clause becomes true.
- The part with PG_SLEEP(15) is meant to cause the database to pause for 15 seconds if the injected condition is evaluated as true.
- The double dash -- starts a comment, so the attacker hopes to discard the rest of the original query and avoid syntax errors.
Important notes:
- The exact syntax may not work on all PostgreSQL versions. PostgreSQL’s pg_sleep function returns void, and some forms like SELECT 284 FROM pg_sleep(15) aren’t valid in every context. A common pattern is to invoke the sleep function directly (e.g., SELECT pg_sleep(15);) or use a condition that evaluates to true/false and triggers the sleep indirectly.
- The intent is to perform a time-based blind injection: if the application’s response time changes (e.g., a 15-second delay), the attacker infers something about the database.
How to defend (key takeaways):
- Use parameterized queries or prepared statements. Never concatenate user input into SQL.
- Validate and whitelist input when possible (e.g., numeric IDs should be digits only, within expected ranges).
- Principle of least privilege: the app’s database user should have only the permissions it needs; avoid granting dangerous functions (like pg_sleep) unless necessary.
- Use ORM or query builders that separate code from data.
- Implement input/output sanitization and error handling to avoid leaking DB error messages.
- Consider web application firewall rules or monitoring to detect unusual query patterns or delays.
If you’re studying for an exam and want, I can help by:
- Explaining the difference between boolean-based and time-based injection.
- Walking through a safe, concrete example of a vulnerable query and how parameterization fixes it.
- Reframing this as a defense question (e.g., how to mitigate with prepared statements in PostgreSQL).
Would you like a short, safe example showing how to fix a vulnerable query with parameterized input in PostgreSQL?