- // 核心代码片段,某些全局变量在 *.h 中定义。。。。
- //
- //
- ///////////////////////////////////////////////////////////////////
- //
- //
- // Ruijie 8021x.exe 客户端验证及其完整性验证(V2.45 以后版本?)
- //
- // 有些变态用了 8 次 MD5 算法检校 0x00401000h --> 0x00421000h 程序段
- // (每段长0x4000h),每分段前加入了服务器返回的 MD5 串,最后得到的
- // 8组 MD5 Hash 再和服务器返回的 MD5 串做运算生成 0x90h 的表 TableC
- // 再作一次 MD5 运算。
- //
- //产生特殊随机字符串
- CString CMentoSupplicantDlg::Randstr(bool过滤词
- {
- CString strFormat,strRandom;
- int a,b,c,d,e;
- unsigned t;
- strFormat="%X%X%X%X%X%X9884773d9f46acafd7839eb38789088ac9534";
- if 过滤词{strFormat="%X%X%X%X%X%X388498639f49ebaca773dfd78789088ac9534";}
- t=time(NULL);
- srand(t);
- a=rand();
- b=rand();
- c=rand();
- d=rand();
- e=rand();
- strRandom.Format(strFormat,a,b,c,d,e,t);
- return strRandom;
- }
- //验证算法
- void CMentoSupplicantDlg::Clog()
- {
- int i,j=0;
- int nLength = 0; //number of bytes read from the file
- const int nBufferSize = 0x4000; //checksum the file in blocks of 4096 bytes
- BYTE Buffer1[nBufferSize]; //buffer for data read from the file
- BYTE Buffer2[nBufferSize+16]; //buffer for data to MD5 Checksum
- BYTE md5rev[16]; //buffer for receive MD5 from the Server
- BYTE *md5Dig1,*md5Dig2;
- ULONGLONG lActual;
- static byte TableC[]={
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
- // Authentication Server MD5 Hash
- for (i=0;i<16;i++)
- md5rev[i]=bMD5Source[24+i];
- // Tranform to TableC
- TableC[0]=md5rev[0];
- for (i=1;i<8;i++){
- TableC[i*18-1]=md5rev[i*2-1];
- TableC[i*18]=md5rev[i*2];}
- TableC[143]=md5rev[15];
- // Check 8021x.exe, Exist ?
- if (CFile::GetStatus(strRJFileN,FileStatus)==FALSE){
- //PrintOutput(" >> 无法找到“8021x.exe”!!!");
- //PrintOutput(" 请复制到本程序目录下,");
- //PrintOutput(" 否则无法生成Ruijie客户端信息。");
- //return a 32 bits Random string
- strMD5Hash=Randstr(false);
- return;
- }
- // Open the 8021.exe for reading.
- CFile File(strRJFileN, CFile::modeRead | CFile::shareDenyWrite | CFile::typeBinary);
- try
- {
- //checksum the file in blocks of 4096 bytes
- lActual=File.Seek (0x1000,CFile::begin);
- while ((nLength = File.Read( Buffer1, nBufferSize )) > 0 && j<8)
- {
-
- for (i=0;i<16;i++){
- Buffer2[i]=md5rev[i];}
- for (i=0;i<nBufferSize;i++){
- Buffer2[i+16]=Buffer1[i];}
-
- //Return each block MD5 Hash
- md5Dig1=ComputeHash(Buffer2,nBufferSize+16);
-
- for (i=0;i<16;i++){
- TableC[18*j+i+1]=md5Dig1[i];}
- j++;
- }//end of while
- // PrintOutput( "MD5_1to8_Done!");
- md5Check=ComputeHash(TableC,144);
-
- //not the best work....
- CString strTemp,strFormat;
- strMD5Hash="";
- for (i=0;i<16;i++){
- if (md5Check[i]) {//if outside
- if (md5Check[i]>0x0f){
- strFormat="%x";}
- else{
- strFormat="0%x";}
- strTemp.Format(strFormat,md5Check[i]);
- strMD5Hash=strMD5Hash+strTemp;}
- else{//if outside
- strMD5Hash=strMD5Hash+"00";}//end of if outside
-
- }//end of for
- PrintOutput(" >> Ruijie “8021x.exe” 验证 MD5: ");
- PrintOutput(" "+strMD5Hash);
- return;
- }//end of try
- //catche Exception error for debug only
- catch (CFileException* e )
- {
- #ifdef _DEBUG
- afxDump << "File could not be opened " << e->m_cause << "\n";
- #endif
- throw e;
- }//end of catch
- }//end of fuction
复制代码 |