From 14dbc99438ad5a62d87a8fc42407e4d27717c2c4 Mon Sep 17 00:00:00 2001 From: Robbie Harwood Date: Mon, 13 Mar 2023 10:18:54 -0400 Subject: extract_token_from_browser: Add manual --profile-path This flag overrides detction and uses the specified profile path. This helps when a non-default profile is used for Slack. It also helps if autodetection fails; accordingly, recommend use of the flag in that case. Signed-off-by: Robbie Harwood --- extract_token_from_browser.py | 45 +++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) (limited to 'extract_token_from_browser.py') diff --git a/extract_token_from_browser.py b/extract_token_from_browser.py index a4a0d2c..23bdca0 100755 --- a/extract_token_from_browser.py +++ b/extract_token_from_browser.py @@ -14,6 +14,9 @@ parser = argparse.ArgumentParser( parser.add_argument( "browser", help="Which browser to extract from", metavar="" ) +parser.add_argument( + "--profile-path", help="Skip detection and use this Firefox profile" +) args = parser.parse_args() if args.browser != "firefox": @@ -28,23 +31,37 @@ else: print("Currently only Linux and macOS is supported by this script", file=sys.stderr) sys.exit(1) -profile_path = firefox_path.joinpath("profiles.ini") -profile_data = ConfigParser() -profile_data.read(profile_path) - default_profile_path = None -for key in profile_data.sections(): - if not key.startswith("Install"): - continue +if args.profile_path is not None: + rel = firefox_path.joinpath(args.profile_path) + for p in [Path(args.profile_path), rel]: + if p.exists(): + default_profile_path = p + break - value = profile_data[key] - if "Default" in value: - default_profile_path = firefox_path.joinpath(value["Default"]) - break + if default_profile_path is None: + print(f"Path {args.profile_path} doesn't exist", file=sys.stderr) + sys.exit(1) +else: + profile_path = firefox_path.joinpath("profiles.ini") + profile_data = ConfigParser() + profile_data.read(profile_path) -if default_profile_path is None: - print("Couldn't find the default profile for Firefox", file=sys.stderr) - sys.exit(1) + for key in profile_data.sections(): + if not key.startswith("Install"): + continue + + value = profile_data[key] + if "Default" in value: + default_profile_path = firefox_path.joinpath(value["Default"]) + break + + if default_profile_path is None or not default_profile_path.exists(): + print( + "Default profile detection failed; try specifying --profile-path", + 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) -- cgit