Skip to content

Instantly share code, notes, and snippets.

@GuyPaddock
Last active May 18, 2023 00:52
Show Gist options
  • Save GuyPaddock/dba1628efd127c67bc3db2c1b9636ec4 to your computer and use it in GitHub Desktop.
Save GuyPaddock/dba1628efd127c67bc3db2c1b9636ec4 to your computer and use it in GitHub Desktop.

Revisions

  1. Guy Elsmore-Paddock revised this gist May 18, 2023. 1 changed file with 16 additions and 1 deletion.
    17 changes: 16 additions & 1 deletion azure_ad_stats.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,22 @@
    #!/bin/bash

    ##
    # @file
    # A script to benchmark how Azure AD App Proxy performs across multiple
    # requests.
    #
    # If you are using pre-authentication (as you usually will be), before using
    # this script, you will need to sign in using your browser and then use
    # developer tools to grab your session cookie so you can paste it below.
    # Azure AD App Proxy session cookies are only valid for 30-60 minutes, so you
    # must perform the benchmark quickly to avoid skewing the results with
    # redirects from Azure.
    #
    # @author ChatGPT
    # @author Guy Elsmore-Paddock ([email protected])
    #

    # Set this to the "Cookie" header value from Developer Tools in Chrome.
    # Azure AD App Proxy session cookies are only valid for 30 minutes.
    session_cookie="<<< YOUR SESSION COOKIE >>>"

    # Set this to the site you are testing with.
  2. Guy Elsmore-Paddock created this gist May 18, 2023.
    79 changes: 79 additions & 0 deletions azure_ad_stats.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,79 @@
    #!/bin/bash

    # Set this to the "Cookie" header value from Developer Tools in Chrome.
    # Azure AD App Proxy session cookies are only valid for 30 minutes.
    session_cookie="<<< YOUR SESSION COOKIE >>>"

    # Set this to the site you are testing with.
    url="http://example.com"

    requests=25
    max_connect_time=10
    max_request_time=30
    timeouts=0
    errors=0

    declare -a times

    for ((i=1; i<=requests; i++)); do
    echo "Request ${i}..."
    result=$(
    curl \
    -w "%{time_total}\n" \
    -o /dev/null \
    -s \
    --max-time $max_request_time \
    --connect-timeout $max_connect_time \
    --max-redirs 0 \
    "${url}" \
    -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' \
    -H 'Accept-Language: en-US,en;q=0.9' \
    -H 'Cache-Control: no-cache' \
    -H 'Connection: keep-alive' \
    -H "Cookie: ${session_cookie}" \
    -H 'Pragma: no-cache' \
    -H 'Referer: https://login.microsoftonline.com/' \
    -H 'Sec-Fetch-Dest: document' \
    -H 'Sec-Fetch-Mode: navigate' \
    -H 'Sec-Fetch-Site: cross-site' \
    -H 'Sec-Fetch-User: ?1' \
    -H 'Upgrade-Insecure-Requests: 1' \
    -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.42' \
    -H 'sec-ch-ua: "Microsoft Edge";v="113", "Chromium";v="113", "Not-A.Brand";v="24"' \
    -H 'sec-ch-ua-mobile: ?0' \
    -H 'sec-ch-ua-platform: "Windows"' \
    --compressed
    )

    exit_code=$?

    if [ $exit_code -eq 28 ]; then
    timeouts=$((timeouts + 1))
    elif [ $exit_code -ne 0 ]; then
    errors=$((errors + 1))
    else
    times+=($result)
    fi

    sleep 1
    done

    # Sort the times array
    sorted_times=($(printf '%s\n' "${times[@]}" | sort -n))

    # Calculate statistics
    total_requests=${#sorted_times[@]}
    average=$(awk '{ total += $1 } END { print total/NR }' <<<"${sorted_times[*]}")
    median=${sorted_times[total_requests/2]}
    min=${sorted_times[0]}
    max=${sorted_times[total_requests-1]}

    # Display results
    echo "Total requests: $total_requests"
    echo "Average time: $average seconds"
    echo "Median time: $median seconds"
    echo "Minimum time: $min seconds"
    echo "Maximum time: $max seconds"
    echo "Timeouts: $timeouts"
    echo "Errors: $errors"
    echo ""