[逆向]
Reversing.kr Ransomware
· 2 分钟阅读 · @admin

首先看程序,发现被加了upx壳,使用脱壳工具脱掉后,看有没有关键的字符串。
来到引用Key的地方。
.text:0044A775 push offset aKey ; "Key : "
.text:0044A77A call ds:printf
.text:0044A780 add esp, 4
.text:0044A783 call sub_401000
.text:0044A788 push offset input_key
.text:0044A78D push offset aS ; "%s"
.text:0044A792 call ds:scanf
.text:0044A798 add esp, 8
.text:0044A79B mov dword ptr [ebp-18h], offset input_key
.text:0044A7A2 mov eax, [ebp-18h]
.text:0044A7A5 add eax, 1
.text:0044A7A8 mov [ebp-1Ch], eax
这段汇编代码把输入用来解密文件的key保存在input_key变量中。然后把input_key赋值给[ebp-18] 和 key值地址加一后的地址赋予[ebp-1c] (即),继续往下走。碰到一个循环。
.text:0044A7AB loc_44A7AB: ; CODE XREF: _main+371DBj
.text:0044A7AB mov ecx, [ebp-18h]
.text:0044A7AE mov dl, [ecx]
.text:0044A7B0 mov [ebp-1Dh], dl
.text:0044A7B3 add dword ptr [ebp-18h], 1
.text:0044A7B7 cmp byte ptr [ebp-1Dh], 0
.text:0044A7BB jnz short loc_44A7AB
依次比较key的每一位,如果为0,退出循环。
.text:0044A7BD mov eax, [ebp-18h]
.text:0044A7C0 sub eax, [ebp-1Ch] ;计算key长度
.text:0044A7C3 mov [ebp-24h], eax
.text:0044A7C6 mov ecx, [ebp-24h]
.text:0044A7C9 mov [ebp-0Ch], ecx
.text:0044A7CC call sub_401000
.text:0044A7D1 mov dword ptr [ebp-8], 0
.text:0044A7D8 push offset aRb ; "rb"
.text:0044A7DD push offset aFile ; "file"
.text:0044A7E2 call ds:fopen ;打开加密文件file
.text:0044A7E8 add esp, 8
.text:0044A7EB mov [ebp-4], eax
.text:0044A7EE call sub_401000
.text:0044A7F3 cmp dword ptr [ebp-4], 0
.text:0044A7F7 jnz short loc_44A819
.text:0044A7F9 call sub_401000
.text:0044A7FE push offset unk_44C1C4
.text:0044A803 call ds:printf
.text:0044A809 add esp, 4
.text:0044A80C call sub_401000
.text:0044A811 push 0
.text:0044A813 call ds:exit
通过key的最后一位的地址减去key值首地址+1来计算key长度,然后打开加密文件file,如果打开失败则退出程序。成功则跳转到loc_44a819处。汇编代码中call sub_401000可忽视,里面都是些垃圾代码。
来到loc_44a819代码。
.text:0044A819 loc_44A819: ; CODE XREF: _main+37217j
.text:0044A819 push 2
.text:0044A81B push 0
.text:0044A81D mov edx, [ebp-4]
.text:0044A820 push edx
.text:0044A821 call ds:fseek ;指向文件末尾
.text:0044A827 add esp, 0Ch
.text:0044A82A call sub_401000
.text:0044A82F mov eax, [ebp-4]
.text:0044A832 push eax
.text:0044A833 call ds:ftell ;计算到文件首的偏移
.text:0044A839 add esp, 4
.text:0044A83C mov [ebp-10h], eax
.text:0044A83F call sub_401000
.text:0044A844 mov ecx, [ebp-4]
.text:0044A847 push ecx
.text:0044A848 call ds:rewind ;重新将文件指针指向文件头
.text:0044A84E add esp, 4
.text:0044A851 call sub_401000
.text:0044A856
.text:0044A856 loc_44A856: ; CODE XREF: _main+372B5j
.text:0044A856 mov edx, [ebp-4] ;
.text:0044A859 push edx
.text:0044A85A call ds:feof
.text:0044A860 add esp, 4
.text:0044A863 test eax, eax
.text:0044A865 jnz short loc_44A897
.text:0044A867 call sub_401000
.text:0044A86C mov eax, [ebp-4]
.text:0044A86F push eax
.text:0044A870 call ds:fgetc
.text:0044A876 add esp, 4
.text:0044A879 mov ecx, [ebp-8];[ebp-8] = fileOffset
.text:0044A87C mov byte_5415B8[ecx], al
.text:0044A882 call sub_401000
.text:0044A887 mov edx, [ebp-8]
.text:0044A88A add edx, 1
.text:0044A88D mov [ebp-8], edx
.text:0044A890 call sub_401000
.text:0044A895 jmp short loc_44A856
开头代码用 将文件指针移动到文件末尾,计算到文件头的偏移来计算文件大小。然后重新加那个文件指针指向文件头。嗯,下面又是一个循环。主要功能就是把文件内容复制到byte_5415B8指向的内存地址。复制完毕后则跳到loc_44A897,这里是个循环。
.text:0044A897 loc_44A897: ; CODE XREF: _main+37285j
.text:0044A897 call sub_401000
.text:0044A89C mov dword ptr [ebp-8], 0;[ebp-8] = fileOffset
.text:0044A8A3 jmp short loc_44A8AE
.text:0044A8A5 loc_44A8A5: ; CODE XREF: _main+3731Dj
.text:0044A8A5 mov eax, [ebp-8]
.text:0044A8A8 add eax, 1
.text:0044A8AB mov [ebp-8], eax
.text:0044A8AE
.text:0044A8AE loc_44A8AE: ; CODE XREF: _main+372C3j
.text:0044A8AE mov ecx, [ebp-8]
.text:0044A8B1 cmp ecx, [ebp-10h] ;
.text:0044A8B4 jnb short loc_44A8FF;偏移大于文件长度则退出循环
.text:0044A8B6 mov edx, [ebp-8]
.text:0044A8B9 movsx ecx, byte_5415B8[edx]
.text:0044A8C0 mov eax, [ebp-8]
.text:0044A8C3 xor edx, edx
.text:0044A8C5 div dword ptr [ebp-0Ch] ;[ebp-0c] key长度
.text:0044A8C8 movsx edx, byte_44D370[edx] ;key地址
.text:0044A8CF xor ecx, edx
.text:0044A8D1 mov eax, [ebp-8]
.text:0044A8D4 mov byte_5415B8[eax], cl
.text:0044A8DA call sub_401000
.text:0044A8DF mov ecx, [ebp-8]
.text:0044A8E2 movsx edx, byte_5415B8[ecx]
.text:0044A8E9 xor edx, 0FFh
.text:0044A8EF mov eax, [ebp-8]
.text:0044A8F2 mov byte_5415B8[eax], dl
.text:0044A8F8 call sub_401000
.text:0044A8FD jmp short loc_44A8A5
这段循环代码就是解密代码了。

