mirror of
https://github.com/troglobit/finit.git
synced 2026-11-21 19:51:46 +00:00
Add protection against UDP inetd looping attacks
This patch adds protection against a common inetd attack vector wherein the reply port to UDP inetd services is forged to an internal inetd service port. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
5723b2e75b
commit
7dfdc2395b
8 files changed
+70
-6
No files matched your search
+16
-2
@@ -27,6 +27,20 @@
|
||||
|
||||
#include "../plugin.h"
|
||||
|
||||
#define NAME "echo"
|
||||
|
||||
static int recv_peer(int sd, char *buf, ssize_t len, struct sockaddr *sa, socklen_t *sa_len)
|
||||
{
|
||||
len = recvfrom(sd, buf, sizeof(buf), MSG_DONTWAIT, sa, sa_len);
|
||||
if (-1 == len)
|
||||
return -1; /* On error, close connection. */
|
||||
|
||||
if (inetd_check_loop(sa, *sa_len, NAME))
|
||||
return -1;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static int cb(int type)
|
||||
{
|
||||
int sd = STDIN_FILENO;
|
||||
@@ -35,7 +49,7 @@ static int cb(int type)
|
||||
struct sockaddr_storage sa;
|
||||
socklen_t sa_len = sizeof(sa);
|
||||
|
||||
len = recvfrom(sd, buf, sizeof(buf), MSG_DONTWAIT, (struct sockaddr *)&sa, &sa_len);
|
||||
len = recv_peer(sd, buf, sizeof(buf), (struct sockaddr *)&sa, &sa_len);
|
||||
if (-1 == len)
|
||||
return -1; /* On error, close connection. */
|
||||
|
||||
@@ -43,7 +57,7 @@ static int cb(int type)
|
||||
}
|
||||
|
||||
static plugin_t plugin = {
|
||||
.name = "echo", /* Must match the inetd /etc/services entry */
|
||||
.name = NAME, /* Must match the inetd /etc/services entry */
|
||||
.inetd = {
|
||||
.cmd = cb
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user