mirror of
git://git.code.sf.net/p/xtables-addons/xtables-addons
synced 2025-09-21 03:54:59 +02:00
Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
dec7d7fc4d | ||
![]() |
5c615a3c73 | ||
![]() |
0c1375414d | ||
![]() |
7e5a8b0501 | ||
![]() |
cb8050172a | ||
![]() |
5be4ac8b2b | ||
![]() |
8d5b7c5b7d | ||
![]() |
f9aca7621c | ||
![]() |
af940bcbae | ||
![]() |
06b82c649d | ||
![]() |
e5093b61cd | ||
![]() |
7cd01e0b14 | ||
![]() |
4eb97c7a01 | ||
![]() |
48fbc6783e | ||
![]() |
a9f383daf8 | ||
![]() |
cbe58f55d0 | ||
![]() |
d11218815f | ||
![]() |
911d3d146a |
@@ -1,4 +1,4 @@
|
|||||||
AC_INIT([xtables-addons], [1.43])
|
AC_INIT([xtables-addons], [1.44])
|
||||||
AC_CONFIG_AUX_DIR([build-aux])
|
AC_CONFIG_AUX_DIR([build-aux])
|
||||||
AC_CONFIG_HEADERS([config.h])
|
AC_CONFIG_HEADERS([config.h])
|
||||||
AC_CONFIG_MACRO_DIR([m4])
|
AC_CONFIG_MACRO_DIR([m4])
|
||||||
|
@@ -3,6 +3,15 @@ HEAD
|
|||||||
====
|
====
|
||||||
|
|
||||||
|
|
||||||
|
v1.44 (2012-07-15)
|
||||||
|
==================
|
||||||
|
Fixes:
|
||||||
|
- SYSRQ: fix double target initialization at module load
|
||||||
|
- build: do not attempt to build IPv6 parts if CONFIG_IP6_NF_IPTABLES=n
|
||||||
|
Enhancements:
|
||||||
|
- TARPIT gained IPv6 support
|
||||||
|
|
||||||
|
|
||||||
v1.43 (2012-06-30)
|
v1.43 (2012-06-30)
|
||||||
==================
|
==================
|
||||||
Fixes:
|
Fixes:
|
||||||
|
@@ -17,7 +17,7 @@ endif
|
|||||||
obj-${build_IPMARK} += xt_IPMARK.o
|
obj-${build_IPMARK} += xt_IPMARK.o
|
||||||
obj-${build_LOGMARK} += xt_LOGMARK.o
|
obj-${build_LOGMARK} += xt_LOGMARK.o
|
||||||
obj-${build_RAWNAT} += xt_RAWNAT.o iptable_rawpost.o
|
obj-${build_RAWNAT} += xt_RAWNAT.o iptable_rawpost.o
|
||||||
ifneq (${CONFIG_IPV6},)
|
ifneq (${CONFIG_IP6_NF_IPTABLES},)
|
||||||
obj-${build_RAWNAT} += ip6table_rawpost.o
|
obj-${build_RAWNAT} += ip6table_rawpost.o
|
||||||
endif
|
endif
|
||||||
obj-${build_SYSRQ} += xt_SYSRQ.o
|
obj-${build_SYSRQ} += xt_SYSRQ.o
|
||||||
|
@@ -19,12 +19,16 @@
|
|||||||
#include <linux/netfilter_ipv6/ip6_tables.h>
|
#include <linux/netfilter_ipv6/ip6_tables.h>
|
||||||
#include <linux/netfilter_arp.h>
|
#include <linux/netfilter_arp.h>
|
||||||
#include <net/ip.h>
|
#include <net/ip.h>
|
||||||
|
#include <net/ipv6.h>
|
||||||
#include <net/route.h>
|
#include <net/route.h>
|
||||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0)
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0)
|
||||||
# include <linux/export.h>
|
# include <linux/export.h>
|
||||||
#endif
|
#endif
|
||||||
#include "compat_skbuff.h"
|
#include "compat_skbuff.h"
|
||||||
#include "compat_xtnu.h"
|
#include "compat_xtnu.h"
|
||||||
|
#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE)
|
||||||
|
# define WITH_IPV6 1
|
||||||
|
#endif
|
||||||
|
|
||||||
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 22)
|
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 22)
|
||||||
static int xtnu_match_run(const struct sk_buff *skb,
|
static int xtnu_match_run(const struct sk_buff *skb,
|
||||||
@@ -613,7 +617,15 @@ void *HX_memmem(const void *space, size_t spacesize,
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(HX_memmem);
|
EXPORT_SYMBOL_GPL(HX_memmem);
|
||||||
|
|
||||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 5, 0)
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0) && defined(WITH_IPV6)
|
||||||
|
int xtnu_ipv6_skip_exthdr(const struct sk_buff *skb, int start,
|
||||||
|
uint8_t *nexthdrp, __be16 *fragoffp)
|
||||||
|
{
|
||||||
|
return ipv6_skip_exthdr(skb, start, nexthdrp);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 5, 0) && defined(WITH_IPV6)
|
||||||
int xtnu_ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
|
int xtnu_ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
|
||||||
int target, unsigned short *fragoff, int *fragflg)
|
int target, unsigned short *fragoff, int *fragflg)
|
||||||
{
|
{
|
||||||
|
@@ -96,6 +96,7 @@
|
|||||||
# define nf_nat_ipv4_multi_range_compat nf_nat_multi_range_compat
|
# define nf_nat_ipv4_multi_range_compat nf_nat_multi_range_compat
|
||||||
# define nf_nat_ipv4_range nf_nat_range
|
# define nf_nat_ipv4_range nf_nat_range
|
||||||
# define NF_NAT_RANGE_MAP_IPS IP_NAT_RANGE_MAP_IPS
|
# define NF_NAT_RANGE_MAP_IPS IP_NAT_RANGE_MAP_IPS
|
||||||
|
# define ipv6_skip_exthdr xtnu_ipv6_skip_exthdr
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(NIP6) && !defined(NIP6_FMT)
|
#if !defined(NIP6) && !defined(NIP6_FMT)
|
||||||
|
@@ -162,6 +162,8 @@ extern void xtnu_csum_replace4(__u16 __bitwise *, __be32, __be32);
|
|||||||
extern void xtnu_proto_csum_replace4(__u16 __bitwise *, struct sk_buff *,
|
extern void xtnu_proto_csum_replace4(__u16 __bitwise *, struct sk_buff *,
|
||||||
__be32, __be32, bool);
|
__be32, __be32, bool);
|
||||||
extern int xtnu_skb_linearize(struct sk_buff *);
|
extern int xtnu_skb_linearize(struct sk_buff *);
|
||||||
|
extern int xtnu_ipv6_skip_exthdr(const struct sk_buff *, int,
|
||||||
|
uint8_t *, __be16 *);
|
||||||
extern int xtnu_ipv6_find_hdr(const struct sk_buff *, unsigned int *,
|
extern int xtnu_ipv6_find_hdr(const struct sk_buff *, unsigned int *,
|
||||||
int, unsigned short *, int *);
|
int, unsigned short *, int *);
|
||||||
|
|
||||||
|
@@ -106,7 +106,7 @@ static void tarpit_tg_save(const void *ip,
|
|||||||
static struct xtables_target tarpit_tg_reg = {
|
static struct xtables_target tarpit_tg_reg = {
|
||||||
.version = XTABLES_VERSION,
|
.version = XTABLES_VERSION,
|
||||||
.name = "TARPIT",
|
.name = "TARPIT",
|
||||||
.family = NFPROTO_IPV4,
|
.family = NFPROTO_UNSPEC,
|
||||||
.size = XT_ALIGN(sizeof(struct xt_tarpit_tginfo)),
|
.size = XT_ALIGN(sizeof(struct xt_tarpit_tginfo)),
|
||||||
.userspacesize = XT_ALIGN(sizeof(struct xt_tarpit_tginfo)),
|
.userspacesize = XT_ALIGN(sizeof(struct xt_tarpit_tginfo)),
|
||||||
.help = tarpit_tg_help,
|
.help = tarpit_tg_help,
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
# include <linux/netfilter_bridge.h>
|
# include <linux/netfilter_bridge.h>
|
||||||
#endif
|
#endif
|
||||||
#include <net/ip.h>
|
#include <net/ip.h>
|
||||||
|
#include <net/ip6_checksum.h>
|
||||||
#include <net/ip6_route.h>
|
#include <net/ip6_route.h>
|
||||||
#include <net/route.h>
|
#include <net/route.h>
|
||||||
#include "compat_xtables.h"
|
#include "compat_xtables.h"
|
||||||
|
@@ -22,8 +22,7 @@
|
|||||||
#include <net/ipv6.h>
|
#include <net/ipv6.h>
|
||||||
#include "compat_xtables.h"
|
#include "compat_xtables.h"
|
||||||
#include "xt_RAWNAT.h"
|
#include "xt_RAWNAT.h"
|
||||||
|
#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE)
|
||||||
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
|
|
||||||
# define WITH_IPV6 1
|
# define WITH_IPV6 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -30,7 +30,7 @@
|
|||||||
(defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE))
|
(defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE))
|
||||||
# define WITH_CRYPTO 1
|
# define WITH_CRYPTO 1
|
||||||
#endif
|
#endif
|
||||||
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
|
#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE)
|
||||||
# define WITH_IPV6 1
|
# define WITH_IPV6 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -359,10 +359,7 @@ static int __init sysrq_crypto_init(void)
|
|||||||
goto fail;
|
goto fail;
|
||||||
do_gettimeofday(&now);
|
do_gettimeofday(&now);
|
||||||
sysrq_seqno = now.tv_sec;
|
sysrq_seqno = now.tv_sec;
|
||||||
ret = xt_register_targets(sysrq_tg_reg, ARRAY_SIZE(sysrq_tg_reg));
|
return 0;
|
||||||
if (ret < 0)
|
|
||||||
goto fail;
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
sysrq_crypto_exit();
|
sysrq_crypto_exit();
|
||||||
|
@@ -42,19 +42,139 @@
|
|||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/skbuff.h>
|
#include <linux/skbuff.h>
|
||||||
#include <linux/version.h>
|
#include <linux/version.h>
|
||||||
|
#include <linux/netfilter_ipv6.h>
|
||||||
#include <linux/netfilter/x_tables.h>
|
#include <linux/netfilter/x_tables.h>
|
||||||
#ifdef CONFIG_BRIDGE_NETFILTER
|
#ifdef CONFIG_BRIDGE_NETFILTER
|
||||||
# include <linux/netfilter_bridge.h>
|
# include <linux/netfilter_bridge.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <net/addrconf.h>
|
||||||
|
#include <net/ip6_checksum.h>
|
||||||
|
#include <net/ip6_route.h>
|
||||||
|
#include <net/ipv6.h>
|
||||||
#include <net/route.h>
|
#include <net/route.h>
|
||||||
#include <net/tcp.h>
|
#include <net/tcp.h>
|
||||||
#include "compat_xtables.h"
|
#include "compat_xtables.h"
|
||||||
#include "xt_TARPIT.h"
|
#include "xt_TARPIT.h"
|
||||||
|
#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE)
|
||||||
|
# define WITH_IPV6 1
|
||||||
|
#endif
|
||||||
|
|
||||||
static void tarpit_tcp(struct sk_buff *oldskb, unsigned int hook,
|
static bool xttarpit_tarpit(struct tcphdr *tcph, const struct tcphdr *oth)
|
||||||
|
{
|
||||||
|
/* No replies for RST, FIN or !SYN,!ACK */
|
||||||
|
if (oth->rst || oth->fin || (!oth->syn && !oth->ack))
|
||||||
|
return false;
|
||||||
|
tcph->seq = oth->ack ? oth->ack_seq : 0;
|
||||||
|
|
||||||
|
/* Our SYN-ACKs must have a >0 window */
|
||||||
|
tcph->window = (oth->syn && !oth->ack) ? htons(5) : 0;
|
||||||
|
if (oth->syn && oth->ack) {
|
||||||
|
tcph->rst = true;
|
||||||
|
tcph->ack_seq = false;
|
||||||
|
} else {
|
||||||
|
tcph->syn = oth->syn;
|
||||||
|
tcph->ack = true;
|
||||||
|
tcph->ack_seq = htonl(ntohl(oth->seq) + oth->syn);
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
|
/* Rate-limit replies to !SYN,ACKs */
|
||||||
|
if (!oth->syn && oth->ack)
|
||||||
|
if (!xrlim_allow(rt_dst(ort), HZ))
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool xttarpit_honeypot(struct tcphdr *tcph, const struct tcphdr *oth,
|
||||||
|
uint16_t payload)
|
||||||
|
{
|
||||||
|
/* Do not answer any resets regardless of combination */
|
||||||
|
if (oth->rst || oth->seq == 0xDEADBEEF)
|
||||||
|
return false;
|
||||||
|
/* Send a reset to scanners. They like that. */
|
||||||
|
if (oth->syn && oth->ack) {
|
||||||
|
tcph->window = 0;
|
||||||
|
tcph->ack = false;
|
||||||
|
tcph->psh = true;
|
||||||
|
tcph->ack_seq = 0xdeadbeef; /* see if they ack it */
|
||||||
|
tcph->seq = oth->ack_seq;
|
||||||
|
tcph->rst = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* SYN > SYN-ACK */
|
||||||
|
if (oth->syn && !oth->ack) {
|
||||||
|
tcph->syn = true;
|
||||||
|
tcph->ack = true;
|
||||||
|
tcph->window = oth->window &
|
||||||
|
((net_random() & 0x1f) - 0xf);
|
||||||
|
tcph->seq = htonl(net_random() & ~oth->seq);
|
||||||
|
tcph->ack_seq = htonl(ntohl(oth->seq) + oth->syn);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ACK > ACK */
|
||||||
|
if (oth->ack && (!(oth->fin || oth->syn))) {
|
||||||
|
tcph->syn = false;
|
||||||
|
tcph->ack = true;
|
||||||
|
tcph->window = oth->window &
|
||||||
|
((net_random() & 0x1f) - 0xf);
|
||||||
|
tcph->ack_seq = payload > 100 ?
|
||||||
|
htonl(ntohl(oth->seq) + payload) :
|
||||||
|
oth->seq;
|
||||||
|
tcph->seq = oth->ack_seq;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* FIN > RST.
|
||||||
|
* We cannot terminate gracefully so just be abrupt.
|
||||||
|
*/
|
||||||
|
if (oth->fin) {
|
||||||
|
tcph->window = 0;
|
||||||
|
tcph->seq = oth->ack_seq;
|
||||||
|
tcph->ack_seq = oth->ack_seq;
|
||||||
|
tcph->fin = false;
|
||||||
|
tcph->ack = false;
|
||||||
|
tcph->rst = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void xttarpit_reset(struct tcphdr *tcph, const struct tcphdr *oth)
|
||||||
|
{
|
||||||
|
tcph->window = 0;
|
||||||
|
tcph->ack = false;
|
||||||
|
tcph->syn = false;
|
||||||
|
tcph->rst = true;
|
||||||
|
tcph->seq = oth->ack_seq;
|
||||||
|
tcph->ack_seq = oth->seq;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool tarpit_generic(struct tcphdr *tcph, const struct tcphdr *oth,
|
||||||
|
uint16_t payload, unsigned int mode)
|
||||||
|
{
|
||||||
|
switch(mode) {
|
||||||
|
case XTTARPIT_TARPIT:
|
||||||
|
if (!xttarpit_tarpit(tcph, oth))
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
case XTTARPIT_HONEYPOT:
|
||||||
|
if (!xttarpit_honeypot(tcph, oth, payload))
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
case XTTARPIT_RESET:
|
||||||
|
xttarpit_reset(tcph, oth);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tarpit_tcp4(struct sk_buff *oldskb, unsigned int hook,
|
||||||
unsigned int mode)
|
unsigned int mode)
|
||||||
{
|
{
|
||||||
struct tcphdr _otcph, *oth, *tcph;
|
struct tcphdr _otcph, *tcph;
|
||||||
|
const struct tcphdr *oth;
|
||||||
unsigned int addr_type = RTN_UNSPEC;
|
unsigned int addr_type = RTN_UNSPEC;
|
||||||
struct sk_buff *nskb;
|
struct sk_buff *nskb;
|
||||||
const struct iphdr *oldhdr;
|
const struct iphdr *oldhdr;
|
||||||
@@ -116,84 +236,8 @@ static void tarpit_tcp(struct sk_buff *oldskb, unsigned int hook,
|
|||||||
/* Reset flags */
|
/* Reset flags */
|
||||||
((u_int8_t *)tcph)[13] = 0;
|
((u_int8_t *)tcph)[13] = 0;
|
||||||
|
|
||||||
if (mode == XTTARPIT_TARPIT) {
|
if (!tarpit_generic(tcph, oth, payload, mode))
|
||||||
/* No replies for RST, FIN or !SYN,!ACK */
|
return;
|
||||||
if (oth->rst || oth->fin || (!oth->syn && !oth->ack))
|
|
||||||
return;
|
|
||||||
tcph->seq = oth->ack ? oth->ack_seq : 0;
|
|
||||||
|
|
||||||
/* Our SYN-ACKs must have a >0 window */
|
|
||||||
tcph->window = (oth->syn && !oth->ack) ? htons(5) : 0;
|
|
||||||
if (oth->syn && oth->ack) {
|
|
||||||
tcph->rst = true;
|
|
||||||
tcph->ack_seq = false;
|
|
||||||
} else {
|
|
||||||
tcph->syn = oth->syn;
|
|
||||||
tcph->ack = true;
|
|
||||||
tcph->ack_seq = htonl(ntohl(oth->seq) + oth->syn);
|
|
||||||
}
|
|
||||||
#if 0
|
|
||||||
/* Rate-limit replies to !SYN,ACKs */
|
|
||||||
if (!oth->syn && oth->ack)
|
|
||||||
if (!xrlim_allow(rt_dst(ort), HZ))
|
|
||||||
return;
|
|
||||||
#endif
|
|
||||||
} else if (mode == XTTARPIT_HONEYPOT) {
|
|
||||||
/* Do not answer any resets regardless of combination */
|
|
||||||
if (oth->rst || oth->seq == 0xDEADBEEF)
|
|
||||||
return;
|
|
||||||
/* Send a reset to scanners. They like that. */
|
|
||||||
if (oth->syn && oth->ack) {
|
|
||||||
tcph->window = 0;
|
|
||||||
tcph->ack = false;
|
|
||||||
tcph->psh = true;
|
|
||||||
tcph->ack_seq = 0xdeadbeef; /* see if they ack it */
|
|
||||||
tcph->seq = oth->ack_seq;
|
|
||||||
tcph->rst = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* SYN > SYN-ACK */
|
|
||||||
if (oth->syn && !oth->ack) {
|
|
||||||
tcph->syn = true;
|
|
||||||
tcph->ack = true;
|
|
||||||
tcph->window = oth->window &
|
|
||||||
((net_random() & 0x1f) - 0xf);
|
|
||||||
tcph->seq = htonl(net_random() & ~oth->seq);
|
|
||||||
tcph->ack_seq = htonl(ntohl(oth->seq) + oth->syn);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ACK > ACK */
|
|
||||||
if (oth->ack && (!(oth->fin || oth->syn))) {
|
|
||||||
tcph->syn = false;
|
|
||||||
tcph->ack = true;
|
|
||||||
tcph->window = oth->window &
|
|
||||||
((net_random() & 0x1f) - 0xf);
|
|
||||||
tcph->ack_seq = payload > 100 ?
|
|
||||||
htonl(ntohl(oth->seq) + payload) :
|
|
||||||
oth->seq;
|
|
||||||
tcph->seq = oth->ack_seq;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* FIN > RST.
|
|
||||||
* We cannot terminate gracefully so just be abrupt.
|
|
||||||
*/
|
|
||||||
if (oth->fin) {
|
|
||||||
tcph->window = 0;
|
|
||||||
tcph->seq = oth->ack_seq;
|
|
||||||
tcph->ack_seq = oth->ack_seq;
|
|
||||||
tcph->fin = false;
|
|
||||||
tcph->ack = false;
|
|
||||||
tcph->rst = true;
|
|
||||||
}
|
|
||||||
} else if (mode == XTTARPIT_RESET) {
|
|
||||||
tcph->window = 0;
|
|
||||||
tcph->ack = false;
|
|
||||||
tcph->syn = false;
|
|
||||||
tcph->rst = true;
|
|
||||||
tcph->seq = oth->ack_seq;
|
|
||||||
tcph->ack_seq = oth->seq;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Adjust TCP checksum */
|
/* Adjust TCP checksum */
|
||||||
tcph->check = 0;
|
tcph->check = 0;
|
||||||
@@ -257,8 +301,133 @@ static void tarpit_tcp(struct sk_buff *oldskb, unsigned int hook,
|
|||||||
kfree_skb(nskb);
|
kfree_skb(nskb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WITH_IPV6
|
||||||
|
static void tarpit_tcp6(struct sk_buff *oldskb, unsigned int hook,
|
||||||
|
unsigned int mode)
|
||||||
|
{
|
||||||
|
struct sk_buff *nskb;
|
||||||
|
struct tcphdr *tcph, oth;
|
||||||
|
unsigned int otcplen;
|
||||||
|
int tcphoff;
|
||||||
|
const struct ipv6hdr *oip6h = ipv6_hdr(oldskb);
|
||||||
|
struct ipv6hdr *ip6h;
|
||||||
|
const uint8_t tclass = 0;
|
||||||
|
uint8_t proto;
|
||||||
|
uint16_t payload;
|
||||||
|
__be16 frag_off;
|
||||||
|
|
||||||
|
proto = oip6h->nexthdr;
|
||||||
|
tcphoff = ipv6_skip_exthdr(oldskb,
|
||||||
|
(uint8_t *)(oip6h + 1) - oldskb->data, &proto, &frag_off);
|
||||||
|
|
||||||
|
if (tcphoff < 0 || tcphoff > oldskb->len) {
|
||||||
|
pr_debug("Cannot get TCP header.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
otcplen = oldskb->len - tcphoff;
|
||||||
|
|
||||||
|
/* IP header checks: fragment, too short. */
|
||||||
|
if (proto != IPPROTO_TCP || otcplen < sizeof(struct tcphdr)) {
|
||||||
|
pr_debug("proto(%d) != IPPROTO_TCP, "
|
||||||
|
"or too short. otcplen = %d\n",
|
||||||
|
proto, otcplen);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (skb_copy_bits(oldskb, tcphoff, &oth, sizeof(struct tcphdr))) {
|
||||||
|
WARN_ON(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check checksum. */
|
||||||
|
if (csum_ipv6_magic(&oip6h->saddr, &oip6h->daddr, otcplen, IPPROTO_TCP,
|
||||||
|
skb_checksum(oldskb, tcphoff, otcplen, 0))) {
|
||||||
|
pr_debug("TCP checksum is invalid\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nskb = skb_copy_expand(oldskb, LL_MAX_HEADER,
|
||||||
|
skb_tailroom(oldskb), GFP_ATOMIC);
|
||||||
|
if (nskb == NULL) {
|
||||||
|
if (net_ratelimit())
|
||||||
|
pr_debug("cannot alloc skb\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This packet will not be the same as the other: clear nf fields */
|
||||||
|
nf_reset(nskb);
|
||||||
|
skb_nfmark(nskb) = 0;
|
||||||
|
skb_init_secmark(nskb);
|
||||||
|
|
||||||
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18)
|
||||||
|
skb_shinfo(nskb)->gso_size = 0;
|
||||||
|
skb_shinfo(nskb)->gso_segs = 0;
|
||||||
|
skb_shinfo(nskb)->gso_type = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
skb_put(nskb, sizeof(struct ipv6hdr));
|
||||||
|
ip6h = ipv6_hdr(nskb);
|
||||||
|
*(__be32 *)ip6h = htonl(0x60000000 | (tclass << 20));
|
||||||
|
ip6h->nexthdr = IPPROTO_TCP;
|
||||||
|
ip6h->saddr = oip6h->daddr;
|
||||||
|
ip6h->daddr = oip6h->saddr;
|
||||||
|
|
||||||
|
/* Adjust IP TTL */
|
||||||
|
if (mode == XTTARPIT_HONEYPOT)
|
||||||
|
ip6h->hop_limit = 128;
|
||||||
|
else
|
||||||
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
|
||||||
|
ip6h->hop_limit = ip6_dst_hoplimit(skb_dst(nskb));
|
||||||
|
#else
|
||||||
|
ip6h->hop_limit = dst_metric(dst, RTAX_HOPLIMIT);
|
||||||
|
if (ip6h->hop_limit < 0)
|
||||||
|
ip6h->hop_limit = ipv6_get_hoplimit((skb_dst(nskb))->dev).
|
||||||
|
#endif
|
||||||
|
|
||||||
|
tcph = (struct tcphdr *)(skb_network_header(nskb) +
|
||||||
|
sizeof(struct ipv6hdr));
|
||||||
|
|
||||||
|
/* Truncate to length (no data) */
|
||||||
|
skb_trim(nskb, sizeof(struct ipv6hdr) + sizeof(struct tcphdr));
|
||||||
|
tcph->doff = sizeof(struct tcphdr)/4;
|
||||||
|
tcph->source = oth.dest;
|
||||||
|
tcph->dest = oth.source;
|
||||||
|
tcph->urg_ptr = 0;
|
||||||
|
/* Reset flags */
|
||||||
|
((uint8_t *)tcph)[13] = 0;
|
||||||
|
|
||||||
|
payload = nskb->len - sizeof(struct ipv6hdr) - sizeof(struct tcphdr);
|
||||||
|
if (!tarpit_generic(&oth, tcph, payload, mode))
|
||||||
|
return;
|
||||||
|
|
||||||
|
ip6h->payload_len = htons(sizeof(struct tcphdr));
|
||||||
|
tcph->check = 0;
|
||||||
|
|
||||||
|
/* Adjust TCP checksum */
|
||||||
|
tcph->check = csum_ipv6_magic(&ipv6_hdr(nskb)->saddr,
|
||||||
|
&ipv6_hdr(nskb)->daddr, sizeof(struct tcphdr),
|
||||||
|
IPPROTO_TCP,
|
||||||
|
csum_partial(tcph, sizeof(struct tcphdr), 0));
|
||||||
|
|
||||||
|
if (ip6_route_me_harder(nskb))
|
||||||
|
goto free_nskb;
|
||||||
|
|
||||||
|
nskb->ip_summed = CHECKSUM_NONE;
|
||||||
|
|
||||||
|
nf_ct_attach(nskb, oldskb);
|
||||||
|
|
||||||
|
NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT, nskb, NULL,
|
||||||
|
skb_dst(nskb)->dev, dst_output);
|
||||||
|
return;
|
||||||
|
|
||||||
|
free_nskb:
|
||||||
|
kfree_skb(nskb);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static unsigned int
|
static unsigned int
|
||||||
tarpit_tg(struct sk_buff **pskb, const struct xt_action_param *par)
|
tarpit_tg4(struct sk_buff **pskb, const struct xt_action_param *par)
|
||||||
{
|
{
|
||||||
const struct sk_buff *skb = *pskb;
|
const struct sk_buff *skb = *pskb;
|
||||||
const struct iphdr *iph = ip_hdr(skb);
|
const struct iphdr *iph = ip_hdr(skb);
|
||||||
@@ -289,29 +458,87 @@ tarpit_tg(struct sk_buff **pskb, const struct xt_action_param *par)
|
|||||||
if (iph->frag_off & htons(IP_OFFSET))
|
if (iph->frag_off & htons(IP_OFFSET))
|
||||||
return NF_DROP;
|
return NF_DROP;
|
||||||
|
|
||||||
tarpit_tcp(*pskb, par->hooknum, info->variant);
|
tarpit_tcp4(*pskb, par->hooknum, info->variant);
|
||||||
return NF_DROP;
|
return NF_DROP;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct xt_target tarpit_tg_reg __read_mostly = {
|
#ifdef WITH_IPV6
|
||||||
.name = "TARPIT",
|
static unsigned int
|
||||||
.revision = 0,
|
tarpit_tg6(struct sk_buff **pskb, const struct xt_action_param *par)
|
||||||
.family = NFPROTO_IPV4,
|
{
|
||||||
.hooks = (1 << NF_INET_LOCAL_IN) | (1 << NF_INET_FORWARD),
|
const struct sk_buff *skb = *pskb;
|
||||||
.proto = IPPROTO_TCP,
|
const struct ipv6hdr *iph = ipv6_hdr(skb);
|
||||||
.target = tarpit_tg,
|
const struct rt6_info *rt = (struct rt6_info *)skb_dst(skb);
|
||||||
.targetsize = sizeof(struct xt_tarpit_tginfo),
|
const struct xt_tarpit_tginfo *info = par->targinfo;
|
||||||
.me = THIS_MODULE,
|
uint8_t proto;
|
||||||
|
__be16 frag_off;
|
||||||
|
|
||||||
|
/* Do we have an input route cache entry? (Not in PREROUTING.) */
|
||||||
|
if (rt == NULL) {
|
||||||
|
pr_debug("Dropping no input route cache entry\n");
|
||||||
|
return NF_DROP;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* No replies to physical multicast/broadcast */
|
||||||
|
/* skb != PACKET_OTHERHOST handled by ip_rcv() */
|
||||||
|
if (skb->pkt_type != PACKET_HOST) {
|
||||||
|
pr_debug("type != PACKET_HOST");
|
||||||
|
return NF_DROP;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Our naive response construction does not deal with IP
|
||||||
|
* options, and probably should not try.
|
||||||
|
*/
|
||||||
|
proto = iph->nexthdr;
|
||||||
|
if (ipv6_skip_exthdr(skb, skb_network_header_len(skb), &proto,
|
||||||
|
&frag_off) != sizeof(struct ipv6hdr))
|
||||||
|
return NF_DROP;
|
||||||
|
|
||||||
|
if ((!(ipv6_addr_type(&iph->saddr) & IPV6_ADDR_UNICAST)) ||
|
||||||
|
(!(ipv6_addr_type(&iph->daddr) & IPV6_ADDR_UNICAST))) {
|
||||||
|
pr_debug("addr is not unicast.\n");
|
||||||
|
return NF_DROP;
|
||||||
|
}
|
||||||
|
|
||||||
|
tarpit_tcp6(*pskb, par->hooknum, info->variant);
|
||||||
|
return NF_DROP;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static struct xt_target tarpit_tg_reg[] __read_mostly = {
|
||||||
|
{
|
||||||
|
.name = "TARPIT",
|
||||||
|
.revision = 0,
|
||||||
|
.family = NFPROTO_IPV4,
|
||||||
|
.hooks = (1 << NF_INET_LOCAL_IN) | (1 << NF_INET_FORWARD),
|
||||||
|
.proto = IPPROTO_TCP,
|
||||||
|
.target = tarpit_tg4,
|
||||||
|
.targetsize = sizeof(struct xt_tarpit_tginfo),
|
||||||
|
.me = THIS_MODULE,
|
||||||
|
},
|
||||||
|
#ifdef WITH_IPV6
|
||||||
|
{
|
||||||
|
.name = "TARPIT",
|
||||||
|
.revision = 0,
|
||||||
|
.family = NFPROTO_IPV6,
|
||||||
|
.hooks = (1 << NF_INET_LOCAL_IN) | (1 << NF_INET_FORWARD),
|
||||||
|
.proto = IPPROTO_TCP,
|
||||||
|
.target = tarpit_tg6,
|
||||||
|
.targetsize = sizeof(struct xt_tarpit_tginfo),
|
||||||
|
.me = THIS_MODULE,
|
||||||
|
},
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
static int __init tarpit_tg_init(void)
|
static int __init tarpit_tg_init(void)
|
||||||
{
|
{
|
||||||
return xt_register_target(&tarpit_tg_reg);
|
return xt_register_targets(tarpit_tg_reg, ARRAY_SIZE(tarpit_tg_reg));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __exit tarpit_tg_exit(void)
|
static void __exit tarpit_tg_exit(void)
|
||||||
{
|
{
|
||||||
xt_unregister_target(&tarpit_tg_reg);
|
xt_unregister_targets(tarpit_tg_reg, ARRAY_SIZE(tarpit_tg_reg));
|
||||||
}
|
}
|
||||||
|
|
||||||
module_init(tarpit_tg_init);
|
module_init(tarpit_tg_init);
|
||||||
@@ -320,3 +547,4 @@ MODULE_DESCRIPTION("Xtables: \"TARPIT\", capture and hold TCP connections");
|
|||||||
MODULE_AUTHOR("Jan Engelhardt <jengelh@medozas.de>");
|
MODULE_AUTHOR("Jan Engelhardt <jengelh@medozas.de>");
|
||||||
MODULE_LICENSE("GPL");
|
MODULE_LICENSE("GPL");
|
||||||
MODULE_ALIAS("ipt_TARPIT");
|
MODULE_ALIAS("ipt_TARPIT");
|
||||||
|
MODULE_ALIAS("ip6t_TARPIT");
|
||||||
|
@@ -33,7 +33,7 @@
|
|||||||
# define WITH_CONNTRACK 1
|
# define WITH_CONNTRACK 1
|
||||||
# include <net/netfilter/nf_conntrack.h>
|
# include <net/netfilter/nf_conntrack.h>
|
||||||
#endif
|
#endif
|
||||||
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
|
#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE)
|
||||||
# define WITH_IPV6 1
|
# define WITH_IPV6 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -3,8 +3,6 @@
|
|||||||
# Converter for MaxMind CSV database to binary, for xt_geoip
|
# Converter for MaxMind CSV database to binary, for xt_geoip
|
||||||
# Copyright © Jan Engelhardt <jengelh@medozas.de>, 2008-2011
|
# Copyright © Jan Engelhardt <jengelh@medozas.de>, 2008-2011
|
||||||
#
|
#
|
||||||
# Use -b argument to create big-endian tables.
|
|
||||||
#
|
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
use IO::Handle;
|
use IO::Handle;
|
||||||
use Text::CSV_XS; # or trade for Text::CSV
|
use Text::CSV_XS; # or trade for Text::CSV
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
.TH xtables-addons 8 "v1.43 (2012-06-30)" "" "v1.43 (2012-06-30)"
|
.TH xtables-addons 8 "v1.44 (2012-07-15)" "" "v1.44 (2012-07-15)"
|
||||||
.SH Name
|
.SH Name
|
||||||
Xtables-addons \(em additional extensions for iptables, ip6tables, etc.
|
Xtables-addons \(em additional extensions for iptables, ip6tables, etc.
|
||||||
.SH Targets
|
.SH Targets
|
||||||
|
Reference in New Issue
Block a user