1. 程式人生 > 其它 >PC端google OTP驗證碼獲取器

PC端google OTP驗證碼獲取器

感覺在安全的路上走遠了qwq,把安全的東西用得不怎麼安全了。

import PySimpleGUI as sg
import hmac
import base64
import struct
import hashlib
import time
import sys
import requests


def get_hotp_token(secret, intervals_no):
    key = base64.b32decode(secret)
    msg = struct.pack(">Q", intervals_no)
    h = hmac.new(key, msg, hashlib.sha1).digest()
    o = h[len(h)-1] & 0x0f
    h = (struct.unpack(">I", h[o:o + 4])[0] & 0x7fffffff) % 1000000
    return h

def get_totp_token(secret):
    intervals_no = int(time.time()) // 30
    totp_token = get_hotp_token(secret, intervals_no)
    return totp_token

if __name__ == '__main__':
    
    Sec1 = 'xxx' #自己更換需要的key
    Sec2 = 'xxx'
    Sec3 = 'xxx'
    Sec1 = Sec1.replace(' ', '').upper()
    Sec2 = Sec2.replace(' ', '').upper()
    Sec3 = Sec3.replace(' ', '').upper()
    #if len(Sec1) % 8 != 0 and len(Sec2) % 8 != 0 and len(Sec3) % 8 != 0:
        #print('Illegal base32 data at input byte %d' % ((len(Sec)//8+1)*8))
        #exit(1)
        
    sg.SetOptions(text_justification='center')
    layout = [
         # key 值代表了是這個輸入框輸入的值,以字典的 鍵 值來表示,這個用於找到輸入框並跟新它的值
        [sg.Text('xxxx', size=(15, 1)), sg.Input(key='HIDSCODE')],#自己設定顯示
        [sg.Text('xxx4A', size=(15, 1)), sg.Input(key='HK4ACODE')],
        [sg.Text('xxx4A', size=(15, 1)), sg.Input(key='SS4ACODE')],
        [sg.Button('GET')]
    ]
	# 建立視窗及設定標題
    window = sg.Window('簡易谷歌驗證碼獲取器', layout)
    # 迴圈按鈕元素的值
    while True:
        event, values = window.read()
            #if read == True:
        if event == 'GET':
            validation_code1 = get_totp_token(Sec1)
            validation_code2 = get_totp_token(Sec2)
            validation_code3 = get_totp_token(Sec3)
            hidscode = '%06d  [!]%02d後秒過期' % (validation_code1, 30 - int(time.time()) % 30)
            baoleijicode = '%06d  [!]%02d後秒過期' % (validation_code2, 30 - int(time.time()) % 30)
            baoleijicode2 = '%06d  [!]%02d後秒過期' % (validation_code3, 30 - int(time.time()) % 30)
            new_hidscode = window['HIDSCODE'].update(hidscode)
            new_4acode = window['HK4ACODE'].update(baoleijicode)
            new_4acode2 = window['SS4ACODE'].update(baoleijicode2)
        if event in (None, 'Exit'):
            break
    # 顯示視窗
    window.read()

    window.close()