V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
kuingsmile
V2EX  ›  程序员

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

  •  1
     
  •   kuingsmile ·
    Kuingsmile · 11 天前 · 2251 次点击

    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.
    
    18 条回复    2024-05-20 16:35:57 +08:00
    YGHMXFAL
        1
    YGHMXFAL  
       11 天前
    不如改变习惯:

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

    包括谷歌认证在内一堆 app 连导出都麻烦的一批,谁爱用谁用
    ufok
        15
    ufok  
       10 天前
    和 Google 比我不相信你们的产品。反正我用谷歌,你们爱用不用
    dislazy2023
        16
    dislazy2023  
       10 天前
    我自建了 bitwarden rust 版本 用了好几年了
    dfdd1811
        17
    dfdd1811  
       6 天前
    阿里云的 mfa 能不能解成密钥,他那个导出出来的密钥没法导入别的软件,真狗啊…
    xwh
        18
    xwh  
       3 天前
    @dfdd1811 #17 确实,一直在找可以把阿里云 mfa 解密的方法,但是一直没找到
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5001 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 08:56 · PVG 16:56 · LAX 01:56 · JFK 04:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.