Форум АНТИЧАТ

Форум АНТИЧАТ (https://forum.antichat.xyz/index.php)
-   Реверсинг (https://forum.antichat.xyz/forumdisplay.php?f=94)
-   -   реверсинг формата хранения учетных записей EmFTP (https://forum.antichat.xyz/showthread.php?t=64773)

ProTeuS 19.03.2008 15:43

реверсинг формата хранения учетных записей EmFTP
 
забыл пас на один акк. надо было "вспомнить". вот и решил, 4то самым простым и эффективным способо будет проресер4ить

алго хранения учетных записей и написать свой расшифровщик. исследуеммый софт: http://emftp.com/.
при запуске ftp-клиента у4етки с сохраненными пасами автомати4ески коннектятся, зна4ит: 1. код сохранения и

расшифровки пасов в исследуемом софте присутсует, 4то уже радует; 2. пасы где-то сохраняются и 4итаются при загрузке

выполняемого файла софта.
итого, проверяем в реестре и, не долго искав, находим клю4 HKEY_CURRENT_USER\Software\Emurasoft\Emftp\Config, в

котором хранятся подклю4и, каждый из которых соотвествует нужному аккаунту (т.е., 4исло подклю4ений = коли4еству

у4еток, который созданы и сохранены у вас в программе). заходим в любой подклю4 и сразу бросается в глаза Binary

Value 'Cust' размером 0x6F8, по определенным смещениям в котором вбиты имя фтп, логин и еще какие-то данные.

предположил, 4то это именно шифрованый пас. открываем ехе, ставим бряки на с4итывание реестра и стопаемся при 4тении

только этого зна4ения 'Cust' тут
Код:

.text:0041E669 sub_41E669      proc near              ; CODE XREF: sub_41E76F+15p
.text:0041E669
.text:0041E669 Src            = byte ptr -704h
.text:0041E669 var_C          = dword ptr -0Ch
.text:0041E669 Type            = dword ptr -8
.text:0041E669 cbData          = dword ptr -4
.text:0041E669 hKey            = dword ptr  8
.text:0041E669
.text:0041E669                push    ebp
.text:0041E66A                mov    ebp, esp
.text:0041E66C                sub    esp, 704h
.text:0041E672                push    ebx
.text:0041E673                push    esi
.text:0041E674                mov    ebx, 6F8h      ; выделение памяти для 4итаемого буфера
.text:0041E679                push    ebx            ; Size
.text:0041E67A                xor    esi, esi
.text:0041E67C                push    esi            ; Val
.text:0041E67D                push    edi            ; Dst
.text:0041E67E                call    _memset
.text:0041E683                add    esp, 0Ch
.text:0041E686                mov    eax, edi
.text:0041E688                call    sub_407366
.text:0041E68D                cmp    [ebp+hKey], esi
.text:0041E690                jz      loc_41E767
.text:0041E696                lea    eax, [ebp+cbData]
.text:0041E699                push    eax            ; lpcbData
.text:0041E69A                push    esi            ; lpData
.text:0041E69B                lea    eax, [ebp+Type]
.text:0041E69E                push    eax            ; lpType
.text:0041E69F                push    esi            ; lpReserved
.text:0041E6A0                push    off_462E78      ; lpValueName
.text:0041E6A6                push    [ebp+hKey]      ; hKey
.text:0041E6A9                call    ds:RegQueryValueExA
.text:0041E6AF                test    eax, eax
.text:0041E6B1                jnz    loc_41E767
.text:0041E6B7                cmp    [ebp+Type], 3
.text:0041E6BB                jnz    loc_41E767
.text:0041E6C1                cmp    [ebp+cbData], ebx
.text:0041E6C4                jz      short loc_41E6D3
.text:0041E6C6                cmp    [ebp+cbData], 5F4h
.text:0041E6CD                jnz    loc_41E767
.text:0041E6D3
.text:0041E6D3 loc_41E6D3:                            ; CODE XREF: sub_41E669+5Bj
.text:0041E6D3                lea    esi, [ebp+Src]
.text:0041E6D9                call    sub_4073C0
.text:0041E6DE                lea    eax, [ebp+cbData]
.text:0041E6E1                push    eax            ; lpcbData
.text:0041E6E2                lea    eax, [ebp+Src]
.text:0041E6E8                push    eax            ; lpData
.text:0041E6E9                lea    eax, [ebp+Type]
.text:0041E6EC                push    eax            ; lpType
.text:0041E6ED                push    0              ; lpReserved
.text:0041E6EF                push    off_462E78      ; lpValueName
.text:0041E6F5                push    [ebp+hKey]      ; hKey
.text:0041E6F8                call    ds:RegQueryValueExA
.text:0041E6FE                mov    [ebp+var_C], eax
.text:0041E701                push    ebx            ; Size
.text:0041E702                lea    eax, [ebp+Src]
.text:0041E708                push    eax            ; Src
.text:0041E709                push    edi            ; Dst
.text:0041E70A                call    _memcpy
.text:0041E70F                mov    eax, [edi+5A0h] ; смещение шифрованого паса в с4итаном буфере
.text:0041E715                add    esp, 0Ch
.text:0041E718                lea    esi, [edi+258h] ; смещение заголовка
.text:0041E71E                lea    ebx, [ebp+hKey]
.text:0041E721                mov    [ebp+hKey], eax
.text:0041E724                call    decrypt        ; расшифровываем
.text:0041E729                test    eax, eax
.text:0041E72B                jnz    short loc_41E73C
.text:0041E72D                push    104h            ; Size
.text:0041E732                push    eax            ; Val
.text:0041E733                push    esi            ; Dst
.text:0041E734                call    _memset
.text:0041E739                add    esp, 0Ch
.text:0041E73C
.text:0041E73C loc_41E73C:                            ; CODE XREF: sub_41E669+C2j
.text:0041E73C                and    dword ptr [edi+5A0h], 0
.text:0041E743                cmp    [ebp+cbData], 5F4h
.text:0041E74A                jnz    short loc_41E75D
.text:0041E74C                mov    dword ptr [edi+5A8h], 16h
.text:0041E756                mov    byte ptr [edi+5E8h], 1
.text:0041E75D
.text:0041E75D loc_41E75D:                            ; CODE XREF: sub_41E669+E1j
.text:0041E75D                xor    eax, eax
.text:0041E75F                cmp    [ebp+var_C], eax
.text:0041E762                setz    al
.text:0041E765                jmp    short loc_41E769
.text:0041E767 ; ---------------------------------------------------------------------------
.text:0041E767
.text:0041E767 loc_41E767:                            ; CODE XREF: sub_41E669+27j
.text:0041E767                                        ; sub_41E669+48j ...
.text:0041E767                xor    eax, eax
.text:0041E769
.text:0041E769 loc_41E769:                            ; CODE XREF: sub_41E669+FCj
.text:0041E769                pop    esi
.text:0041E76A                pop    ebx
.text:0041E76B                leave
.text:0041E76C                retn    4
.text:0041E76C sub_41E669      endp

Код:

.text:00403053 decrypt        proc near              ; CODE XREF: sub_41E669+BBp
.text:00403053
.text:00403053 Size            = dword ptr -10h
.text:00403053 Dst            = dword ptr -0Ch
.text:00403053 hProv          = dword ptr -8
.text:00403053 hKey            = dword ptr -4
.text:00403053
.text:00403053                push    ebp
.text:00403054                mov    ebp, esp
.text:00403056                sub    esp, 10h
.text:00403059                push    edi
.text:0040305A                xor    edi, edi
.text:0040305C                push    edi            ; dwFlags
.text:0040305D                push    1              ; dwProvType
.text:0040305F                push    edi            ; szProvider
.text:00403060                push    edi            ; szContainer
.text:00403061                lea    eax, [ebp+hProv]
.text:00403064                push    eax            ; phProv
.text:00403065                mov    [ebp+hProv], edi
.text:00403068                mov    [ebp+hKey], edi
.text:0040306B                call    ds:CryptAcquireContextA
.text:00403071                test    eax, eax
.text:00403073                jz      short loc_4030C5
.text:00403075                push    4              ; Size
.text:00403077                lea    eax, [ebp+Dst]
.text:0040307A                push    esi            ; Src
.text:0040307B                push    eax            ; Dst
.text:0040307C                call    _memcpy
.text:00403081                add    esp, 0Ch
.text:00403084                lea    eax, [ebp+hKey]
.text:00403087                push    eax            ; phKey
.text:00403088                push    edi            ; dwFlags
.text:00403089                push    edi            ; hPubKey
.text:0040308A                push    [ebp+Dst]      ; dwDataLen
.text:0040308D                lea    eax, [esi+4]
.text:00403090                push    eax            ; pbData
.text:00403091                push    [ebp+hProv]    ; hProv
.text:00403094                call    ds:CryptImportKey
.text:0040309A                test    eax, eax
.text:0040309C                jz      short loc_4030C5
.text:0040309E                mov    eax, [ebp+Dst]
.text:004030A1                mov    ecx, [ebx]
.text:004030A3                sub    ecx, eax
.text:004030A5                sub    ecx, 4
.text:004030A8                mov    [ebp+Size], ecx
.text:004030AB                lea    ecx, [ebp+Size]
.text:004030AE                push    ecx            ; pdwDataLen
.text:004030AF                lea    eax, [eax+esi+4]
.text:004030B3                push    eax            ; pbData
.text:004030B4                push    edi            ; dwFlags
.text:004030B5                push    1              ; Final
.text:004030B7                push    edi            ; hHash
.text:004030B8                push    [ebp+hKey]      ; hKey
.text:004030BB                call    ds:CryptDecrypt
.text:004030C1                test    eax, eax
.text:004030C3                jnz    short loc_4030C9
.text:004030C5
.text:004030C5 loc_4030C5:                            ; CODE XREF: decrypt+20j
.text:004030C5                                        ; decrypt+49j
.text:004030C5                xor    eax, eax
.text:004030C7                jmp    short loc_403102
.text:004030C9 ; ---------------------------------------------------------------------------
.text:004030C9
.text:004030C9 loc_4030C9:                            ; CODE XREF: decrypt+70j
.text:004030C9                push    [ebp+Size]      ; Size
.text:004030CC                mov    eax, [ebp+Dst]
.text:004030CF                lea    eax, [eax+esi+4]
.text:004030D3                push    eax            ; Src
.text:004030D4                push    esi            ; Dst
.text:004030D5                call    _memcpy_0
.text:004030DA                mov    eax, [ebp+Size]
.text:004030DD                add    esp, 0Ch
.text:004030E0                cmp    [ebp+hKey], edi
.text:004030E3                mov    [ebx], eax
.text:004030E5                jz      short loc_4030F0
.text:004030E7                push    [ebp+hKey]      ; hKey
.text:004030EA                call    ds:CryptDestroyKey
.text:004030F0
.text:004030F0 loc_4030F0:                            ; CODE XREF: decrypt+92j
.text:004030F0                cmp    [ebp+hProv], edi
.text:004030F3                jz      short loc_4030FF
.text:004030F5                push    edi            ; dwFlags
.text:004030F6                push    [ebp+hProv]    ; hProv
.text:004030F9                call    ds:CryptReleaseContext
.text:004030FF
.text:004030FF loc_4030FF:                            ; CODE XREF: decrypt+A0j
.text:004030FF                xor    eax, eax
.text:00403101                inc    eax
.text:00403102
.text:00403102 loc_403102:                            ; CODE XREF: decrypt+74j
.text:00403102                pop    edi
.text:00403103                leave
.text:00403104                retn
.text:00403104 decrypt        endp

продебажив, можно легко найти смещения в буфере, по которым с4итывается заголовок, клю4и, юзаемые функциями MS

CryptoApi, имя фтп-логин и дешифруемый пас. поням алго фишрования, состряпаем такой работоспособный код, который

будет выводить имя фтп, логи и пас для первого найденного фтп-аккаунта из существующих (кому нужно, парсинг и вывод

всех акков доделает сам, юзая RegEnumKey):
Код:

include 'win32ax.inc'

section '.text' code readable writable executable

RootKey        EQU  HKEY_CURRENT_USER
BUF_SIZE      =    $6F8
header              =    $258 + 4;
spacer              =    $4C;
key_offset    =    $5A0;
ftp_offset    =    $104;
username_offset=    $208;
ftp_caption  db  'FTP: ', 0;
user_caption  db  ', username: ', 0;
pass_caption  db  ', password is: ', 0;
KeyName      db  'Software\Emurasoft\Emftp\Config\account-name', 0;
ValName      db  'Cust', 0;
ValType      db  ?
hReg              dd  ?
hProv              dd  ?
hKey              dd  ?
openkey      dd  ?
result              dd  ?
decrypted    dd  ?
ftpserver    dd  ?
size              dd  ?
key              db  ?
BufSize      dd  BUF_SIZE
account      rb  BUF_SIZE
.code

start:
    invoke  RegOpenKeyExA, RootKey, KeyName, 0, KEY_READ, hReg
    or            eax, eax
    jnz    .err
    mov    [ValType], REG_BINARY
    invoke  RegQueryValueExA, [hReg], ValName, 0, ValType, account, BufSize
    or            eax, eax
    jnz    .err
    invoke  RegCloseKey, [hReg]

    mov    al, [account+key_offset]                      ;key for decrypting
    mov    [key], al                                      ;key :=  Src[key_offset];
    invoke  CryptAcquireContextA, hProv, 0, 0, 1, 0
    invoke  CryptImportKey, [hProv], account+header, spacer, 0, 0, hKey
    xor    eax, eax
    mov    al, [key]
    sub    eax, spacer
    sub    eax, 4
    mov    [size], eax                                ;size := key - spacer - 4;
    mov    eax, account+header+spacer
    mov    [decrypted], eax
    invoke  CryptDecrypt, [hKey], 0, 1, 0, [decrypted], size

    invoke  lstrcatA, result, ftp_caption
    invoke  lstrcatA, result, account+ftp_offset      ;ftp servername
    invoke  lstrcatA, result, user_caption
    invoke  lstrcatA, result, account+username_offset  ;username
    invoke  lstrcatA, result, pass_caption
    invoke  lstrcatA, result, account+header+spacer    ;decrypted pass
    invoke  MessageBox, 0, result, 0, MB_OK              ;show results

    invoke  ExitProcess

 .err:
      ret
.end start



Время: 17:25