从Google Authenticator解密获取2FA密钥备份教程

发布于 2024-05-12  860 次阅读


启用2FA可以有效的保证账户安全,但一旦手机丢失或者换手机等操作不当丢失2FA密钥就会导致账户可能再也无法找回。Google Authenticator是一个常用的二步验证动态口令生成工具,支持设备间转移和google云备份,但是在软件内不能直接查看到密钥,不能很方便的进行密钥的本地保存和备份,或者是迁移到其它2FA平台。这里介绍一个从Google Authenticator解密获取到2FA密钥的工具和使用方法。

操作过程

导出配置文件二维码

  1. 打开Google Authenticator,点击左上角的三条横线按钮,选择转移账号
  2. 选择导出账号
  3. 勾选需要导出的账号并点击下一步

这里我们会看到一个二维码,截图保存为文件,比如ga.jpg

使用decodeGoogleOTP工具解码

为了方便整个过程,我写了一个命令行工具decodeGoogleOTP,前往Github下载页面,根据自己的平台,下载最新版本的工具。

下载后解压,为了方便操作可以重命名一下,比如windows平台重命名为decodeGoogleOTP.exe,然后和ga.jpg放在一个文件夹下。

decodeGoogleOTP支持将结果导出为csv文件、json文件、txt文件或者二维码图片等多种格式。如果我们需要将结果导出为json文件,运行如下命令即可

decodeGoogleOTP -i ga.jpg -c output.json

输出的结果格式如下:

[
  {
    "issuer": "",
    "name": "xx",
    "secret": "AAAAAAAAAAA",
    "type": "totp",
    "counter": 0,
    "url": "otpauth://totp/xx?secret=AAAAAAAAAAA"
  }
]

其中secret字段就是2FA密钥,有了密钥就可以方便的转移到其它平台。而url可以用来生成二维码供其它2FA软件扫描导入,也可以使用decodeGoogleOTP直接导出二维码图片供扫描

更详细的使用方法参考下面的说明

$ decodeGoogleOTP -h

decodeGoogleOTP is a command line tool to decode Google OTP QR codes. Output can be json, csv, qrcode or plain text.

Usage:
  decodeGoogleOTP [flags]
  decodeGoogleOTP [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  help        Help about any command
  version     Print current version of the application

Flags:
  -c, --csv string      Output in CSV format and specify the output file
  -d, --debug           Enable debug mode
  -h, --help            help for decodeGoogleOTP
  -i, --input string    Input file path
  -j, --json string     Output in JSON format and specify the output file
  -p, --print-qr        Print QR code to terminal
  -q, --qrcode string   Output in QR code image format and specify the output directory
  -s, --silent          Enable silent mode
  -t, --text string     Output url list in plain text format and specify the output file
  -u, --url string      Output in URL format and specify the output file
  -v, --version         Print version information

Use "decodeGoogleOTP [command] --help" for more information about a command.