Skip to contentSkip to conversation

New target: passive OS fingerprinting.

FUN Evgeniy Polyakov 2 participants 9 messages Nov 23, 2003 – Nov 27, 2003 netfilter

lore
Share & tools
lore
#0 lore raw

New target which trying to determine(by passive fingerprinting) remote OS by set of parameters from initial SYN packet which was sent to us.

Fingerprints must be loaded through procfs (/proc/sys/net/ipv4/OSF). For information about fingerprints please see help for OSF matching module.

Example:

  # iptables -I INPUT -j OSF -p tcp

Run and see syslog. You will find something like this:

ipt_OSF: Windows [Windows XP Pro SP1, 2000 SP3]: 11.22.33.55:4024 ->
11.22.33.44:139

NOTE: -p tcp is obviously required as it is a TCP match.

All OSF patches(help, config...) actually are osf.patch set with a bit changed content, so please review them, since i nderstand not very well how patch-o-matic works :).

OSF was tested with 2.6-test9 (with uncommented line number 66) and it works stable.
I've only compiled OSF target module with 2.4, without any testing.

Please test and apply.
Thank you.

Evgeniy Polyakov ( s0mbre )

patch-o-matic_2.5/base/OSF.patch new file +722 -0
@@ -0,0 +1,722 @@
+--- /dev/null	Thu Oct 30 21:31:23 2003
++++ linux/net/ipv4/netfilter/ipt_OSF.c	Sun Nov 23 23:39:38 2003
+@@ -0,0 +1,686 @@
++/*
++ * ipt_OSF.c
++ *
++ * Copyright (c) 2003 Evgeniy Polyakov <[email protected]>
++ *
++ *
++ * This program is free software; you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation; either version 2 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
++ */
++
++#include <linux/module.h>
++#include <linux/ip.h>
++#include <net/tcp.h>
++#include <linux/file.h>
++#include <linux/ip.h>
++#include <linux/proc_fs.h>
++#include <linux/fs.h>
++#include <linux/slab.h>
++#include <linux/spinlock.h>
++#include <linux/ctype.h>
++#include <linux/list.h>
++
++#include <net/sock.h>
++#include <net/ip.h>
++
++#include <linux/netfilter_ipv4/ip_tables.h>
++
++#include <linux/netfilter_ipv4/ipt_osf.h>
++
++#define log(x...) 		printk(KERN_INFO "ipt_OSF: " x)
++#define loga(x...) 		printk(x)
++
++#define FMATCH_WRONG		0
++#define FMATCH_OK		1
++#define FMATCH_OPT_WRONG	2
++
++#define OPTDEL			','
++#define OSFPDEL 		':'
++#define MAXOPTSTRLEN		128
++#define OSFFLUSH		"FLUSH"
++
++static rwlock_t osf_lock = RW_LOCK_UNLOCKED;
++static struct list_head	finger_list;	
++
++static unsigned int
++ipt_osf_target(struct sk_buff **pskb,
++	       const struct net_device *in,
++	       const struct net_device *out,
++//	       unsigned int hooknum,
++	       const void *targinfo,
++	       void *userinfo)
++{
++	struct ipt_osf_info *info = (struct ipt_osf_info *)targinfo;
++	struct iphdr *ip = (*pskb)->nh.iph;
++	struct tcphdr *tcp;
++	int fmatch = FMATCH_WRONG, fcount = 0;
++	unsigned long totlen, optsize = 0, window;
++	unsigned char df, *optp = NULL, *_optp = NULL;
++	char check_WSS = 0;
++	struct list_head *ent;
++	struct osf_finger *f = NULL;
++
++	if (!ip || !info)
++		return IPT_CONTINUE;
++				
++	tcp = (struct tcphdr *)((u_int32_t *)ip + ip->ihl);
++
++	if (!tcp->syn)
++		return IPT_CONTINUE;
++	else if (tcp->ack)
++		return IPT_CONTINUE;
++	
++	totlen = ntohs(ip->tot_len);
++	df = ((ntohs(ip->frag_off) & IP_DF)?1:0);
++	window = ntohs(tcp->window);
++	
++	if (tcp->doff*4 > sizeof(struct tcphdr))
++	{
++		_optp = optp = (char *)(tcp+1);
++		optsize = tcp->doff*4 - sizeof(struct tcphdr);
++	}
++
++	
++	/* Actually we can create hash/table of all genres and search
++	 * only in appropriate part, but here is initial variant,
++	 * so will use slow path.
++	 */
++	read_lock_bh(&osf_lock);
++	list_for_each(ent, &finger_list)
++	{
++		f = list_entry(ent, struct osf_finger, flist);
++		
++		optp = _optp;
++
++		if (	ip->ttl == f->ttl &&
++			totlen	== f->ss &&
++			df	== f->df)
++		{
++			unsigned long foptsize;
++			int optnum;
++			unsigned short mss = 0;
++
++			check_WSS = 0;
++
++			switch (f->wss.wc)
++			{
++				case 0:	  check_WSS = 0; break;
++				case 'S': check_WSS = 1; break;
++				case 'T': check_WSS = 2; break;
++				case '%': check_WSS = 3; break;
++				default:  check_WSS = 4; break;
++			}
++			if (check_WSS == 4)
++				continue;
++
++			/* Check options */
++
++			foptsize = 0;
++			for (optnum=0; optnum<f->opt_num; ++optnum)
++				foptsize += f->opt[optnum].length;
++
++				
++			if (foptsize > MAX_IPOPTLEN || optsize > MAX_IPOPTLEN || optsize != foptsize)
++				continue;
++
++			if (!optp)
++			{
++				fmatch = FMATCH_OK;
++				loga("\tYEP : matching without options.\n");
++				break;
++			}
++			
++
++			for (optnum=0; optnum<f->opt_num; ++optnum)
++			{
++				if (f->opt[optnum].kind == (*optp))
++				{
++					unsigned char len = f->opt[optnum].length;
++					unsigned char *optend = optp + len;
++
++					fmatch = FMATCH_OK;
++
++					if (*optp == OSFOPT_MSS) /* MSS */
++						mss = ntohs(*(unsigned short *)(optp+2));
++					
++					if (len != 1)
++					{
++						if (f->opt[optnum].wc.wc != 0)
++						{
++							unsigned long tmp = 0;
++							
++							/* Hmmm... It looks a bit ugly. :) */
++							memcpy(&tmp, &f->opt[optnum].wc.val, 
++								(len > sizeof(unsigned long)?
++								 	sizeof(unsigned long):len));
++
++							tmp = ntohl(tmp);
++							if (tmp != f->opt[optnum].wc.val)
++								fmatch = FMATCH_OPT_WRONG;
++						}
++					}
++
++					optp = optend;
++				}
++				else
++					fmatch = FMATCH_OPT_WRONG;
++
++				if (fmatch != FMATCH_OK)
++					break;
++			}
++
++			if (fmatch != FMATCH_OPT_WRONG)
++			{
++				fmatch = FMATCH_WRONG;
++
++				switch (check_WSS)
++				{
++					case 0:
++						if (window == f->wss.val)
++							fmatch = FMATCH_OK;
++						break;
++					case 1: /* MSS */
++						if (window == f->wss.val*mss)
++							fmatch = FMATCH_OK;
++						break;
++					case 2: /* MTU */
++						if (window == f->wss.val*(mss+40))
++							fmatch = FMATCH_OK;
++						break;
++					case 3: /* MOD */
++						if (window % f->wss.val == 0)
++							fmatch = FMATCH_OK;
++						break;
++				}
++			}
++
++			if (fmatch == FMATCH_OK)
++			{
++				fcount++;
++				log("%s [%s]: %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u\n", 
++					f->genre, f->details,
++					NIPQUAD(ip->saddr), ntohs(tcp->source),
++					NIPQUAD(ip->daddr), ntohs(tcp->dest));
++			}
++		}
++	}
++
++	if (!fcount)
++	{
++		log("Unknown: %lu:%d:%d:%lu:", window, ip->ttl, df, totlen);
++		if (optp)
++		{
++			unsigned char opt[4 * 15 - sizeof(struct tcphdr)];
++			unsigned int i, optsize;
++
++			optsize = tcp->doff * 4 - sizeof(struct tcphdr);
++			if (skb_copy_bits((*pskb), ip->ihl*4 + sizeof(struct tcphdr),
++					  opt, optsize) < 0)
++				loga("TRUNCATED");
++			else
++				for (i = 0; i < optsize; i++)
++					loga("%02X", opt[i]);
++			
++		}  
++		loga(" %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u\n", 
++			NIPQUAD(ip->saddr), ntohs(tcp->source),
++			NIPQUAD(ip->daddr), ntohs(tcp->dest));
++	}
++	
++	read_unlock_bh(&osf_lock);
++
++	return IPT_CONTINUE;
++}
++
++static int ipt_osf_checkentry(const char *tablename,
++			      const struct ipt_entry *e,
++			      void *targinfo,
++			      unsigned int targinfosize,
++			      unsigned int hook_mask)
++{
++	if (targinfosize != IPT_ALIGN(sizeof(struct ipt_osf_info))) {
++		log("OSF: targinfosize %u != %u\n",
++		       targinfosize, IPT_ALIGN(sizeof(struct ipt_osf_info)));
++		return 0;
++	}
++       if (e->ip.proto != IPPROTO_TCP)
++	       return 0;
++
++	return 1;
++}
++
++static struct ipt_target ipt_osf_reg = {
++	.name		= "OSF",
++	.target		= ipt_osf_target,
++	.checkentry	= ipt_osf_checkentry,
++	.me		= THIS_MODULE,
++};
++
++static char * osf_strchr(char *ptr, char c)
++{
++	char *tmp;
++
++	tmp = strchr(ptr, c);
++
++	while (tmp && tmp+1 && isspace(*(tmp+1)))
++		tmp++;
++
++	return tmp;
++}
++
++static struct osf_finger * finger_alloc(void)
++{
++	struct osf_finger *f;
++
++	f = kmalloc(sizeof(struct osf_finger), GFP_KERNEL);
++	if (f)
++		memset(f, 0, sizeof(struct osf_finger));
++	
++	return f;
++}
++
++static void finger_free(struct osf_finger *f)
++{
++	memset(f, 0, sizeof(struct osf_finger));
++	kfree(f);
++}
++
++
++static void osf_parse_opt(struct osf_opt *opt, int *optnum, char *obuf, int olen)
++{
++	int i, op;
++	char *ptr, wc;
++	unsigned long val;
++
++	ptr = &obuf[0];
++	i = 0;
++	while (ptr != NULL && i < olen)
++	{
++		val = 0;
++		op = 0;
++		wc = 0;
++		switch (obuf[i])
++		{
++			case 'N': 
++				op = OSFOPT_NOP;
++				ptr = osf_strchr(&obuf[i], OPTDEL);
++				if (ptr)
++				{
++					*ptr = '\0';
++					ptr++;
++					i += (int)(ptr-&obuf[i]);
++
++				}
++				else
++					i++;
++				break;
++			case 'S': 
++				op = OSFOPT_SACKP;
++				ptr = osf_strchr(&obuf[i], OPTDEL);
++				if (ptr)
++				{
++					*ptr = '\0';
++					ptr++;
++					i += (int)(ptr-&obuf[i]);
++
++				}
++				else
++					i++;
++				break;
++			case 'T': 
++				op = OSFOPT_TS;
++				ptr = osf_strchr(&obuf[i], OPTDEL);
++				if (ptr)
++				{
++					*ptr = '\0';
++					ptr++;
++					i += (int)(ptr-&obuf[i]);
++
++				}
++				else
++					i++;
++				break;
++			case 'W': 
++				op = OSFOPT_WSO;
++				ptr = osf_strchr(&obuf[i], OPTDEL);
++				if (ptr)
++				{
++					switch (obuf[i+1])
++					{
++						case '%':	wc = '%'; break;
++						case 'S':	wc = 'S'; break;
++						case 'T':	wc = 'T'; break;
++						default:	wc = 0; break;
++					}
++					
++					*ptr = '\0';
++					ptr++;
++					if (wc)
++						val = simple_strtoul(&obuf[i+2], NULL, 10);
++					else
++						val = simple_strtoul(&obuf[i+1], NULL, 10);
++					i += (int)(ptr-&obuf[i]);
++
++				}
++				else
++					i++;
++				break;
++			case 'M': 
++				op = OSFOPT_MSS;
++				ptr = osf_strchr(&obuf[i], OPTDEL);
++				if (ptr)
++				{
++					if (obuf[i+1] == '%')
++						wc = '%';
++					*ptr = '\0';
++					ptr++;
++					if (wc)
++						val = simple_strtoul(&obuf[i+2], NULL, 10);
++					else
++						val = simple_strtoul(&obuf[i+1], NULL, 10);
++					i += (int)(ptr-&obuf[i]);
++
++				}
++				else
++					i++;
++				break;
++			case 'E': 
++				op = OSFOPT_EOL;
++				ptr = osf_strchr(&obuf[i], OPTDEL);
++				if (ptr)
++				{
++					*ptr = '\0';
++					ptr++;
++					i += (int)(ptr-&obuf[i]);
++
++				}
++				else
++					i++;
++				break;
++			default:
++				ptr = osf_strchr(&obuf[i], OPTDEL);
++				if (ptr)
++				{
++					ptr++;
++					i += (int)(ptr-&obuf[i]);
++
++				}
++				else
++					i++;
++				break;
++		}
++
++		opt[*optnum].kind 	= IANA_opts[op].kind;
++		opt[*optnum].length 	= IANA_opts[op].length;
++		opt[*optnum].wc.wc 	= wc;
++		opt[*optnum].wc.val	= val;
++
++		(*optnum)++;
++	}
++}
++
++static int osf_proc_read(char *buf, char **start, off_t off, int count, int *eof, void *data)
++{
++	struct list_head *ent;
++	struct osf_finger *f = NULL;
++	int i;
++	
++	*eof = 1;
++	count = 0;
++
++	read_lock_bh(&osf_lock);
++	list_for_each(ent, &finger_list)
++	{
++		f = list_entry(ent, struct osf_finger, flist);
++
++		log("%s - %s", f->genre, f->details);
++		
++		count += sprintf(buf+count, "%s - %s[%s] : %s", 
++					f->genre, f->version,
++					f->subtype, f->details);
++		
++		if (f->opt_num)
++		{
++			loga(" OPT: ");
++			//count += sprintf(buf+count, " OPT: ");
++			for (i=0; i<f->opt_num; ++i)
++			{
++				//count += sprintf(buf+count, "%d.%c%lu; ", 
++				//	f->opt[i].kind, (f->opt[i].wc.wc)?f->opt[i].wc.wc:' ', 
++				//	f->opt[i].wc.val);
++				loga("%d.%c%lu; ", 
++					f->opt[i].kind, (f->opt[i].wc.wc)?f->opt[i].wc.wc:' ', 
++					f->opt[i].wc.val);
++			}
++		}
++		loga("\n");
++		count += sprintf(buf+count, "\n");
++	}
++	read_unlock_bh(&osf_lock);
++
++	return count;
++}
++
++static int osf_proc_write(struct file *file, const char *buffer, unsigned long count, void *data)
++{
++	int cnt;
++	unsigned long i;
++	char obuf[MAXOPTSTRLEN];
++	struct osf_finger *finger;
++	struct list_head *ent, *n;
++
++	char *pbeg, *pend;
++
++	if (count == strlen(OSFFLUSH) && !strncmp(buffer, OSFFLUSH, strlen(OSFFLUSH)))
++	{
++		int i = 0;
++		write_lock_bh(&osf_lock);
++		list_for_each_safe(ent, n, &finger_list)
++		{
++			i++;
++			finger = list_entry(ent, struct osf_finger, flist);
++			list_del(&finger->flist);
++			finger_free(finger);
++		}
++		write_unlock_bh(&osf_lock);
++	
++		log("Flushed %d entries.\n", i);
++		
++		return count;
++	}
++
++	
++	cnt = 0;
++	for (i=0; i<count && buffer[i] != '\0'; ++i)
++		if (buffer[i] == ':')
++			cnt++;
++
++	if (cnt != 8 || i != count)
++	{
++		log("Wrong input line cnt=%d[8], len=%lu[%lu]\n", 
++			cnt, i, count);
++		return count;
++	}
++
++	memset(obuf, 0, sizeof(obuf));
++	
++	finger = finger_alloc();
++	if (!finger)
++	{
++		log("Failed to allocate new fingerprint entry.\n");
++		return -ENOMEM;
++	}
++
++	pbeg = (char *)buffer;
++	pend = osf_strchr(pbeg, OSFPDEL);
++	if (pend)
++	{
++		*pend = '\0';
++		if (pbeg[0] == 'S')
++		{
++			finger->wss.wc = 'S';
++			if (pbeg[1] == '%')
++				finger->wss.val = simple_strtoul(pbeg+2, NULL, 10);
++			else if (pbeg[1] == '*')
++				finger->wss.val = 0;
++			else 
++				finger->wss.val = simple_strtoul(pbeg+1, NULL, 10);
++		}
++		else if (pbeg[0] == 'T')
++		{
++			finger->wss.wc = 'T';
++			if (pbeg[1] == '%')
++				finger->wss.val = simple_strtoul(pbeg+2, NULL, 10);
++			else if (pbeg[1] == '*')
++				finger->wss.val = 0;
++			else 
++				finger->wss.val = simple_strtoul(pbeg+1, NULL, 10);
++		}
++		if (isdigit(pbeg[0]))
++		{
++			finger->wss.wc = 0;
++			finger->wss.val = simple_strtoul(pbeg, NULL, 10);
++		}
++
++		pbeg = pend+1;
++	}
++	pend = osf_strchr(pbeg, OSFPDEL);
++	if (pend)
++	{
++		*pend = '\0';
++		finger->ttl = simple_strtoul(pbeg, NULL, 10);
++		pbeg = pend+1;
++	}
++	pend = osf_strchr(pbeg, OSFPDEL);
++	if (pend)
++	{
++		*pend = '\0';
++		finger->df = simple_strtoul(pbeg, NULL, 10);
++		pbeg = pend+1;
++	}
++	pend = osf_strchr(pbeg, OSFPDEL);
++	if (pend)
++	{
++		*pend = '\0';
++		finger->ss = simple_strtoul(pbeg, NULL, 10);
++		pbeg = pend+1;
++	}
++
++	pend = osf_strchr(pbeg, OSFPDEL);
++	if (pend)
++	{
++		*pend = '\0';
++		cnt = snprintf(obuf, sizeof(obuf), "%s", pbeg);
++		pbeg = pend+1;
++	}
++
++	pend = osf_strchr(pbeg, OSFPDEL);
++	if (pend)
++	{
++		*pend = '\0';
++		if (pbeg[0] == '@' || pbeg[0] == '*')
++			cnt = snprintf(finger->genre, sizeof(finger->genre), "%s", pbeg+1);
++		else
++			cnt = snprintf(finger->genre, sizeof(finger->genre), "%s", pbeg);
++		pbeg = pend+1;
++	}
++	
++	pend = osf_strchr(pbeg, OSFPDEL);
++	if (pend)
++	{
++		*pend = '\0';
++		cnt = snprintf(finger->version, sizeof(finger->version), "%s", pbeg);
++		pbeg = pend+1;
++	}
++	
++	pend = osf_strchr(pbeg, OSFPDEL);
++	if (pend)
++	{
++		*pend = '\0';
++		cnt = snprintf(finger->subtype, sizeof(finger->subtype), "%s", pbeg);
++		pbeg = pend+1;
++	}
++
++	cnt = snprintf(finger->details, 
++			((count - (pbeg - buffer)+1) > MAXDETLEN)?MAXDETLEN:(count - (pbeg - buffer)+1), 
++			"%s", pbeg);
++	
++	log("%s - %s[%s] : %s\n", 
++		finger->genre, finger->version,
++		finger->subtype, finger->details);
++	
++	osf_parse_opt(finger->opt, &finger->opt_num, obuf, sizeof(obuf));
++	
++
++	write_lock_bh(&osf_lock);
++	list_add(&finger->flist, &finger_list);
++	write_unlock_bh(&osf_lock);
++
++	return count;
++}
++
++static int __init osf_init(void)
++{
++	int err;
++	struct proc_dir_entry *p;
++
++	log("Startng OS fingerprint target module.\n");
++
++	INIT_LIST_HEAD(&finger_list);
++	
++	err = ipt_register_target(&ipt_osf_reg);
++	if (err)
++	{
++		log("Failed to register OS fingerprint target module.\n");
++		return -ENXIO;
++	}
++
++	p = create_proc_entry("sys/net/ipv4/OSF", S_IFREG | 0644, NULL);
++	if (!p)
++	{
++		ipt_unregister_target(&ipt_osf_reg);
++		return -ENXIO;
++	}
++
++	p->write_proc = osf_proc_write;
++	p->read_proc  = osf_proc_read;
++
++	return 0;
++}
++
++static void __exit osf_fini(void)
++{
++	struct list_head *ent, *n;
++	struct osf_finger *f;
++	
++	remove_proc_entry("sys/net/ipv4/OSF", NULL);
++	ipt_unregister_target(&ipt_osf_reg);
++
++	list_for_each_safe(ent, n, &finger_list)
++	{
++		f = list_entry(ent, struct osf_finger, flist);
++		list_del(&f->flist);
++		finger_free(f);
++	}
++	
++	log("OS fingerprint target module finished.\n");
++}
++
++module_init(osf_init);
++module_exit(osf_fini);
++
++MODULE_LICENSE("GPL");
++MODULE_AUTHOR("Evgeniy Polyakov <[email protected]>");
++MODULE_DESCRIPTION("Passive OS fingerprint target module");
++
+--- /dev/null	Thu Oct 30 21:31:23 2003
++++ linux/include/linux/netfilter_ipv4/ipt_OSF.h	Sun Nov 23 20:55:30 2003
+@@ -0,0 +1,30 @@
++/*
++ * ipt_OSF.h
++ *
++ * Copyright (c) 2003 Evgeniy Polyakov <[email protected]>
++ *
++ *
++ * This program is free software; you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation; either version 2 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
++ */
++
++#ifndef _IPT_OSF_H
++#define _IPT_OSF_H
++
++struct ipt_osf_info
++{
++	int unused;
++};
++
++#endif /* _IPT_OSF_H */
userspace/extensions/libipt_OSF.c new file +77 -0

77 lines not on this page · raw message

#1 lore raw
Quoted 3 lines · Evgeniy Polyakov

New target which trying to determine(by passive fingerprinting) remote OS by set of parameters from initial SYN packet which was sent to us.

why an additional target? I don't think it's a good idea to copy+paste all that code.

You could maybe add a '--log' option to the match or whatever... but I really don't think it's a good idea to have the same code replicated as match and as target.

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
#2 lore raw

On Mon, 24 Nov 2003 11:18:06 +0100
Harald Welte <[email protected]> wrote:

Hi, Harald.

Quoted 11 lines · Evgeniy Polyakov
Quoted 3 lines

New target which trying to determine(by passive fingerprinting) remote OS by set of parameters from initial SYN packet which was sent to us.

why an additional target? I don't think it's a good idea to copy+paste all that code.

You could maybe add a '--log' option to the match or whatever... but I really don't think it's a good idea to have the same code replicated as match and as target.

Yep, but this target was created for convenient logging.
For example, if we only want to know, what OSes connecting to our server. And we can't use match, since we don't know in advance, what OS will connect to us. So we must enter --genre Linux, --genre OpenBSD, --genre AIX and so on...

Or do you propose new option for OSF match( --log), that will make OSF logs all corresponding fingerprints even if they will not match desired genre? That is defenitely good idea.

Quoted 3 lines
Signature · 2 lines
- Harald Welte <[email protected]>            
http://www.netfilter.org/

Evgeniy Polyakov ( s0mbre )

#3 lore raw
In reply to Harald Welte

On Mon, 24 Nov 2003 11:18:06 +0100
Harald Welte <[email protected]> wrote:

Hi, Harald.

Quoted 3 lines

You could maybe add a '--log' option to the match or whatever... but I really don't think it's a good idea to have the same code replicated as match and as target.

Here is patch.

It adds:
- new parameter for matching: --log 1/0.
If present, OSF will log determined genres even if they don't match desired one.
0 - log all determined entries,
1 - only first one.
- new parameter: --smart
if present, OSF will use some smartness to determine remote OS Now only not use TTL( with it far remote machines can be determined).

Please test and apply.

Quoted 3 lines
Signature · 2 lines
- Harald Welte <[email protected]>            
http://www.netfilter.org/

Evgeniy Polyakov ( s0mbre )

patch-o-matic/base/osf.patch +74 -33
@@ -1,6 +1,6 @@
---- linux-2.4/net/ipv4/netfilter/ipt_osf.c.orig	2002-08-31 03:31:37.000000000 +0400
-+++ linux-2.4/net/ipv4/netfilter/ipt_osf.c	2003-09-22 18:03:47.000000000 +0400
-@@ -0,0 +1,699 @@
+--- linux/net/ipv4/netfilter/ipt_osf.c	Thu Oct 30 21:31:23 2003
++++ linux/net/ipv4/netfilter/ipt_osf.c	Mon Nov 24 21:12:37 2003
+@@ -0,0 +1,733 @@
 +/*
 + * ipt_osf.c
 + *
@@ -31,6 +31,8 @@
 + * for his p0f.
 + */
 +
++#include <linux/config.h>
++#include <linux/kernel.h>
 +#include <linux/smp.h>
 +#include <linux/module.h>
 +#include <linux/skbuff.h>
@@ -48,9 +50,9 @@
 +
 +#include <linux/netfilter_ipv4/ip_tables.h>
 +
-+#include <linux/netfilter_ipv4/ipt_osf.h>
++#include <linux/netfilter_ipv4/ipt_osf.h>
 +
-+//#define OSF_DEBUG
++#define OSF_DEBUG
 +
 +#ifdef OSF_DEBUG
 +#define log(x...) 		printk(KERN_INFO "ipt_osf: " x)
@@ -87,20 +90,28 @@
 +	THIS_MODULE 
 +};
 +
++static inline int smart_dec(unsigned long flags, unsigned char ip_ttl, unsigned char f_ttl)
++{
++	if (flags & IPT_OSF_SMART)
++		return 1;
++	else
++		return (ip_ttl == f_ttl);
++}
++
 +static int
 +match(const struct sk_buff *skb,
 +      const struct net_device *in,
 +      const struct net_device *out,
 +      const void *matchinfo,
 +      int offset,
-+      const void *hdr,
-+      u_int16_t datalen,
++      const void *hdr,
++      u_int16_t datalen,
 +      int *hotdrop)
 +{
 +	struct ipt_osf_info *info = (struct ipt_osf_info *)matchinfo;
 +	struct iphdr *ip = skb->nh.iph;
 +	struct tcphdr *tcp;
-+	int fmatch = FMATCH_WRONG;
++	int fmatch = FMATCH_WRONG, fcount = 0;
 +	unsigned long totlen, optsize = 0, window;
 +	unsigned char df, *optp = NULL, *_optp = NULL;
 +	char check_WSS = 0;
@@ -114,6 +125,8 @@
 +
 +	if (!tcp->syn)
 +		return 0;
++	else if (tcp->ack)
++		return 0;
 +	
 +	totlen = ntohs(ip->tot_len);
 +	df = ((ntohs(ip->frag_off) & IP_DF)?1:0);
@@ -134,15 +147,15 @@
 +	list_for_each(ent, &finger_list)
 +	{
 +		f = list_entry(ent, struct osf_finger, flist);
-+		
-+		if (strcmp(info->genre, f->genre)) 
++	
++		if (!(info->flags & IPT_OSF_LOG) && strcmp(info->genre, f->genre)) 
 +			continue;
 +
 +		optp = _optp;
++		fmatch = FMATCH_WRONG;
 +
-+		if (	ip->ttl == f->ttl &&
-+			totlen	== f->ss &&
-+			df	== f->df)
++		if (totlen == f->ss && df == f->df && 
++			smart_dec(info->flags, ip->ttl, f->ttl))
 +		{
 +			unsigned long foptsize;
 +			int optnum;
@@ -178,7 +191,11 @@
 +			{
 +				fmatch = FMATCH_OK;
 +				loga("\tYEP : matching without options.\n");
-+				break;
++				if ((info->flags & IPT_OSF_LOG) && 
++					info->loglevel == IPT_OSF_LOGLEVEL_FIRST)
++					break;
++				else
++					continue;
 +			}
 +			
 +
@@ -251,16 +268,38 @@
 +
 +			if (fmatch == FMATCH_OK)
 +			{
-+
-+				log("genre %s[%25s]: ttl=%d, size=%lu, df=%d, "
-+					"check_WSS=%d, win=%lu, optsize=%lu:\n", 
-+					f->genre, f->details, 
-+					ip->ttl, totlen, df, 
-+					check_WSS, window, optsize);
-+				break;
++				fcount++;
++				log("%s [%s]: %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u\n", 
++					f->genre, f->details,
++					NIPQUAD(ip->saddr), ntohs(tcp->source),
++					NIPQUAD(ip->daddr), ntohs(tcp->dest));
++				if ((info->flags & IPT_OSF_LOG) && 
++					info->loglevel == IPT_OSF_LOGLEVEL_FIRST)
++					break;
 +			}
 +		}
 +	}
++	if (!fcount && (info->flags & IPT_OSF_LOG))
++	{
++		log("Unknown: %lu:%d:%d:%lu:", window, ip->ttl, df, totlen);
++		if (optp)
++		{
++			unsigned char opt[4 * 15 - sizeof(struct tcphdr)];
++			unsigned int i, optsize;
++
++			optsize = tcp->doff * 4 - sizeof(struct tcphdr);
++			if (skb_copy_bits(skb, ip->ihl*4 + sizeof(struct tcphdr),
++					  opt, optsize) < 0)
++				loga("TRUNCATED");
++			else
++				for (i = 0; i < optsize; i++)
++					loga("%02X", opt[i]);
++			
++		}  
++		loga(" %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u\n", 
++			NIPQUAD(ip->saddr), ntohs(tcp->source),
++			NIPQUAD(ip->daddr), ntohs(tcp->dest));
++	}
 +	read_unlock(&osf_lock);
 +
 +	return (fmatch == FMATCH_OK)?1:0;
@@ -293,7 +332,7 @@
 +	return tmp;
 +}
 +
-+static struct osf_finger * finger_alloc()
++static struct osf_finger * finger_alloc(void)
 +{
 +	struct osf_finger *f;
 +
@@ -440,10 +479,6 @@
 +		opt[*optnum].wc.wc 	= wc;
 +		opt[*optnum].wc.val	= val;
 +
-+		log("opt %2d: kind=%2d, length=%2d, wc.wc=%d, wc.val=%5lu\n",
-+			*optnum, opt[*optnum].kind, opt[*optnum].length, 
-+			opt[*optnum].wc.wc, opt[*optnum].wc.val);
-+		
 +		(*optnum)++;
 +	}
 +}
@@ -462,8 +497,7 @@
 +	{
 +		f = list_entry(ent, struct osf_finger, flist);
 +
-+		log("%s - %s: ttl=%d, wss=%c%lu, df=%d, size=%lu",
-+			f->genre, f->details, f->ttl, (f->wss.wc)?f->wss.wc:' ', f->wss.val, f->df, f->ss);
++		log("%s [%s]", f->genre, f->details);
 +		
 +		count += sprintf(buf+count, "%s - %s[%s] : %s", 
 +					f->genre, f->version,
@@ -641,7 +675,7 @@
 +	
 +
 +	write_lock_bh(&osf_lock);
-+	list_add(&finger->flist, &finger_list);
++	list_add_tail(&finger->flist, &finger_list);
 +	write_unlock_bh(&osf_lock);
 +
 +	return count;
@@ -700,9 +734,9 @@
 +MODULE_LICENSE("GPL");
 +MODULE_AUTHOR("Evgeniy Polyakov <[email protected]>");
 +MODULE_DESCRIPTION("Passive OS fingerprint matching.");
---- linux-2.4.22/include/linux/netfilter_ipv4/ipt_osf.h.orig	2002-08-31 03:31:37.000000000 +0400
-+++ linux-2.4.22/include/linux/netfilter_ipv4/ipt_osf.h	2003-09-22 16:15:13.000000000 +0400
-@@ -0,0 +1,121 @@
+--- linux/include/linux/netfilter_ipv4/ipt_osf.h 	Thu Oct 30 21:31:23 2003
++++ linux/include/linux/netfilter_ipv4/ipt_osf.h	Mon Nov 24 18:33:42 2003
+@@ -0,0 +1,130 @@
 +/*
 + * ipt_osf.h
 + *
@@ -730,12 +764,21 @@
 +#define MAXGENRELEN		32
 +#define MAXDETLEN		64
 +
++#define IPT_OSF_GENRE		1
++#define IPT_OSF_SMART		2
++#define IPT_OSF_LOG		4
++
++#define IPT_OSF_LOGLEVEL_ALL		0
++#define IPT_OSF_LOGLEVEL_FIRST	1
++
 +#include <linux/list.h>
 +
 +struct ipt_osf_info
 +{
 +	char 			genre[MAXGENRELEN];
 +	int			len;
++	unsigned long		flags;
++	int			loglevel;
 +	int			invert; /* UNSUPPORTED */
 +};
 +
@@ -824,4 +867,3 @@
 +#endif /* __KERNEL__ */
 +
 +#endif /* _IPT_OSF_H */
-+
userspace/extensions/libipt_osf.c +28 -7
@@ -31,18 +31,26 @@
 #include <ctype.h>
 
 #include <iptables.h>
-#include <linux/netfilter_ipv4/ipt_osf.h>
+#include <linux/netfilter_ipv4/ipt_osf.h>
+
+#define IPTABLES_VERSION	"1.2.6a" /* It looks like FIXME */
 
 static void help(void)
 {
 	printf("OS fingerprint match v%s options:\n"
-		"  --genre [!] string          Match a OS genre bypassive fingerprinting.\n",
+		"--genre [!] string	Match a OS genre by passive fingerprinting.\n"
+		"--smart		Use some smart extensions to determine OS (do not use TTL).\n"
+		"--log level		Log all(or only first) determined genres even if "
+					"they do not match desired one. "
+					"Level may be 0(all) or 1(only first entry).\n",
 		IPTABLES_VERSION);
 }
 
 
 static struct option opts[] = {
-	{ .name = "genre",     .has_arg = 1, .flag = 0, .val = '1' },
+	{ .name = "genre",	.has_arg = 1, .flag = 0, .val = '1' },
+	{ .name = "smart",	.has_arg = 0, .flag = 0, .val = '2' },
+	{ .name = "log",	.has_arg = 1, .flag = 0, .val = '3' },
 	{ .name = 0 }
 };
 
@@ -71,15 +79,28 @@
 	
 	switch(c) 
 	{
-		case '1':
-			if (*flags)
-				exit_error(PARAMETER_PROBLEM, "Can't specify multiple strings");
+		case '1': /* --genre */
+			if (*flags & IPT_OSF_GENRE)
+				exit_error(PARAMETER_PROBLEM, "Can't specify multiple genre parameter");
 			check_inverse(optarg, &invert, &optind, 0);
 			parse_string(argv[optind-1], info);
 			if (invert)
 				info->invert = 1;
 			info->len=strlen((char *)info->genre);
-			*flags = 1;
+			*flags |= IPT_OSF_GENRE;
+			break;
+		case '2': /* --smart */
+			if (*flags & IPT_OSF_SMART)
+				exit_error(PARAMETER_PROBLEM, "Can't specify multiple smart parameter");
+			*flags |= IPT_OSF_SMART;
+			info->flags |= IPT_OSF_SMART;
+			break;
+		case '3': /* --log */
+			if (*flags & IPT_OSF_LOG)
+				exit_error(PARAMETER_PROBLEM, "Can't specify multiple log parameter");
+			*flags |= IPT_OSF_LOG;
+			info->loglevel = atoi(argv[optind-1]);
+			info->flags |= IPT_OSF_LOG;
 			break;
 		default:
 			return 0;
#4 lore raw

Hi, Harald.

Quoted 3 lines
Quoted 3 lines

You could maybe add a '--log' option to the match or whatever... but I really don't think it's a good idea to have the same code replicated as match and as target.

Here is new patchset.
Patches were made against previous patchset applied.

It adds:

revision 1.9
date: 2003/11/26 01:00:02; author: s0mbre; state: Exp; lines: +3 -2 Added hops-to-source destination logging.
----------------------------
revision 1.8
date: 2003/11/26 00:44:02; author: s0mbre; state: Exp; lines: +21 -3 Extended ``smartness'':
if source address is in our local network, than check initial TTL, else do not use TTL.
----------------------------
revision 1.7
date: 2003/11/25 23:48:28; author: s0mbre; state: Exp; lines: +26 -10 Fixed various bugs in option processing.
Added '%' handling in WSS (was broken in fingerprints loading part).

Please test and apply.

Quoted 3 lines
Quoted 3 lines
Signature · 2 lines
- Harald Welte <[email protected]>            
http://www.netfilter.org/

Evgeniy Polyakov ( s0mbre )

patch-o-matic/base/osf.patch +59 -23
@@ -1,6 +1,6 @@
 --- linux/net/ipv4/netfilter/ipt_osf.c	Thu Oct 30 21:31:23 2003
-+++ linux/net/ipv4/netfilter/ipt_osf.c	Mon Nov 24 21:12:37 2003
-@@ -0,0 +1,733 @@
++++ linux/net/ipv4/netfilter/ipt_osf.c	Wed Nov 26 04:03:49 2003
+@@ -0,0 +1,768 @@
 +/*
 + * ipt_osf.c
 + *
@@ -44,6 +44,7 @@
 +#include <linux/spinlock.h>
 +#include <linux/ctype.h>
 +#include <linux/list.h>
++#include <linux/inetdevice.h>
 +
 +#include <net/sock.h>
 +#include <net/ip.h>
@@ -73,9 +74,10 @@
 +
 +static rwlock_t osf_lock = RW_LOCK_UNLOCKED;
 +static struct list_head	finger_list;	
-+
 +static int match(const struct sk_buff *, const struct net_device *, const struct net_device *,
-+		      const void *, int, const void *, u_int16_t, int *);
++		      const void *, int, 
++		      const void *, u_int16_t, 
++		      int *);
 +static int checkentry(const char *, const struct ipt_ip *, void *,
 +		           unsigned int, unsigned int);
 +
@@ -89,12 +91,29 @@
 +	THIS_MODULE 
 +};
 +
-+static inline int smart_dec(unsigned long flags, unsigned char ip_ttl, unsigned char f_ttl)
++static inline int smart_dec(const struct sk_buff *skb, unsigned long flags, unsigned char f_ttl)
 +{
++	struct iphdr *ip = skb->nh.iph;
++
 +	if (flags & IPT_OSF_SMART)
++	{
++		struct in_device *in_dev = in_dev_get(skb->dev);
++
++		for_ifa(in_dev)
++		{
++			if (inet_ifa_match(ip->saddr, ifa))
++			{
++				in_dev_put(in_dev);
++				return (ip->ttl == f_ttl);
++			}
++		}
++		endfor_ifa(in_dev);
++		
++		in_dev_put(in_dev);
 +		return 1;
++	}
 +	else
-+		return (ip_ttl == f_ttl);
++		return (ip->ttl == f_ttl);
 +}
 +
 +static int
@@ -154,7 +173,7 @@
 +		fmatch = FMATCH_WRONG;
 +
 +		if (totlen == f->ss && df == f->df && 
-+			smart_dec(info->flags, ip->ttl, f->ttl))
++			smart_dec(skb, info->flags, f->ttl))
 +		{
 +			unsigned long foptsize;
 +			int optnum;
@@ -215,17 +234,27 @@
 +						/* Skip kind and length fields*/
 +						optp += 2; 
 +
-+						if (f->opt[optnum].wc.wc != 0)
++						if (f->opt[optnum].wc.val != 0)
 +						{
 +							unsigned long tmp = 0;
 +							
 +							/* Hmmm... It looks a bit ugly. :) */
-+							memcpy(&tmp, &f->opt[optnum].wc.val, 
++							memcpy(&tmp, optp, 
 +								(len > sizeof(unsigned long)?
 +								 	sizeof(unsigned long):len));
-+
-+							tmp = ntohl(tmp);
-+							if (tmp != f->opt[optnum].wc.val)
++							/* 2 + 2: optlen(2 bytes) + 
++							 * 	kind(1 byte) + length(1 byte) */
++							if (len == 4) 
++								tmp = ntohs(tmp);
++							else
++								tmp = ntohl(tmp);
++
++							if (f->opt[optnum].wc.wc == '%')
++							{
++								if ((tmp % f->opt[optnum].wc.val) != 0)
++									fmatch = FMATCH_OPT_WRONG;
++							}
++							else if (tmp != f->opt[optnum].wc.val)
 +								fmatch = FMATCH_OPT_WRONG;
 +						}
 +					}
@@ -246,7 +275,7 @@
 +				switch (check_WSS)
 +				{
 +					case 0:
-+						if (window == f->wss.val)
++						if (f->wss.val == 0 || window == f->wss.val)
 +							fmatch = FMATCH_OK;
 +						break;
 +					case 1: /* MSS */
@@ -254,11 +283,11 @@
 +							fmatch = FMATCH_OK;
 +						break;
 +					case 2: /* MTU */
-+						if (window == f->wss.val*(mss+40))
++					if (window == f->wss.val*(mss+40))
 +							fmatch = FMATCH_OK;
 +						break;
 +					case 3: /* MOD */
-+						if (window % f->wss.val == 0)
++						if ((window % f->wss.val) == 0)
 +							fmatch = FMATCH_OK;
 +						break;
 +				}
@@ -268,10 +297,12 @@
 +			if (fmatch == FMATCH_OK)
 +			{
 +				fcount++;
-+				log("%s [%s]: %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u\n", 
-+					f->genre, f->details,
++				log("%s [%s:%s:%s] : %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u hops=%d\n", 
++					f->genre, f->version,
++					f->subtype, f->details,
 +					NIPQUAD(ip->saddr), ntohs(tcp->source),
-+					NIPQUAD(ip->daddr), ntohs(tcp->dest));
++					NIPQUAD(ip->daddr), ntohs(tcp->dest),
++					f->ttl - ip->ttl);
 +				if ((info->flags & IPT_OSF_LOG) && 
 +					info->loglevel == IPT_OSF_LOGLEVEL_FIRST)
 +					break;
@@ -597,7 +628,12 @@
 +			else 
 +				finger->wss.val = simple_strtoul(pbeg+1, NULL, 10);
 +		}
-+		if (isdigit(pbeg[0]))
++		else if (pbeg[0] == '%')
++		{
++			finger->wss.wc = '%';
++			finger->wss.val = simple_strtoul(pbeg+1, NULL, 10);
++		}
++		else if (isdigit(pbeg[0]))
 +		{
 +			finger->wss.wc = 0;
 +			finger->wss.val = simple_strtoul(pbeg, NULL, 10);
@@ -733,8 +769,8 @@
 +MODULE_LICENSE("GPL");
 +MODULE_AUTHOR("Evgeniy Polyakov <[email protected]>");
 +MODULE_DESCRIPTION("Passive OS fingerprint matching.");
---- linux/include/linux/netfilter_ipv4/ipt_osf.h 	Thu Oct 30 21:31:23 2003
-+++ linux/include/linux/netfilter_ipv4/ipt_osf.h	Mon Nov 24 18:33:42 2003
+--- linux/inlude/linux/netfilter_ipv4/ipt_osf.h	Thu Oct 30 21:31:23 2003
++++ linux/inlude/linux/netfilter_ipv4/ipt_osf.h	Mon Nov 24 18:33:42 2003
 @@ -0,0 +1,130 @@
 +/*
 + * ipt_osf.h
@@ -764,10 +800,10 @@
 +#define MAXDETLEN		64
 +
 +#define IPT_OSF_GENRE		1
-+#define IPT_OSF_SMART		2
++#define	IPT_OSF_SMART		2
 +#define IPT_OSF_LOG		4
 +
-+#define IPT_OSF_LOGLEVEL_ALL		0
++#define IPT_OSF_LOGLEVEL_ALL	0
 +#define IPT_OSF_LOGLEVEL_FIRST	1
 +
 +#include <linux/list.h>
#5 lore raw
In reply to Evgeniy Polyakov
Quoted 10 lines · Evgeniy Polyakov

On Mon, 24 Nov 2003 11:18:06 +0100
Harald Welte <[email protected]> wrote:

Hi, Harald.

Quoted 3 lines

You could maybe add a '--log' option to the match or whatever... but I really don't think it's a good idea to have the same code replicated as match and as target.

Here is patch.

Ok, I'll apply it to CVS.

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
#6 lore raw
Quoted 2 lines · On Wed, 26 Nov 2003 20:44:54 +0100 Harald Welte <[email protected]> wrote:

Ok, I'll apply it to CVS.

Thank you.

Here is third patchset on top of previous two.
It adds:

Some "smart" hardware/software changes MSS while doing NAT/DSL, so make additional compare with "good" MSS value(predefined 1460).
----------------------------
Whitespace cleanup.
----------------------------
Packets from outside(loopback is outside too) may have equal to fingerprint ttl, not necessarily lesser.

If we have timestamp option, do not compare it with one from fingerprint.(For now it is always 0).

Please test and apply.

Quoted 3 lines
Signature · 2 lines
- Harald Welte <[email protected]>            
http://www.netfilter.org/

Evgeniy Polyakov ( s0mbre )

#7 lore raw
Quoted 9 lines
Quoted 2 lines · On Wed, 26 Nov 2003 20:44:54 +0100 Harald Welte <[email protected]> wrote:

Ok, I'll apply it to CVS.

Thank you.

Here is third patchset on top of previous two.

Attached.

Quoted 2 lines

Please test and apply.

Evgeniy Polyakov ( s0mbre )

patch-o-matic/base/osf.patch +27 -8
@@ -1,6 +1,6 @@
 --- linux/net/ipv4/netfilter/ipt_osf.c	Thu Oct 30 21:31:23 2003
-+++ linux/net/ipv4/netfilter/ipt_osf.c	Wed Nov 26 04:03:49 2003
-@@ -0,0 +1,768 @@
++++ linux/net/ipv4/netfilter/ipt_osf.c	Thu Nov 27 04:14:11 2003
+@@ -0,0 +1,787 @@
 +/*
 + * ipt_osf.c
 + *
@@ -110,7 +110,7 @@
 +		endfor_ifa(in_dev);
 +		
 +		in_dev_put(in_dev);
-+		return 1;
++		return (ip->ttl <= f_ttl);
 +	}
 +	else
 +		return (ip->ttl == f_ttl);
@@ -219,15 +219,30 @@
 +
 +			for (optnum=0; optnum<f->opt_num; ++optnum)
 +			{
-+				if (f->opt[optnum].kind == (*optp))
++				if (f->opt[optnum].kind == (*optp)) 
 +				{
 +					unsigned char len = f->opt[optnum].length;
 +					unsigned char *optend = optp + len;
++					int loop_cont = 0;
 +
 +					fmatch = FMATCH_OK;
 +
-+					if (*optp == OSFOPT_MSS) /* MSS */
-+						mss = ntohs(*(unsigned short *)(optp+2));
++
++					switch (*optp)
++					{
++						case OSFOPT_MSS:
++							mss = ntohs(*(unsigned short *)(optp+2));
++							break;
++						case OSFOPT_TS:
++							loop_cont = 1;
++							break;
++					}
++					
++					if (loop_cont)
++					{
++						optp = optend;
++						continue;
++					}
 +					
 +					if (len != 1)
 +					{
@@ -279,11 +294,15 @@
 +							fmatch = FMATCH_OK;
 +						break;
 +					case 1: /* MSS */
-+						if (window == f->wss.val*mss)
++/* Lurked in OpenBSD */
++#define SMART_MSS	1460
++						if (window == f->wss.val*mss || 
++							window == f->wss.val*SMART_MSS)
 +							fmatch = FMATCH_OK;
 +						break;
 +					case 2: /* MTU */
-+					if (window == f->wss.val*(mss+40))
++						if (window == f->wss.val*(mss+40) ||
++							window == f->wss.val*(SMART_MSS+40))
 +							fmatch = FMATCH_OK;
 +						break;
 +					case 3: /* MOD */
#8 lore raw

And the fourth patch on top of previous 3:
right comments.

Kudos to Michal Zalewski and Mike Frantzen about SMART_MSS idea.

Evgeniy Polyakov ( s0mbre )

patch-o-matic/base/osf.patch +3 -3
@@ -294,7 +294,7 @@
 +							fmatch = FMATCH_OK;
 +						break;
 +					case 1: /* MSS */
-+/* Lurked in OpenBSD */
++/* Lurked in OpenBSD.  Idea of Michal Zalewski */
 +#define SMART_MSS	1460
 +						if (window == f->wss.val*mss || 
 +							window == f->wss.val*SMART_MSS)
@@ -788,8 +788,8 @@
 +MODULE_LICENSE("GPL");
 +MODULE_AUTHOR("Evgeniy Polyakov <[email protected]>");
 +MODULE_DESCRIPTION("Passive OS fingerprint matching.");
---- linux/inlude/linux/netfilter_ipv4/ipt_osf.h	Thu Oct 30 21:31:23 2003
-+++ linux/inlude/linux/netfilter_ipv4/ipt_osf.h	Mon Nov 24 18:33:42 2003
+--- linux/include/linux/netfilter_ipv4/ipt_osf.h	Thu Oct 30 21:31:23 2003
++++ linux/include/linux/netfilter_ipv4/ipt_osf.h	Mon Nov 24 18:33:42 2003
 @@ -0,0 +1,130 @@
 +/*
 + * ipt_osf.h