Last active
May 18, 2023 00:52
-
-
Save GuyPaddock/dba1628efd127c67bc3db2c1b9636ec4 to your computer and use it in GitHub Desktop.
Benchmark Azure AD App Proxy using a session cookie acquired from Browser Developer Tools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. | |
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 "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment