Skip to content

Commit d0f3a6e

Browse files
committed
PROXYBOUND_ALLOW_LEAKS in connect()
1 parent d669d49 commit d0f3a6e

3 files changed

Lines changed: 87 additions & 56 deletions

File tree

README

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ Used environment variable:
2121
- PROXYBOUND_SOCKS5_HOST: Specify unique socks 5 proxy to use
2222
- PROXYBOUND_SOCKS5_PORT: Socks 5 port
2323
- PROXYBOUND_FORCE_DNS: Force dns requests through (1 or 0)
24-
- PROXYBOUND_ALLOW_LEAKS: Not yet implemented (Allow unproxyfied protocols "UDP/ICMP/RAW")
24+
- PROXYBOUND_ALLOW_LEAKS: Allow/Block unproxyfied protocols "UDP/ICMP/RAW"
25+
Blocked by default (1 or 0)
2526

2627
Install:
2728
========

proxybound

-20.1 KB
Binary file not shown.

src/libproxybound.c

Lines changed: 85 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -335,74 +335,106 @@ static void manual_socks5_env(proxy_data *pd, unsigned int *proxy_count, chain_t
335335
/******* HOOK FUNCTIONS *************************************************************************************************************************************/
336336

337337
int connect(int sock, const struct sockaddr *addr, socklen_t len) {
338-
int socktype = 0, flags = 0, ret = 0;
339-
socklen_t optlen = 0;
340-
ip_type dest_ip;
341-
#ifdef DEBUG
342-
char str[256];
343-
#endif
344-
struct in_addr *p_addr_in;
345-
unsigned short port;
346-
size_t i;
347-
int remote_dns_connect = 0;
348-
INIT();
349-
optlen = sizeof(socktype);
350-
getsockopt(sock, SOL_SOCKET, SO_TYPE, &socktype, &optlen);
351-
352338

339+
PDEBUG("\n\n\n\n\n\n\n\n...INJECT... \n\n\n\n\n\n\n\n");
340+
341+
int socktype = 0, flags = 0, ret = 0;
342+
socklen_t optlen = 0;
343+
ip_type dest_ip;
344+
char ip[256];
345+
struct in_addr *p_addr_in;
346+
unsigned short port;
347+
size_t i;
348+
int remote_dns_connect = 0;
349+
INIT();
350+
optlen = sizeof(socktype);
351+
getsockopt(sock, SOL_SOCKET, SO_TYPE, &socktype, &optlen);
352+
353+
// Sock family list (not complete)
354+
// AF_UNIX_CCSID /* - Unix domain sockets */
355+
// AF_UNIX /* 1 - Unix domain sockets */
356+
// AF_INET /* 2 - Internet IP Protocol */
357+
// AF_INET6 /* 10 - IPv6 */
358+
// AF_UNSPEC /* 0 */
359+
// AF_AX25 /* 3 - Amateur Radio AX.25 */
360+
// AF_IPX /* 4 - Novell IPX */
361+
// AF_APPLETALK /* 5 - Appletalk DDP */
362+
// AF_NETROM /* 6 - Amateur radio NetROM */
363+
// AF_BRIDGE /* 7 - Multiprotocol bridge */
364+
// AF_AAL5 /* 8 - Reserved for Werner's ATM */
365+
// AF_X25 /* 9 - Reserved for X.25 project */
366+
// AF_MAX /* 12 - For now.. */
367+
// Etc.
368+
369+
//Allow direct unix
370+
if (SOCKFAMILY(*addr) == AF_UNIX) {
371+
PDEBUG("allowing direct unix connect()\n\n");
372+
return true_connect(sock, addr, len);
373+
}
374+
353375
p_addr_in = &((struct sockaddr_in *) addr)->sin_addr;
354-
355-
PDEBUG("aaaaaaaaaaa\n");
356-
for(i = 0; i < num_localnet_addr; i++) {
357-
PDEBUG("eeeeeeeeeeee\n");
358-
if((localnet_addr[i].in_addr.s_addr & localnet_addr[i].netmask.s_addr) == (p_addr_in->s_addr & localnet_addr[i].netmask.s_addr)) {
359-
PDEBUG("bbbbbbbbbbbbbb\n");
360-
}
361-
}
362-
363-
//if(!(SOCKFAMILY(*addr) == AF_INET && socktype == SOCK_STREAM)) {
364-
if((SOCKFAMILY(*addr) != AF_INET) || (socktype != SOCK_STREAM)) {
376+
port = ntohs(((struct sockaddr_in *) addr)->sin_port);
377+
inet_ntop(AF_INET, p_addr_in, ip, sizeof(ip));
378+
379+
#ifdef DEBUG
380+
//PDEBUG("localnet: %s; ", inet_ntop(AF_INET, &in_addr_localnet, ip, sizeof(ip)));
381+
//PDEBUG("netmask: %s; " , inet_ntop(AF_INET, &in_addr_netmask, ip, sizeof(ip)));
382+
PDEBUG("target: %s\n\n", ip);
383+
PDEBUG("port: %d\n\n", port);
384+
#endif
385+
386+
//Allow direct local 127.x.x.x
387+
if ((ip[0] == '1') && (ip[1] == '2') && (ip[2] == '7') && (ip[3] == '.')) {
388+
PDEBUG("Local ip detected... ignoring\n\n");
389+
return true_connect(sock, addr, len);
390+
}
391+
392+
//Allow empty ip
393+
/*if (!ip[0]) {
394+
PDEBUG("Noip... ignoring\n\n");
395+
return true_connect(sock, addr, len);
396+
}*/
397+
398+
//Block other sock
399+
if (SOCKFAMILY(*addr) != AF_INET) {
365400
if (proxybound_allow_leak) {
366-
PDEBUG("allowing unproxified non tcp connect()\n");
401+
PDEBUG("allowing direct non tcp connect()\n\n");
367402
return true_connect(sock, addr, len);
368403
} else {
369-
PDEBUG("blocking unproxified non tcp connect()\n");
370-
//exit(0);
404+
PDEBUG("blocking direct non tcp connect() \n\n");
371405
return -1;
372406
}
373407
}
374-
375-
//Rejecting non local udp
376-
/*if (socktype == SOCK_DGRAM){
408+
409+
//Block udp
410+
if (socktype != SOCK_STREAM) {
377411
if (proxybound_allow_leak) {
378-
PDEBUG("allowing unproxified udp connect()\n");
412+
PDEBUG("allowing direct udp connect()\n\n");
379413
return true_connect(sock, addr, len);
380414
} else {
381-
PDEBUG("blocking unproxified udp connect()\n");
382-
//exit(0);
415+
PDEBUG("blocking direct udp connect() \n\n");
383416
return -1;
384417
}
385-
}*/
386-
387-
388-
389-
390-
port = ntohs(((struct sockaddr_in *) addr)->sin_port);
418+
}
391419

392-
#ifdef DEBUG
393-
//PDEBUG("localnet: %s; ", inet_ntop(AF_INET,&in_addr_localnet, str, sizeof(str)));
394-
//PDEBUG("netmask: %s; " , inet_ntop(AF_INET, &in_addr_netmask, str, sizeof(str)));
395-
PDEBUG("target: %s\n", inet_ntop(AF_INET, p_addr_in, str, sizeof(str)));
396-
PDEBUG("port: %d\n", port);
397-
#endif
420+
//Block udp
421+
if (socktype == SOCK_DGRAM){
422+
if (proxybound_allow_leak) {
423+
PDEBUG("allowing direct udp connect()\n\n");
424+
return true_connect(sock, addr, len);
425+
} else {
426+
PDEBUG("blocking direct udp connect() \n\n");
427+
return -1;
428+
}
429+
}
398430

399431
// Check if connect called from proxydns
400432
remote_dns_connect = (ntohl(p_addr_in->s_addr) >> 24 == remote_dns_subnet);
401433

402434
for(i = 0; i < num_localnet_addr && !remote_dns_connect; i++) {
403435
if((localnet_addr[i].in_addr.s_addr & localnet_addr[i].netmask.s_addr) == (p_addr_in->s_addr & localnet_addr[i].netmask.s_addr)) {
404436
if(!localnet_addr[i].port || localnet_addr[i].port == port) {
405-
PDEBUG("accessing localnet using true_connect\n");
437+
PDEBUG("accessing localnet using true_connect\n\n");
406438
return true_connect(sock, addr, len);
407439
}
408440
}
@@ -414,17 +446,13 @@ int connect(int sock, const struct sockaddr *addr, socklen_t len) {
414446

415447
dest_ip.as_int = SOCKADDR(*addr);
416448

417-
ret = connect_proxy_chain(sock,
418-
dest_ip,
419-
SOCKPORT(*addr),
420-
proxybound_pd, proxybound_proxy_count, proxybound_ct, proxybound_max_chain);
449+
ret = connect_proxy_chain(sock, dest_ip, SOCKPORT(*addr), proxybound_pd, proxybound_proxy_count, proxybound_ct, proxybound_max_chain);
421450

422451
fcntl(sock, F_SETFL, flags);
423452
if(ret != SUCCESS)
424453
errno = ECONNREFUSED;
425454
return ret;
426455
}
427-
428456
/*
429457
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen) {
430458
return true_sendto(sockfd, buf, len, flags, *dest_addr, addrlen);
@@ -435,16 +463,17 @@ ssize_t send(int sockfd, const void *buf, size_t len, int flags) {
435463
return true_send(sockfd, buf, len, flags);
436464
//return 0;
437465
}
466+
467+
438468
ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags) {
439-
return true_sendmsg(sockfd, *msg, flags);
469+
return true_sendmsg(sockfd, msg, flags);
440470
//return 0;
441471
}*/
442472

443-
//sendmsg
444-
445473
//ssize_t send(int sockfd, const void *buf, size_t len, int flags) {}
446474

447475
//TODO: DNS LEAK: OTHER RESOLVER FUNCTION
476+
//=======================================
448477
//realresinit = dlsym(lib, "res_init");
449478
//realresquery = dlsym(lib, "res_query");
450479
//realressend = dlsym(lib, "res_send");
@@ -454,6 +483,7 @@ ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags) {
454483
//realgetipnodebyname = dlsym(lib, "getipnodebyname");
455484

456485
//UDP & DNS LEAK
486+
//==============
457487
//realsendto = dlsym(lib, "sendto");
458488
//realsendmsg = dlsym(lib, "sendmsg");
459489

0 commit comments

Comments
 (0)