implement detection and denial of endless connection loops

it is quite easy to bring down a proxy server by forcing it to make
connections to one of its own ports, because this will result in an endless
loop spawning more and more connections, until all available fds are exhausted.
since there's a potentially infinite number of potential DNS/ip addresses
resolving to the proxy, it is impossible to detect an endless loop by simply
looking at the destination ip address and port.

what *is* possible though is to record the ip/port tuples assigned to outgoing
connections, and then compare them against new incoming connections. if they
match, the sender was the proxy itself and therefore needs to reject that
connection.

fixes #199.
This commit is contained in:
rofl0r authored and rofl0r committed 2019-12-21 00:43:45 +00:00
1 parent f6d4da5d81
commit cd005a94ce
6 files changed
+117 -1

No files matched your search

+15
View File
@@ -49,6 +49,7 @@
#include "connect-ports.h"
#include "conf.h"
#include "basicauth.h"
#include "loop.h"
/*
* Maximum length of a HTTP line
@@ -1560,6 +1561,20 @@ void handle_connection (int fd, union sockaddr_union* addr)
return;
}
if (connection_loops (addr)) {
log_message (LOG_CONN,
"Prevented endless loop (file descriptor %d): %s",
fd, peer_ipaddr);
indicate_http_error(connptr, 400, "Bad Request",
"detail",
"You tried to connect to the "
"machine the proxy is running on",
NULL);
goto fail;
}
if (check_acl (peer_ipaddr, addr, config.access_list) <= 0) {
update_stats (STAT_DENIED);
indicate_http_error (connptr, 403, "Access denied",