Генератор ключей GAuth

CaJlaT

Овощ
Автор темы
Модератор
2,806
2,607
Версия MoonLoader
.027.0-preview
Решил сделать авто-логин с GAuth, но столкнулся с проблемой... генерирует НЕ верные коды, секретку проверил раза 4 уже, всё верно. Код ниже не работает
Lua:
local sha1 = require "sha1"
local basexx = require "basexx"
local band = bit.band

----------------------------
--- Секретный ключ Google Authenticator
secret = ''
--- ID диалога с авторизацией GAuth
ad = 389
----------------------------

function genCode(skey)
skey = basexx.from_base32(skey)
value = math.floor(os.time() / 30)
value = string.char(
0, 0, 0, 0,
band(value, 0xFF000000) / 0x1000000,
band(value, 0xFF0000) / 0x10000,
band(value, 0xFF00) / 0x100,
band(value, 0xFF))
local hash = sha1.hmac_binary(skey, value)
local offset = band(hash:sub(-1):byte(1, 1), 0xF)
local function bytesToInt(a,b,c,d)
    return a*0x1000000 + b*0x10000 + c*0x100 + d
end
hash = bytesToInt(hash:byte(offset + 1, offset + 4))
hash = band(hash, 0x7FFFFFFF) % 1000000
return ("%06d"):format(hash)
end

function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    while not isSampAvailable() do wait(100) end
    while true do
        wait(0)
        if sampIsDialogActive() then
        did = sampGetCurrentDialogId()
        wait(0)
            if did == ad then
                if secret ~= '' then
                    code = genCode(secret)
                            sampAddChatMessage("{808080}[GAuth] {FFFFFF}Входим в игру с кодом "..code, 0xC1C1C1)
                            sampSendDialogResponse(ad, 1, 0, code)
                            sampCloseCurrentDialogWithButton(1)
                else
                    sampAddChatMessage("{808080}[GAuth] {FFFFFF}Не найден секретный ключ.", 0xC1C1C1)
                    return
                end
             end
        end
    end
end
1590148338749.png
Может важно, у меня часовой пояс +1 к МСК
 
Решение
Тут есть исходник и всё работает правильно, смотри как он делал

Albertio

Attention! Thanks for your attention.
877
702
Тут есть исходник и всё работает правильно, смотри как он делал
 
  • Нравится
Реакции: CaJlaT

CaJlaT

Овощ
Автор темы
Модератор
2,806
2,607
Тут есть исходник и всё работает правильно, смотри как он делал
Взял genСode() оттуда, не работает.

Lua:
local samp = require "samp.events"
local lsha1, sha1         = pcall(require, 'sha1') -- gauth
local lbasexx, basexx     = pcall(require, 'basexx') -- gauth
local band = bit.band

----------------------------
--- Секретный ключ Google Authenticator
secret = ''
-- Пароль
pass = ''
----------------------------

function genCode(skey)
    if lbasexx and lsha1 then
        skey = basexx.from_base32(skey)
        value = math.floor(os.time() / 30)
        value = string.char(
        0, 0, 0, 0,
        band(value, 0xFF000000) / 0x1000000,
        band(value, 0xFF0000) / 0x10000,
        band(value, 0xFF00) / 0x100,
        band(value, 0xFF))
        local hash = sha1.hmac_binary(skey, value)
        local offset = band(hash:sub(-1):byte(1, 1), 0xF)
        local function bytesToInt(a,b,c,d)
            return a*0x1000000 + b*0x10000 + c*0x100 + d
        end
        hash = bytesToInt(hash:byte(offset + 1, offset + 4))
        hash = band(hash, 0x7FFFFFFF) % 1000000
        return ('%06d'):format(hash)
    end
end
function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    while not isSampAvailable() do wait(100) end
    while true do
        wait(0)
    end
end
function samp.onShowDialog(id,s,t,b1,b2,text)
    if id == 0 and t:find('Авторизация') then
        sampAddChatMessage("{808080}[GAuth] {FFFFFF}Пароль был введён автоматически.", 0xC1C1C1)
         sampSendDialogResponse(id, 1, 0, pass)
         return false
    end
    if id == 239 and t:find('Google') then
        print('1')
        if secret ~= '' then
            print('2')
            code = genCode(secret)
            sampAddChatMessage("{808080}[GAuth] {FFFFFF}Входим в игру с кодом "..code, 0xC1C1C1)
            sampSendDialogResponse(id, 1, 0, code)
            return false
        else
            sampAddChatMessage("{808080}[GAuth] {FFFFFF}Не найден секретный ключ.", 0xC1C1C1)
            return true
        end
    end
end
1590160782536.png
 

Albertio

Attention! Thanks for your attention.
877
702
Взял genСode() оттуда, не работает.

Lua:
local samp = require "samp.events"
local lsha1, sha1         = pcall(require, 'sha1') -- gauth
local lbasexx, basexx     = pcall(require, 'basexx') -- gauth
local band = bit.band

----------------------------
--- Секретный ключ Google Authenticator
secret = ''
-- Пароль
pass = ''
----------------------------

function genCode(skey)
    if lbasexx and lsha1 then
        skey = basexx.from_base32(skey)
        value = math.floor(os.time() / 30)
        value = string.char(
        0, 0, 0, 0,
        band(value, 0xFF000000) / 0x1000000,
        band(value, 0xFF0000) / 0x10000,
        band(value, 0xFF00) / 0x100,
        band(value, 0xFF))
        local hash = sha1.hmac_binary(skey, value)
        local offset = band(hash:sub(-1):byte(1, 1), 0xF)
        local function bytesToInt(a,b,c,d)
            return a*0x1000000 + b*0x10000 + c*0x100 + d
        end
        hash = bytesToInt(hash:byte(offset + 1, offset + 4))
        hash = band(hash, 0x7FFFFFFF) % 1000000
        return ('%06d'):format(hash)
    end
end
function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    while not isSampAvailable() do wait(100) end
    while true do
        wait(0)
    end
end
function samp.onShowDialog(id,s,t,b1,b2,text)
    if id == 0 and t:find('Авторизация') then
        sampAddChatMessage("{808080}[GAuth] {FFFFFF}Пароль был введён автоматически.", 0xC1C1C1)
         sampSendDialogResponse(id, 1, 0, pass)
         return false
    end
    if id == 239 and t:find('Google') then
        print('1')
        if secret ~= '' then
            print('2')
            code = genCode(secret)
            sampAddChatMessage("{808080}[GAuth] {FFFFFF}Входим в игру с кодом "..code, 0xC1C1C1)
            sampSendDialogResponse(id, 1, 0, code)
            return false
        else
            sampAddChatMessage("{808080}[GAuth] {FFFFFF}Не найден секретный ключ.", 0xC1C1C1)
            return true
        end
    end
end
Посмотреть вложение 57212
Значит не верно юзаешь, так как тот скрипт воркает верно
 

Albertio

Attention! Thanks for your attention.
877
702
Как это sampSendDialogResponse(id, 1, 0, genCode(account_info['gauth'])) можно юзать не правильно?
Давай логически подумаем, в скрипте который я тебе кинул, всё работает гуд, ты пытаешься сделать так же, у тебя не выходит, это не значит что в том примере не верно, это значит что ты делаешь не верно
 

CaJlaT

Овощ
Автор темы
Модератор
2,806
2,607
Давай логически подумаем, в скрипте который я тебе кинул, всё работает гуд, ты пытаешься сделать так же, у тебя не выходит, это не значит что в том примере не верно, это значит что ты делаешь не верно
Решил проблему, перекачав библиотеки.
1590162353023.png