Задача Задача №3622774
А
А
That looks like a time-based blind SQL injection payload for PostgreSQL.
What it does (high level):
- The snippet tries to break out of the intended SQL logic and inject an OR condition.
- It uses a subquery with pg_sleep(31.516). If the app is vulnerable and the input is unsafely concatenated into SQL, the query will sleep for about 31.5 seconds, indicating the injection was successful.
- The expression 564 = (SELECT 564 FROM PG_SLEEP(31.516)) is a technique to force a delay and then compare constants, so you can infer truth by measuring response time.
- The trailing “--” is a comment to ignore the rest of the original query.
Why this matters:
- It’s a classic time-based blind SQL injection technique. If your app responds with a noticeable delay only for certain inputs, you may have an injection vulnerability.
Defensive measures (strong recommendations):
- Use parameterized queries everywhere. Do not concatenate user input into SQL.
- Examples by language:
- Python (psycopg2): cursor.execute("SELECT * FROM users WHERE id = %s", (user_input,))
- Node.js (pg): client.query("SELECT * FROM users WHERE id = $1", [user_input])
- Java (JDBC): PreparedStatement ps = conn.prepareStatement("SELECT * FROM users WHERE id = ?");
- Examples by language:
- Validate and constrain inputs to expected types/values; but do not rely on validation alone—use parameterization.
- Principle of least privilege: The app should connect to the DB with a user that has only the minimum rights needed; disallow dangerous functions if possible.
- Disable or restrict risky operations/functions where appropriate (e.g., pg_sleep) at the application layer or DB role level.
- Use a web application firewall and security scanners to detect injection patterns.
- Error handling: Avoid returning DB error details to clients that could aid an attacker.
If you want, I can:
- Show a concrete safe example in your preferred language.
- Walk through how to test for SQL injection safely in a controlled environment.
- Explain how to detect timing-based vulnerabilities in logs and monitoring.