Skip to content

Instantly share code, notes, and snippets.

@EdOverflow
Created April 6, 2019 15:26
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EdOverflow/7111eef16249c56e9dfaa18ab29901d4 to your computer and use it in GitHub Desktop.
Save EdOverflow/7111eef16249c56e9dfaa18ab29901d4 to your computer and use it in GitHub Desktop.
Quickly determine the validity and scope of a GitHub access token.
#!/bin/bash
GREEN='\033[0;32m'
RED='\033[0;31m'
END='\033[0m'
request=$(curl -s -u "hehe:$1" https://api.github.com/user)
name=$(echo "$request" | jq -r ".login" 2> /dev/null)
if [[ $name == "null" ]]; then
echo -e "${RED}Not a GitHub access token.${END}"
exit 1
fi
org=$(curl -s -H "Authorization: token $1" "https://api.github.com/users/$name/orgs" | jq -r ".[].login" 2> /dev/null)
scope=$(curl -s -H "Authorization: token $1" "https://api.github.com/users/$name" -I | grep -i "X-OAuth-Scopes:")
if [[ $org || $scope ]]; then
echo -e "Status: ${GREEN}Vulnerable${END}"
echo "Username: $name"
echo "Organisation(s): $org"
echo "Scope: $scope"
else
echo -e "Status: ${RED}Not vulnerable${END}"
echo "Username: $name"
echo "Organisation(s): $org"
echo "Scope: $scope"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment