Skip to main content

Auth Checker

#!/bin/bash

# Description:
# This script processes a list of endpoints to compare responses between:
# 1. Cookies and No Cookies
# 2. Two different Cookie headers
# 3. Bearer token and No Bearer token
# 4. Two different Bearer tokens
#
# The script performs both GET and POST requests to each endpoint.
# It prints the endpoints where both requests return a 200 status code along with the response sizes.
# It also displays a progress bar during the processing.
#
# How to run:
# ./cookie_checker.sh <file_with_endpoints>
#
# Sample inputs:
# File 'endpoints.txt' containing:
# http://example.com/endpoint1
# http://example.com/endpoint2
# http://example.com/endpoint3

# Function to display colored and styled text
print_info() {
echo -e "\033[1;34m$1\033[0m"
}

print_endpoint() {
echo -e "\033[1;32m$1\033[0m"
}

print_code_size() {
echo -e "\033[1;33m$1 ($2 bytes)\033[0m"
}

# Function to show a progress bar
progress_bar() {
local progress=$1
local total=$2
local percent=$(( progress * 100 / total ))
local bar_length=50
local filled_length=$(( percent * bar_length / 100 ))
local bar=""

for ((i=0; i<filled_length; i++)); do
bar="${bar}#"
done
for ((i=filled_length; i<bar_length; i++)); do
bar="${bar}-"
done

printf "\rProgress: [%-50s] %d%%" "$bar" "$percent"
}

# Function to perform the menu operation
menu() {
print_info "1. Cookies -> No Cookies"
print_info "2. Compare Two Cookies"
print_info "3. Bearer Token -> No Bearer Token"
print_info "4. Compare Two Bearer Tokens"
print_info "5. Exit"
echo -n "Please choose an option: "
read option

case $option in
1)
echo -n "Enter the Cookie header: "
read cookie
process_endpoints_cookie "$cookie" "$file"
;;
2)
echo -n "Enter the first Cookie header: "
read cookie1
echo -n "Enter the second Cookie header: "
read cookie2
compare_cookies "$cookie1" "$cookie2" "$file"
;;
3)
echo -n "Enter the Bearer token (without 'Bearer ' prefix): "
read token
process_endpoints_bearer "$token" "$file"
;;
4)
echo -n "Enter the first Bearer token (without 'Bearer ' prefix): "
read token1
echo -n "Enter the second Bearer token (without 'Bearer ' prefix): "
read token2
compare_bearer_tokens "$token1" "$token2" "$file"
;;
5)
exit 0
;;
*)
echo "Invalid option"
menu
;;
esac
}

# Function to process the endpoints with Cookie and No Cookie
process_endpoints_cookie() {
local cookie=$1
local file=$2

local total=$(wc -l < "$file")
local count=0

while IFS= read -r endpoint; do
((count++))
progress_bar $count $total

if [[ "$endpoint" =~ \.js$ || "$endpoint" =~ \.map$ || "$endpoint" = \.svg$ ]]; then
continue
fi

# Perform GET requests
response_with_cookies=$(curl -s -w "%{http_code} %{size_download}" -o /dev/null -H "Cookie: $cookie" "$endpoint")
response_without_cookies=$(curl -s -w "%{http_code} %{size_download}" -o /dev/null "$endpoint")

code_with_cookies=$(echo "$response_with_cookies" | awk '{print $1}')
size_with_cookies=$(echo "$response_with_cookies" | awk '{print $2}')
code_without_cookies=$(echo "$response_without_cookies" | awk '{print $1}')
size_without_cookies=$(echo "$response_without_cookies" | awk '{print $2}')

if [ "$code_with_cookies" == "200" ] && [ "$code_without_cookies" == "200" ]; then
print_endpoint "\nEndpoint: $endpoint"
print_code_size "GET with cookies code: $code_with_cookies" "$size_with_cookies"
print_code_size "GET without cookies code: $code_without_cookies" "$size_without_cookies"
fi

# Perform POST requests
response_with_cookies=$(curl -s -w "%{http_code} %{size_download}" -o /dev/null -X POST -H "Cookie: $cookie" -d "" "$endpoint")
response_without_cookies=$(curl -s -w "%{http_code} %{size_download}" -o /dev/null -X POST -d "" "$endpoint")

code_with_cookies=$(echo "$response_with_cookies" | awk '{print $1}')
size_with_cookies=$(echo "$response_with_cookies" | awk '{print $2}')
code_without_cookies=$(echo "$response_without_cookies" | awk '{print $1}')
size_without_cookies=$(echo "$response_without_cookies" | awk '{print $2}')

if [ "$code_with_cookies" == "200" ] && [ "$code_without_cookies" == "200" ]; then
print_endpoint "\nEndpoint: $endpoint"
print_code_size "POST with cookies code: $code_with_cookies" "$size_with_cookies"
print_code_size "POST without cookies code: $code_without_cookies" "$size_without_cookies"
fi
done < "$file"

echo -e "\nDone."
}

# Function to compare requests between two cookies
compare_cookies() {
local cookie1=$1
local cookie2=$2
local file=$3

local total=$(wc -l < "$file")
local count=0

while IFS= read -r endpoint; do
((count++))
progress_bar $count $total

if [[ "$endpoint" =~ \.js$ || "$endpoint" =~ \.map$ ]]; then
continue
fi

# Perform GET requests
response_with_cookie1=$(curl -s -w "%{http_code} %{size_download}" -o /dev/null -H "Cookie: $cookie1" "$endpoint")
response_with_cookie2=$(curl -s -w "%{http_code} %{size_download}" -o /dev/null -H "Cookie: $cookie2" "$endpoint")

code_with_cookie1=$(echo "$response_with_cookie1" | awk '{print $1}')
size_with_cookie1=$(echo "$response_with_cookie1" | awk '{print $2}')
code_with_cookie2=$(echo "$response_with_cookie2" | awk '{print $1}')
size_with_cookie2=$(echo "$response_with_cookie2" | awk '{print $2}')

if [ "$code_with_cookie1" == "200" ] && [ "$code_with_cookie2" == "200" ]; then
print_endpoint "\nEndpoint: $endpoint"
print_code_size "GET with cookie1 code: $code_with_cookie1" "$size_with_cookie1"
print_code_size "GET with cookie2 code: $code_with_cookie2" "$size_with_cookie2"
fi

# Perform POST requests
response_with_cookie1=$(curl -s -w "%{http_code} %{size_download}" -o /dev/null -X POST -H "Cookie: $cookie1" -d "" "$endpoint")
response_with_cookie2=$(curl -s -w "%{http_code} %{size_download}" -o /dev/null -X POST -H "Cookie: $cookie2" -d "" "$endpoint")

code_with_cookie1=$(echo "$response_with_cookie1" | awk '{print $1}')
size_with_cookie1=$(echo "$response_with_cookie1" | awk '{print $2}')
code_with_cookie2=$(echo "$response_with_cookie2" | awk '{print $1}')
size_with_cookie2=$(echo "$response_with_cookie2" | awk '{print $2}')

if [ "$code_with_cookie1" == "200" ] && [ "$code_with_cookie2" == "200" ]; then
print_endpoint "\nEndpoint: $endpoint"
print_code_size "POST with cookie1 code: $code_with_cookie1" "$size_with_cookie1"
print_code_size "POST with cookie2 code: $code_with_cookie2" "$size_with_cookie2"
fi
done < "$file"

echo -e "\nDone."
}

# Function to process the endpoints with Bearer token and No Bearer token
process_endpoints_bearer() {
local token=$1
local file=$2

local total=$(wc -l < "$file")
local count=0

while IFS= read -r endpoint; do
((count++))
progress_bar $count $total

if [[ "$endpoint" =~ \.js$ || "$endpoint" =~ \.map$ ]]; then
continue
fi

# Perform GET requests
response_with_token=$(curl -s -w "%{http_code} %{size_download}" -o /dev/null -H "Authorization: Bearer $token" "$endpoint")
response_without_token=$(curl -s -w "%{http_code} %{size_download}" -o /dev/null "$endpoint")

code_with_token=$(echo "$response_with_token" | awk '{print $1}')
size_with_token=$(echo "$response_with_token" | awk '{print $2}')
code_without_token=$(echo "$response_without_token" | awk '{print $1}')
size_without_token=$(echo "$response_without_token" | awk '{print $2}')

if [ "$code_with_token" == "200" ] && [ "$code_without_token" == "200" ]; then
print_endpoint "\nEndpoint: $endpoint"
print_code_size "GET with token code: $code_with_token" "$size_with_token"
print_code_size "GET without token code: $code_without_token" "$size_without_token"
fi

# Perform POST requests
response_with_token=$(curl -s -w "%{http_code} %{size_download}" -o /dev/null -X POST -H "Authorization: Bearer $token" -d "" "$endpoint")
response_without_token=$(curl -s -w "%{http_code} %{size_download}" -o /dev/null -X POST -d "" "$endpoint")

code_with_token=$(echo "$response_with_token" | awk '{print $1}')
size_with_token=$(echo "$response_with_token" | awk '{print $2}')
code_without_token=$(echo "$response_without_token" | awk '{print $1}')
size_without_token=$(echo "$response_without_token" | awk '{print $2}')

if [ "$code_with_token" == "200" ] && [ "$code_without_token" == "200" ]; then
print_endpoint "\nEndpoint: $endpoint"
print_code_size "POST with token code: $code_with_token" "$size_with_token"
print_code_size "POST without token code: $code_without_token" "$size_without_token"
fi
done < "$file"

echo -e "\nDone."
}

# Function to compare requests between two Bearer tokens
compare_bearer_tokens() {
local token1=$1
local token2=$2
local file=$3

local total=$(wc -l < "$file")
local count=0

while IFS= read -r endpoint; do
((count++))
progress_bar $count $total

if [[ "$endpoint" =~ \.js$ || "$endpoint" =~ \.map$ ]]; then
continue
fi

# Perform GET requests
response_with_token1=$(curl -s -w "%{http_code} %{size_download}" -o /dev/null -H "Authorization: Bearer $token1" "$endpoint")
response_with_token2=$(curl -s -w "%{http_code} %{size_download}" -o /dev/null -H "Authorization: Bearer $token2" "$endpoint")

code_with_token1=$(echo "$response_with_token1" | awk '{print $1}')
size_with_token1=$(echo "$response_with_token1" | awk '{print $2}')
code_with_token2=$(echo "$response_with_token2" | awk '{print $1}')
size_with_token2=$(echo "$response_with_token2" | awk '{print $2}')

if [ "$code_with_token1" == "200" ] && [ "$code_with_token2" == "200" ]; then
print_endpoint "\nEndpoint: $endpoint"
print_code_size "GET with token1 code: $code_with_token1" "$size_with_token1"
print_code_size "GET with token2 code: $code_with_token2" "$size_with_token2"
fi

# Perform POST requests
response_with_token1=$(curl -s -w "%{http_code} %{size_download}" -o /dev/null -X POST -H "Authorization: Bearer $token1" -d "" "$endpoint")
response_with_token2=$(curl -s -w "%{http_code} %{size_download}" -o /dev/null -X POST -H "Authorization: Bearer $token2" -d "" "$endpoint")

code_with_token1=$(echo "$response_with_token1" | awk '{print $1}')
size_with_token1=$(echo "$response_with_token1" | awk '{print $2}')
code_with_token2=$(echo "$response_with_token2" | awk '{print $1}')
size_with_token2=$(echo "$response_with_token2" | awk '{print $2}')

if [ "$code_with_token1" == "200" ] && [ "$code_with_token2" == "200" ]; then
print_endpoint "\nEndpoint: $endpoint"
print_code_size "POST with token1 code: $code_with_token1" "$size_with_token1"
print_code_size "POST with token2 code: $code_with_token2" "$size_with_token2"
fi
done < "$file"

echo -e "\nDone."
}

# Main script
if [ $# -ne 1 ]; then
echo "Usage: $0 <file_with_endpoints>"
exit 1
fi

file=$1
menu