Skip to contentSkip to conversation

scrubbing support in Netfilter

PATCH Nicolas Bareil 1 participant 1 message May 27, 2008

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

Hi!

I developped a Netfilter module which performs packet normalization, the "scrubbing" feature of OpenBSD[1]. Normalized trafic offers the following possibilities :

* Just before an IDS, we can make its works easier by feeding it normalized trafic : there is no TTL trick used to escape detection anymore.

* Minimize OS fingerprinting, Even through the "Application Layer" will give hints to an attacker (User-Agent in HTTP header or mail enveloppe), not every protocol has this "flaw" : DNS, IKE, SMTP, etc. Furthermore, there is not only the fingerprinting issue : an administrator can wish to hide the fact he is running a farm of DNATed
servers.

* Misshapen trafic can be discarded, the time of "Ping of death" is not over! Last year, there were (simple) major vulnerabilities in missshapen packets : the IPv6 routing header issues, old school flaws in pre-beta of Microsoft Windows Vista.

* Protection, or interface with embedded equipment : some legacy equipment in end of life could still have TCP ISN vulnerability without any update possible.

Performing normalization should be harmless as long as we stick to two rules :
* Stay RFC compliant
* Keep in mind the consequences of a change : we can lower a TTL but never rise it!

The current patch achieves the following transformations :

* IPv4
- Random IP ID
- Zeroify ToS
- TTL normalization

* TCP
- Random TCP Sequence
- TCP Options
- Random Timestamp
- Sanity checks on MSS
- TTL seal : The TTL cannot be modified within a TCP connection It means that you must make sure there is only one only route to the destination (there cannot be two paths with different distances). This feature is disabled by default because of this issue.

There isn't any IPv6 transformations yet but there should be more soon (Routing Headers issues).

The following patch is "self-contained" : only nf_conntrack_proto_tcp.c is modified, the other files are new. The iptables patch is following this email.

This work has been done at EADS Innovation Works.

include/linux/netfilter/nf_conntrack_common.h +24 -0
index bad1eb7..4a03f56 100644
@@ -175,4 +175,28 @@ extern void need_conntrack(void);
 
 #endif /* __KERNEL__ */
 
+enum nf_scrub_transformations {
+	/* scrub tcp sequence adjusting */
+	SCRUB_TCP_SEQ_ADJUST_BIT = 1,
+	SCRUB_TCP_SEQ_ADJUST = (1 << SCRUB_TCP_SEQ_ADJUST_BIT),
+
+	SCRUB_IP_RAND_ID_ADJUST_BIT = 2,
+	SCRUB_IP_RAND_ID_ADJUST = (1 << SCRUB_IP_RAND_ID_ADJUST_BIT),
+
+	SCRUB_IP_TTL_ADJUST_BIT = 3,
+	SCRUB_IP_TTL_ADJUST = (1 << SCRUB_IP_TTL_ADJUST_BIT),
+
+	SCRUB_IP_TOS_ADJUST_BIT = 4,
+	SCRUB_IP_TOS_ADJUST = (1 << SCRUB_IP_TOS_ADJUST_BIT),
+
+	SCRUB_TCP_OPT_MSS_ADJUST_BIT = 5,
+	SCRUB_TCP_OPT_MSS_ADJUST = (1 << SCRUB_TCP_OPT_MSS_ADJUST_BIT),
+
+	SCRUB_TCP_OPT_TIMESTAMP_ADJUST_BIT = 6,
+	SCRUB_TCP_OPT_TIMESTAMP_ADJUST = (1 << SCRUB_TCP_OPT_TIMESTAMP_ADJUST_BIT),
+
+	SCRUB_IP_SEALED_TTL_ADJUST_BIT = 7,
+	SCRUB_IP_SEALED_TTL_ADJUST = (1 << SCRUB_IP_SEALED_TTL_ADJUST_BIT),
+};
+
 #endif /* _NF_CONNTRACK_COMMON_H */
include/linux/netfilter_ipv4/ipt_SCRUB.h new file +19 -0
new file mode 100644
index 0000000..31492cf
@@ -0,0 +1,19 @@
+/*
+ * (C) 2007 by Nicolas Bareil <[email protected]>
+ */
+
+#ifndef _IPT_SCRUB_H
+#define _IPT_SCRUB_H
+
+static unsigned int
+ipt_scrub_target(struct sk_buff *skb,
+		 const struct net_device *in, const struct net_device *out,
+		 unsigned int hooknum, const struct xt_target *target,
+		 const void *targinfo);
+
+static bool ipt_scrub_checkentry(const char *tablename,
+				const void *e,
+				const struct xt_target *target,
+				void *targinfo,
+				unsigned int hook_mask);
+#endif
include/linux/netfilter_ipv4/nf_scrub.h new file +19 -0
new file mode 100644
index 0000000..14de9b2
@@ -0,0 +1,19 @@
+#ifndef _NF_SCRUB_V4_H
+#define _NF_SCRUB_V4_H
+
+#include <net/netfilter/nf_conntrack_extend.h>
+
+extern bool nf_scrub_ipv4_adjust(struct sk_buff *skb
+				 , struct nf_conn *ct
+				 , enum ip_conntrack_info ctinfo);
+
+extern void nf_scrub_ip_tos_adjust(struct iphdr *iph, struct nf_conn *ct);
+extern bool nf_scrub_ip_rand_id_adjust(struct iphdr *iph, struct nf_conn *ct);
+extern bool nf_scrub_ip_sealed_ttl_adjust(struct iphdr *iph, struct nf_conn *ct);
+extern bool nf_scrub_ip_ttl_adjust(struct iphdr *iph, struct nf_conn *ct);
+
+extern bool nf_scrub_ipv4_setup(const struct sk_buff *skb
+				, struct nf_conn *ct
+				, enum ip_conntrack_info ctinfo
+				, struct ipt_scrub_info *info);
+#endif
include/linux/netfilter_ipv6/nf_scrub.h new file +14 -0
new file mode 100644
index 0000000..a473180
@@ -0,0 +1,14 @@
+#ifndef _NF_SCRUB_V6_H
+#define _NF_SCRUB_V6_H
+
+#include <net/netfilter/nf_conntrack_extend.h>
+
+extern bool nf_scrub_ipv6_adjust(struct sk_buff *skb
+				 , struct nf_conn *ct
+				 , enum ip_conntrack_info ctinfo);
+
+extern bool nf_scrub_ipv6_setup(const struct sk_buff *skb
+				, struct nf_conn *ct
+				, enum ip_conntrack_info ctinfo
+				, struct ipt_scrub_info *info);
+#endif
include/net/netfilter/nf_conntrack.h +4 -0
index 2dbd6c0..7481f54 100644
@@ -124,6 +124,10 @@ struct nf_conn
 	u_int32_t secmark;
 #endif
 
+#ifdef CONFIG_NF_SCRUB_NEEDED
+	u_int32_t scrub;
+#endif
+
 	/* Storage reserved for other modules: */
 	union nf_conntrack_proto proto;
 
include/net/netfilter/nf_conntrack_extend.h +2 -0
index f736e84..3eb03af 100644
@@ -7,11 +7,13 @@ enum nf_ct_ext_id
 {
 	NF_CT_EXT_HELPER,
 	NF_CT_EXT_NAT,
+	NF_CT_EXT_SCRUB,
 	NF_CT_EXT_NUM,
 };
 
 #define NF_CT_EXT_HELPER_TYPE struct nf_conn_help
 #define NF_CT_EXT_NAT_TYPE struct nf_conn_nat
+#define NF_CT_EXT_SCRUB_TYPE struct nf_conn_scrub
 
 /* Extensions: optional stuff which isn't permanently in struct. */
 struct nf_ct_ext {
include/net/netfilter/nf_scrub.h new file +53 -0

53 lines not on this page · raw message

include/net/netfilter/nf_scrub_tcp.h new file +56 -0

56 lines not on this page · raw message

net/ipv4/netfilter/Makefile +4 -0
index d9b92fb..cd2a1f2 100644
@@ -34,6 +34,10 @@ obj-$(CONFIG_NF_NAT_PROTO_GRE) += nf_nat_proto_gre.o
 obj-$(CONFIG_NF_NAT_PROTO_UDPLITE) += nf_nat_proto_udplite.o
 obj-$(CONFIG_NF_NAT_PROTO_SCTP) += nf_nat_proto_sctp.o
 
+# SCRUB
+obj-$(CONFIG_NF_SCRUB) += nf_scrub_ipv4.o
+obj-$(CONFIG_IP_NF_TARGET_SCRUB) += ipt_SCRUB.o
+
 # generic IP tables 
 obj-$(CONFIG_IP_NF_IPTABLES) += ip_tables.o
 
net/ipv4/netfilter/ipt_SCRUB.c new file +91 -0

91 lines not on this page · raw message

net/ipv4/netfilter/nf_scrub_ipv4.c new file +244 -0

244 lines not on this page · raw message

net/ipv6/netfilter/Makefile +4 -0
index fbf2c14..278a49b 100644
@@ -29,3 +29,7 @@ obj-$(CONFIG_IP6_NF_MATCH_RT) += ip6t_rt.o
 obj-$(CONFIG_IP6_NF_TARGET_HL) += ip6t_HL.o
 obj-$(CONFIG_IP6_NF_TARGET_LOG) += ip6t_LOG.o
 obj-$(CONFIG_IP6_NF_TARGET_REJECT) += ip6t_REJECT.o
+
+# SCRUB
+obj-$(CONFIG_NF_SCRUB) += nf_scrub_ipv6.o
+obj-$(CONFIG_NF_SCRUB) += ip6t_SCRUB.o
net/ipv6/netfilter/ip6t_SCRUB.c new file +91 -0

91 lines not on this page · raw message

net/ipv6/netfilter/nf_scrub_ipv6.c new file +88 -0

88 lines not on this page · raw message

net/netfilter/Kconfig +18 -0
index aa8d80c..4b7d205 100644
@@ -828,5 +828,23 @@ config NETFILTER_XT_MATCH_HASHLIMIT
 	  destination address' or `500pps from any given source address'
 	  with a single rule.
 
+config NF_SCRUB
+	tristate "Packet normalization"
+	depends on NF_CONNTRACK
+	default n
+	help
+	   Packet's field are normalized by Netfilter.
+
+config NF_SCRUB_NEEDED
+	bool
+	depends on NF_SCRUB
+	default y
+
+config IP_NF_TARGET_SCRUB
+       tristate "SCRUB target"
+       depends on NF_SCRUB && IP_NF_IPTABLES && NF_CONNTRACK
+       help
+          Scrubbing is the process of packet normalization.
+
 endmenu
 
net/netfilter/Makefile +4 -0
index 5c4b183..3d025f8 100644
@@ -83,3 +83,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_STRING) += xt_string.o
 obj-$(CONFIG_NETFILTER_XT_MATCH_TCPMSS) += xt_tcpmss.o
 obj-$(CONFIG_NETFILTER_XT_MATCH_TIME) += xt_time.o
 obj-$(CONFIG_NETFILTER_XT_MATCH_U32) += xt_u32.o
+
+# SCRUB
+obj-$(CONFIG_NF_SCRUB) += nf_scrub_core.o
+obj-$(CONFIG_NF_SCRUB) += nf_scrub_core_tcp.o
net/netfilter/nf_conntrack_proto_tcp.c +29 -0
index ba94004..3c000b9 100644
@@ -26,6 +26,10 @@
 #include <net/netfilter/nf_conntrack_ecache.h>
 #include <net/netfilter/nf_log.h>
 
+#ifdef CONFIG_NF_SCRUB_NEEDED
+#   include <net/netfilter/nf_scrub_tcp.h>
+#endif
+
 /* Protects ct->proto.tcp */
 static DEFINE_RWLOCK(tcp_lock);
 
@@ -819,6 +823,20 @@ static int tcp_packet(struct nf_conn *ct,
 	new_state = tcp_conntracks[dir][index][old_state];
 	tuple = &ct->tuplehash[dir].tuple;
 
+#ifdef CONFIG_NF_SCRUB_NEEDED
+	/*
+	 * we don't care if the scrubbing code is compiled but the
+	 * module is not loaded because the test_bit() test will
+	 * fail.
+	 */
+
+	if (test_bit(SCRUB_TCP_SEQ_ADJUST_BIT, &ct->scrub)
+	    && dir == IP_CT_DIR_ORIGINAL) {
+		if (!nf_scrub_tcp_seq_adjust((struct tcphdr *)th, ct, ctinfo))
+			return -NF_ACCEPT;
+	}
+#endif
+
 	switch (new_state) {
 	case TCP_CONNTRACK_SYN_SENT:
 		if (old_state < TCP_CONNTRACK_TIME_WAIT)
@@ -930,6 +948,17 @@ static int tcp_packet(struct nf_conn *ct,
 		write_unlock_bh(&tcp_lock);
 		return -NF_ACCEPT;
 	}
+#ifdef CONFIG_NF_SCRUB_NEEDED
+	if (test_bit(SCRUB_TCP_SEQ_ADJUST_BIT, &ct->scrub)
+	    && dir == IP_CT_DIR_REPLY) {
+		if (!nf_scrub_tcp_ack_adjust((struct tcphdr *)th, ct, ctinfo))
+			return -NF_ACCEPT;
+
+		if (!nf_scrub_tcp_sack_adjust((struct tcphdr *)th, ct, ctinfo))
+			return -NF_ACCEPT;
+	}
+#endif
+
      in_window:
 	/* From now on we have got in-window packets */
 	ct->proto.tcp.last_index = index;
net/netfilter/nf_scrub_core.c new file +216 -0

216 lines not on this page · raw message

net/netfilter/nf_scrub_core_tcp.c new file +358 -0

358 lines not on this page · raw message