-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPuddleJump.c
More file actions
83 lines (60 loc) · 1.54 KB
/
Copy pathPuddleJump.c
File metadata and controls
83 lines (60 loc) · 1.54 KB
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
/* PuddleJump.c */
#include "PuddleJump.h"
Req *request(struct sockaddr_in *sock2) {
Req *req;
req = malloc(reqsize);
req->vn = 4;
req->cd = 1;
req->dstport = sock2->sin_port;
req->dstip = sock2->sin_addr.s_addr;
strncpy(req->userid, USERNAME, 13);
return req;
}
int connect(int s2, const struct sockaddr *sock2,
socklen_t addrlen) {
int s;
struct sockaddr_in sock;
Req *req;
Res *res;
char buf[ressize];
int success;
char tmp[512];
int (*p)(int,const struct sockaddr*,socklen_t);
p = dlsym(RTLD_NEXT, "connect");
s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0) {
perror("socket");
return -1;
}
sock.sin_family = AF_INET;
sock.sin_port = htons(PROXYPORT);
sock.sin_addr.s_addr = inet_addr(PROXY);
if (p(s, (struct sockaddr *)&sock, sizeof(sock))) {
perror("connect");
return -1;
}
printf("Connected to proxy\n");
req = request((struct sockaddr_in *)sock2);
write(s, req, reqsize);
memset(buf, 0, ressize);
if (read(s, buf, ressize) < 1) {
perror("read");
free(req);
close(s);
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(s);
free(req);
return -1;
}
printf("Connected through the proxy. \n");
dup2(s, s2);
free(req);
return 0;
}