-
February 1st, 2011, 02:39 PM
#1
proxy server problem c++
I'm trying to build a proxy server using socks5 tcp/ip. I'm having problems when sendind packets to the client,i get the following errors when trying to connect to google.com. For client i use Proxifier:
Code:
[25:23] Starting: Test 1: Connection to the Proxy Server
[25:23] IP Address: 127.0.0.1
[25:23] Connection established
[25:23] Test passed.
[25:23] Starting: Test 2: Connection through the Proxy Server
[25:23] Authentication was successful.
[25:24] Warning : the proxy server has returned an unexpected answer (0xFFFFFF84).
[25:24] Connection to www.google.com:80 established through the proxy server.
[25:24] Error : the reply that was recieved from the target host does not look like a usual Web Server reply.
Please make sure that the target host is a Web Server.
The error may also indicate that the proxy server is not operating properly.
Target host reply = www.google.c
[25:24] Test failed.
[25:24] Testing Finished.
And this is my code where i receive and send packets:
Code:
void HandleConnection()
{
cout << "You are connected !!!" << endl;
char temp[30];
Recv(temp, sizeof(temp));
// Client sends 5,1,0 (version,nr of methods, the method(0 = no auth))
if(temp[0] == 5) // test for version
{
char* reply = new char[2];
reply[0] = 5; // version
reply[1] = 0; // method choosed (no auth required)
Send(reply, sizeof(reply)); // i send 5,0 (version,method choosed) i get warning that i send an unexpected answer
delete [] reply;
memset(temp, '\0', sizeof(temp));
Recv(temp, sizeof(temp));
// i receive 5,0,0,3,14,www.google.com,80 (version,command, reserved,type of address, dest adress, dest port)
int version = static_cast<int>(temp[0]);
int connectionType = static_cast<int>(temp[1]);
int adrressType = static_cast<int>(temp[3]);
int domainLen = static_cast<int>(temp[4]);
char* destinationAdrress = static_cast<char*>(&temp[5]);
int port1 = static_cast<int>(temp[19]);
int port2 = static_cast<int>(temp[20]);
int packetSize = sizeof(temp);
cout << "Size of packet: " << packetSize << endl;
cout << "Version: " << version << endl;
cout << "Conn type: " << connectionType << endl;
cout << "Adrr type: " << adrressType << endl;
cout << "Domain lenght: " << domainLen << endl;
cout << "Destination adrress: " << destinationAdrress << endl;
cout << "Destination port: " << port2 << endl;
if(version == 5) // test for version
{
char reply[21];
reply[0] = 5; // version
reply[1] = 0; // succed
reply[2] = 0; // reserved
reply[3] = 3; // its a domain
reply[4] = domainLen;; // lenght of domain
for(int j = 0; j < domainLen; ++j)
{
reply[j + 5] = destinationAdrress[j];
}
reply[5 + domainLen] = htons(port1);
reply[6 + domainLen] = htons(port2);
Send(reply, sizeof(reply));
Connect();
}
}
}
I hope i find someone who can help me,i'm strugling for days,with no answer.Thanks in advanced.
-
February 2nd, 2011, 07:09 PM
#2
Re: proxy server problem c++
The variable named "reply" is a char pointer, and its size is therefore 4 bytes.
Thus, all of your calls to "Send(reply, sizeof(reply))" are wrong, since they always send 4 bytes.
Mike
PS: Your call to memset on "temp" is also wrong, for the same reason.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|