Skip to contentSkip to conversation

Passive OS fingerprint xtables match.

PATCH Evgeniy Polyakov 2 participants 8 messages Mar 26, 2009 – May 1, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi.

Passive OS fingerprinting netfilter module allows to passively detect remote OS and perform various netfilter actions based on that knowledge. This module compares some data (WS, MSS, options and it's order, ttl, df and others) from packets with SYN bit set with dynamically loaded OS fingerprints.

Fingerprint matching rules can be downloaded from OpenBSD source tree and loaded via netfilter netlink subsystem into the kernel via special util found in archive.

Archive contains library file (also attached), which was shipped with iptables extensions some time ago (at least when ipt_osf existed in patch-o-matic).

This release moves library build to the 1.4.3 features and adds nfnetlink support for the module configuration.
Also I incorporated all comments which were rised during the previous sends.

Fingerprints can be downloaded from
http://www.openbsd.org/cgi-bin/cvsweb/src/etc/pf.os

Example usage:

# modrpobe xt_osf
# ./nfnl_osf -f ./pf.os
-d switch removes fingerprints
# iptables -I INPUT -j ACCEPT -p tcp -m osf --genre Linux --log 0 --ttl 2

You will find something like this in the syslog:
Windows [2000:SP3:Windows XP Pro SP1, 2000 SP3]: 11.22.33.55:4024 -> 11.22.33.44:139 hops=4 Linux [2.5:] : 1.2.3.4:44448 -> 11.22.33.44:22 hops=4

Please consider for inclusion.
Thank you.

Passive OS fingerprint homepage (archives, examples):
http://www.ioremap.net/projects/osf

And a small foot note: netfilter guys, you have really, Really, REALLY weird feel of the reality since porting whatever else to the netfilter netlink code requires non-trivial amount of god-blessed substances processed by the brain of the poor human.

include/linux/netfilter/nfnetlink.h +2 -1
index 7d8e045..71babbd 100644
@@ -46,7 +46,8 @@ struct nfgenmsg {
 #define NFNL_SUBSYS_CTNETLINK_EXP	2
 #define NFNL_SUBSYS_QUEUE		3
 #define NFNL_SUBSYS_ULOG		4
-#define NFNL_SUBSYS_COUNT		5
+#define NFNL_SUBSYS_OSF			5
+#define NFNL_SUBSYS_COUNT		6
 
 #ifdef __KERNEL__
 
include/linux/netfilter/xt_osf.h new file +119 -0

119 lines not on this page · raw message

net/netfilter/Kconfig +13 -0
index c2bac9c..1e74c97 100644
@@ -853,6 +853,19 @@ config NETFILTER_XT_MATCH_U32
 
 	  Details and examples are in the kernel module source.
 
+config NETFILTER_XT_MATCH_OSF
+	tristate '"osf" Passive OS fingerprint match'
+	depends on NETFILTER_ADVANCED
+	help
+	  This option selects the Passive OS Fingerprinting match module
+	  that allows to passively match the remote operating system by
+	  analyzing incoming TCP SYN packets.
+
+	  Rules and loading software can be downloaded from
+	  http://www.ioremap.net/projects/osf
+
+	  To compile it as a module, choose M here.  If unsure, say N.
+
 endif # NETFILTER_XTABLES
 
 endmenu
net/netfilter/Makefile +1 -0
index da3d909..96b7754 100644
@@ -73,6 +73,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_LIMIT) += xt_limit.o
 obj-$(CONFIG_NETFILTER_XT_MATCH_MAC) += xt_mac.o
 obj-$(CONFIG_NETFILTER_XT_MATCH_MARK) += xt_mark.o
 obj-$(CONFIG_NETFILTER_XT_MATCH_MULTIPORT) += xt_multiport.o
+obj-$(CONFIG_NETFILTER_XT_MATCH_OSF) += xt_osf.o
 obj-$(CONFIG_NETFILTER_XT_MATCH_OWNER) += xt_owner.o
 obj-$(CONFIG_NETFILTER_XT_MATCH_PHYSDEV) += xt_physdev.o
 obj-$(CONFIG_NETFILTER_XT_MATCH_PKTTYPE) += xt_pkttype.o
net/netfilter/xt_osf.c new file +503 -0

503 lines not on this page · raw message

Signature · 1 line
	Evgeniy Polyakov

/*
* Copyright (c) 2003+ Evgeniy Polyakov <[email protected]>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

/*
* iptables interface for OS fingerprint matching module. */

#include <stdio.h>
#include <netdb.h>
#include <string.h>
#include <stdlib.h>
#include <getopt.h>
#include <ctype.h>

#include <linux/types.h>

#include <xtables.h>

#include <netinet/ip.h>
#include <netinet/tcp.h>

#include "ipt_osf.h"

static void osf_help(void)
{
printf("OS fingerprint match options:\n"
"--genre [!] string Match a OS genre by passive fingerprinting.\n"
"--ttl Use some TTL check extensions to determine OS:\n"
" 0 true ip and fingerprint TTL comparison. Works for LAN.\n"
" 1 check if ip TTL is less than fingerprint one. Works for global addresses.\n"
" 2 do not compare TTL at all. Allows to detect NMAP, but can produce false results.\n"
"--log level Log determined genres into dmesg even if they do not match desired one:\n"
" 0 log all matched or unknown signatures.\n"
" 1 log only first one.\n"
" 2 log all known matched signatures.\n"
);
}

static const struct option osf_opts[] = {
	{ .name = "genre",	.has_arg = true, .val = '1' },
	{ .name = "ttl",	.has_arg = true, .val = '2' },
	{ .name = "log",	.has_arg = true, .val = '3' },
	{ .name = NULL }
};

static void osf_parse_string(const unsigned char *s, struct ipt_osf_info *info)

{
	if (strlen(s) < MAXGENRELEN) 
		strcpy(info->genre, s);
	else 
		exit_error(PARAMETER_PROBLEM, "Genre string too long `%s' [%d], max=%d", 
				s, strlen(s), MAXGENRELEN);
}

static int osf_parse(int c, char **argv, int invert, unsigned int *flags,
const void *entry,
struct xt_entry_match **match)

{
	struct ipt_osf_info *info = (struct ipt_osf_info *)(*match)->data;
	
	switch(c) {
		case '1': /* --genre */
			if (*flags & IPT_OSF_GENRE)
				exit_error(PARAMETER_PROBLEM, "Can't specify multiple genre parameter");
			check_inverse(optarg, &invert, &optind, 0);
			osf_parse_string(argv[optind-1], info);
			if (invert)
				info->flags |= IPT_OSF_INVERT;
			info->len=strlen(info->genre);
			*flags |= IPT_OSF_GENRE;
			break;
		case '2': /* --ttl */
			if (*flags & IPT_OSF_TTL)
				exit_error(PARAMETER_PROBLEM, "Can't specify multiple ttl parameter");
			*flags |= IPT_OSF_TTL;
			info->flags |= IPT_OSF_TTL;
			if (!xtables_strtoui(argv[optind-1], NULL, &info->ttl, 0, 2))
				xtables_error(PARAMETER_PROBLEM, "TTL parameter is too big");
			break;
		case '3': /* --log */
			if (*flags & IPT_OSF_LOG)
				exit_error(PARAMETER_PROBLEM, "Can't specify multiple log parameter");
			*flags |= IPT_OSF_LOG;
			if (!xtables_strtoui(argv[optind-1], NULL, &info->loglevel, 0, 2))
				xtables_error(PARAMETER_PROBLEM, "Log level parameter is too big");
			info->flags |= IPT_OSF_LOG;
			break;
		default:
			return 0;
	}

	return 1;
}

static void osf_final_check(unsigned int flags)

{
	if (!flags)
		exit_error(PARAMETER_PROBLEM, "OS fingerprint match: You must specify `--genre'");
}

static void osf_print(const void *ip, const struct xt_entry_match *match, int numeric)

{
	const struct ipt_osf_info *info = (const struct ipt_osf_info*) match->data;

	printf("OS fingerprint match %s%s ", (info->flags & IPT_OSF_INVERT) ? "! " : "", info->genre);
}

static void osf_save(const void *ip, const struct xt_entry_match *match)

{
	const struct ipt_osf_info *info = (const struct ipt_osf_info*) match->data;

	printf("--genre %s%s ", (info->flags & IPT_OSF_INVERT) ? "! ": "", info->genre);
}
static struct xtables_match osf_match = {
	.name		= "osf",
	.version	= XTABLES_VERSION,
	.size		= XT_ALIGN(sizeof(struct ipt_osf_info)),
	.userspacesize	= XT_ALIGN(sizeof(struct ipt_osf_info)),
	.help		= osf_help,
	.parse		= osf_parse,
	.print		= osf_print,
	.final_check	= osf_final_check,
	.save		= osf_save,
	.extra_opts	= osf_opts,
	.family		= NFPROTO_IPV4
};

void _init(void)

{
	xtables_register_match(&osf_match);
}
#1 lore raw

net/netfilter/xt_osf.c line 170

Quoted 6 lines · Evgeniy Polyakov
net/netfilter/xt_osf.c new file +6 -0
+static void xt_osf_send_connector(const struct xt_osf_user_finger *f,
+				   const struct sk_buff *skb)
+{
+#if 1
+	return;
+#else

Please get rid of the connector remains.

The decision whether to still merge it in this window is up to Dave. I already have some late-comers queued up that I hope to still get in and I don't want to unnecessarily decrease my chances :)

#2 lore raw
Quoted 10 lines · Patrick McHardy

net/netfilter/xt_osf.c line 170

Quoted 6 lines · Evgeniy Polyakov
net/netfilter/xt_osf.c new file +6 -0
+static void xt_osf_send_connector(const struct xt_osf_user_finger *f,
+				   const struct sk_buff *skb)
+{
+#if 1
+	return;
+#else

Please get rid of the connector remains.

Quoted 3 lines

The decision whether to still merge it in this window is up to Dave. I already have some late-comers queued up that I hope to still get in and I don't want to unnecessarily decrease my chances :)

I left that chunk to the case when we will want to send notifications to the userspace, right now we do not , so it is commented. And yes, names were not changed :)

If Dave will refuse to pull it, please queue it into the netfilter tree for the next merge window update, since I will miss it almost for sure.

Signature · 1 line
	Evgeniy Polyakov
#3 lore raw
Quoted 10 lines · Evgeniy Polyakov
Quoted 9 lines · Patrick McHardy

net/netfilter/xt_osf.c line 170

Quoted 6 lines · Evgeniy Polyakov
net/netfilter/xt_osf.c new file +6 -0
+static void xt_osf_send_connector(const struct xt_osf_user_finger *f,
+				   const struct sk_buff *skb)
+{
+#if 1
+	return;
+#else

Please get rid of the connector remains.

Quoted 7 lines
Quoted 3 lines

The decision whether to still merge it in this window is up to Dave. I already have some late-comers queued up that I hope to still get in and I don't want to unnecessarily decrease my chances :)

I left that chunk to the case when we will want to send notifications to the userspace, right now we do not , so it is commented. And yes, names were not changed :)

nfnetlink also supports notifications. Please get rid of this, it should be no problem to resurrect the necessary parts later if this is desired.

Quoted 2 lines

If Dave will refuse to pull it, please queue it into the netfilter tree for the next merge window update, since I will miss it almost for sure.

Will do.

#4 lore raw
Quoted 3 lines · Patrick McHardy

nfnetlink also supports notifications. Please get rid of this, it should be no problem to resurrect the necessary parts later if this is desired.

Ok, patch below does not contain it.

include/linux/netfilter/nfnetlink.h +2 -1
index 7d8e045..71babbd 100644
@@ -46,7 +46,8 @@ struct nfgenmsg {
 #define NFNL_SUBSYS_CTNETLINK_EXP	2
 #define NFNL_SUBSYS_QUEUE		3
 #define NFNL_SUBSYS_ULOG		4
-#define NFNL_SUBSYS_COUNT		5
+#define NFNL_SUBSYS_OSF			5
+#define NFNL_SUBSYS_COUNT		6
 
 #ifdef __KERNEL__
 
include/linux/netfilter/xt_osf.h new file +119 -0

119 lines not on this page · raw message

net/netfilter/Kconfig +13 -0
index c2bac9c..1e74c97 100644
@@ -853,6 +853,19 @@ config NETFILTER_XT_MATCH_U32
 
 	  Details and examples are in the kernel module source.
 
+config NETFILTER_XT_MATCH_OSF
+	tristate '"osf" Passive OS fingerprint match'
+	depends on NETFILTER_ADVANCED
+	help
+	  This option selects the Passive OS Fingerprinting match module
+	  that allows to passively match the remote operating system by
+	  analyzing incoming TCP SYN packets.
+
+	  Rules and loading software can be downloaded from
+	  http://www.ioremap.net/projects/osf
+
+	  To compile it as a module, choose M here.  If unsure, say N.
+
 endif # NETFILTER_XTABLES
 
 endmenu
net/netfilter/Makefile +1 -0
index da3d909..96b7754 100644
@@ -73,6 +73,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_LIMIT) += xt_limit.o
 obj-$(CONFIG_NETFILTER_XT_MATCH_MAC) += xt_mac.o
 obj-$(CONFIG_NETFILTER_XT_MATCH_MARK) += xt_mark.o
 obj-$(CONFIG_NETFILTER_XT_MATCH_MULTIPORT) += xt_multiport.o
+obj-$(CONFIG_NETFILTER_XT_MATCH_OSF) += xt_osf.o
 obj-$(CONFIG_NETFILTER_XT_MATCH_OWNER) += xt_owner.o
 obj-$(CONFIG_NETFILTER_XT_MATCH_PHYSDEV) += xt_physdev.o
 obj-$(CONFIG_NETFILTER_XT_MATCH_PKTTYPE) += xt_pkttype.o
net/netfilter/xt_osf.c new file +469 -0

469 lines not on this page · raw message

Signature · 1 line
	Evgeniy Polyakov
#5 lore raw
Quoted 6 lines · Evgeniy Polyakov
Quoted 3 lines · Patrick McHardy

nfnetlink also supports notifications. Please get rid of this, it should be no problem to resurrect the necessary parts later if this is desired.

Ok, patch below does not contain it.

Thanks. I'll wait for Dave's decision before applying it.

#6 lore raw
Quoted 1 line · Patrick McHardy

Thanks. I'll wait for Dave's decision before applying it.

Looks like David did not pull it in, please queue OSF and its library into netfilter tree.
Thank you.

Signature · 1 line
	Evgeniy Polyakov
#7 lore raw

Hi.

Quoted 6 lines · Evgeniy Polyakov
Quoted 1 line · Patrick McHardy

Thanks. I'll wait for Dave's decision before applying it.

Looks like David did not pull it in, please queue OSF and its library into netfilter tree.
Thank you.

Just curious... Ping? :)

Signature · 1 line
	Evgeniy Polyakov