从 Google Authenticator 解密获取 2FA 密钥进行备份和平台转移的方法

37 天前
 kuingsmile

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.
2660 次点击
所在节点    程序员
18 条回复
YGHMXFAL
37 天前
不如改变习惯:

每次添加 2FA,先使用 https://f-droid.org/packages/com.atharok.barcodescanner/ 这个开源离线 APP 来解码成字符串并且保存,再正常走 2FA 绑定流程
xiaobai332
37 天前
或许可以下载开源软件 2fas ,扫码导入谷歌验证器中的所有 2fa ,直接看各个密钥(缺点大概是得一个一个看!?)
uuhhme
37 天前
直接转到 ente auth 就可以了。之后随时可以看
ltkun
37 天前
找个开源的用比如 aegis
hnliuzesen
37 天前
@xiaobai332
2FAS 如果有 root 权限还可以直接从谷歌验证器导入
xxbing
37 天前
@YGHMXFAL #1 我也是这么做的,我单独下载一个二维码扫码的 app,绑 2FA 前先用 扫码 APP 扫一下,再用 google auth 扫描绑定. 二维码 APP 还有扫码历史记录
xxbing
37 天前
@YGHMXFAL #1 为了防止二维码 APP 泄密,我还在设置里面,禁用了它的上网权限.
Achophiark
37 天前
keepass 等已经集成了,很方便了,为什么不用
YGHMXFAL
37 天前
@xxbing #7 我也是,这样完全不被捆绑在任何 2FA 上
mahaoqu
37 天前
MS Authenticator 怎么办
Andim
37 天前
@mahaoqu 不管 google 还是 ms 都可以解除现有 2FA ,然后重新绑定,记得保存那个二维码,用时不会超过 2 分钟,还不会有外泄风险
cioccamilosch697
37 天前
@YGHMXFAL 你是真不怕密钥泄露,不如买个硬件安全密钥存里面双备份即可
YGHMXFAL
37 天前
@cioccamilosch697 怎么泄露?安装扫码器就禁止它联网了,解码成字符串就加密同步到电脑
BeautifulSoap
37 天前
全交给 bitwarden 了至少没那么麻烦

包括谷歌认证在内一堆 app 连导出都麻烦的一批,谁爱用谁用
ufok
36 天前
和 Google 比我不相信你们的产品。反正我用谷歌,你们爱用不用
dislazy2023
36 天前
我自建了 bitwarden rust 版本 用了好几年了
dfdd1811
32 天前
阿里云的 mfa 能不能解成密钥,他那个导出出来的密钥没法导入别的软件,真狗啊…
xwh
29 天前
@dfdd1811 #17 确实,一直在找可以把阿里云 mfa 解密的方法,但是一直没找到

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1039942

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX