mirror of
git://git.code.sf.net/p/xtables-addons/xtables-addons
synced 2025-09-07 13:15:12 +02:00
psd: rip out scanlogd leftovers
scanlogd remembers tcp flags and uses the *_CHANGING values in its logger function to determine the best log format to use (e.g. TTL is not logged if HF_TTL_CHANGING was set, as TTL values were different). As psd does not log at all, we do not need track this. Also get rid of bogus/misleading comments.
This commit is contained in:

committed by
Jan Engelhardt

parent
7cc774641a
commit
ac58f2e94b
@@ -40,10 +40,6 @@ MODULE_AUTHOR(" Mohd Nawawi Mohamad Jamili <nawawi@tracenetworkcorporation.com>"
|
|||||||
MODULE_DESCRIPTION("Xtables: PSD - portscan detection");
|
MODULE_DESCRIPTION("Xtables: PSD - portscan detection");
|
||||||
MODULE_ALIAS("ipt_psd");
|
MODULE_ALIAS("ipt_psd");
|
||||||
|
|
||||||
#define HF_DADDR_CHANGING 0x01
|
|
||||||
#define HF_SPORT_CHANGING 0x02
|
|
||||||
#define HF_TOS_CHANGING 0x04
|
|
||||||
#define HF_TTL_CHANGING 0x08
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Information we keep per each target port
|
* Information we keep per each target port
|
||||||
@@ -51,8 +47,6 @@ MODULE_ALIAS("ipt_psd");
|
|||||||
struct port {
|
struct port {
|
||||||
u_int16_t number; /* port number */
|
u_int16_t number; /* port number */
|
||||||
u_int8_t proto; /* protocol number */
|
u_int8_t proto; /* protocol number */
|
||||||
u_int8_t and_flags; /* tcp ANDed flags */
|
|
||||||
u_int8_t or_flags; /* tcp ORed flags */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -67,9 +61,6 @@ struct host {
|
|||||||
int count; /* Number of ports in the list */
|
int count; /* Number of ports in the list */
|
||||||
int weight; /* Total weight of ports in the list */
|
int weight; /* Total weight of ports in the list */
|
||||||
struct port ports[SCAN_MAX_COUNT - 1]; /* List of ports */
|
struct port ports[SCAN_MAX_COUNT - 1]; /* List of ports */
|
||||||
unsigned char tos; /* TOS */
|
|
||||||
unsigned char ttl; /* TTL */
|
|
||||||
unsigned char flags; /* HF_ flags bitmask */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -111,26 +102,20 @@ xt_psd_match(const struct sk_buff *pskb, struct xt_action_param *match)
|
|||||||
} _buf;
|
} _buf;
|
||||||
struct in_addr addr;
|
struct in_addr addr;
|
||||||
u_int16_t src_port,dest_port;
|
u_int16_t src_port,dest_port;
|
||||||
u_int8_t tcp_flags, proto;
|
u_int8_t proto;
|
||||||
unsigned long now;
|
unsigned long now;
|
||||||
struct host *curr, *last, **head;
|
struct host *curr, *last, **head;
|
||||||
int hash, index, count;
|
int hash, index, count;
|
||||||
/* Parameters from userspace */
|
/* Parameters from userspace */
|
||||||
const struct xt_psd_info *psdinfo = match->matchinfo;
|
const struct xt_psd_info *psdinfo = match->matchinfo;
|
||||||
|
|
||||||
/* IP header */
|
|
||||||
iph = ip_hdr(pskb);
|
iph = ip_hdr(pskb);
|
||||||
|
|
||||||
/* Sanity check */
|
|
||||||
if (iph->frag_off & htons(IP_OFFSET)) {
|
if (iph->frag_off & htons(IP_OFFSET)) {
|
||||||
pr_debug("sanity check failed\n");
|
pr_debug("sanity check failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TCP or UDP ? */
|
|
||||||
proto = iph->protocol;
|
proto = iph->protocol;
|
||||||
/* Get the source address, source & destination ports, and TCP flags */
|
|
||||||
|
|
||||||
addr.s_addr = iph->saddr;
|
addr.s_addr = iph->saddr;
|
||||||
/* We're using IP address 0.0.0.0 for a special purpose here, so don't let
|
/* We're using IP address 0.0.0.0 for a special purpose here, so don't let
|
||||||
* them spoof us. [DHCP needs this feature - HW] */
|
* them spoof us. [DHCP needs this feature - HW] */
|
||||||
@@ -148,7 +133,6 @@ xt_psd_match(const struct sk_buff *pskb, struct xt_action_param *match)
|
|||||||
/* Yep, it's dirty */
|
/* Yep, it's dirty */
|
||||||
src_port = tcph->source;
|
src_port = tcph->source;
|
||||||
dest_port = tcph->dest;
|
dest_port = tcph->dest;
|
||||||
tcp_flags = *((u_int8_t*)tcph + 13);
|
|
||||||
} else if (proto == IPPROTO_UDP || proto == IPPROTO_UDPLITE) {
|
} else if (proto == IPPROTO_UDP || proto == IPPROTO_UDPLITE) {
|
||||||
udph = skb_header_pointer(pskb, match->thoff,
|
udph = skb_header_pointer(pskb, match->thoff,
|
||||||
sizeof(_buf.udph), &_buf.udph);
|
sizeof(_buf.udph), &_buf.udph);
|
||||||
@@ -156,14 +140,11 @@ xt_psd_match(const struct sk_buff *pskb, struct xt_action_param *match)
|
|||||||
return false;
|
return false;
|
||||||
src_port = udph->source;
|
src_port = udph->source;
|
||||||
dest_port = udph->dest;
|
dest_port = udph->dest;
|
||||||
tcp_flags = 0;
|
|
||||||
} else {
|
} else {
|
||||||
pr_debug("protocol not supported\n");
|
pr_debug("protocol not supported\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Use jiffies here not to depend on someone setting the time while we're
|
|
||||||
* running; we need to be careful with possible return value overflows. */
|
|
||||||
now = jiffies;
|
now = jiffies;
|
||||||
|
|
||||||
spin_lock(&state.lock);
|
spin_lock(&state.lock);
|
||||||
@@ -181,7 +162,6 @@ xt_psd_match(const struct sk_buff *pskb, struct xt_action_param *match)
|
|||||||
} while ((curr = curr->next) != NULL);
|
} while ((curr = curr->next) != NULL);
|
||||||
|
|
||||||
if (curr != NULL) {
|
if (curr != NULL) {
|
||||||
|
|
||||||
/* We know this address, and the entry isn't too old. Update it. */
|
/* We know this address, and the entry isn't too old. Update it. */
|
||||||
if (now - curr->timestamp <= (psdinfo->delay_threshold*HZ)/100 &&
|
if (now - curr->timestamp <= (psdinfo->delay_threshold*HZ)/100 &&
|
||||||
time_after_eq(now, curr->timestamp)) {
|
time_after_eq(now, curr->timestamp)) {
|
||||||
@@ -190,8 +170,6 @@ xt_psd_match(const struct sk_buff *pskb, struct xt_action_param *match)
|
|||||||
for (index = 0; index < curr->count; index++) {
|
for (index = 0; index < curr->count; index++) {
|
||||||
if (curr->ports[index].number == dest_port) {
|
if (curr->ports[index].number == dest_port) {
|
||||||
curr->ports[index].proto = proto;
|
curr->ports[index].proto = proto;
|
||||||
curr->ports[index].and_flags &= tcp_flags;
|
|
||||||
curr->ports[index].or_flags |= tcp_flags;
|
|
||||||
goto out_no_match;
|
goto out_no_match;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -203,26 +181,15 @@ xt_psd_match(const struct sk_buff *pskb, struct xt_action_param *match)
|
|||||||
/* Packet to a new port, and not TCP/ACK: update the timestamp */
|
/* Packet to a new port, and not TCP/ACK: update the timestamp */
|
||||||
curr->timestamp = now;
|
curr->timestamp = now;
|
||||||
|
|
||||||
/* Logged this scan already? Then drop the packet. */
|
/* Matched this scan already? Then Leave. */
|
||||||
if (curr->weight >= psdinfo->weight_threshold)
|
if (curr->weight >= psdinfo->weight_threshold)
|
||||||
goto out_match;
|
goto out_match;
|
||||||
|
|
||||||
/* Specify if destination address, source port, TOS or TTL are not fixed */
|
|
||||||
if (curr->dest_addr.s_addr != iph->daddr)
|
|
||||||
curr->flags |= HF_DADDR_CHANGING;
|
|
||||||
if (curr->src_port != src_port)
|
|
||||||
curr->flags |= HF_SPORT_CHANGING;
|
|
||||||
if (curr->tos != iph->tos)
|
|
||||||
curr->flags |= HF_TOS_CHANGING;
|
|
||||||
if (curr->ttl != iph->ttl)
|
|
||||||
curr->flags |= HF_TTL_CHANGING;
|
|
||||||
|
|
||||||
/* Update the total weight */
|
/* Update the total weight */
|
||||||
curr->weight += (ntohs(dest_port) < 1024) ?
|
curr->weight += (ntohs(dest_port) < 1024) ?
|
||||||
psdinfo->lo_ports_weight : psdinfo->hi_ports_weight;
|
psdinfo->lo_ports_weight : psdinfo->hi_ports_weight;
|
||||||
|
|
||||||
/* Got enough destination ports to decide that this is a scan? */
|
/* Got enough destination ports to decide that this is a scan? */
|
||||||
/* Then log it and drop the packet. */
|
|
||||||
if (curr->weight >= psdinfo->weight_threshold)
|
if (curr->weight >= psdinfo->weight_threshold)
|
||||||
goto out_match;
|
goto out_match;
|
||||||
|
|
||||||
@@ -230,8 +197,6 @@ xt_psd_match(const struct sk_buff *pskb, struct xt_action_param *match)
|
|||||||
if (curr->count < ARRAY_SIZE(curr->ports)) {
|
if (curr->count < ARRAY_SIZE(curr->ports)) {
|
||||||
curr->ports[curr->count].number = dest_port;
|
curr->ports[curr->count].number = dest_port;
|
||||||
curr->ports[curr->count].proto = proto;
|
curr->ports[curr->count].proto = proto;
|
||||||
curr->ports[curr->count].and_flags = tcp_flags;
|
|
||||||
curr->ports[curr->count].or_flags = tcp_flags;
|
|
||||||
curr->count++;
|
curr->count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,10 +268,6 @@ xt_psd_match(const struct sk_buff *pskb, struct xt_action_param *match)
|
|||||||
curr->weight = (ntohs(dest_port) < 1024) ? psdinfo->lo_ports_weight : psdinfo->hi_ports_weight;
|
curr->weight = (ntohs(dest_port) < 1024) ? psdinfo->lo_ports_weight : psdinfo->hi_ports_weight;
|
||||||
curr->ports[0].number = dest_port;
|
curr->ports[0].number = dest_port;
|
||||||
curr->ports[0].proto = proto;
|
curr->ports[0].proto = proto;
|
||||||
curr->ports[0].and_flags = tcp_flags;
|
|
||||||
curr->ports[0].or_flags = tcp_flags;
|
|
||||||
curr->tos = iph->tos;
|
|
||||||
curr->ttl = iph->ttl;
|
|
||||||
|
|
||||||
out_no_match:
|
out_no_match:
|
||||||
spin_unlock(&state.lock);
|
spin_unlock(&state.lock);
|
||||||
|
Reference in New Issue
Block a user