Created
November 8, 2019 21:29
-
-
Save Sawaba/1eac9e5321a8136b6649bf73764df24a to your computer and use it in GitHub Desktop.
Quick python script to delete all tokens from a Canary console
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
import requests | |
import sys | |
import re | |
def main(args): | |
if len(args) < 2: | |
print("usage: python delete_tokens.py <console_url> <api_key>") | |
auth = args[1] | |
console = args[0] | |
get_url = "{base}/api/v1/canarytokens/fetch?auth_token={auth}".format( | |
base=console, auth=auth) | |
resp = requests.get(get_url) | |
resp_obj = resp.json() | |
print("Current tokens on your console") | |
print("-----------------------------------------------------------------------------------") | |
print("kind\t\ttoken\t\t\t\t\tmemo") | |
print("-----------------------------------------------------------------------------------") | |
for token in resp_obj['tokens']: | |
print("{}\t\t{}\t\t{}".format(token['kind'], token['canarytoken'], token['memo'])) | |
print("-----------------------------------------------------------------------------------") | |
canarytoken = input("Are you sure you would like to delete all your Canarytokens? [Y\\n] PLEASE NOTE: This is irreversible! ") | |
if canarytoken != 'Y': | |
print("Not deleting any canarytokens from your Canary console.") | |
exit(0) | |
delete_url = "{base}/api/v1/canarytoken/delete".format(base=console) | |
for token in resp_obj['tokens']: | |
print("Deleting {}: {}".format(token['canarytoken'], token['kind'])) | |
data = { | |
'auth_token': auth, | |
'canarytoken': token['canarytoken'] | |
} | |
resp = requests.post(delete_url, data=data) | |
print("-----------------------------------------------------------------------------------") | |
print("All deleted. Go create some more! They're on us ;)") | |
if __name__ == "__main__": | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment