安恒杯九月赛_NewDriver
2018-09-22 本文已影响151人
Kirin_say
今天的比赛
因为有事,下午快结束才开始看
只弄了一个简单的逆向
其他的以后复现
NewDriver
找到main函数,F5存在sp指针错误
直接ALT+K修复掉负数指针即可
看到main:
if ( strlen(v11) == 33 )
{
v3 = base64_enc(v11);
sub_F91000(&v7, (int)&v9, strlen(&v9));
sub_F910E0((int)&v7, (int)v3, strlen(v3));
v4 = 0;
v5 = v3 - key;
do
{
if ( key[v5 + v4] != key[v4] )
exit(0);
++v4;
}
while ( v4 < 44 );
printf("Congratulation!!!!!!\n");
}
程序过程:
判断输入长度是否为33
而后对输入进行三次加密
最终与预先定义的key进行比较
三次加密:
第一次很显然是自行定义字母顺序的一个base64加密:
ABCDEFGHIJSTUVWKLMNOPQRXYZabcdqrstuvwxefghijklmnopyz0123456789+/
第二个不用逆,猜测大概是去在v7中生成一段16*16的数据在第三个加密中使用:
第三个
v3 = (v3 + 1) % 256; // v3++;
v6 = *(_BYTE *)(v3 + result); // v6=key2[v3]
v4 = (v6 + v4) % 256;
*(_BYTE *)(v3 + result) = *(_BYTE *)(v4 + result);
*(_BYTE *)(v4 + result) = v6;
*(_BYTE *)(v5++ + base64_enc) ^= *(_BYTE *)((v6 + *(unsigned __int8 *)(v3 + result)) % 256 + result);
}
while ( v5 < len );
}
return result;
}
很简单的矩阵变换(解出flag才想起是rc4,不过这里看不出也不影响)
其最后进行:
*(_BYTE *)(v5++ + base64_enc) ^= *(_BYTE *)((v6 + *(unsigned __int8 *)(v3 + result)) % 256 + result);
我们只需要知道每步的:
*(_BYTE *)((v6 + *(unsigned __int8 *)(v3 + result)) % 256 + result)
(这里直接提取出第二步加密后的v7所指处的数据,套用第三步加密步骤即可)
再与预先的key进行异或即可得到正确的base64_enc
再根据程序自行定义的字母顺序base64_decode即可:
key=[0x66, 0x32, 0xCA, 0xA0, 0xBF, 0x98, 0x2D, 0x76, 0xF1, 0x59, 0x2A, 0x4A, 0xF4, 0x30, 0xAD, 0xD2, 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68, 0xAB, 0x36, 0xDA, 0xC8, 0xE2, 0x37, 0xD9, 0xA2, 0x5A, 0xD7, 0x6A, 0xB5, 0xFF, 0xE9, 0xBA, 0x52, 0x15, 0xF6, 0xBC, 0x9A, 0xB6, 0xEF, 0x6D, 0xCB, 0x4D, 0xAE, 0xE4, 0xA1, 0xAC, 0xEB, 0x0E, 0x71, 0x7B, 0xF3, 0x24, 0xC2, 0xFB, 0x7D, 0x86, 0x55, 0xAF, 0x3A, 0xDF, 0x3E, 0x14, 0xB9, 0x9B, 0x16, 0xDC, 0x73, 0x57, 0xE5, 0xC7, 0x8A, 0xA8, 0x66, 0x6C, 0x61, 0x67, 0x7B, 0x74, 0x68, 0x69, 0x73, 0x5F, 0x69, 0x73, 0x5F, 0x6E, 0x6F, 0x74, 0x5F, 0x74, 0x68, 0x65, 0x5F, 0x66, 0x6C, 0x61, 0x67, 0x5F, 0x68, 0x61, 0x68, 0x61, 0x68, 0x61, 0x7D]
key2=[0x20, 0xC3, 0x1A, 0xAE, 0x97, 0x3C, 0x7A, 0x41, 0xDE, 0xF6, 0x78, 0x15, 0xCB, 0x4B, 0x4C, 0xDC, 0x26, 0x55, 0x8B, 0x55, 0xE5, 0xE9, 0x55, 0x75, 0x40, 0x3D, 0x82, 0x13, 0xA5, 0x60, 0x13, 0x3B, 0xF5, 0xD8, 0x19, 0x0E, 0x47, 0xCF, 0x5F, 0x5E, 0xDE, 0x9D, 0x14, 0xBD]
key3=[]
v3=0
v4=0
v6=0
s=""
for v3 in range(44):
v3+=1
v6=key[v3]
v4=(v6+v4)%256
key[v3]=key[v4]
key[v4]=v6
key3.append(key[(key[v3]+v6)%256])
for i in range(44):
key2[i]^=key3[i]
for i in key2:
s+=chr(i)
print s
base64_decode:
#include<stdio.h>
#include<string.h>
int findchar(char *str,char c){
for(int i=0;str[i];i++)
if(str[i]==c)
return i;
return -1;
}
int main(){
char key[]="ABCDEFGHIJSTUVWKLMNOPQRXYZabcdqrstuvwxefghijklmnopyz0123456789+/";
char str[100];
char ans[100];
int temp[2];
memset(str,0,100);
memset(ans,0,100);
scanf("%s",str);
for(int i=0,j=0;str[i];i+=4,j+=3)
{temp[0]=findchar(key,str[i]);
temp[1]=findchar(key,str[i+1]);
ans[j]=(temp[0]<<2&0xfc)|(temp[1]>>4&0x3);
if(!str[i+2]||str[i+2]=='=')
break;
else{
temp[0]=findchar(key,str[i+2]);
ans[j+1]=(temp[1]<<4&0xf0)|(temp[0]>>2&0xf);
}
if(!str[i+3]||str[i+3]=='=')
break;
else{
temp[1]=findchar(key,str[i+3]);
ans[j+2]=(temp[0]<<6&0xc0)|(temp[1]&0x3f);
}
}
puts(ans);
}