В поиск прошу не посылать, перечитал уже кучу веток.
итак, правильно ли расшифровываеться пакет (от шока)?
Код:
Connected
Packet size: 186
______________________________________________________
0x00 | ba 00 d4 38 d7 c5 97 bf 98 d5 ad 92 fa b6 bb 09
0x10 | a5 f5 75 34 6a 7e be b1 1a 41 76 39 de d3 cd 11
0x20 | d7 7d 1f 2d 57 09 b9 ae 91 8c 02 e5 75 bb 93 1c
0x30 | 5a b5 71 9d e5 52 cd 24 77 4b df 0e 5a 1d 11 3b
0x40 | f0 b8 74 e7 49 e4 9e e1 56 b2 ea 12 ee f2 f8 ae
0x50 | 80 53 3c 4c cf 03 96 a2 65 87 2d 48 2e 4f a1 62
0x60 | 8c 09 35 8c 38 12 32 ea bf 09 4a 6f 7c 05 4f a3
0x70 | 49 d4 f2 b9 50 ab 85 f4 c5 cd 47 3d 74 a8 a2 8f
0x80 | 75 c4 5c ac 8d fe dc fd 87 3d 6a 93 0d 86 23 75
0x90 | c0 b6 ca 82 89 26 de ca d6 c2 4d 9d c9 73 ba 95
0xa0 | d5 c0 47 30 5a ea b9 48 7b 07 e4 99 a6 27 e3 8b
0xb0 | 29 3c 1a 78 5d eb 5f 3a 39 da 00 00
Decrypt BlowFish
______________________________________________________
0x00 | ba 00 00 04 ff 02 28 2d 84 85 b4 db 13 c0 0e db
0x10 | a6 3b 44 c7 ff c7 53 e5 17 bd d0 62 7c 0b 98 d8
0x20 | d0 72 4a 2c 67 ec 1e 61 27 1c 5a dd 7c 5e 92 87
0x30 | d4 67 d2 1c 40 95 c0 33 31 a9 cd 3a 50 21 2d 9f
0x40 | f0 b3 6c 0d 74 c0 3e 44 f1 5b 5d e8 56 84 18 53
0x50 | 42 8b ab 8b ae c2 4e eb 6c 59 c0 4d 71 40 bc 58
0x60 | c4 7f 35 16 17 95 3e 15 3e e5 57 2a a2 46 06 a0
0x70 | db 19 63 8f 9a a5 4a 5d 07 93 bc ef 6b 79 79 3d
0x80 | de 94 d8 46 49 5a 86 34 bb 0b 37 b6 39 a2 9c 2d
0x90 | 08 0f 85 cd 05 f5 c8 f2 70 c2 f7 37 8a f6 fc 2d
0xa0 | 1c 92 9a 84 7a e2 fc b1 55 7b 5b cd bc bc ab 29
0xb0 | 3e 33 b2 d4 dd 2b 44 52 aa 91 26 0b
Decrypt XOR
______________________________________________________
0x00 | dd 2b 44 52
______________________________________________________
0x00 | ba 00 00 04 ff 02 28 2d 95 45 b2 8e 8d 07 b5 67
0x10 | 45 fa f6 1d 0e 8b 7c 07 33 ba 58 d5 ac c6 ad 34
0x20 | 8b 56 bf f2 86 f7 d4 43 fb 41 c8 5d d0 00 c0 7b
0x30 | 94 14 6d 12 af f3 83 d6 e1 77 d7 af 60 6d 89 65
0x40 | e4 73 75 49 3b 94 93 13 df 27 5a 59 94 fc 8e d9
0x50 | e8 c9 9a 10 02 e4 0e 28 63 99 5b 75 35 e6 50 b5
0x60 | d1 ec ec fc e9 c9 72 ff 60 dc ad 75 fb af 26 2b
0x70 | 41 7a 29 a2 61 29 21 38 de cb 6b d5 d9 12 51 03
0x80 | 97 3e 5d ad 22 5d 89 a6 6c 56 5c 53 31 a7 19 66
0x90 | f3 85 32 e3 75 b7 38 e3 06 e8 03 13 7e 67 86 56
0xa0 | 36 0c f1 d4 a9 a6 c9 72 e1 1f 33 25 46 ae e5 e2
0xb0 | e3 18 f6 86 00 00 00 00 aa 91 26 0b
Proto: -1304062675
______________________________________________________
0x00 | 2d 95 45 b2
скромный код (вроде нигде не накосячил)
Код:
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <iostream>
#include <openssl/blowfish.h>
int print_packet(char *raw, int len) {
int i, c = 0;
for(i=0;i<54;i++) printf("_");
for(i=0;i<len;i++)
{
if((c % 0x10)==0)
printf("\n0x%.2x | ", c);
printf("%.2x ",raw[i] & 0xFF);
c++;
}
printf("\n\n");
}
void XORdecrypt( unsigned char *data, unsigned int len, unsigned char *Key )
{
int i,k;
i=len-8;
k=(*((int*)Key));
while(i>=6)
{
*((int*)&data[i])=(*((int*)&data[i]))^k;
k=k-(*((int*)&data[i]));
i=i-4;
}
}
using namespace std;
int main(void)
{
int sock=0;
sock=socket(AF_INET,SOCK_STREAM,0);
if (sock==-1)
cerr<<"Create socket"<<endl;
struct hostent *he;
struct sockaddr_in server;
int sockfd;
/* resolve localhost to an IP (should be 127.0.0.1) */
if ((he = gethostbyname("95.211.81.129")) == NULL) {
cerr<<"error resolving hostname.."<<endl;
return 1;
}
/*
* copy the network address part of the structure to the
* sockaddr_in structure which is passed to connect()
*/
memcpy(&server.sin_addr, he->h_addr_list[0], he->h_length);
server.sin_family = AF_INET;
server.sin_port = htons(2106);
/* connect */
if (connect(sock, (struct sockaddr *)&server, sizeof(server))) {
cerr<<"error connecting.."<<endl;
return 1;
}
cout<<"Connected"<<endl;
short pack_size;
recv(sock,(char*)&pack_size,2,0);
cout<<"Packet size: "<<pack_size<<endl;
char *buf=new char[pack_size+2];
recv(sock,buf+2,pack_size,0);
memcpy(buf,&pack_size,2);
print_packet(buf,pack_size+2);
cout<<"Decrypt BlowFish"<<endl;
unsigned char bkey[16]={0x6B,0x60,0xCB,0x5B,0x82,0xCE,0x90,0xB1,0xCC,0x2B,0x6C,0x55,0x6C,0x6C,0x6C,0x6C};
BF_KEY bfkey;
BF_set_key(&bfkey, 16, (unsigned char *)bkey);
for(int i = 0; i <(pack_size-2)/4; i++)
BF_decrypt((BF_LONG *)(&buf[2+i*4]), &bfkey);
print_packet(buf,pack_size+2);
cout<<"Decrypt XOR"<<endl;
int i=180;
print_packet((char*)&key,4);
print_packet((buf+i),4);
XORdecrypt((unsigned char*)(buf),pack_size+2,(unsigned char*)(buf+i));
print_packet(buf,pack_size+2);
int proto=0;
memcpy((char*)&proto,&buf[2+1+4],4);
cout<<"Proto: "<<proto<<endl;
print_packet((char*)&proto,4);
delete []buf;
close(sock);
return 0;
}