Browse Source

tpws, nfqws: clear bounding set

pull/33/head
bolvan 6 years ago
parent
commit
12f530b287
  1. BIN
      binaries/aarch64/nfqws
  2. BIN
      binaries/aarch64/tpws
  3. BIN
      binaries/armhf/nfqws
  4. BIN
      binaries/armhf/tpws
  5. BIN
      binaries/mips32r1-lsb/nfqws
  6. BIN
      binaries/mips32r1-lsb/tpws
  7. BIN
      binaries/mips32r1-msb/nfqws
  8. BIN
      binaries/mips32r1-msb/tpws
  9. BIN
      binaries/mips64r2-msb/nfqws
  10. BIN
      binaries/mips64r2-msb/tpws
  11. BIN
      binaries/ppc/nfqws
  12. BIN
      binaries/ppc/tpws
  13. BIN
      binaries/x86/nfqws
  14. BIN
      binaries/x86/tpws
  15. BIN
      binaries/x86_64/nfqws
  16. BIN
      binaries/x86_64/tpws
  17. 39
      nfq/nfqws.c
  18. 67
      tpws/tpws.c

BIN
binaries/aarch64/nfqws

Binary file not shown.

BIN
binaries/aarch64/tpws

Binary file not shown.

BIN
binaries/armhf/nfqws

Binary file not shown.

BIN
binaries/armhf/tpws

Binary file not shown.

BIN
binaries/mips32r1-lsb/nfqws

Binary file not shown.

BIN
binaries/mips32r1-lsb/tpws

Binary file not shown.

BIN
binaries/mips32r1-msb/nfqws

Binary file not shown.

BIN
binaries/mips32r1-msb/tpws

Binary file not shown.

BIN
binaries/mips64r2-msb/nfqws

Binary file not shown.

BIN
binaries/mips64r2-msb/tpws

Binary file not shown.

BIN
binaries/ppc/nfqws

Binary file not shown.

BIN
binaries/ppc/tpws

Binary file not shown.

BIN
binaries/x86/nfqws

Binary file not shown.

BIN
binaries/x86/tpws

Binary file not shown.

BIN
binaries/x86_64/nfqws

Binary file not shown.

BIN
binaries/x86_64/tpws

Binary file not shown.

39
nfq/nfqws.c

@ -365,31 +365,52 @@ static int cb(struct nfq_q_handle *qh, struct nfgenmsg *nfmsg,
return nfq_set_verdict(qh, id, NF_ACCEPT, 0, NULL); return nfq_set_verdict(qh, id, NF_ACCEPT, 0, NULL);
} }
bool dropcaps() bool setpcap(cap_value_t *caps,int ncaps)
{ {
cap_value_t cap_values[] = {CAP_NET_ADMIN};
cap_t capabilities; cap_t capabilities;
if (!(capabilities = cap_init())) if (!(capabilities = cap_init()))
{
perror("cap_init");
return false; return false;
}
if (cap_set_flag(capabilities, CAP_PERMITTED, sizeof(cap_values)/sizeof(*cap_values), cap_values, CAP_SET) || if (ncaps && (cap_set_flag(capabilities, CAP_PERMITTED, ncaps, caps, CAP_SET) ||
cap_set_flag(capabilities, CAP_EFFECTIVE, sizeof(cap_values)/sizeof(*cap_values), cap_values, CAP_SET)) cap_set_flag(capabilities, CAP_EFFECTIVE, ncaps, caps, CAP_SET)))
{ {
perror("cap_set_flag");
cap_free(capabilities); cap_free(capabilities);
return false; return false;
} }
if (cap_set_proc(capabilities)) if (cap_set_proc(capabilities))
{ {
perror("cap_set_proc");
cap_free(capabilities); cap_free(capabilities);
return false; return false;
} }
cap_free(capabilities); cap_free(capabilities);
return true; return true;
} }
bool dropcaps()
{
// must have CAP_SETPCAP at the end. its required to clear bounding set
cap_value_t cap_values[] = {CAP_NET_ADMIN,CAP_SETPCAP};
int capct=sizeof(cap_values)/sizeof(*cap_values);
if (setpcap(cap_values, capct))
{
for(int cap=0;cap<=CAP_LAST_CAP;cap++)
{
if (cap_drop_bound(cap))
{
perror("cap_drop_bound");
return false;
}
}
}
// now without CAP_SETPCAP
if (!setpcap(cap_values, capct - 1))
{
perror("setpcap");
return false;
}
return true;
}
bool droproot(uid_t uid, gid_t gid) bool droproot(uid_t uid, gid_t gid)
{ {
if (uid || gid) if (uid || gid)

67
tpws/tpws.c

@ -24,6 +24,7 @@
#include <pwd.h> #include <pwd.h>
#include <signal.h> #include <signal.h>
#include <sys/capability.h> #include <sys/capability.h>
#include <sys/prctl.h>
#include "tpws.h" #include "tpws.h"
#include "tpws_conn.h" #include "tpws_conn.h"
@ -102,13 +103,6 @@ size_t send_with_flush(int sockfd, const void *buf, size_t len, int flags)
return wr; return wr;
} }
void close_tcp_conn(tproxy_conn_t *conn, struct tailhead *conn_list,
struct tailhead *close_list) {
conn->state = CONN_CLOSED;
TAILQ_REMOVE(conn_list, conn, conn_ptrs);
TAILQ_INSERT_TAIL(close_list, conn, conn_ptrs);
}
#define RD_BLOCK_SIZE 8192 #define RD_BLOCK_SIZE 8192
// pHost points to "Host: ..." // pHost points to "Host: ..."
@ -278,7 +272,8 @@ void modify_tcp_segment(char *segment,size_t *size,size_t *split_pos)
} }
bool handle_epollin(tproxy_conn_t *conn, ssize_t *data_transferred) { bool handle_epollin(tproxy_conn_t *conn, ssize_t *data_transferred)
{
int numbytes; int numbytes;
int fd_in, fd_out; int fd_in, fd_out;
bool bOutgoing; bool bOutgoing;
@ -351,7 +346,8 @@ bool handle_epollin(tproxy_conn_t *conn, ssize_t *data_transferred) {
return rd != -1 && wr != -1; return rd != -1 && wr != -1;
} }
void remove_closed_connections(struct tailhead *close_list) { void remove_closed_connections(struct tailhead *close_list)
{
tproxy_conn_t *conn = NULL; tproxy_conn_t *conn = NULL;
while (close_list->tqh_first != NULL) { while (close_list->tqh_first != NULL) {
@ -367,7 +363,15 @@ void remove_closed_connections(struct tailhead *close_list) {
} }
} }
int event_loop(int listen_fd) { void close_tcp_conn(tproxy_conn_t *conn, struct tailhead *conn_list, struct tailhead *close_list)
{
conn->state = CONN_CLOSED;
TAILQ_REMOVE(conn_list, conn, conn_ptrs);
TAILQ_INSERT_TAIL(close_list, conn, conn_ptrs);
}
int event_loop(int listen_fd)
{
int retval = 0, num_events = 0; int retval = 0, num_events = 0;
int tmp_fd = 0; //Used to temporarily hold the accepted file descriptor int tmp_fd = 0; //Used to temporarily hold the accepted file descriptor
tproxy_conn_t *conn = NULL; tproxy_conn_t *conn = NULL;
@ -483,7 +487,8 @@ int event_loop(int listen_fd) {
return retval; return retval;
} }
int8_t block_sigpipe() { int8_t block_sigpipe()
{
sigset_t sigset; sigset_t sigset;
memset(&sigset, 0, sizeof(sigset)); memset(&sigset, 0, sizeof(sigset));
@ -790,29 +795,61 @@ void daemonize()
/* stderror */ /* stderror */
} }
bool dropcaps() bool setpcap(cap_value_t *caps,int ncaps)
{ {
cap_t capabilities; cap_t capabilities;
if (!(capabilities = cap_init())) if (!(capabilities = cap_init()))
return false;
if (ncaps && (cap_set_flag(capabilities, CAP_PERMITTED, ncaps, caps, CAP_SET) ||
cap_set_flag(capabilities, CAP_EFFECTIVE, ncaps, caps, CAP_SET)))
{ {
perror("cap_init"); cap_free(capabilities);
return false; return false;
} }
if (cap_set_proc(capabilities)) if (cap_set_proc(capabilities))
{ {
perror("cap_set_proc");
cap_free(capabilities); cap_free(capabilities);
return false; return false;
} }
cap_free(capabilities); cap_free(capabilities);
return true; return true;
} }
bool dropcaps()
{
// must have CAP_SETPCAP at the end. its required to clear bounding set
cap_value_t cap_values[] = {CAP_SETPCAP};
int capct=sizeof(cap_values)/sizeof(*cap_values);
if (setpcap(cap_values, capct))
{
for(int cap=0;cap<=CAP_LAST_CAP;cap++)
{
if (cap_drop_bound(cap))
{
perror("cap_drop_bound");
return false;
}
}
}
// now without CAP_SETPCAP
if (!setpcap(cap_values, capct - 1))
{
perror("setpcap");
return false;
}
return true;
}
bool droproot() bool droproot()
{ {
if (params.uid || params.gid) if (params.uid || params.gid)
{ {
if (prctl(PR_SET_KEEPCAPS, 1L))
{
perror("prctl(PR_SET_KEEPCAPS): ");
return false;
}
if (setgid(params.gid)) if (setgid(params.gid))
{ {
perror("setgid: "); perror("setgid: ");

Loading…
Cancel
Save