📄 sniffer.cpp
字号:
{
int outlen;
char *decrypted=NULL;
int nRet;
CString usekey;
CString str;
outlen=buflen;
int startpos,endpos;
nRet=TryDecrypt(buf,buflen,&startpos,&endpos,usekey);
if(nRet==1){
decrypted=new char[endpos-startpos+1];
nRet=Decrypt(buf,startpos,endpos,decrypted,&outlen);
}
DWORD uuid=188088158;
uuid=htonl(uuid);
if(nRet==1){
nRet=SearchInBuf(decrypted,outlen,(char*)&uuid,sizeof(DWORD));
str.Format("好友列表!!!!!!!!%d\n解密成功。\n起始位置:%d,结束位置%d,使用密钥%s\n解密后数据:\n%s\n",nRet,startpos,endpos,usekey,BufToHex(decrypted,outlen));
qq_str=str;
delete decrypted;
return 1;
}
if(decrypted!=NULL){
delete decrypted;
}
return 0;
}
CString BufToHex(char *buf,int len)
{
int i;
CString ret;
CString tmp;
for(i=0;i<len;i++){
tmp.Format("0x%2.2X ",(unsigned char)buf[i]);
ret=ret+tmp;
}
tmp=tmp+"\n";
return ret;
}
int CSniffer::Init(DWORD msg_id,HWND hWnd,DWORD uid,char *pwd)
{
m_inited=true;
m_hWnd=hWnd;
MSG_DATAREACH=msg_id;
memcpy(m_pwd_key,pwd,16);
m_uid=uid;
return 1;
}
int CSniffer::TryDecrypt(char *buf,int buflen,int *startpos,int *endpos,CString &whichkey)
{
int nRet;
CString usekey;
int len;
int i;
int outlen;
char *decrypted=new char[buflen];
len=buflen-buflen%8;
nRet=0;
for(i=buflen-len;i<buflen-9;i++)
{
outlen=buflen;
nRet=qq_crypt(DECRYPT,(unsigned char *)&buf[i],buflen-i,(unsigned char *)m_pwd_key,(unsigned char *)decrypted,&outlen);
if(nRet!=1){
outlen=buflen;
nRet=qq_crypt(DECRYPT,(unsigned char *)&buf[i],buflen-i,(unsigned char *)m_key_session,(unsigned char *)decrypted,&outlen);
if(nRet!=1){
outlen=buflen;
nRet=qq_crypt(DECRYPT,(unsigned char *)&buf[i],buflen-i,(unsigned char *)m_key_rand,(unsigned char *)decrypted,&outlen);
if(nRet!=1){
whichkey="无法解密\n";
continue;
}
else{
usekey="随机密钥";
break;
}
}
else{
usekey="会话密钥";
break;
}
}
else{
usekey="密码密钥";
break;
}
}
delete decrypted;
if(nRet==1){
*startpos=i;
*endpos=buflen-1;
whichkey=usekey;
return 1;
}
return 0;
}
int CSniffer::Decrypt(char *buf,int buflen,char *decrypted,int *outlen){
int nRet;
*outlen=buflen;
nRet=qq_crypt(DECRYPT,(unsigned char *)buf,buflen,(unsigned char *)m_pwd_key,(unsigned char *)decrypted,outlen);
if(nRet!=1){
*outlen=buflen;
nRet=qq_crypt(DECRYPT,(unsigned char *)buf,buflen,(unsigned char *)m_key_session,(unsigned char *)decrypted,outlen);
if(nRet!=1){
*outlen=buflen;
nRet=qq_crypt(DECRYPT,(unsigned char *)buf,buflen,(unsigned char *)m_key_rand,(unsigned char *)decrypted,outlen);
if(nRet!=1){
return 0;
}
}
}
return 1;
}
int CSniffer::Decrypt(char *buf,int startpos,int endpos,char *decrypted,int *outlen){
int len;
len=endpos-startpos+1;
return Decrypt(&buf[startpos],len,decrypted,outlen);
}
int CSniffer::SearchInBuf(char *buf,int buflen,char *data,int datalen)
{
int i;
int j;
bool equal;
for(i=0;i<buflen-datalen;i++)
{
equal=true;
for(j=0;j<datalen;j++){
if(buf[i+j]!=data[j]){
equal=false;
break;
}
}
if(equal){
return i;
}
}
return -1;
}
int CSniffer::DecodeGetFriendList(char *buf,int buflen,CString &qq_str,QQ_HEADER *qq_hdr)
{
WORD newindex;
if(qq_hdr->wVer>0x100){
qq_str="正在请求好友列表!\n";
return 1;
}
int len;
DWORD uid;
unsigned char age;
WORD namelen;
char name[30];
int count=0;
CString tmp;
CString str;
char *decrypted;
decrypted=new char[buflen];
int outlen=buflen;
int nRet;
nRet=Decrypt(buf,buflen,decrypted,&outlen);
if (nRet!=1){
delete decrypted;
return 0;
}
memcpy(&newindex,decrypted,2);
newindex=ntohs(newindex);
len=0;
len=len+2;
while(len<outlen-1){
count++;
memcpy(&uid,&decrypted[len],4);
uid=ntohl(uid);
age=decrypted[len+6];
namelen=(unsigned char)decrypted[len+8];
//memcpy(&namelen,&decrypted[len+7],2);
//namelen=ntohs(namelen);
memset(name,0,30);
memcpy(name,&decrypted[len+9],namelen);
tmp.Format("好友%2.2d:QQ号码:%10d,年龄:%d,昵称:%s\t\t\n头像:%s,未知2:%s\n性别:%s\n",
count,uid,age,name,BufToHex(&decrypted[len+4],2),BufToHex(&decrypted[len+9+namelen],4),BufToHex(&decrypted[len+7],1));
str=str+tmp;
len=len+9+namelen+4;
}
qq_str=str;
delete decrypted;
return 1;
}
int CSniffer::DecodeGetOnlineFriendList(char *buf,int buflen,CString &qq_str,QQ_HEADER *qq_hdr)
{
char *decrypted;
int outlen;
int nRet;
if(qq_hdr->wVer>0x100){
outlen=buflen;
decrypted=new char[outlen];
nRet=Decrypt(&buf[4],buflen-4,decrypted,&outlen);
if(nRet==1){
qq_str.Format("获取在线好友,起始位置:%d\n",(unsigned char)decrypted[1]);
delete decrypted;
return 1;
}
else{
delete decrypted;
return 0;
}
}
outlen=buflen;
decrypted=new char[outlen];
nRet=Decrypt(buf,buflen,decrypted,&outlen);
if(nRet!=1){
delete decrypted;
return 0;
}
DWORD uid;
char ip[4];
WORD port;
char state;
char key[16];
char flag1;
char flag2;
int len;
CString tmp;
CString str;
len=1;
while(len<outlen-1)
{
memcpy(&uid,&decrypted[len],4);
uid=ntohl(uid);
len+=4;
len++;
memcpy(ip,&decrypted[len],4);
len=len+4;
memcpy(&port,&decrypted[len],2);
port=ntohs(port);
len=len+2;
len=len+1;
state=decrypted[len];
len=len+1;
len=len+2;
memcpy(key,&buf[len],16);
len=len+16;
len=len+2;
flag1=buf[len];
len=len+1;
flag2=buf[len];
len=len+1;
len=len+2;
len=len+1;
tmp.Format("好友QQ号码:%d,IP地址:%d.%d.%d.%d:%d\n当前状态:0x%2.2X\n通讯密钥:\n%s\n标志1:0x%2.2X,标志2:0x%2.2X\n",
uid,(unsigned char)ip[0],(unsigned char)ip[1],(unsigned char)ip[2],(unsigned char)ip[3],port,(unsigned char)state,
BufToHex(key,16),(unsigned char)flag1,(unsigned char)flag2);
str=str+tmp;
}
qq_str=str;
return 1;
}
int CSniffer::Decode0x67(char *buf,int buflen,CString &qq_str,QQ_HEADER *qq_hdr)
{
char *decrypted;
int outlen;
int nRet;
WORD count;
int i;
DWORD uid;
CString temp;
if(qq_hdr->wVer>0x100){
outlen=buflen;
decrypted=new char[outlen];
nRet=Decrypt(&buf[4],buflen-4,decrypted,&outlen);
if(nRet==1){
if(decrypted[0]!=0x03){
delete decrypted;
return 0;
}
memcpy(&count,&decrypted[1],2);
count=ntohs(count);
i=0;
while(i<count){
memcpy(&uid,&decrypted[3+i*8],4);
uid=ntohl(uid);
temp.Format("QQ号码:%8d,未知:%s\n",
uid,BufToHex(&decrypted[3+i*8+4],4));
qq_str=qq_str+temp;
i++;
}
delete decrypted;
return 1;
}
else{
delete decrypted;
return 0;
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -