Skip to contentSkip to conversation

Remove debian directory, and add new UNIXSOCK input plugin

PATCH In review Pierre Chifflier 3 participants 10 messages Aug 23, 2009 – Sep 8, 2009 netfilter

lore
Share & tools
lore
#0 lore raw

Hi,

[1] remove debian directory: the packaging is outdated, and not used in Debian anyway. It is easier to maintain it outside sources, so delete it.

(These patches are not related)

[2] add new input plugin UNISOCK, using a unix socket. This allows userspace applications to send packets to ulogd, for example to send packets offline. It uses a key-length-value protocol to handle optional fields or extensions.
[3] is a Perl script to load a PCAP file and send it to ulogd using the UNIXSOCK plugin.

Regards,
Pierre

#1 lore raw

PATCH 1/3 Remove debian directory

Remove Debian packaging files, it is easier to maintain the packaging files outside of the sources.

---
 debian/changelog                    |    5 ---
 debian/control                      |   54 -----------------------------------
 debian/rules                        |   11 -------
 debian/ulogd-input-nfct.install     |    1 -
 debian/ulogd-input-nflog.install    |    1 -
 debian/ulogd-output-mysql.install   |    1 -
 debian/ulogd-output-pcap.install    |    1 -
 debian/ulogd-output-pgsql.install   |    1 -
 debian/ulogd-output-sqlite3.install |    1 -
 debian/ulogd.install                |   10 ------
 10 files changed, 0 insertions(+), 86 deletions(-)
 delete mode 100644 debian/changelog
 delete mode 100644 debian/control
 delete mode 100755 debian/rules
 delete mode 100644 debian/ulogd-input-nfct.install
 delete mode 100644 debian/ulogd-input-nflog.install
 delete mode 100644 debian/ulogd-output-mysql.install
 delete mode 100644 debian/ulogd-output-pcap.install
 delete mode 100644 debian/ulogd-output-pgsql.install
 delete mode 100644 debian/ulogd-output-sqlite3.install
 delete mode 100644 debian/ulogd.install
debian/changelog deleted +0 -5
deleted file mode 100644
index d71ceba..0000000
@@ -1,5 +0,0 @@
-ulogd (2.00beta1) unstable; urgency=low
-
-  * initial debian release
-
- -- Harald Welte <[email protected]>  Sat, 07 Jan 2006 15:55:51 +0100
debian/control deleted +0 -54

54 lines not on this page · raw message

debian/rules deleted +0 -11
deleted file mode 100755
index 138a976..0000000
@@ -1,11 +0,0 @@
-#!/usr/bin/make -f
-# -*- mode: makefile; coding: utf-8 -*-
-
-UPSTREAM_VERSION := $(shell dpkg-parsechangelog | egrep '^Version:' | cut -f2 -d' ' | cut -f1 -d-)
-DEB_TARBALL := ulogd-$(UPSTREAM_VERSION).tar.bz2
-DEB_TAR_SRCDIR := ulogd-$(UPSTREAM_VERSION)
-
-include /usr/share/cdbs/1/rules/debhelper.mk
-include /usr/share/cdbs/1/class/autotools.mk
-
-DEB_DH_INSTALL_SOURCEDIR := debian/tmp
debian/ulogd-input-nfct.install deleted +0 -1
deleted file mode 100644
index 4fa02c3..0000000
@@ -1 +0,0 @@
-usr/lib/ulogd/ulogd_input_NFCT.so*
debian/ulogd-input-nflog.install deleted +0 -1
deleted file mode 100644
index e99af30..0000000
@@ -1 +0,0 @@
-usr/lib/ulogd/ulogd_input_NFLOG.so*
debian/ulogd-output-mysql.install deleted +0 -1
deleted file mode 100644
index 19eb379..0000000
@@ -1 +0,0 @@
-usr/lib/ulogd/ulogd_output_MYSQL.so*
debian/ulogd-output-pcap.install deleted +0 -1
deleted file mode 100644
index de25c45..0000000
@@ -1 +0,0 @@
-usr/lib/ulogd/ulogd_output_PCAP.so*
debian/ulogd-output-pgsql.install deleted +0 -1
deleted file mode 100644
index eddd68b..0000000
@@ -1 +0,0 @@
-usr/lib/ulogd/ulogd_output_PGSQL.so*
debian/ulogd-output-sqlite3.install deleted +0 -1
deleted file mode 100644
index 9ea3344..0000000
@@ -1 +0,0 @@
-usr/lib/ulogd/ulogd_output_SQLITE3.so*
debian/ulogd.install deleted +0 -10
deleted file mode 100644
index dec8583..0000000
@@ -1,10 +0,0 @@
-usr/sbin
-usr/share/man
-usr/lib/ulogd/ulogd_filter_IFINDEX.so*
-usr/lib/ulogd/ulogd_filter_PWSNIFF.so*
-usr/lib/ulogd/ulogd_inppkt_ULOG.so*
-usr/lib/ulogd/ulogd_output_IPFIX.so*
-usr/lib/ulogd/ulogd_output_LOGEMU.so*
-usr/lib/ulogd/ulogd_output_OPRINT.so*
-usr/lib/ulogd/ulogd_output_SYSLOG.so*
-usr/lib/ulogd/ulogd_raw2packet_BASE.so*
Signature · 1 line
1.6.3.3
#2 lore raw

PATCH 2/3 Add new input plugin UNIXSOCK

In reply to Pierre Chifflier

This input plugins creates a unix socket which can be used to log packets. Scripts or applications can connect to the socket (only one client allowed per socket) and send data in a Key-Length-Value format (including the payload).

---
 input/packet/Makefile.am             |    5 +-
 input/packet/ulogd_inppkt_UNIXSOCK.c |  658 ++++++++++++++++++++++++++++++++++
 ulogd.conf.in                        |    7 +
 3 files changed, 669 insertions(+), 1 deletions(-)
 create mode 100644 input/packet/ulogd_inppkt_UNIXSOCK.c
input/packet/Makefile.am +4 -1
index e90e46e..566b817 100644
@@ -3,7 +3,7 @@ AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include
 AM_CFLAGS=-fPIC -Wall
 LIBS=
 
-pkglib_LTLIBRARIES = ulogd_inppkt_NFLOG.la ulogd_inppkt_ULOG.la
+pkglib_LTLIBRARIES = ulogd_inppkt_NFLOG.la ulogd_inppkt_ULOG.la ulogd_inppkt_UNIXSOCK.la
 
 ulogd_inppkt_NFLOG_la_SOURCES = ulogd_inppkt_NFLOG.c
 ulogd_inppkt_NFLOG_la_LDFLAGS = -avoid-version -module $(LIBNETFILTER_LOG_LIBS)
@@ -12,3 +12,6 @@ ulogd_inppkt_NFLOG_la_CFLAGS = $(AM_CFLAGS) $(LIBNETFILTER_LOG_CFLAGS)
 ulogd_inppkt_ULOG_la_SOURCES = ulogd_inppkt_ULOG.c
 ulogd_inppkt_ULOG_la_LDFLAGS = -avoid-version -module
 ulogd_inppkt_ULOG_la_LIBADD = ../../libipulog/libipulog.la
+
+ulogd_inppkt_UNIXSOCK_la_SOURCES = ulogd_inppkt_UNIXSOCK.c
+ulogd_inppkt_UNIXSOCK_la_LDFLAGS = -avoid-version -module
input/packet/ulogd_inppkt_UNIXSOCK.c new file +658 -0

658 lines not on this page · raw message

ulogd.conf.in +7 -0
index 4542fc4..603efff 100644
@@ -27,6 +27,7 @@ loglevel=1
 
 plugin="@libdir@/ulogd/ulogd_inppkt_NFLOG.so"
 #plugin="@libdir@/ulogd/ulogd_inppkt_ULOG.so"
+#plugin="@libdir@/ulogd/ulogd_inppkt_UNIXSOCK.so"
 plugin="@libdir@/ulogd/ulogd_inpflow_NFCT.so"
 plugin="@libdir@/ulogd/ulogd_filter_IFINDEX.so"
 plugin="@libdir@/ulogd/ulogd_filter_IP2STR.so"
@@ -75,6 +76,9 @@ plugin="@libdir@/ulogd/ulogd_raw2packet_BASE.so"
 # this is a stack for logging packets to syslog after a collect via NFLOG
 #stack=log3:NFLOG,base1:BASE,ifi1:IFINDEX,ip2str1:IP2STR,print1:PRINTPKT,sys1:SYSLOG
 
+# this is a stack for logging packets to syslog after a collect via NuFW
+#stack=nuauth1:UNIXSOCK,base1:BASE,ifi1:IFINDEX,ip2str1:IP2STR,print1:PRINTPKT,sys1:SYSLOG
+
 # this is a stack for flow-based logging to MySQL
 #stack=ct1:NFCT,ip2bin1:IP2BIN,mysql2:MYSQL
 
@@ -137,6 +141,9 @@ numeric_label=1 # you can label the log info based on the packet verdict
 nlgroup=1
 #numeric_label=0 # optional argument
 
+[nuauth1]
+socket_path="/tmp/nuauth_ulogd2.sock"
+
 [emu1]
 file="/var/log/ulogd_syslogemu.log"
 sync=1
Signature · 1 line
1.6.3.3
#3 lore raw

Re: [PATCH 2/3] Add new input plugin UNIXSOCK

input/packet/ulogd_inppkt_UNIXSOCK.c line 19

Quoted 3 lines · Pierre Chifflier
input/packet/ulogd_inppkt_UNIXSOCK.c new file +3 -0
+
+/* Size of the receive buffer for the unix socket. */
+#define UNIXSOCK_BUFSIZE_DEFAULT	150000

Hm. Would it make some sene to '(ab)use' getsockopt(SO_RCVBUF) as the (runtime!) value for the default buffer size?

Quoted 9 lines
input/packet/ulogd_inppkt_UNIXSOCK.c new file +8 -0
+/* Default unix socket path */
+#define UNIXSOCK_UNIXPATH_DEFAULT	"/tmp/ulogd2.sock"
+
+
+#define UNIX_PATH_MAX	108
...
+static int _create_unix_socket(const char *unix_path)
+{
+	int ret = -1;

input/packet/ulogd_inppkt_UNIXSOCK.c line 416

Quoted 10 lines
input/packet/ulogd_inppkt_UNIXSOCK.c new file +10 -0
+	struct sockaddr_un server_sock;
+	int s;
+	socklen_t len;
+
+	s = socket(AF_UNIX, SOCK_STREAM, 0);
+	if (s < 0)
+		return -1;
+
+	server_sock.sun_family = AF_UNIX;
+	strncpy(server_sock.sun_path, unix_path, UNIX_PATH_MAX-1);

You can use sizeof(server_sock.sun_path) instead,
obviating the need for UNIX_PATH_MAX.

Also you should - as printf is called in the error case below - ensure it is '\0'-terminated.

input/packet/ulogd_inppkt_UNIXSOCK.c line 417

Quoted 1 line
input/packet/ulogd_inppkt_UNIXSOCK.c new file +1 -0
+	len = strlen(server_sock.sun_path) + sizeof(server_sock.sun_family);

len should be sizeof(server_sock)...

input/packet/ulogd_inppkt_UNIXSOCK.c line 422

Quoted 1 line
input/packet/ulogd_inppkt_UNIXSOCK.c new file +1 -0
+	ret = bind(s, (struct sockaddr *)&server_sock, len);

... and since it can be directly passed in:

	ret = bind(s, server_sock, sizeof(server_sock));

input/packet/ulogd_inppkt_UNIXSOCK.c line 460

Quoted 4 lines
input/packet/ulogd_inppkt_UNIXSOCK.c new file +4 -0
+/* callback called from ulogd core when fd is readable */
+static int unixsock_instance_read_cb(int fd, unsigned int what, void *param)
+{
+	struct ulogd_pluginstance *upi = (struct ulogd_pluginstance *)param;

There is no cast needed for void*s.

input/packet/ulogd_inppkt_UNIXSOCK.c line 523

Quoted 4 lines
input/packet/ulogd_inppkt_UNIXSOCK.c new file +4 -0
+/* callback called from ulogd core when fd is readable */
+static int unixsock_server_read_cb(int fd, unsigned int what, void *param)
+{
+	struct ulogd_pluginstance *upi = (struct ulogd_pluginstance *)param;

Same

input/packet/ulogd_inppkt_UNIXSOCK.c line 535

Quoted 9 lines
input/packet/ulogd_inppkt_UNIXSOCK.c new file +9 -0
+	struct sockaddr_storage saddr;
+
+	if (!(what & ULOGD_FD_READ))
+		return 0;
+
+	ulogd_log(ULOGD_DEBUG, "New server connected on unixsock socket\n");
+
+	len = sizeof(saddr);
+	s = accept(fd, (struct sockaddr*)&saddr, &len);

Since only unix sockets can connect, one could probably use sockaddr_un over sockaddr_storage (though _storage is always a good fallback).

input/packet/ulogd_inppkt_UNIXSOCK.c line 643

Quoted 9 lines
input/packet/ulogd_inppkt_UNIXSOCK.c new file +9 -0
+struct ulogd_plugin libunixsock_plugin = {
+	.name = "UNIXSOCK",
+	.input = {
+		.type = ULOGD_DTYPE_SOURCE,
+	},
+	.output = {
+		.type = ULOGD_DTYPE_RAW,
+		.keys = output_keys,
+		.num_keys = sizeof(output_keys)/sizeof(struct ulogd_key),

Hmmm. Does ulogd have an ARRAY_SIZE that could make .num_keys easier?

input/packet/ulogd_inppkt_UNIXSOCK.c line 658

Quoted 6 lines
input/packet/ulogd_inppkt_UNIXSOCK.c new file +6 -0
+void __attribute__ ((constructor)) init(void);
+
+void init(void)
+{
+	ulogd_register_plugin(&libunixsock_plugin);
+}

This can become

static void __attribute__((constructor)) init(void) { ... }

Modules are always self-contained shared libraries if I read the Makefiles right, so there should not be any benefit of giving them 'extern'al linkage.

#4 lore raw

Re: [PATCH 2/3] Add new input plugin UNIXSOCK

Hi Jan,

Thanks for your feedback.
I'm currently working on a new version of the patch with the changes (and some other fixes that were found after some real-life tests) I will send the updated parts ASAP.

Regards,
Pierre

Quoted 104 lines · Jan Engelhardt

input/packet/ulogd_inppkt_UNIXSOCK.c line 19

Quoted 3 lines · Pierre Chifflier
input/packet/ulogd_inppkt_UNIXSOCK.c new file +3 -0
+
+/* Size of the receive buffer for the unix socket. */
+#define UNIXSOCK_BUFSIZE_DEFAULT	150000

Hm. Would it make some sene to '(ab)use' getsockopt(SO_RCVBUF) as the (runtime!) value for the default buffer size?

Quoted 9 lines
input/packet/ulogd_inppkt_UNIXSOCK.c new file +8 -0
+/* Default unix socket path */
+#define UNIXSOCK_UNIXPATH_DEFAULT	"/tmp/ulogd2.sock"
+
+
+#define UNIX_PATH_MAX	108
...
+static int _create_unix_socket(const char *unix_path)
+{
+	int ret = -1;

input/packet/ulogd_inppkt_UNIXSOCK.c line 416

Quoted 10 lines
input/packet/ulogd_inppkt_UNIXSOCK.c new file +10 -0
+	struct sockaddr_un server_sock;
+	int s;
+	socklen_t len;
+
+	s = socket(AF_UNIX, SOCK_STREAM, 0);
+	if (s < 0)
+		return -1;
+
+	server_sock.sun_family = AF_UNIX;
+	strncpy(server_sock.sun_path, unix_path, UNIX_PATH_MAX-1);

You can use sizeof(server_sock.sun_path) instead,
obviating the need for UNIX_PATH_MAX.

Also you should - as printf is called in the error case below - ensure it is '\0'-terminated.

input/packet/ulogd_inppkt_UNIXSOCK.c line 417

Quoted 1 line
input/packet/ulogd_inppkt_UNIXSOCK.c new file +1 -0
+	len = strlen(server_sock.sun_path) + sizeof(server_sock.sun_family);

len should be sizeof(server_sock)...

input/packet/ulogd_inppkt_UNIXSOCK.c line 422

Quoted 1 line
input/packet/ulogd_inppkt_UNIXSOCK.c new file +1 -0
+	ret = bind(s, (struct sockaddr *)&server_sock, len);

... and since it can be directly passed in:

	ret = bind(s, server_sock, sizeof(server_sock));

input/packet/ulogd_inppkt_UNIXSOCK.c line 460

Quoted 4 lines
input/packet/ulogd_inppkt_UNIXSOCK.c new file +4 -0
+/* callback called from ulogd core when fd is readable */
+static int unixsock_instance_read_cb(int fd, unsigned int what, void *param)
+{
+	struct ulogd_pluginstance *upi = (struct ulogd_pluginstance *)param;

There is no cast needed for void*s.

input/packet/ulogd_inppkt_UNIXSOCK.c line 523

Quoted 4 lines
input/packet/ulogd_inppkt_UNIXSOCK.c new file +4 -0
+/* callback called from ulogd core when fd is readable */
+static int unixsock_server_read_cb(int fd, unsigned int what, void *param)
+{
+	struct ulogd_pluginstance *upi = (struct ulogd_pluginstance *)param;

Same

input/packet/ulogd_inppkt_UNIXSOCK.c line 535

Quoted 9 lines
input/packet/ulogd_inppkt_UNIXSOCK.c new file +9 -0
+	struct sockaddr_storage saddr;
+
+	if (!(what & ULOGD_FD_READ))
+		return 0;
+
+	ulogd_log(ULOGD_DEBUG, "New server connected on unixsock socket\n");
+
+	len = sizeof(saddr);
+	s = accept(fd, (struct sockaddr*)&saddr, &len);

Since only unix sockets can connect, one could probably use sockaddr_un over sockaddr_storage (though _storage is always a good fallback).

input/packet/ulogd_inppkt_UNIXSOCK.c line 643

Quoted 9 lines
input/packet/ulogd_inppkt_UNIXSOCK.c new file +9 -0
+struct ulogd_plugin libunixsock_plugin = {
+	.name = "UNIXSOCK",
+	.input = {
+		.type = ULOGD_DTYPE_SOURCE,
+	},
+	.output = {
+		.type = ULOGD_DTYPE_RAW,
+		.keys = output_keys,
+		.num_keys = sizeof(output_keys)/sizeof(struct ulogd_key),

Hmmm. Does ulogd have an ARRAY_SIZE that could make .num_keys easier?

input/packet/ulogd_inppkt_UNIXSOCK.c line 658

Quoted 6 lines
input/packet/ulogd_inppkt_UNIXSOCK.c new file +6 -0
+void __attribute__ ((constructor)) init(void);
+
+void init(void)
+{
+	ulogd_register_plugin(&libunixsock_plugin);
+}

This can become

static void __attribute__((constructor)) init(void) { ... }

Modules are always self-contained shared libraries if I read the Makefiles right, so there should not be any benefit of giving them 'extern'al linkage.

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw

(unknown)

In reply to Jan Engelhardt

Hi,

Here is an updated version of the UNIXSOCK plugin (part 2 only, other parts are unchanged).
I think all remarks from Jan have been integrated:
- use sizeof(server_sock.sun_path) and do not use UNIX_PATH_MAX
- remove useless casts from void*
- use ARRAY_SIZE
- if no buffer size was provided, try to determine it using getsockopt(SO_RECVBUF) at runtime
- use one line for init function attributes, and make it static

Cheers,
Pierre

#6 lore raw

PATCH 2/3 Add new input plugin UNIXSOCK

In reply to Jan Engelhardt

This input plugins creates a unix socket which can be used to log packets. Scripts or applications can connect to the socket (only one client allowed per socket) and send data in a Key-Length-Value format (including the payload).

---
 input/packet/Makefile.am             |    5 +-
 input/packet/ulogd_inppkt_UNIXSOCK.c |  694 ++++++++++++++++++++++++++++++++++
 ulogd.conf.in                        |    7 +
 3 files changed, 705 insertions(+), 1 deletions(-)
 create mode 100644 input/packet/ulogd_inppkt_UNIXSOCK.c
input/packet/Makefile.am +4 -1
index e90e46e..566b817 100644
@@ -3,7 +3,7 @@ AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include
 AM_CFLAGS=-fPIC -Wall
 LIBS=
 
-pkglib_LTLIBRARIES = ulogd_inppkt_NFLOG.la ulogd_inppkt_ULOG.la
+pkglib_LTLIBRARIES = ulogd_inppkt_NFLOG.la ulogd_inppkt_ULOG.la ulogd_inppkt_UNIXSOCK.la
 
 ulogd_inppkt_NFLOG_la_SOURCES = ulogd_inppkt_NFLOG.c
 ulogd_inppkt_NFLOG_la_LDFLAGS = -avoid-version -module $(LIBNETFILTER_LOG_LIBS)
@@ -12,3 +12,6 @@ ulogd_inppkt_NFLOG_la_CFLAGS = $(AM_CFLAGS) $(LIBNETFILTER_LOG_CFLAGS)
 ulogd_inppkt_ULOG_la_SOURCES = ulogd_inppkt_ULOG.c
 ulogd_inppkt_ULOG_la_LDFLAGS = -avoid-version -module
 ulogd_inppkt_ULOG_la_LIBADD = ../../libipulog/libipulog.la
+
+ulogd_inppkt_UNIXSOCK_la_SOURCES = ulogd_inppkt_UNIXSOCK.c
+ulogd_inppkt_UNIXSOCK_la_LDFLAGS = -avoid-version -module
input/packet/ulogd_inppkt_UNIXSOCK.c new file +694 -0

694 lines not on this page · raw message

ulogd.conf.in +7 -0
index 4542fc4..323462b 100644
@@ -27,6 +27,7 @@ loglevel=1
 
 plugin="@libdir@/ulogd/ulogd_inppkt_NFLOG.so"
 #plugin="@libdir@/ulogd/ulogd_inppkt_ULOG.so"
+#plugin="@libdir@/ulogd/ulogd_inppkt_UNIXSOCK.so"
 plugin="@libdir@/ulogd/ulogd_inpflow_NFCT.so"
 plugin="@libdir@/ulogd/ulogd_filter_IFINDEX.so"
 plugin="@libdir@/ulogd/ulogd_filter_IP2STR.so"
@@ -75,6 +76,9 @@ plugin="@libdir@/ulogd/ulogd_raw2packet_BASE.so"
 # this is a stack for logging packets to syslog after a collect via NFLOG
 #stack=log3:NFLOG,base1:BASE,ifi1:IFINDEX,ip2str1:IP2STR,print1:PRINTPKT,sys1:SYSLOG
 
+# this is a stack for logging packets to syslog after a collect via NuFW
+#stack=nuauth1:UNIXSOCK,base1:BASE,ip2str1:IP2STR,print1:PRINTPKT,sys1:SYSLOG
+
 # this is a stack for flow-based logging to MySQL
 #stack=ct1:NFCT,ip2bin1:IP2BIN,mysql2:MYSQL
 
@@ -137,6 +141,9 @@ numeric_label=1 # you can label the log info based on the packet verdict
 nlgroup=1
 #numeric_label=0 # optional argument
 
+[nuauth1]
+socket_path="/tmp/nuauth_ulogd2.sock"
+
 [emu1]
 file="/var/log/ulogd_syslogemu.log"
 sync=1
Signature · 1 line
1.6.3.3
#7 lore raw

Re: [PATCH 2/3] Add new input plugin UNIXSOCK

input/packet/ulogd_inppkt_UNIXSOCK.c line 24

Quoted 9 lines · Pierre Chifflier
input/packet/ulogd_inppkt_UNIXSOCK.c new file +9 -0
+#include <ulogd/ulogd.h>
+
+/* Default size of the receive buffer for the unix socket
+   0 means that ulogd will use getsockopt(SO_RCVBUF) to determine it
+   at runtime */
+#define UNIXSOCK_BUFSIZE_DEFAULT	0
+
+/* Default unix socket path */
+#define UNIXSOCK_UNIXPATH_DEFAULT	"/tmp/ulogd2.sock"

That does not look like a good default path, though it might be configurable at runtime. It seems that, because sockets are world-connectable by default, random users could spam your socket.

Subsequently, there also seems to be an easy DoS whereby a user process only needs to connect to block a legitimate program from sending packets to the module.

Finally, but this is not so much of a problem, a user could also create ulogd2.sock first and then receive potentially interesting packets from a legitimate program that thought it would connect to ulogd2.

I would just move it out to, for example, /var/run/ulogd/ulogd2.sock so one can set restrictions on /var/run/ulogd as needed.

What are your thoughts?

#8 lore raw

Re: [PATCH 2/3] Add new input plugin UNIXSOCK

Quoted 10 lines · Jan Engelhardt

input/packet/ulogd_inppkt_UNIXSOCK.c line 24

Quoted 2 lines
input/packet/ulogd_inppkt_UNIXSOCK.c new file +2 -0
+/* Default unix socket path */
+#define UNIXSOCK_UNIXPATH_DEFAULT	"/tmp/ulogd2.sock"

That does not look like a good default path, though it might be configurable at runtime. It seems that, because sockets are world-connectable by default, random users could spam your socket.

Subsequently, there also seems to be an easy DoS whereby a user process only needs to connect to block a legitimate program from sending packets to the module.

True, when using unix socket you always have to set path, permissions and chown it ...

Maybe this could even be an option of ulogd.conf: unixsock_perms and unixsock_owner ?

Quoted 7 lines

Finally, but this is not so much of a problem, a user could also create ulogd2.sock first and then receive potentially interesting packets from a legitimate program that thought it would connect to ulogd2.

I would just move it out to, for example, /var/run/ulogd/ulogd2.sock so one can set restrictions on /var/run/ulogd as needed.

Indeed, the only drawback is that the plugin will fail if the parent directory does not exist.

Pierre

#9 lore raw

PATCH 3/3 Add helper script pcap2ulog

In reply to Pierre Chifflier

This script uses the Net::Pcap Perl library to parse an pcap file and send packets to ulogd2 throught the UNIXSOCK input module.

---
 contrib/pcap2ulog |   96 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 96 insertions(+), 0 deletions(-)
 create mode 100755 contrib/pcap2ulog
contrib/pcap2ulog new file +96 -0
new file mode 100755
index 0000000..0a42b89
@@ -0,0 +1,96 @@
+#!/usr/bin/perl -w
+
+# Copyright (C) 2009 Pierre Chifflier <[email protected]>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the same terms as Perl itself, either Perl version 5.8.4 or,
+# at your option, any later version of Perl 5 you may have available.
+
+use strict;
+
+use IO::Socket;
+use Net::Pcap;
+
+
+my $dumpfile = shift or die "Unable to open pcap file";
+my($pcap_t, $err);
+my($ulogd_client);
+my $socketfile = "/var/run/ulogd2.sock";
+
+sub connect_ulogd2 {
+    (-S $socketfile) or die "ulogd2 socket $socketfile does not exist - is ulogd running ?";
+
+    $ulogd_client = IO::Socket::UNIX->new(Peer  => $socketfile,
+                                          Type      => SOCK_STREAM ) or die $!;
+}
+
+sub process_pkt {
+    my($user, $hdr, $pkt) = @_;
+
+    if (($user ne "xyz") or !defined($hdr) or !defined($pkt)) {
+        print("Bad args passed to callback\n");
+        print("Bad user data\n"), if ($user ne "xyz");
+        print("Bad pkthdr\n"), if (!defined($hdr));
+        print("Bad pkt data\n"), if (!defined($pkt));
+        print("not ok\n");
+        exit;
+    }
+
+    #print "Header: len $hdr->{len}\n";
+    #my $len = length $pkt;
+    #print "Packet length: $len\n";
+
+    # decode packet
+    # packet type (sent by us: 4)
+    # link layer address type: 1
+    # link layer address length: 6
+    # src dst
+    # protocol (IP, ARP, PPP, SNMP ...)
+    # data
+    my $ignored = substr ($pkt, 0, 6);
+    my $srcmac = substr ($pkt, 6, 6);
+    my $protocol = unpack ("n", substr ($pkt, 12, 2));
+    my $size = length($pkt) - 16;
+
+    (my $hex_src = unpack("H*", $srcmac)) =~ s/(..)/$1:/g;
+    chop $hex_src;
+    #printf "source mac: $hex_src\n";
+
+    my $hex_dst = "\0";
+
+    # format data
+    my $data;
+
+    my $options_num=2;
+    my $options_len=length($hex_src) + length($hex_dst);
+    # total length
+    $data = pack ('n', $size + 4 + (4*$options_num) + ($options_len));
+    print $ulogd_client $data;
+    # payload length + payload
+    $data = pack ('na*', $size, substr($pkt,16,$size));
+    print $ulogd_client $data;
+    # options
+    my $OOB_IN = 2;
+    $data = pack ('nna*', $OOB_IN, length($hex_src), $hex_src);
+    print $ulogd_client $data;
+    my $OOB_OUT = 3;
+    $data = pack ('nna*', $OOB_OUT, length($hex_dst), $hex_dst);
+    print $ulogd_client $data;
+
+    #exit;
+}
+
+
+connect_ulogd2 or die $!;
+
+$pcap_t = Net::Pcap::open_offline($dumpfile, \$err);
+if (!defined($pcap_t)) {
+    print("Net::Pcap::dump_open failed: ", Net::Pcap::geterr($pcap_t), "\n");
+    exit;
+}
+
+Net::Pcap::loop($pcap_t, 10, \&process_pkt, "xyz");
+Net::Pcap::close($pcap_t);
+
+
+
Signature · 1 line
1.6.3.3