密文存储在%SYSTEM%\micsystem.bin中,OD字符串参考直接看到。
PEiD查壳为Borland C++,在CreateFileA上下断,F9运行;经过读取两次断在LoadIc
onA中,一次读login2.dat配置上,第四次向下找点跟进就是decipher过程。
稍微跟一下,过程就很清晰了。
004025D7|. push dword ptr [ebp+8] ; /指向文件中的密文
004025DA|. call <jmp.&cw3220._strlen> ; \_strlen
004025DF|. pop ecx
004025E0|. dec eax
004025E1|. mov dword ptr [ebp-10], eax
004025E4|. xor ebx, ebx
004025E6|. cmp ebx, dword ptr [ebp-10] ; 长度为0?
004025E9|. jg short 0040265E
004025EB|> /mov eax, dword ptr [ebp+8]
004025EE|. |mov dl, byte ptr [eax+ebx]
004025F1|. |mov byte ptr [ebp+ebx-74], dl
004025F5|. |movsx esi, byte ptr [ebp+ebx-74] ; 取字符放入esi
004025FA|. |cmp esi, 20
004025FD|. |jl short 00402658
004025FF|. |cmp esi, 7E
00402602|. |jg short 00402658
00402604|. |inc ebx
00402605|. |add esi, -20 ; buf - 0x20
00402608|. |mov eax, dword ptr [ebp-4] ; 0x75B9
0040260B|. |imul ebx ; 0x75B9 * (i + 1)
0040260D|. |mov ecx, 188B9 ; ecx = 0x188b9
00402612|. |cdq
00402613|. |idiv ecx
00402615|. |mov dword ptr [ebp-78], edx ; 存放余数结果
00402618|. |fild dword ptr [ebp-78] ; 浮点运算开始
0040261B|. |fld tbyte ptr [40266A] ; f1
00402621|. |fmulp st(1), st
00402623|. |fmul dword ptr [402676] ; f2 = 96.00000
00402629|. |fstp qword ptr [ebp-C]
0040262C|. |fld qword ptr [ebp-C]
0040262F|. |call <jmp.&cw3220.__ftol> ; 转换成整形
00402634|. |push eax ; 结果压栈
00402635|. |mov eax, esi ; eax = buf - 0x20
00402637|. |pop edx
00402638|. |sub eax, edx ; eax减去浮点结果
0040263A|. |mov ecx, 5F
0040263F|. |cdq
00402640|. |idiv ecx ; 除以0x5F,第二次取模
00402642|. |mov esi, edx ; esi = 余数结果
00402644|. |test esi, esi
00402646|. |jge short 0040264B
00402648|. |add esi, 5F ; 若结果小于0,加上5f修正
0040264B|> |add esi, 20
0040264E|. |dec ebx ; 恢复i
0040264F|. |mov eax, esi
00402651|. |mov byte ptr [edi+to_text], al ; 存放明文结果
00402657|. |inc edi
00402658|> |inc ebx
00402659|. |cmp ebx, dword ptr [ebp-10]
0040265C|.^ \jle short 004025EB
// filename: readpass.c
// purpose: fetch saved account password of dr.com client
// lhjjx, Apr 21th, 2007
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <windows.h>
#define BUFSIZE 0x60
const char* szFilename = "\\micsystem.bin";
char* decipher(char buf[], int len)
{
double f1 = 9.9465868287297208320e-06,
f2 = 96.00000, f;
char* szPlainText;
int i, r;
char c;
szPlainText = malloc(len);
for(i = 0; i < len; i++){
if (buf < 0x20 || buf > 0x7E) continue;
else{
c = buf - 0x20;
r = (0x75B9 * (i + 1)) % 0x188B9; // 第一轮余数计算
f = (double)r * f1 * f2; // 浮点运算
c = (c - (int)f) % 0x5F; // 最后一轮余数运算,结果
if(c <= 0) c += 0x7F;
else c += 0x20;
szPlainText = c;
}
}
return szPlainText;
}
int main()
{
char szFilePath[128];
char buf[BUFSIZE] = {0};
FILE* fp;
GetSystemDirectory(szFilePath, MAX_PATH);
strcat(szFilePath, szFilename);
if((fp = fopen(szFilePath, "r")) != NULL)
{
fgets(buf, BUFSIZE, fp);
printf("%s", decipher(buf, strlen(buf)));
getch();
fclose(fp);
}
else{
printf("\ncannot open file: %s\n", szFilePath);
return 1;
}
return 0;
} |