Задача Задача №3621809
А
А
That looks like a time-based blind SQL injection payload for PostgreSQL using pg_sleep.
High-level idea
- Time-based blind SQLi relies on delaying the database response to infer something about the true/false result of a condition.
- pg_sleep(seconds) makes the database wait for the given number of seconds. If the injected condition triggers that sleep, you can infer that the condition evaluated to true based on how long the query takes.
- The part you posted (something like “555-1 OR 537=(SELECT 537 FROM PG_SLEEP(15))--”) is crafted to be injected into a vulnerable SQL query. The OR clause can turn a false condition into true, and the subquery with pg_sleep(15) is intended to cause a 15-second delay to signal a positive condition. The -- comments out the rest of the original query.
Notes for exams (concepts you should know)
- Time-based blind SQL injection vs. error-based or union-based injections.
- Why pg_sleep is often used: it creates a measurable delay without needing to return data.
- How an attacker could use timing to infer information about the database (e.g., whether a particular condition is true, which characters exist in a value, etc.).
Defensive approaches (what you should study for prevention)
- Use parameterized queries and prepared statements everywhere. Do not concatenate user input into SQL strings.
- Validate and whitelist input: constrain allowed characters and patterns.
- Use an ORM or query builder that automatically handles parameterization.
- Principle of least privilege: the app DB user should have only the minimum rights needed (no unnecessary superuser rights).
- Disable or tightly restrict dangerous functions if possible (e.g., pg_sleep) or run the app with a DB user that cannot execute such functions.
- Implement input handling, error handling, and proper logging to detect unusual query patterns.
- Use a Web Application Firewall (WAF) and regular security testing (DAST/SAST, ethical testing in a controlled environment).
- Timeouts and query limits can help mitigate slow delays from any injection attempt.
If you’re studying for an exam and want, I can:
- Break down the exact syntax and why it behaves the way it does in PostgreSQL.
- Provide safe practice questions about identifying vulnerable patterns and fixing them.
- Walk through a secure coding example showing how to rewrite a vulnerable query into a parameterized one.