I’ve been following a networking tutorial on sock4 Toralizer which implementated a sock4 protocol to make http request. So i believed why not make the advance within the implementation and make it for sock5 as advised within the video and feedback.
The toralize.h file
#embody
#embody
#embody
#embody
#embody
#embody
#embody
#embody
#outline FREEPROXY "204.10.194.63"
#outline FREEPROXYPORT 10087
// 103.174.178.131 : 1020 /* All free proxy server I've tried */
// 128.199.157.192 : 36838
// 208.102.51.6 : 58208
// 199.116.112.6 : 4145
// 188.165.249.131 : 9050
// 192.154.194.99 : 9000
// 67.149.165.201 : 9090
// 176.117.237.132 : 1080
// 192.252.215.5 : 16137
// 163.53.204.178 : 9813
// 68.71.252.38 : 4145
// 103.157.237.150 : 1080
// 46.105.105.223 : 51020
// 143.47.255.13 : 59900
// 162.240.146.101 : 31815
// 51.15.205.29 : 16379
// 204.10.194.63 : 10087
uint8_t supported_methods[] = {0x00};
#outline nmethods sizeof(supported_methods) / sizeof(supported_methods[0])
#outline hreqsize 2 + nmethods
#outline hressize sizeof(struct sock_handshake_res)
#outline reqsize sizeof(struct sock_connection_req)
#outline ressize 22
struct sock_handshake_req
{
uint8_t model;
uint8_t n_methods;
uint8_t strategies[];
};
struct sock_handshake_res
{
uint8_t model;
uint8_t methodology;
} ;
struct sock_connection_req
{
uint8_t model; // 5
uint8_t command; // 1 - join , 2 - bind , 3 - udp
uint8_t reserved; // 0
uint8_t addr_type; // 1 - ipv4 , 3- area , 4 - ipv6
uint32_t dst_addr; // Variable
uint16_t dst_port;
};
struct sock_connection_res
{
uint8_t model; // 5
uint8_t reply;
uint8_t reserved; // 0
uint8_t addr_type; // 1 - ipv4 , 3- area , 4 - ipv6
uint32_t bind_addr; // Variable
uint16_t bind_port;
};
typedef struct sock_handshake_req Initial_Req;
typedef struct sock_handshake_res Initial_Res;
typedef struct sock_connection_req Req;
typedef struct sock_connection_res Res;
Req* request(const char* dstip, const int dstport);
and toralize.cpp file
#embody "toralize.h"
Initial_Req *hrequest()
{
Initial_Req *req;
req = malloc(hreqsize);
req->model = 5;
req->n_methods = nmethods;
memcpy(req->strategies, supported_methods, sizeof(supported_methods));
return req;
}
Req *request(const char *dstip, const int dstport){
Req *req;
req = malloc(reqsize);
req->model = 5;
req->command = 1;
req->reserved = 0;
req->addr_type = 1;
req->dst_addr = inet_addr(dstip);
req->dst_port = htons(dstport);
return req;
}
int principal(int argc, char *argv[])
{
char *host;
int port, s;
struct sockaddr_in sock;
Initial_Req *hreq;
Initial_Res *hres;
Req *req;
Res *res;
char hbuf[hressize];
char buf[ressize];
int success;
char tmp[512];
if (argc < 3)
{
fprintf(stderr, "Utilization: %s n", argv[0]);
return -1;
}
host = argv[1];
port = atoi(argv[2]);
s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s < 0)
{
perror("socket");
return -1;
}
sock.sin_family = AF_INET;
sock.sin_port = htons(FREEPROXYPORT);
sock.sin_addr.s_addr = inet_addr(FREEPROXY);
if (join(s, (struct sockaddr*)&sock, sizeof(sock)))
{
perror("Join");
return -1;
}
printf("Linked to proxyn");
hreq = hrequest();
write(s,hreq,hreqsize);
memset(hbuf, 0 ,hressize);
if(learn(s,hbuf,hressize) < 1){
perror("learn");
free(hreq);
shut(s);
return -1;
}
hres = (Initial_Res *)hbuf;
success = (hres->methodology != 255);
printf("Preliminary Technique Negotiation Response: ");
for (int i = 0; i < hressize; i++)
{
printf("%x ", hbuf[i]);
}
printf("n");
if (!success)
{
fprintf(stderr, "Errorn");
free(hreq);
shut(s);
return -1;
}
req = request(host,port);
write(s, req, reqsize);
memset(buf, 0, ressize);
if (learn(s, buf, ressize) < 1)
{
perror("learn");
free(hreq);
free(req);
shut(s);
return -1;
}
// if(buf[3] != 1){
// perror("Totally different Ip Model");
// free(hreq);
// free(req);
// shut(s);
// return -1;
// }
printf("Connection Institution Response: ");
for (int i = 0; i < 10; i++)
{
printf("%x ", buf[i]);
}
printf("nn");
res = (Res *)buf;
struct in_addr paddr;
paddr.s_addr = res->bind_addr;
printf("Linked to proxy "
"%s:%dnn",
inet_ntoa(paddr), ntohs(res->bind_port));
printf("Efficiently related by the proxy to "
"%s:%dnnn",
host, port);
memset(tmp, 0, 512);
snprintf(tmp, 511,
"GET / HTTP/1.0rn"
"Host: www.instance.comrn"
"Consumer-Agent: CustomClient/1.0rn"
"Settle for: */*rn"
"Connection: closern"
"rn");
write(s,tmp,strlen(tmp));
memset(tmp, 0, 512);
learn(s, tmp, 511);
printf("'%s'n", tmp);
shut(s);
free(hreq);
free(req);
return 0;
}
I name the code by the makefile by first calling host www.instance.com and getting the ip after which name this system utilizing a makefile
all:
gcc toralize.c -o toralize && ./toralize 80
however the outcome i get is
gcc toralize.c -o toralize && ./toralize 80
Linked to proxy
Preliminary Technique Negotiation Response: 5 0
Connection Institution Response: 5 4 0 1 0 0 0 0 0 0
Linked to proxy 0.0.0.0:0
Efficiently related by the proxy to :80
''
i get the dst.ip and dst.port as 0 after which no output for the http request in addition to typically i get
Linked to proxy
Preliminary Technique Negotiation Response: 5 0
Connection Institution Response: 5 0 0 1 0 0 0 0 ffffff8f ffffffe6
Linked to proxy 0.0.0.0:36838
Efficiently related by the proxy to :80
'HTTP/1.0 501 Not Applied
Content material-Sort: textual content/html
Content material-Size: 357
Connection: shut
Date: Thu, 09 Jan 2025 07:44:25 GMT
Server: ECLF (lac/55F7)
501 - Not Applied
I get the anticipated outcome after I simply run the identical request with out sock5 with the identical header so I can not seem to pinpoint the rationale behind it. Is it that the proxy server, which does not assist http and solely helps https or some error in my implementation.
I’m connecting to the free proxy server discovered on this web site
Right here
Some full the strategy negotiation however after I begin the tunnel institution they provide learn: connection reset by peer
what appears to be the difficulty is what I can not pinpoint.