Skip to content

Commit 32df7ff

Browse files
committed
connect(): handle ipv4-mapped ipv6 addresses
if an ipv4-mapped ipv6 address is detected, the ip is converted into v4 format because it may actually be one of our remote dns ips. it was reported that a program called "maven", when getting handed our fake ips in the remote dns subnet, converts the ip to v6 prior to calling connect(): [proxychains] Strict chain ... 127.0.0.1:1080 ... ::ffff:224.0.0.1:443 <--socket error or timeout! fixes rofl0r#77
1 parent 097c7f9 commit 32df7ff

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Diff for: src/libproxychains.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,10 @@ int close(int fd) {
307307
errno = EBADF;
308308
return -1;
309309
}
310-
310+
static int is_v4inv6(const struct in6_addr *a) {
311+
return a->s6_addr32[0] == 0 && a->s6_addr32[1] == 0 &&
312+
a->s6_addr16[4] == 0 && a->s6_addr16[5] == 0xffff;
313+
}
311314
int connect(int sock, const struct sockaddr *addr, unsigned int len) {
312315
INIT();
313316
PFUNC();
@@ -334,6 +337,12 @@ int connect(int sock, const struct sockaddr *addr, unsigned int len) {
334337
p_addr_in6 = &((struct sockaddr_in6 *) addr)->sin6_addr;
335338
port = !v6 ? ntohs(((struct sockaddr_in *) addr)->sin_port)
336339
: ntohs(((struct sockaddr_in6 *) addr)->sin6_port);
340+
struct in_addr v4inv6;
341+
if(v6 && is_v4inv6(p_addr_in6)) {
342+
memcpy(&v4inv6.s_addr, &p_addr_in6->s6_addr32[3], 4);
343+
v6 = dest_ip.is_v6 = 0;
344+
p_addr_in = &v4inv6;
345+
}
337346

338347
// PDEBUG("localnet: %s; ", inet_ntop(AF_INET,&in_addr_localnet, str, sizeof(str)));
339348
// PDEBUG("netmask: %s; " , inet_ntop(AF_INET, &in_addr_netmask, str, sizeof(str)));

0 commit comments

Comments
 (0)