Target ipt_XOR
This patch adds a new target "XOR" wich can encrypt TCP and UDP traffic using a simple xor encryption. See netfilter-extensions.sgml.diff for usage.
Suggestions, comments and bug-fixes are welcome...
Regards,
Tim
patch-o-matic/extra/XOR.patch +124 -0
@@ -0,0 +1,124 @@ +diff -Nru linux-2.4.20-plain/include/linux/netfilter_ipv4/ipt_XOR.h linux-2.4.20-XOR/include/linux/netfilter_ipv4/ipt_XOR.h +--- linux-2.4.20-plain/include/linux/netfilter_ipv4/ipt_XOR.h 1970-01-01 01:00:00.000000000 +0100 ++++ linux-2.4.20-XOR/include/linux/netfilter_ipv4/ipt_XOR.h 2003-05-28 18:31:50.000000000 +0200 +@@ -0,0 +1,9 @@ ++#ifndef _IPT_XOR_H ++#define _IPT_XOR_H ++ ++struct ipt_XOR_info { ++ char key[30]; ++ u_int8_t block_size; ++}; ++ ++#endif /* _IPT_XOR_H */ +diff -Nru linux-2.4.20-plain/net/ipv4/netfilter/ipt_XOR.c linux-2.4.20-XOR/net/ipv4/netfilter/ipt_XOR.c +--- linux-2.4.20-plain/net/ipv4/netfilter/ipt_XOR.c 1970-01-01 01:00:00.000000000 +0100 ++++ linux-2.4.20-XOR/net/ipv4/netfilter/ipt_XOR.c 2003-05-28 18:53:22.000000000 +0200 +@@ -0,0 +1,107 @@ ++/* XOR target for IP tables ++ * (C) 2000 by Tim Vandermeersch <[email protected]> ++ * Based on ipt_TTL.c ++ * ++ * Version 1.0 ++ * ++ * This software is distributed under the terms of GNU GPL ++ */ ++ ++#include <linux/module.h> ++#include <linux/skbuff.h> ++#include <linux/ip.h> ++#include <linux/tcp.h> ++#include <linux/udp.h> ++ ++#include <linux/netfilter_ipv4/ip_tables.h> ++#include <linux/netfilter_ipv4/ipt_XOR.h> ++ ++MODULE_AUTHOR("Tim Vandermeersch <[email protected]>"); ++MODULE_DESCRIPTION("IP tables XOR module"); ++MODULE_LICENSE("GPL"); ++ ++static unsigned int ipt_xor_target(struct sk_buff **pskb, unsigned int hooknum, ++ const struct net_device *in, const struct net_device *out, ++ const void *targinfo, void *userinfo) ++{ ++ struct ipt_XOR_info *info = (void *) targinfo; ++ struct iphdr *iph = (*pskb)->nh.iph; ++ struct tcphdr *tcph; ++ struct udphdr *udph; ++ int i, j, k; ++ ++ if (iph->protocol == IPPROTO_TCP) { ++ tcph = (struct tcphdr *) ((*pskb)->data + iph->ihl*4); ++ for (i=0, j=0; i<(ntohs(iph->tot_len) - iph->ihl*4 - tcph->doff*4); ) { ++ for (k=0; k<=info->block_size; k++) { ++ (char) (*pskb)->data[ iph->ihl*4 + tcph->doff*4 + i ] ^= ++ info->key[j]; ++ i++; ++ } ++ j++; ++ if (info->key[j] == 0x00) ++ j = 0; ++ } ++ } else if (iph->protocol == IPPROTO_UDP) { ++ udph = (struct udphdr *) ((*pskb)->data + iph->ihl*4); ++ for (i=0, j=0; i<(ntohs(udph->len)-8); ) { ++ for (k=0; k<=info->block_size; k++) { ++ (char) (*pskb)->data[ iph->ihl*4 + sizeof(struct udphdr) + i ] ^= ++ info->key[j]; ++ i++; ++ } ++ j++; ++ if (info->key[j] == 0x00) ++ j = 0; ++ } ++ } ++ ++ return IPT_CONTINUE; ++} ++ ++static int ipt_xor_checkentry(const char *tablename, const struct ipt_entry *e, ++ void *targinfo, unsigned int targinfosize, ++ unsigned int hook_mask) ++{ ++ struct ipt_XOR_info *info = targinfo; ++ ++ if (targinfosize != IPT_ALIGN(sizeof(struct ipt_XOR_info))) { ++ printk(KERN_WARNING "XOR: targinfosize %u != %Zu\n", ++ targinfosize, IPT_ALIGN(sizeof(struct ipt_XOR_info))); ++ return 0; ++ } ++ ++ if (strcmp(tablename, "mangle")) { ++ printk(KERN_WARNING "XOR: can only be called from" ++ "\"mangle\" table, not \"%s\"\n", tablename); ++ return 0; ++ } ++ ++ if (!strcmp(info->key, "")) { ++ printk(KERN_WARNING "XOR: You must specify a key"); ++ return 0; ++ } ++ ++ if (info->block_size == 0) { ++ printk(KERN_WARNING "XOR: You must specify a block-size"); ++ return 0; ++ } ++ ++ return 1; ++} ++ ++static struct ipt_target ipt_XOR = { { NULL, NULL }, "XOR", ++ ipt_xor_target, ipt_xor_checkentry, NULL, THIS_MODULE }; ++ ++static int __init init(void) ++{ ++ return ipt_register_target(&ipt_XOR); ++} ++ ++static void __exit fini(void) ++{ ++ ipt_unregister_target(&ipt_XOR); ++} ++ ++module_init(init); ++module_exit(fini);
patch-o-matic/extra/XOR.patch.config.in +2 -0
@@ -0,0 +1,2 @@ + dep_tristate ' LOG target support' CONFIG_IP_NF_TARGET_LOG $CONFIG_IP_NF_IPTABLES + dep_tristate ' XOR target support' CONFIG_IP_NF_TARGET_XOR $CONFIG_IP_NF_IPTABLES
patch-o-matic/extra/XOR.patch.configure.help +8 -0
@@ -0,0 +1,8 @@ +CONFIG_IP_NF_TARGET_LOG +XOR target support +CONFIG_IP_NF_TARGET_XOR + This option adds a `XOR' target, which can encrypt TCP and + UDP traffic using a simple XOR encryption. + + If you want to compile it as a module, say M here and read + Documentation/modules.txt. If unsure, say `N'.
patch-o-matic/extra/XOR.patch.help +6 -0
@@ -0,0 +1,6 @@ +Author: Tim Vandermeersch <[email protected]> +Status: Experimental + +This adds CONFIG_IP_NF_TARGET_XOR option, which can +encrypt TCP and UDP traffic using a simple XOR +encryption
patch-o-matic/extra/XOR.patch.makefile +2 -0
@@ -0,0 +1,2 @@ +obj-$(CONFIG_IP_NF_TARGET_LOG) += ipt_LOG.o +obj-$(CONFIG_IP_NF_TARGET_XOR) += ipt_XOR.o
userspace/extensions/libipt_XOR.c +112 -0
112 lines not on this page · raw message
documentation/HOWTO/netfilter-extensions-HOWTO.sgml +38 -0
@@ -1274,6 +1274,44 @@ <url url="http://www.gnumonks.org/projects/ulogd" name="web page"> containing the proper documentation for ULOG, so there is no point for me to explain this here.. +<sect1>XOR patch +<p> +This patch by Tim Vandermeersch <[email protected]> adds a new target that +enables the user to encrypt TCP and UDP traffic using a simple xor encryption. + +<p> +For example, if you want to encrypt all TCP and UDP traffic between host A and host B, you can do as follows : + +<tscreen><verb> +(on host A, 1.2.3.4) +# iptables -t mangle -A OUTPUT -d 1.2.3.5 -j XOR --key somekey --block-size 3 +# iptables -t mangle -A INPUT -s 1.2.3.4 -j XOR --key somekey --block-size 3 + +# iptables -t mangle -L +Chain OUTPUT (policy ACCEPT) +target prot opt source destination +XOR all -- anywhere 1.2.3.5 key: somekey block-size: 3 +XOR all -- 1.2.3.5 anywhere key: somekey block-size: 3 + +(on host B, 1.2.3.5) +# iptables -t mangle -A OUTPUT -d 1.2.3.4 -j XOR --key somekey --block-size 3 +# iptables -t mangle -A INPUT -s 1.2.3.5 -j XOR --key somekey --block-size 3 + +# iptables -t mangle -L +Chain OUTPUT (policy ACCEPT) +target prot opt source destination +XOR all -- anywhere 1.2.3.4 key: somekey block-size: 3 +XOR all -- 1.2.3.4 anywhere key: somekey block-size: 3 +</verb></tscreen> + +<p> +Supported options for the TTL target are : + +<descrip> +<tag>--key string</> Set the encryption key +<tag>--block-size value</> Specify the block size +</descrip> + <sect>New connection tracking patches <p> In this sections, we will show the available connection tracking/nat patches.
Quoted 2 lines · Tim Vandermeersch
This patch adds a new target "XOR" wich can encrypt TCP and UDP traffic using a simple xor encryption. See netfilter-extensions.sgml.diff for usage.
thanks, patch applied to CVS.
Quoted 2 lines
Regards,
Tim
Signature · 5 lines
- Harald Welte <[email protected]> http://www.netfilter.org/ ============================================================================ "Fragmentation is like classful addressing -- an interesting early architectural error that shows how much experimentation was going on while IP was being designed." -- Paul Vixie