You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在boofuzz中使用session.post_send?黑盒Rest API模糊测试验证咨询

Using session.post_send to Validate System Health After Fuzzing Requests

Absolutely! Leveraging session.post_send (especially if you’re using a framework like Boofuzz, which includes this callback) is a perfect way to verify your target system stays responsive with a known-good request after each fuzzed payload. Here’s a step-by-step breakdown of how to implement this:

1. First, Define Your Baseline Request

Start by creating a function that sends a completely unfuzzed, valid request to your API. This will be your "health check" to confirm the system hasn’t crashed or entered an unstable state post-fuzzing.

import requests

def send_baseline_request():
    # Replace with your actual valid API request details
    baseline_url = "https://your-target-api.com/health-check-endpoint"
    baseline_headers = {"Authorization": "Bearer your-valid-token", "Content-Type": "application/json"}
    baseline_payload = {"action": "status_check", "user_id": "valid-test-user"}
    
    try:
        response = requests.post(baseline_url, headers=baseline_headers, json=baseline_payload, timeout=10)
        # Adjust success criteria to match your API's normal behavior
        return response.status_code == 200 and response.json().get("status") == "healthy"
    except requests.exceptions.RequestException as e:
        print(f"Baseline request failed with error: {e}")
        return False

2. Create the post_send Callback Function

This function runs right after every fuzzed request is sent. It triggers your baseline health check and handles validation logic.

def post_send_callback(session, sock, msg, start_time, end_time, exception):
    # Optional: Print context about the fuzzed request for debugging
    print(f"\nFinished sending fuzzed payload to {session.target.host}:{session.target.port}")
    if exception:
        print(f"Fuzzed request threw exception: {exception}")
    
    # Run the baseline health check
    print("Running system health check...")
    system_healthy = send_baseline_request()
    
    if not system_healthy:
        print("⚠️ SYSTEM UNHEALTHY: Baseline request failed after fuzzing!")
        # Optional: Stop fuzzing immediately to investigate the issue
        # session.fuzz_stop()
    else:
        print("✅ System is still healthy. Continuing fuzzing...")

3. Attach the Callback to Your Fuzzing Session

If you’re using Boofuzz (a popular Python fuzzing framework), attach the post_send callback when setting up your session:

from boofuzz import Session, Target, TCPConnection

# Configure your fuzzing target (adjust protocol/port for your API)
target = Target(connection=TCPConnection(host="your-target-api.com", port=443, ssl=True))
session = Session(target=target)

# Link your callback to the session's post_send hook
session.post_send = post_send_callback

# ... Add your fuzzing request templates, fuzzers, and other setup here ...

# Start the fuzzing process
session.fuzz()

Key Tips for Reliable Validation

  • Keep the baseline request lightweight: Use a simple, read-only endpoint (like a status check) to avoid modifying system state or triggering heavy backend processes.
  • Account for rate limits: If your API enforces rate limits, add a small delay (time.sleep(1)) in the baseline function to avoid false positives.
  • Customize success checks: Adjust the validation logic in send_baseline_request to match your API’s normal behavior—this might include checking specific response headers, payload fields, or status codes.
  • Log results: For long fuzzing runs, write validation outcomes to a log file instead of just printing them. This makes it easier to correlate failed health checks with specific fuzzed payloads.

内容的提问来源于stack exchange,提问作者user1636063

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:05:59