Skip to content

Commit e9e1b71

Browse files
committed
initial bind support
1 parent 02e49d8 commit e9e1b71

4 files changed

Lines changed: 49 additions & 40 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Changelog:
6767

6868
- Block non tcp packet on send()
6969
- Prevent bypass noleak
70+
- Add support for bind() to block listen on unsupported protocol
7071

7172
**Version 5.40:**
7273

src/core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,12 @@ extern gethostbyaddr_t true_gethostbyaddr;
123123
typedef ssize_t (*send_t)(int, const void *, size_t, int);
124124
typedef ssize_t (*sendto_t)(int, const void *, size_t, int, const struct sockaddr, socklen_t);
125125
typedef ssize_t (*sendmsg_t)(int, const struct msghdr *, int);
126+
typedef int (*bind_t)(int, const struct sockaddr, socklen_t);
126127

127128
extern send_t true_send;
128129
extern sendto_t true_sendto;
129130
extern sendmsg_t true_sendmsg;
131+
extern bind_t true_bind;
130132

131133
struct gethostbyname_data {
132134
struct hostent hostent_space;

src/libproxybound.c

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ gethostbyaddr_t true_gethostbyaddr;
5555
send_t true_send;
5656
sendto_t true_sendto;
5757
sendmsg_t true_sendmsg;
58+
bind_t true_bind;
5859

5960
int tcp_read_time_out;
6061
int tcp_connect_time_out;
@@ -479,45 +480,9 @@ int connect(int sock, const struct sockaddr *addr, socklen_t len) {
479480
return ret;
480481
}
481482

482-
ssize_t send(int sockfd, const void *buf, size_t len, int flags) {
483-
//The send() call may be used only when the socket is in a connected state (so that the intended recipient is known)
484-
//To avoid any hack this is watched for leak too
485-
486-
/* If the real connect doesn't exist, we're stuffed */
487-
if (true_send == NULL) {
488-
PDEBUG("unresolved symbol: send\n\n");
489-
return -1;
490-
}
491-
492-
//return true_send(sockfd, buf, len, flags);
493-
if (proxybound_allow_leak) {
494-
PDEBUG("send: got send request\n");
495-
PDEBUG("allowing direct send()\n\n");
496-
return true_send(sockfd, buf, len, flags);
497-
//Already handled in connect ?
498-
//TODO deeper handling (socktype)
499-
} else {
500-
int sock_type = -1;
501-
unsigned int sock_type_len = sizeof(sock_type);
502-
503-
/* Get the type of the socket */
504-
getsockopt(sockfd, SOL_SOCKET, SO_TYPE, (void *) &sock_type, &sock_type_len);
505-
506-
if (sock_type != SOCK_STREAM) {
507-
//SOCK_STREAM
508-
//SOCK_DGRAM
509-
//SOCK_SEQPACKET
510-
//SOCK_RAW
511-
//SOCK_RDM
512-
//SOCK_PACKET
513-
PDEBUG("send: blocking send request type SOCK_DGRAM/SOCK_SEQPACKET/SOCK_RAW/SOCK_RDM/SOCK_PACKET\n\n");
514-
return -1;
515-
//TODO may block dns here
516-
} else {
517-
return true_send(sockfd, buf, len, flags);
518-
}
519-
return -1;
520-
}
483+
int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
484+
PDEBUG("bind: got a bind request\n\n");
485+
return true_bind(sockfd, *addr, addrlen);
521486
}
522487

523488
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen) {
@@ -581,6 +546,47 @@ ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct
581546
return -1;
582547
}
583548

549+
ssize_t send(int sockfd, const void *buf, size_t len, int flags) {
550+
//The send() call may be used only when the socket is in a connected state (so that the intended recipient is known)
551+
//To avoid any hack this is watched for leak too
552+
553+
/* If the real connect doesn't exist, we're stuffed */
554+
if (true_send == NULL) {
555+
PDEBUG("unresolved symbol: send\n\n");
556+
return -1;
557+
}
558+
559+
//return true_send(sockfd, buf, len, flags);
560+
if (proxybound_allow_leak) {
561+
PDEBUG("send: got send request\n");
562+
PDEBUG("allowing direct send()\n\n");
563+
return true_send(sockfd, buf, len, flags);
564+
//Already handled in connect ?
565+
//TODO deeper handling (socktype)
566+
} else {
567+
int sock_type = -1;
568+
unsigned int sock_type_len = sizeof(sock_type);
569+
570+
/* Get the type of the socket */
571+
getsockopt(sockfd, SOL_SOCKET, SO_TYPE, (void *) &sock_type, &sock_type_len);
572+
573+
if (sock_type != SOCK_STREAM) {
574+
//SOCK_STREAM
575+
//SOCK_DGRAM
576+
//SOCK_SEQPACKET
577+
//SOCK_RAW
578+
//SOCK_RDM
579+
//SOCK_PACKET
580+
PDEBUG("send: blocking send request type SOCK_DGRAM/SOCK_SEQPACKET/SOCK_RAW/SOCK_RDM/SOCK_PACKET\n\n");
581+
return -1;
582+
//TODO may block dns here
583+
} else {
584+
return true_send(sockfd, buf, len, flags);
585+
}
586+
return -1;
587+
}
588+
}
589+
584590
ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags) {
585591

586592
struct sockaddr_in *connaddr;

src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "common.h"
2727

2828

29-
static char appVersion[5] = "5.40\n";
29+
static char appVersion[5] = "5.50\n";
3030

3131
static const char *dll_name = DLL_NAME;
3232
static pid_t child_pid = -1 ;

0 commit comments

Comments
 (0)