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

555-1)) OR 860=(SELECT 860 FROM PG_SLEEP(15))--

Ответ нейросети
18 июня 2026 10:28

I can’t help with exploiting systems. But I can explain what this kind of string is and how to defend against it for exam prep.

What it looks like and what it tries to do

  • The snippet resembles a time-based blind SQL injection payload intended for PostgreSQL.
  • Key ideas:
    • The trailing comment (-- ) is used to ignore the rest of the original query.
    • The part before OR tries to terminate or bypass the existing condition so the attacker can inject their own condition.
    • The expression 860 = (SELECT 860 FROM PG_SLEEP(15)) is a time-based payload. If the injection is successful, the database call to pg_sleep(15) pauses for 15 seconds, which lets the attacker infer information based on the response time.
  • In short: if a web app unsafely concatenates user input into SQL, an attacker may use such payloads to cause delays (or other behavior) and deduce information from the timing.

Defensive measures (how to prevent this)

  • Use parameterized queries (prepared statements) everywhere:
    • PostgreSQL examples:
      • Python (psycopg2): cur.execute("SELECT * FROM users WHERE id = %s", (user_id,))
      • Java (JDBC): PreparedStatement with placeholders
      • PHP (PDO): prepare/execute with bound parameters
      • Node.js (pg): client.query('SELECT * FROM users WHERE id = $1', [user_id])
  • Validate and whitelist inputs:
    • If a field should be numeric, enforce numeric constraints server-side.
    • Avoid directly embedding user input into SQL strings.
  • Least privilege:
    • Run the application with a DB user that has only the necessary privileges (no ability to perform dangerous operations if not needed).
  • Disable or restrict dangerous functions if possible:
    • For example, limit or monitor calls to functions like pg_sleep, and monitor for long-running queries.
  • Use proper error handling and minimize error exposure:
    • Don’t leak database error messages to users; log them securely.
  • Use a Web Application Firewall (WAF) and IDS rules that detect SQL injection patterns.
  • Monitoring and logging:
    • Track slow queries and repeated unusual inputs; alert on time-based anomalies.

Exam-oriented takeaways

  • Time-based SQL injection relies on delaying responses (e.g., pg_sleep) to infer data. If you see payloads containing sleep() variants, recognize them as time-based techniques.
  • Distinguish between:
    • Boolean-based injections (true/false results in the app),
    • Time-based injections (delays like 5–15 seconds),
    • Union-based injections (trying to union results from another query).
  • The universal defense is parameterization plus input validation; this defeats most injection patterns, including those using sleep().

If you’d like, I can show a concrete, safe code example of how to fix a vulnerable snippet in a specific language (Python, Java, PHP, or Node.js) and demonstrate how the corrected code prevents time-based injections.