Skip to content

Latest commit

 

History

History
64 lines (51 loc) · 6.04 KB

mitigations.md

File metadata and controls

64 lines (51 loc) · 6.04 KB

Mitigation Strategies Analysis for wg/wrk

  1. Scheduled Testing Windows: Conduct wrk load tests only during pre-defined, scheduled maintenance windows. Communicate these windows to relevant teams (operations, security, etc.).
  2. Controlled Test Environments: Ideally, run wrk tests against a dedicated staging or testing environment that mirrors the production environment as closely as possible. Never run high-load wrk tests directly against production without extreme caution and coordination.
  3. Limited Concurrency and Duration: Carefully control the -c (connections), -t (threads), and -d (duration) parameters in wrk. Start with low values and gradually increase them, monitoring the impact on the target system. Avoid unnecessarily long test durations.
  4. Realistic Request Patterns: Craft wrk scripts (Lua) that simulate realistic user behavior. Don't just hammer a single endpoint with identical requests. Vary request parameters, headers, and timing to mimic real-world traffic.
  5. Avoid Default User-Agent (in Production-Like Tests): While useful for differentiating controlled tests, change the default wrk User-Agent string (-H "User-Agent: My-Realistic-Agent") when testing in environments that resemble production. This helps avoid accidentally triggering special-case handling that might be in place for the default wrk agent. It also makes your tests more representative of real user traffic.
  6. Rate Limiting Within wrk (Lua Scripting): Use wrk's Lua scripting capabilities to implement client-side rate limiting within the test itself. This is not a security measure, but a way to control the load generated by wrk and prevent it from overwhelming the target, even if server-side rate limiting isn't yet in place. This is particularly useful during development. You can use request() and delay() functions in Lua to achieve this.
  7. Controlled Source IPs: If possible, run wrk tests from a limited set of known IP addresses. This makes it easier to identify and filter wrk traffic at the network level (though this is not a primary security measure).
  8. Avoid unnecessary headers: Do not include unnecessary headers in requests.
  • Threats Mitigated:

    • Accidental Denial of Service (DoS) (High Severity): Prevents wrk itself from causing an outage due to excessive load during testing.
    • Unrealistic Test Results (Medium Severity): Ensures that load tests accurately reflect real-world usage patterns.
    • Misinterpretation of Test Traffic (Low Severity): Helps differentiate legitimate wrk testing from potential attacks (when using controlled environments and custom User-Agents).
    • Resource Exhaustion (in Test Environment) (Medium Severity): Protects the test environment from being overwhelmed.
  • Impact:

    • Accidental DoS: High impact; directly prevents self-inflicted DoS.
    • Unrealistic Test Results: High impact; ensures the validity of test results.
    • Misinterpretation of Traffic: Moderate impact; aids in distinguishing test traffic.
    • Resource Exhaustion (Test): High impact; protects the test environment.
  • Currently Implemented:

    • wrk tests are run against a staging environment.
    • Basic control over -c, -t, and -d parameters.
  • Missing Implementation:

    • No formal scheduled testing windows.
    • wrk scripts don't fully simulate realistic user behavior.
    • Default wrk User-Agent is often used.
    • No client-side rate limiting within wrk scripts.
    • No restriction on source IPs.
  1. Input Validation: Within your Lua scripts, always validate and sanitize any input data used to construct requests (URLs, headers, body content). This is crucial even though it's "just a test" because vulnerabilities exposed during testing are still real vulnerabilities.
  2. Avoid Hardcoding Sensitive Data: Do not hardcode API keys, passwords, or other sensitive information directly into wrk scripts. Use environment variables or other secure methods to provide these values.
  3. Limit Script Functionality: Keep wrk scripts focused on their core purpose: generating HTTP requests. Avoid unnecessary complexity or functionality that could introduce vulnerabilities.
  4. Error Handling: Implement proper error handling within the Lua scripts. Handle potential errors gracefully and avoid leaking sensitive information in error messages.
  5. Code Review: Subject all wrk Lua scripts to thorough code reviews, paying close attention to security best practices.
  6. Regular Audits: Periodically audit existing wrk scripts to ensure they remain secure and up-to-date.
  7. Use functions wisely: Use wrk Lua functions (setup, init, delay, request, response) in the intended way.
  • Threats Mitigated:

    • Injection Vulnerabilities (Medium-High Severity): Prevents attackers from exploiting vulnerabilities in the application through malicious wrk scripts.
    • Data Leakage (Medium Severity): Prevents scripts from accidentally exposing sensitive information.
    • Scripting Errors (Low-Medium Severity): Reduces the risk of errors in the scripts causing unexpected behavior.
  • Impact:

    • Injection Vulnerabilities: High impact; directly addresses the threat.
    • Data Leakage: Moderate impact; reduces the risk of data exposure.
    • Scripting Errors: Moderate impact; improves the reliability of testing.
  • Currently Implemented:

    • wrk scripts are stored in version control.
  • Missing Implementation:

    • No mandatory code reviews for wrk scripts.
    • No consistent input validation or sanitization within scripts.
    • No regular audits of existing scripts.