Access 97 , Access 2k , Access 03 数据库密码破解

        前阵子应要求解密一个Access数据库文件。

        已知的是数据库密码存放在数据库 mdb 文件中,偏移量为 0x42处 。数据库文件的版本信息存放在 mdb 文件偏移量为 0x14

处的一字节 , 值为0 代表 Access 97的数据库文件,值为1代表Access 2k 及 Access 03 的数据库文件。

        以上就是我得到的信息。分析思路:既然已经知道了数据库密码存放的方式以及偏移量,说明在校验输入的密码是否正确的过程中一定会对存储的密码数据进行访问。只需要对 ReadFile 读取进来的数据,偏移量为 0x42处的一字节下硬件访问断点,不断的跟踪数据就可以得到密码验证过程了。

       好了,有了思路后,开始分析。数据库文件得到后,双击打开,提示输入密码。OD 附加到 Access 97 ,在 ReadFile

下断点,输入密码点击确定后,在ReadFile断下了,获得了缓冲区地址参数后,Ctrl+F9 运行到返回,得到读取的数据内容,

并在0x42处下一字节的硬件访问断点。 F9 继续运行,断下,发现在msjet35.dll 模块的 4047647 函数内 断下,暂且把这个函数

称为 Decrypt_S1 (short for Decrypt Stage 1) , 根据IDA的静态分析,并动态调试追踪函数的参数, 分析得到这个函数共有

4个参数,其中两个是用 栈传递的,还有两个是用寄存器传递的。

.text:04047851 push    7Eh
.text:04047853 lea     eax, [ebp+18h]
.text:04047856 lea     ecx, [esp+224h+init_key]
.text:0404785D push    eax
.text:0404785E lea     esi, [ebp+42h]
.text:04047861 call    Decrypt_S1

        第一个参数是读取的数据库文件的 +0x18 偏移地址,第二个参数是解密次数,第三个参数ecx是前面调用函数初始化

的一个解密数据 init_key,第四个参数是数据库文件的 +0x42 偏移地址。

        其中未知的是第三个参数的值是否是变化的,我进行多次的调试分析,得到结论是:解密任何数据库用的解密数据

init_key 是一样的。 解密函数 Decrypt_S1  的算法非常简单,就是异或而已。以下是我重写的解密过程代码:

void Decrypt_s1_97(char * buf,int offset) 
 {
 	unsigned char *esi=init_key+6;
 	char *edi=buf+offset;
 	unsigned char bl=0,dl=0,dh=0;
 	bl=init_key[4];
 	dl=init_key[5];
 	bl++;
 	
 	unsigned char al=0;
 	int ebp=0x7e;				//解密长度 
 	unsigned char cl=esi[bl];
 	unsigned char ch;
	int max=0; 
 	do{
 		dl=dl+cl;
 		ch=*edi;				//ch 由源文件读取 
 		edi++;
 		al= esi[dl] ;			//经过多次调试发现,代码没错……错的是没有吧 init_key  初始化完整…… 
 		esi[dl ]=cl;
 		esi[bl ]=al ;
 		al+=cl;
 		bl++;
 		ch ^= esi[al];		//al的值没错,错的是 在al偏移位置的值 ……气死了,我复制更长的 init_key 结果就能得到密码了。。。 
 		
 		--ebp;
 		*(edi-1)=ch;
 		cl=esi[(int)bl];			//cl 从init_key 读取 
	 }while(ebp);
	 init_key[4]=0;
	 init_key[5]=dl;
	
 	
 }

    代码写得少,比较丑,见谅~

################################################################################

      好了,有了前面的分析思路,对于 Access 2k 以及 Access 03 也是一样的分析方法,只是 2k 跟 03 的数据库多了

一个 Decrypt_s2 函数而已,这个函数也很简单,只是调用 floor() 函数,用返回值再对 Decrypt_s1 得到的密码在进行

一轮的异或解密而已。

 void Decrypt_s2(char * buf,int offset)
 {
 	double x= *((double *) &buf[0x72]);		//数据类型为 double 8字节 ,float 4字节 
 	factor=floor(x);						//floor(double x) 
 	int *target=(int*)(buf+offset);
 	for(int i=0;i<10;i++)
 		*(target+i)^=factor;
 }

      ok ,以上就是我对Access 数据库 97 ~ 03 的密码分析过程,第一次写这种文章,写的很烂,见谅哈哈。

下面附上我写的解密源码,Dev C++可以直接编译运行:

#include<stdio.h>
#include<stdlib.h>
#include<memory.h>
#include<math.h> 
#define readSize 0x1000
unsigned char init_key[]={
0xC7, 0xDA, 0x39, 0x6B, 0x00, 0x00, 0x4E, 0xA2, 0xDD, 0x43, 0x16, 0xD0, 0x34, 0xBE, 0x26, 0x60,
0x9B, 0x11, 0x56, 0xAE, 0x12, 0x8C, 0xF6, 0x22, 0x7C, 0xCB, 0x4D, 0xCD, 0x8D, 0xF1, 0x5E, 0x27,
0x52, 0x1D, 0x24, 0x3E, 0x72, 0x3C, 0xE3,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, 0xD1, 0xD7,
0x8B, 0xFE, 0x76, 0xA7, 0xBB, 0x9D, 0x0E, 0xA5, 0x81, 0x64, 0x95, 0xF9, 0x2F, 0x62, 0x94, 0x05,
0x0F, 0x87, 0x4B, 0xD6, 0xC7, 0xA9, 0x74, 0x96, 0x41, 0x13, 0xD8, 0xF7, 0x65, 0xB6, 0xBC, 0xEC,
0x86, 0xDF, 0x3B, 0xDE, 0x67, 0x0D, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};



int factor=0xa926;		//第二次解密密钥 ,不同密码值不同。。。我靠 

//--------------------------03 破解函数 

void Decrypt_s1(char * buf,int offset) ;

void Decrypt_s2(char * buf,int offset);

void Decrypt_03(char * buf);	//包装函数 

void show(char *buf) ; 					//输出密码 

//---------------------------97 破解函数 

void Decrypt_s1_97(char * buf,int offset) ;

void show_97(char *buf) ;

void Decrypt_97(char * buf);	//包装函数 

void show(char * buf);				//输出密码 



int main(int argc,char **argv)
{
	FILE *fp;	
	
	if(argc !=2 )
	{
		printf("Access 97 ~ 2003 password recover\nUsage:%s dbFileName.mdb\n",argv[0]);
		return 0;
	}
	
	if((fp=fopen(argv[1],"r")) == 0)
	{
		printf("Could not open file %s\n",argv[1]);
		return 0;
	}
	
	char *buf=(char*)malloc(readSize*sizeof(char));	
	
	memset(buf,0,readSize);
	
	fread(buf,readSize,1,fp);
	
	fclose(fp);
	
	if(buf[0x14] == 0)		//97 版本 
		 Decrypt_97(buf);
	else if(buf[0x14] == 1)	//03 版本 
		Decrypt_03(buf);
	 
	 free(buf);
 } 
 
 void Decrypt_s1(char * buf,int offset) 
 {
 	unsigned char *esi=init_key+6;
 	char *edi=buf+offset;
 	unsigned char bl=0,dl=0,dh=0;
 	bl=init_key[4];
 	dl=init_key[5];
 	bl++;
 	
 	unsigned char al=0;
 	int ebp=0x80;
 	unsigned char cl=esi[bl];
 	unsigned char ch;
	int max=0; 
 	do{
 		dl=dl+cl;
 		ch=*edi;				//ch 由源文件读取 
 		edi++;
 		al= esi[dl] ;			//经过多次调试发现,代码没错……错的是没有吧 init_key  初始化完整…… 
 		esi[dl ]=cl;
 		esi[bl ]=al ;
 		al+=cl;
 		bl++;
 		ch ^= esi[al];		//al的值没错,错的是 在al偏移位置的值 ……气死了,我复制更长的 init_key 结果就能得到密码了。。。 
 		
 		--ebp;
 		*(edi-1)=ch;
 		cl=esi[(int)bl];			//cl 从init_key 读取 
	 }while(ebp);
	 init_key[4]=0;
	 init_key[5]=dl;
 	
 }
 
 void Decrypt_s2(char * buf,int offset)
 {
 	double x= *((double *) &buf[0x72]);		//数据类型为 double 8字节 ,float 4字节 
 	factor=floor(x);						//floor(double x) 
 	int *target=(int*)(buf+offset);
 	for(int i=0;i<10;i++)
 		*(target+i)^=factor;
 }
 
 void show(char *buf) 
 {
 	printf("password is  :\n" );
 	char tmp[21];
 	memset(tmp,0,21);
 	for(int i=0;i<20 ;i++)
 	{
 		if(buf[0x42+i*2] !=0 )
 			tmp[i]=buf[0x42+i*2];
 		else
 			break;
	 }
	 printf("%s",tmp);
 }
 
 
  void Decrypt_s1_97(char * buf,int offset) 
 {
 	unsigned char *esi=init_key+6;
 	char *edi=buf+offset;
 	unsigned char bl=0,dl=0,dh=0;
 	bl=init_key[4];
 	dl=init_key[5];
 	bl++;
 	
 	unsigned char al=0;
 	int ebp=0x7e;				//解密长度 
 	unsigned char cl=esi[bl];
 	unsigned char ch;
	int max=0; 
 	do{
 		dl=dl+cl;
 		ch=*edi;				//ch 由源文件读取 
 		edi++;
 		al= esi[dl] ;			//经过多次调试发现,代码没错……错的是没有吧 init_key  初始化完整…… 
 		
 		esi[dl ]=cl;
 		esi[bl ]=al ;
 		al+=cl;
 		bl++;
 		
 		ch ^= esi[al];		//al的值没错,错的是 在al偏移位置的值 ……气死了,我复制更长的 init_key 结果就能得到密码了。。。 
 		
 		--ebp;
 		*(edi-1)=ch;
 		cl=esi[(int)bl];			//cl 从init_key 读取 
	 }while(ebp);
	 init_key[4]=0;
	 init_key[5]=dl;

 
 	
 }
  void show_97(char *buf) 
 {
 	printf("password is  :\n" );
 	char tmp[21];
 	memset(tmp,0,21);
 	for(int i=0;i<20 ;i++)
 	{
 		if(buf[i+0x42] !=0 )
 			//printf("%c",buf[0x42+i*2]);
 			tmp[i]=buf[0x42+i];
 		else
 			break;
	 }
	 printf("%s",tmp);
 }
 
 
 void Decrypt_97(char * buf)
 {
 	Decrypt_s1_97(buf,0x18);
 	show_97(buf); 
} 

void Decrypt_03(char * buf)
{
	//先用 init_key key 解密 0x18 偏移起始的 0x80 字节
	 Decrypt_s1(buf,0x18);
	 
	//第二次用 factor 解密 0x42 偏移起始的 0x2a 字节的密码
	 
	 Decrypt_s2(buf,0x42); 
	 
	 show(buf);
}
 
 

猜你喜欢

转载自blog.csdn.net/cwg2552298/article/details/81284643