【问题标题】:Tor Socks4a Incomplete ResponseTor Socks4a 不完整的响应
【发布时间】:2015-01-24 18:48:28
【问题描述】:

我的应用程序需要通过 socks4a 代理使用 Tor。根据这篇维基百科文章SOCKS

字段 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

【问题讨论】:

    标签: c++ networking proxy tor socks


    【解决方案1】:

    Tor 似乎将此视为可选字段,它似乎记住了连接地址,解析它,然后将握手后的任何数据转发到解析的域。

    【讨论】:

      猜你喜欢
      • 2019-05-05
      • 2016-05-24
      • 2012-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-14
      相关资源
      最近更新 更多