我的应用程序需要在socks4a代理上使用Tor。目前我的来自tor的回复被报告为成功,但根据维基百科文章SOCKS,没有报告的袜子4a变体所需的Port或Ip:
字段1:空字节
字段2:状态,1字节:0x5a =授予的请求
0x5b =请求被拒绝或失败
0x5c =请求失败
0x5d =请求失败字段3:网络字节顺序端口号,2字节
字段4:网络字节顺序IP地址,4字节
Tor没有填写第3和第4栏,为什么要这样做以及如何解决?
袜子握手的结果:
Request: 0x04, 0x01, 0x00, 0x50, 0x00, 0x00, 0x00, 0x08, 0x00, 0x77,
0x77, 0x77, 0x2E, 0x67, 0x6F, 0x6F, 0x67, 0x6C, 0x65, 0x2E, 0x63, 0x6F, 0x6D, 0x00
Response from Tor: 0x00, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
源代码:
retval = connect(in_Socket, in_Socks, socksLen); //Connecting to Socks Server
if (retval != 0)
return retval; //Error if !=0
if (szUserId)
lPacketLen += strlen(szUserId); //If there is a userid, add its length to the packet length
lPacketLen += strlen(szHostName); //www.google.com
lPacketLen += 1;
char *packet = new char[lPacketLen];//Allocate a packet
memset(packet, 0x00, lPacketLen); //Init to zero
packet[0] = SOCKS_VER4; //Socks version: 0x4
packet[1] = 0x01; //Connect code
memcpy(packet + 2,(char *)&(((sockaddr_in *)in_szName)->sin_port),2); //Copy the port, 80 in this case
//Send a Malformed IP, as per Socks4a states
packet[4] = 0x00;
packet[5] = 0x00;
packet[6] = 0x00;
packet[7] = 0x8;
int IDLen = strlen(szUserId);
if (szUserId) //If there was a userid, copy it now
memcpy(packet + 8, szUserId, ++IDLen); //Account for null terminator /0
else
packet[8] = 0; //Send null ID if none provided
//Write the hostname we want Tor to resolve, i used www.google.com
memcpy(packet + 8 + IDLen, szHostName, strlen(szHostName) + 1);
if (m_Interval == 0)
Sleep(SOCKS_INTERVAL);
else
Sleep(m_Interval);
printf("\nRequest: ");
PrintArray(packet, lPacketLen);
send(in_Socket, packet, lPacketLen, 0); //Send the packet
delete[] packet; //Unallocate the packet
char reply[8]; //Allocate memory for the reply packet
memset(reply, 0, 8); //Init To 0
long bytesRecv = 0;
bytesRecv = recv(in_Socket, reply, 8, 0); //Get the reply packet
printf("\nResponse from Tor: ");
PrintArray(reply, 8);
//Check Reply Codes later
答案 0 :(得分:0)
Tor似乎将此视为可选字段,它似乎记住连接地址,解析它,然后在握手后将任何数据转发到已解析的域。