Новая Школа - онлайн-школа подготовки к ЕГЭ
Задача Задача №3620801
А
Аноним
18 июня 2026 01:44 · публичный вопрос
А
Аноним

555-1) OR 453=(SELECT 453 FROM PG_SLEEP(28.39))--

Нейросеть18 июня 2026 01:44

It looks like a time-based blind SQL injection payload aimed at PostgreSQL, using the pg_sleep function. I’ll explain conceptually (for exam prep) and then cover defenses.

What the string represents (high level)

  • pg_sleep(seconds) is a PostgreSQL function that pauses the current database session for the given number of seconds.
  • The fragment “SELECT 453 FROM PG_SLEEP(28.39)” executes the sleep, then returns the value 453.
  • The outer expression “453 = (SELECT 453 FROM PG_SLEEP(28.39))” becomes a boolean that is true after the sleep completes (since the subquery returns 453).
  • The “OR … --” pattern is a typical injection trick: it injects extra SQL that is evaluated as part of a WHERE clause (or similar) and then the “--” comments out the rest of the original query to avoid syntax errors.
  • In short, if this injection reaches the server, it will cause the database to delay for ~28.39 seconds, which can be used to infer whether the injection point is vulnerable (a time-based blind technique).

Why this is a vulnerability

  • It relies on concatenating user input into SQL without proper parameterization, allowing an attacker to alter the query’s logic.
  • The delay acts as a side channel to infer information about the database (or simply to cause a denial-of-service-like delay).

Defensive takeaways (exam-friendly protections)

  • Use parameterized queries and prepared statements everywhere. Do not concatenate user input into SQL strings.
    • Example idea (conceptual): SELECT * FROM users WHERE username = ? AND password_hash = ? (with bound parameters) rather than embedding values directly.
  • Validate and constrain inputs (whitelist allowed values, enforce type and length limits).
  • Apply least privilege for the database user:
    • The application user should not have permission to execute risky functions (like pg_sleep) or to run arbitrary dynamic SQL.
    • Consider revoking EXECUTE on pg_sleep (and similar functions) from the application role, or place such functionality behind safe, vetted wrappers.
  • Avoid dynamic SQL whenever possible. If you must use it, ensure all inputs are strictly sanitized and bound.
  • Use an application-layer defense-in-depth:
    • Web Application Firewall (WAF) with rules for common SQL injection patterns.
    • Monitoring and logging of unusual query patterns, latencies, or error messages.
  • Defensive testing in a safe environment:
    • Use test databases or fixtures to understand what kinds of inputs can cause delays, without targeting production data.
    • Prefer formal security testing methods (e.g., parameterized query testing, static analysis, automated security scanners) rather than manual exploitation on live systems.
  • Configure informative error handling:
    • Do not reveal detailed DB errors to users; minimal error messages reduce information leakage that attackers can use.

If you’re prepping for an exam, you might be asked to:

  • Explain what time-based blind SQL injection is and why pg_sleep enables it in PostgreSQL.
  • Describe safe coding practices to prevent such injections.
  • Demonstrate with a safe, parameterized example how user input should be handled in queries.
  • Outline a defense plan for a vulnerable application (privileges, input validation, logging).

Would you like a concise, exam-style example of defending against this pattern (with sample parameterized code in a specific language), or a quick comparison between boolean-based vs time-based SQL injection defenses?

555-1) OR 453=(SELECT 453 FROM PG_SLEEP(28.39))--
It looks like a time-based blind SQL injection payload aimed at PostgreSQL, using the pg_sleep function. I’ll explain conceptually (for exam prep) and then cover defenses. What the string represents (high level) - pg_sleep(seconds) is a PostgreSQL function that pauses the current database session for the given number of seconds. - The fragment “SELECT 453 FROM PG_SLEEP(28.39)” executes the sleep, then returns the value 453. - The outer expression “453 = (SELECT 453 FROM PG_SLEEP(28.39))” becomes a boolean that is true after the sleep completes (since the subquery returns 453). - The “OR … --” pattern is a typical injection trick: it injects extra SQL that is evaluated as part of a WHERE clause (or similar) and then the “--” comments out the rest of the original query to avoid syntax errors. - In short, if this injection reaches the server, it will cause the database to delay for ~28.39 seconds, which can be used to infer whether the injection point is vulnerable (a time-based blind technique). Why this is a vulnerability - It relies on concatenating user input into SQL without proper parameterization, allowing an attacker to alter the query’s logic. - The delay acts as a side channel to infer information about the database (or simply to cause a denial-of-service-like delay). Defensive takeaways (exam-friendly protections) - Use parameterized queries and prepared statements everywhere. Do not concatenate user input into SQL strings. - Example idea (conceptual): SELECT * FROM users WHERE username = ? AND password_hash = ? (with bound parameters) rather than embedding values directly. - Validate and constrain inputs (whitelist allowed values, enforce type and length limits). - Apply least privilege for the database user: - The application user should not have permission to execute risky functions (like pg_sleep) or to run arbitrary dynamic SQL. - Consider revoking EXECUTE on pg_sleep (and similar functions) from the application role, or place such functionality behind safe, vetted wrappers. - Avoid dynamic SQL whenever possible. If you must use it, ensure all inputs are strictly sanitized and bound. - Use an application-layer defense-in-depth: - Web Application Firewall (WAF) with rules for common SQL injection patterns. - Monitoring and logging of unusual query patterns, latencies, or error messages. - Defensive testing in a safe environment: - Use test databases or fixtures to understand what kinds of inputs can cause delays, without targeting production data. - Prefer formal security testing methods (e.g., parameterized query testing, static analysis, automated security scanners) rather than manual exploitation on live systems. - Configure informative error handling: - Do not reveal detailed DB errors to users; minimal error messages reduce information leakage that attackers can use. If you’re prepping for an exam, you might be asked to: - Explain what time-based blind SQL injection is and why pg_sleep enables it in PostgreSQL. - Describe safe coding practices to prevent such injections. - Demonstrate with a safe, parameterized example how user input should be handled in queries. - Outline a defense plan for a vulnerable application (privileges, input validation, logging). Would you like a concise, exam-style example of defending against this pattern (with sample parameterized code in a specific language), or a quick comparison between boolean-based vs time-based SQL injection defenses?