This file is indexed.

/usr/src/west-chamber-20100405+svn20111107.r124/extensions/xt_CUI.c is in west-chamber-dkms 20100405+svn20111107.r124-7.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*
 *	"CUI" target extension for Xtables
 *	copied from "DELUDE" target
 *	Copyright © Jan Engelhardt <jengelh [at] medozas de>, 2007 - 2008
 *      Klzgrad <klzgrad@gmail.com>, 2010
 *
 *	Based upon linux-2.6.18.5/net/ipv4/netfilter/ipt_REJECT.c:
 *	(C) 1999-2001 Paul `Rusty' Russell
 *	(C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
 *
 *	This program is free software; you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License version 2 as
 *	published by the Free Software Foundation.
 */
#include <linux/module.h>
#include <linux/skbuff.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/netfilter/x_tables.h>
#ifdef CONFIG_BRIDGE_NETFILTER
#	include <linux/netfilter_bridge.h>
#endif
#include <net/tcp.h>
#include "compat_xtables.h"
#define PFX KBUILD_MODNAME ": "

static void cui_send_reset(struct net *net, struct sk_buff *oldskb, unsigned int hook)
{
	struct tcphdr _otcph, *tcph;
	const struct tcphdr *oth;
	const struct iphdr *oiph;
	struct sk_buff *skb;
	struct iphdr *iph;
	unsigned int addr_type;

	oiph = ip_hdr(oldskb);

	/* do not deal with fragment */
	if (oiph->frag_off & htons(IP_OFFSET))
		return;

	oth = skb_header_pointer(oldskb, ip_hdrlen(oldskb),
				 sizeof(_otcph), &_otcph);
	if (oth == NULL)
		return;

	/* syn[ack] only */
	if (!oth->syn || oth->ack || oth->rst || oth->fin)
		return;

	/* check checksum */
	if (nf_ip_checksum(oldskb, hook, ip_hdrlen(oldskb), IPPROTO_TCP))
		return;

	skb = alloc_skb(sizeof(struct iphdr) + sizeof(struct tcphdr) +
	                 LL_MAX_HEADER, GFP_ATOMIC);
	if (skb == NULL)
		return;

	/* construct from scratch */
	skb_reserve(skb, LL_MAX_HEADER);
	skb_reset_network_header(skb);
	iph = (struct iphdr *)skb_put(skb, sizeof(struct iphdr));
	iph->version  = 4;
	iph->ihl      = sizeof(struct iphdr) / 4;
	iph->tos      = 0;
	iph->id       = 0;
	iph->frag_off = htons(IP_DF);
	iph->protocol = IPPROTO_TCP;
	iph->check    = 0;
	iph->saddr    = oiph->daddr;
	iph->daddr    = oiph->saddr;

	tcph = (struct tcphdr *)skb_put(skb, sizeof(struct tcphdr));
	memset(tcph, 0, sizeof(*tcph));
	tcph->source = oth->dest;
	tcph->dest   = oth->source;
	tcph->doff   = sizeof(struct tcphdr) / 4;
	tcph->window = 0xffffU;

	tcph->rst     = true;
	tcph->seq     = 0;

#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 20)
	tcph->check = tcp_v4_check(tcph, sizeof(struct tcphdr), iph->saddr,
	              iph->daddr, csum_partial((char *)tcph,
	              sizeof(struct tcphdr), 0));
#else
	tcph->check = tcp_v4_check(sizeof(struct tcphdr), iph->saddr,
	              iph->daddr, csum_partial((char *)tcph,
	              sizeof(struct tcphdr), 0));
#endif

	addr_type = RTN_UNSPEC;
#ifdef CONFIG_BRIDGE_NETFILTER
	if (hook != NF_INET_FORWARD || (skb->nf_bridge != NULL &&
	    skb->nf_bridge->mask & BRNF_BRIDGED))
#else
	if (hook != NF_INET_FORWARD)
#endif
		addr_type = RTN_LOCAL;

	/* ip_route_me_harder expects skb->dst to be set */
	skb_dst_set(skb, dst_clone(skb_dst(oldskb)));

	if (ip_route_me_harder(net, skb, addr_type))
		goto free_skb;
	else
		iph = ip_hdr(skb);

	iph->ttl       = dst_metric_raw(skb_dst(skb), RTAX_HOPLIMIT);
	skb->ip_summed = CHECKSUM_NONE;

	/* "Never happens" */
	if (skb->len > dst_mtu(skb_dst(skb)))
		goto free_skb;

	ip_local_out(net, skb->sk, skb);

	return;
free_skb:
	kfree_skb(skb);
}

static void cui_send_synack(struct net *net, struct sk_buff *oldskb, unsigned int hook)
{
	struct tcphdr _otcph, *tcph;
	const struct tcphdr *oth;
	const struct iphdr *oiph;
	struct sk_buff *skb;
	struct iphdr *iph;
	unsigned int addr_type;

	oiph = ip_hdr(oldskb);

	/* do not deal with fragment */
	if (oiph->frag_off & htons(IP_OFFSET))
		return;

	oth = skb_header_pointer(oldskb, ip_hdrlen(oldskb),
				 sizeof(_otcph), &_otcph);
	if (oth == NULL)
		return;

	/* syn[ack] only */
	if (!oth->syn || oth->ack || oth->rst || oth->fin)
		return;

	/* check checksum */
	if (nf_ip_checksum(oldskb, hook, ip_hdrlen(oldskb), IPPROTO_TCP))
		return;

	skb = alloc_skb(sizeof(struct iphdr) + sizeof(struct tcphdr) +
	                 LL_MAX_HEADER, GFP_ATOMIC);
	if (skb == NULL)
		return;

	/* construct from scratch */
	skb_reserve(skb, LL_MAX_HEADER);
	skb_reset_network_header(skb);
	iph = (struct iphdr *)skb_put(skb, sizeof(struct iphdr));
	iph->version  = 4;
	iph->ihl      = sizeof(struct iphdr) / 4;
	iph->tos      = 0;
	iph->id       = 0;
	iph->frag_off = htons(IP_DF);
	iph->protocol = IPPROTO_TCP;
	iph->check    = 0;
	iph->saddr    = oiph->daddr;
	iph->daddr    = oiph->saddr;

	tcph = (struct tcphdr *)skb_put(skb, sizeof(struct tcphdr));
	memset(tcph, 0, sizeof(*tcph));
	tcph->source = oth->dest;
	tcph->dest   = oth->source;
	tcph->doff   = sizeof(struct tcphdr) / 4;
	tcph->window = 0xffffU;

	tcph->syn     = true;
	tcph->ack     = true;
	tcph->seq     = 0;
	tcph->ack_seq = oth->seq;

#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 20)
	tcph->check = tcp_v4_check(tcph, sizeof(struct tcphdr), iph->saddr,
	              iph->daddr, csum_partial((char *)tcph,
	              sizeof(struct tcphdr), 0));
#else
	tcph->check = tcp_v4_check(sizeof(struct tcphdr), iph->saddr,
	              iph->daddr, csum_partial((char *)tcph,
	              sizeof(struct tcphdr), 0));
#endif

	addr_type = RTN_UNSPEC;
#ifdef CONFIG_BRIDGE_NETFILTER
	if (hook != NF_INET_FORWARD || (skb->nf_bridge != NULL &&
	    skb->nf_bridge->mask & BRNF_BRIDGED))
#else
	if (hook != NF_INET_FORWARD)
#endif
		addr_type = RTN_LOCAL;

	/* ip_route_me_harder expects skb->dst to be set */
	skb_dst_set(skb, dst_clone(skb_dst(oldskb)));

	if (ip_route_me_harder(net, skb, addr_type))
		goto free_skb;
	else
		iph = ip_hdr(skb);

	iph->ttl       = dst_metric_raw(skb_dst(skb), RTAX_HOPLIMIT);
	skb->ip_summed = CHECKSUM_NONE;

	/* "Never happens" */
	if (skb->len > dst_mtu(skb_dst(skb)))
		goto free_skb;

	ip_local_out(net, skb->sk, skb);

	return;
free_skb:
	kfree_skb(skb);
}

static unsigned int
cui_tg(struct sk_buff *pskb, const struct xt_action_param *par)
{
	/* WARNING: This code causes reentry within iptables.
	   This means that the iptables jump stack is now crap.  We
	   must return an absolute verdict. --RR */
	cui_send_synack(par_net(par), pskb, par->hooknum);
	cui_send_reset(par_net(par), pskb, par->hooknum);
	cui_send_synack(par_net(par), pskb, par->hooknum);
	cui_send_reset(par_net(par), pskb, par->hooknum);
	return NF_ACCEPT;
}

static struct xt_target cui_tg_reg __read_mostly = {
	.name     = "CUI",
	.revision = 0,
	.family   = NFPROTO_IPV4,
	.table    = "filter",
	.hooks    = (1 << NF_INET_LOCAL_IN),
	.proto    = IPPROTO_TCP,
	.target   = cui_tg,
	.me       = THIS_MODULE,
};

static int __init cui_tg_init(void)
{
	return xt_register_target(&cui_tg_reg);
}

static void __exit cui_tg_exit(void)
{
	xt_unregister_target(&cui_tg_reg);
}

module_init(cui_tg_init);
module_exit(cui_tg_exit);
MODULE_DESCRIPTION("Xtables: Cui Yingying");
MODULE_AUTHOR("Jan Engelhardt <jengelh@medozas.de>");
MODULE_AUTHOR("Klzgrad <klzgrad@gmail.com>");
MODULE_LICENSE("GPL");
MODULE_ALIAS("ipt_CUI");