aboutsummaryrefslogtreecommitdiffstats
path: root/extract_token_from_browser.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2022-03-19 13:21:33 +0100
committerTrygve Aaberge <trygveaa@gmail.com>2022-09-18 16:36:55 +0200
commit73e1c7df0277fb3f3602f5ed6fa2a3e59b49b52e (patch)
treeea389933aa1ba4cda4ecd61296958f1171091ed3 /extract_token_from_browser.py
parent30328658d53b5327044abf2169339e0e5c15a6ee (diff)
downloadwee-slack-73e1c7df0277fb3f3602f5ed6fa2a3e59b49b52e.tar.gz
Add a script to get session tokens and cookies from Firefox
Diffstat (limited to 'extract_token_from_browser.py')
-rwxr-xr-xextract_token_from_browser.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/extract_token_from_browser.py b/extract_token_from_browser.py
new file mode 100755
index 0000000..34235ab
--- /dev/null
+++ b/extract_token_from_browser.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python3
+
+import argparse
+import json
+from pathlib import Path
+import sqlite3
+import sys
+
+parser = argparse.ArgumentParser(
+ description="Extract Slack tokens from the browser files"
+)
+parser.add_argument(
+ "browser", help="Which browser to extract from", metavar="<browser>"
+)
+args = parser.parse_args()
+
+if args.browser != "firefox":
+ print("Currently only firefox is supported by this script", file=sys.stderr)
+ sys.exit(1)
+
+if sys.platform.startswith("linux"):
+ firefox_path = Path.home().joinpath(".mozilla/firefox")
+elif sys.platform.startswith("darwin"):
+ firefox_path = Path.home().joinpath("Library/Application Support/Firefox/Profiles")
+else:
+ print("Currently only Linux and macOS is supported by this script", file=sys.stderr)
+ sys.exit(1)
+
+try:
+ default_profile_path = next(firefox_path.glob("*.default-release"))
+except StopIteration:
+ print("Couldn't find the default profile for Firefox", file=sys.stderr)
+ sys.exit(1)
+
+cookies_path = default_profile_path.joinpath("cookies.sqlite")
+con = sqlite3.connect(f"file:{cookies_path}?immutable=1", uri=True)
+cookies_query = "SELECT value FROM moz_cookies WHERE host = '.slack.com' AND name = 'd'"
+cookie_d_value = con.execute(cookies_query).fetchone()[0]
+con.close()
+
+local_storage_path = default_profile_path.joinpath("webappsstore.sqlite")
+con = sqlite3.connect(f"file:{local_storage_path}?immutable=1", uri=True)
+local_storage_query = "SELECT value FROM webappsstore2 WHERE key = 'localConfig_v2'"
+local_config_str = con.execute(local_storage_query).fetchone()[0]
+con.close()
+
+local_config = json.loads(local_config_str)
+
+for team in local_config["teams"].values():
+ print(f"{team['name']}: /slack register {team['token']}:{cookie_d_value}")