-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoralize.c
90 lines (70 loc) · 1.91 KB
/
toralize.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "toralize.h"
Req *request(const char *dstip, const int dstport){
Req *req;
req = malloc(reqsize);
req->vn = 4;
req->cd = 1;
req->dstport = htons(dstport);
req->dstip = inet_addr(dstip);
strncpy(req->userid, USERNAME,8);
return req;
}
int main(int argc, char *argv[]){
char *host;
int port, sock_fd;
Req *req;
Res *res;
char buf[ressize];
struct sockaddr_in sock;
int success;
if (argc < 3){
fprintf(stderr, "Usage: %s <ip_addr> <port_num>\n", argv[0]);
return 1;
}
printToralizeBanner();
host = argv[1];
port = atoi(argv[2]);
sock_fd = socket(AF_INET, SOCK_STREAM, 0);
if (sock_fd < 0 ){
perror("socker");
return 1;
}
sock.sin_family = AF_INET;
sock.sin_port = htons(PROXYPORT);
sock.sin_addr.s_addr= inet_addr(PROXY);
if (connect(sock_fd, (struct sockaddr *)&sock, sizeof(sock))){
perror("connect");
return 1;
}
printf("Connection established\n");
req = request(host, port);
write(sock_fd, req,reqsize);
//set buffer to zero
memset(buf,0,ressize);
if(read(sock_fd,buf,ressize) < 1){
perror("read");
free(req);
close(sock_fd);
return -1;
}
res = (Res *) buf;
success = (res->cd == 90);
if(!success){
fprintf(stderr, "Unable to traverse the proxy,"
"error code: %d\n", res->cd);
close(sock_fd);
free(req);
return -1;
}
printf("Succesfully connected through the proxy to %s:%d\n",host, port);
close(sock_fd);
free(req);
return 0;
}
void printToralizeBanner() {
printf(" _____ _ _ \n");
printf("|_ _|__ _ __ __ _| (_)_______ \n");
printf(" | |/ _ \| '__/ _` | | |_ / _ \ \n");
printf(" | | (_) | | | (_| | | |/ / __/ \n");
printf(" |_|\___/|_| \__,_|_|_/___\___| \n");
}