[Вопрос по Си] MRIM авторизация

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by f0rward, 1 Apr 2010.

  1. f0rward

    f0rward New Member

    Joined:
    26 Oct 2008
    Messages:
    10
    Likes Received:
    2
    Reputations:
    0
    Code:
    int mrim_test() {
    	SOCKET hSock;
    	struct sockaddr_in hAddr;
    	char buf[1024], req[256];
    	int res;
    	struct _MRIM_ADDR mrim_addr;
    	struct mrim_packet_header_t cs, sc;
    
    	if((hSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) {
    		printf("[-] create socket\n");
    		return -1;
    	}
    	printf("[+] create socket\n");
    	hAddr.sin_family = AF_INET;
    	hAddr.sin_port = htons(MRIM_PORT);
    	hAddr.sin_addr.s_addr = inet_addr(MRIM_HOST); // ip mrim.mail.ru
    	if(connect(hSock, (struct sockaddr*)&hAddr, sizeof(struct sockaddr_in)) == SOCKET_ERROR) {
    		printf("[-] connect 2 mrim.mail.ru:443\n");
    		closesocket(hSock);
    		return -1;
    	}
    	printf("[+] connect 2 mrim.mail.ru:443\n");
    	sprintf(req, "CONNECT mrim.mail.ru:443 HTTP/1.0\r\n\r\n");
    	if(send(hSock, req, strlen(req), 0)==SOCKET_ERROR) {
    		printf("[-] send packet 2 mrim.mail.ru:443\n");
    		closesocket(hSock);
    		return -1;
    	}
    	printf("[+] send packet 2 mrim.mail.ru:443\n");
    	if(recv(hSock, buf, sizeof(buf)-1, 0)==SOCKET_ERROR) {
    		printf("[-] recv answer from mrim.mail.ru:443\n");
    		closesocket(hSock);
    		return -1;
    	}
    	printf("[+] recv answer from mrim.mail.ru:443\n");
    	strtok(buf, "\r\n");
    	strtok(buf, ":");
    	strcpy(mrim_addr.host, buf); 
    	mrim_addr.port = atoi(strtok(NULL, ":"));
    	printf("[+] get connection server: %s:%d\n", mrim_addr.host, mrim_addr.port);
    	printf("\nrecreating socket...\n\n");
    	closesocket(hSock);
    	hSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    	if((hSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) {
    		printf("[-] create socket\n");
    		return -1;
    	}
    	printf("[+] create socket\n");
    	hAddr.sin_family = AF_INET;
    	hAddr.sin_port = htons(mrim_addr.port);
    	hAddr.sin_addr.s_addr = inet_addr(mrim_addr.host);
    	if(connect(hSock, (struct sockaddr*)&hAddr, sizeof(struct sockaddr_in)) == SOCKET_ERROR) {
    		printf("[-] connect 2 %s:%d\n", mrim_addr.host, mrim_addr.port);
    		closesocket(hSock);
    		return -1;
    	}
    	printf("[+] connect 2 %s:%d\n", mrim_addr.host, mrim_addr.port);
    	cs.magic = CS_MAGIC;
    	cs.proto = PROTO_VERSION;
    	cs.msg = MRIM_CS_HELLO;
    	if(send(hSock, (unsigned char*)&cs, PACKET_SIZE, 0) == SOCKET_ERROR) {
    		printf("[-] send MRIM_CS_HELLO\n");
    		closesocket(hSock);
    		return -1;
    	}
    	printf("[+] send MRIM_CS_HELLO\n");
    	if (recv(hSock, (char *)&sc, PACKET_SIZE, 0) == SOCKET_ERROR) {	printf("[-] recv MRIM_CS_HELLO\n");
    		closesocket(hSock);
    		return -1;
    	}
    	[COLOR=Red][B]printf((sc.msg == MRIM_CS_HELLO_ACK ? "[+] recv MRIM_CS_HELLO_ACK\n": "[+] recv %d\n"), sc.msg);[/B][/COLOR]
    
    	closesocket(hSock);
    	return 0;
    }
    Собственно в выделенном месте серв должен возвращать MRIM_CS_HELLO_ACK на сколько я понимаю, но у меня этого не происходит, скорее всего что-то напутал.
    Прошу помощи, нужно дойти до авторизации.
     
  2. Gar|k

    Gar|k Moderator

    Joined:
    20 Mar 2009
    Messages:
    1,166
    Likes Received:
    266
    Reputations:
    82
    2 f0rward
    http://forum.antichat.ru/thread170703.html
    http://forum.antichat.ru/thread133090.html
     
    _________________________