15
Name:
Anonymous
2007-05-25 14:55
ID:me+NyHor
Comparing the files side by side in a hex editor indicates that many of the bytes remain the same in all files. This would indicate to me that some sort of XOR-based algorithm is in place and those sections that are the same will largely be 00s.
How to determine the XOR key? Well, first it is useful to determine how large it is - does it have periodicity? Picking a couple of bytes from the parts of the files that are largely the same and searching for it again in that file shows that the pattern repeats itself every 662 (decimal) bytes.
Next, I picked what looked like a relatively sparse file (i.e. when decrypted will be mostly zeroes) and ran a program on it to count the frequencies at which different bytes appear in the repeated sections of 662 bytes.
/* datstat.c */
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
int main(int argc, char* argv[])
{
unsigned char buffer[662];
int frequencies[662*256] = {0};
int bytes_read = 0;
int i, j;
int highest_freq, highest_pos, tmp;
_setmode(_fileno(stdin), _O_BINARY);
do {
bytes_read = fread(buffer, 1, 662, stdin);
for (i=0;i<bytes_read;i++)
{
frequencies[i*256+(int)(buffer[i])]++;
}
} while(bytes_read > 0 || !feof(stdin));
printf("unsigned char key[662] = {\n");
for(i=0;i<662;i++)
{
highest_pos = 0;
highest_freq = 0;
for(j=0;j<256;j++)
{
tmp = frequencies[i*256+j];
if (tmp>highest_freq)
{
highest_pos = j;
highest_freq = tmp;
}
}
printf(" 0x%02X", highest_pos);
if (i<661)
printf(",");
if (7==i%8)
printf("\n");
}
printf("};");
return 0;
}
Running datstat < BanNick.dat
spat out a likely key, which I then included in the next program to decode the dat files:
/* datdec.c */
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
unsigned char key[662] = {
0xA5, 0x93, 0xF7, 0xB5, 0x6C, 0x63, 0x5B, 0x4A,
0xA6, 0x0A, 0xA8, 0xE0, 0xB3, 0xB9, 0x59, 0xD2,
0x10, 0x47, 0xFA, 0x4A, 0xCF, 0xD4, 0x3D, 0x07,
0x44, 0xAC, 0x4B, 0x5E, 0x02, 0x6D, 0x58, 0x7F,
0x06, 0x6D, 0x7A, 0xFA, 0x31, 0x56, 0xBB, 0x82,
0xFC, 0x13, 0x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0x95, 0x98, 0x6C, 0xCB, 0xCF,
0x4D, 0x60, 0xEF, 0x9A, 0x83, 0x42, 0x06, 0x64,
0x39, 0x1D, 0xBA, 0xBC, 0x17, 0x0D, 0x85, 0xC2,
0x0D, 0x54, 0x76, 0xDC, 0x38, 0xAB, 0x32, 0xAB,
0x05, 0xD6, 0x39, 0x3E, 0x98, 0x7B, 0x6A, 0x85,
0x6F, 0x34, 0xCA, 0x08, 0x42, 0xE3, 0x81, 0xD8,
0x2E, 0x46, 0x25, 0xC6, 0x13, 0xCB, 0x3B, 0xD4,
0x3B, 0xA5, 0xFB, 0xE9, 0x3C, 0x1F, 0x54, 0xC9,
0x1F, 0x30, 0x30, 0x43, 0xC1, 0x50, 0xF9, 0xAD,
0x7A, 0x8B, 0x5C, 0x8D, 0xFD, 0xD4};
int main(int argc, char* argv[])
{
unsigned char buffer[662];
int bytes_read = 0;
int i;
_setmode(_fileno(stdin), _O_BINARY);
_setmode(_fileno(stdout), _O_BINARY);
do {
bytes_read = fread(buffer, 1, 662, stdin);
for (i=0;i<bytes_read;i++)
{
buffer[i] ^= key[i];
}
fwrite(buffer, 1, bytes_read, stdout);
} while(bytes_read > 0 || !feof(stdin));
return 0;
}
One for %a in (*.dat) do datdec.exe < %a > %a.dec
later and they're all decrypted. Some visual checking in the hex editor shows that it was successful.
They're not XLS files though. The data is stored in a custom format but the records are fixed size. All text appears to be Unicode and much of it is in Korean.