Passive OS fingerprint matching module update. Dynamic fingerprint loading.
PATCH 1/1 Passive OS fingerprint matching module update. Dynamic fingerprint loading.
Hello.
Please see and comments attached patch against initial code imported to netfilter CVS by Harald Welte <[email protected]>. This patch includes patch from Piotr Gasid'o<[email protected]> to fix multiple -m matching with OSF, wich
was posted to mailing list yesterday, but contains a typo.
This patch also adds possibility to dynamically load fingerprints(for complete list of supported fingerprints please see
http://www.openbsd.org/cgi-bin/cvsweb/src/etc/pf.os and
http://lcamtuf.coredump.cx/p0f.shtml) through /proc interface.
Examples:
loading new rule:
echo "16384:64:0:44:M512:.:AIX:4.3.2 and earlier">/proc/sys/net/ipv4/osf For documentation about this magic string please see p0f.fp in p0f ((c) Michal Zalewski ([email protected])) distribution(http://lcamtuf.coredump.cx/p0f.shtml)
reading loaded rules(not in loading format, but for info about genries/details only):
cat /proc/sys/net/ipv4/osf
All rules are added to linked list(with proper locking) without any check, if this rule already exists.
One can drop whole fingerprint table with the following command:
echo -en FLUSH > /proc/sys/net/ipv4/osf
For loading from file one can use attached script(osf_load.sh):osf_load.sh osf.fp /proc/sys/net/ipv4/osf
Any feedback is allways appreciated.
Evgeniy Polyakov
Index: ipt_osf.c
===================================================================
RCS file: /usr/local/cvsroot/osf/ipt_osf.c,v
retrieving revision 1.1.1.1
ipt_osf.c +447 -208
@@ -33,6 +33,12 @@#include <linux/skbuff.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>
@@ -41,189 +47,41 @@#include "ipt_osf.h" +//#define OSF_DEBUG +#ifdef OSF_DEBUG -#define log(x...) printk(KERN_ERR "ipt_osf: " x) -#define loga(x...) printk(x) +#define log(x...) printk(KERN_ERR "ipt_osf: " x) +#define loga(x...) printk(x)#else -#define log(x...) -#define log(x...) +#define log(x...) do {} while(0) +#define loga(x...) do {} while(0)#endif #define FMATCH_WRONG 0#define FMATCH_OK 1#define FMATCH_OPT_WRONG 2 -static struct osf_finger fingers[] = -{ -/*----------------- Linux ------------------- */ - - {{0 ,512 },64 ,0 ,44 ,"Linux" ,"2.0.3x" , -1 , {{2 ,4 }, } }, - {{0 ,16384 } ,64 ,0 ,44 ,"Linux" ,"2.0.3x" , -1 , {{2 ,4 }, } }, - {{0 ,5440 },64 ,1 ,60 ,"Linux" ,"(Google crawlbot)" , -5 , {{2 ,4 ,{'W' ,1360 }}, {4 ,2 }, {8 ,10 }, {1 ,1 }, {3 ,3 }} }, - {{'S' ,3 },64 ,1 ,60 ,"Linux" ,"2.4.18 and newer" , -5 , {{2 ,4 }, {4 ,2 }, {8 ,10 }, {1 ,1 }, {3 ,3 }} }, - {{'S' ,4 },64 ,1 ,60 ,"Linux" ,"2.4" , -5 , {{2 ,4 }, {4 ,2 }, {8 ,10 }, {1 ,1 }, {3 ,3 }} }, - {{'S' ,3 },64 ,1 ,60 ,"Linux" ,"2.5 (newer)" , -5 , {{2 ,4 }, {4 ,2 }, {8 ,10 }, {1 ,1 }, {3 ,3 }} },/* W1 - what is it ??? */ - {{'S' ,4 },64 ,1 ,60 ,"Linux" ,"2.5 (sometimes 2.4)" , -5 , {{2 ,4 }, {4 ,2 }, {8 ,10 }, {1 ,1 }, {3 ,3 }} },/* ??? */ - - {{'S' ,20 },64 ,1 ,60 ,"Linux" ,"2.2.20 and newer" , -5 , {{2 ,4 }, {4 ,2 }, {8 ,10 }, {1 ,1 }, {3 ,3 }} }, - {{'S' ,22 },64 ,1 ,60 ,"Linux" ,"2.2" , -5 , {{2 ,4 }, {4 ,2 }, {8 ,10 }, {1 ,1 }, {3 ,3 }} }, - -/* This needs to be investigated. On some systems, WSS -* is selected as a multiple of MTU instead of MSS. I got -* many submissions for this for many late versions of 2.4, -*/ - - {{'T' ,4 },64 ,1 ,60 ,"Linux" ,"late 2.4 (uncommon)" , -5 , {{2 ,4 ,{0 ,1412 }}, {4 ,2 }, {8 ,10 }, {1 ,1 }, {3 ,3 }} }, - -/* That's quite stupid, but happens. The WSS is a multiplier of -* MSS, but not that MSS - the default ethernet MSS instead. It -* is believed to be related to having two network cards in certain -* configurations, -*/ - -/* Maybe PIX? */ - {{0 ,5840 },64 ,1 ,60 ,"Linux" ,"2.4 (1) (NAT or snafu)" , -5 , {{2 ,4 }, {4 ,2 }, {8 ,10 }, {1 ,1 }, {3 ,3 }} }, - {{0 ,5840 },64 ,1 ,60 ,"Linux" ,"2.4 (2) (NAT or snafu)" , -5 , {{2 ,4 }, {4 ,2 }, {8 ,10 }, {1 ,1 }, {3 ,3 , {0 ,1 }}} }, - -/* Opera visitors, */ - {{0 ,32767 },64 ,1 ,60 ,"Linux" ,"2.4 (Opera?)" , -5 , {{2 ,4 }, {4 ,2 }, {8 ,10 }, {1 ,1 }, {3 ,3 }} }, - {{0 ,16384 },64 ,1 ,60 ,"Linux" ,"2.2 (Opera?)" , -5 , {{2 ,4 }, {4 ,2 }, {8 ,10 }, {1 ,1 }, {3 ,3 }} }, - -/* This happens only over loopback, -* {{'S', 8}, 64, 1, 60, "Linux", "2.2 (local)", -5, {{2,4}, {4, 2}, {8,10}, {1,1}, {3,3}} }, -* Some fairly common mods, -* {{'S', 4}, 64, 1, 52, "Linux", "2.4 w/o timestamps", -6, {{2,4}, {1,1}, {1,1}, {4, 2}, {1,1}, {3,3}} }, -*/ - -/* ----------------- FreeBSD ----------------- */ - - {{0 ,16384 },64 ,1 ,44 ,"FreeBSD" ,"2.0-4.1 (sometimes AIX 4.3)" , -1 , {{2 ,4 }} }, - {{0 ,16384 },64 ,1 ,60 ,"FreeBSD" ,"4.4" , -6 , {{2 ,4 }, {1 ,1 }, {3 ,3 }, {1 ,1 }, {1 ,1 }, {8 ,10 }} }, - {{0 ,1024 },64 ,1 ,60 ,"FreeBSD" ,"4.4" , -6 , {{2 ,4 }, {1 ,1 }, {3 ,3 }, {1 ,1 }, {1 ,1 }, {8 ,10 }} }, - - {{'S' ,0 },64 ,1 ,60 ,"FreeBSD" ,"4.6" , -6 , {{2 ,4 }, {1 ,1 }, {3 ,3 }, {1 ,1 }, {1 ,1 }, {8 ,10 }} }, - - {{0 ,57344 },64 ,1 ,44 ,"FreeBSD" ,"4.6-4.8 (no RFC1323)" , -1 , {{2 ,4 }} }, - {{0 ,57344 },64 ,1 ,60 ,"FreeBSD" ,"4.6-4.8" , -6 , {{2 ,4 }, {1 ,1 }, {3 ,3 }, {1 ,1 }, {1 ,1 }, {8 ,10 }} }, - -/* Power of 2 WSS are also shared by MacOS X 10.2 when DF set */ - {{0 ,32768 },64 ,1 ,60 ,"FreeBSD" ,"4.8-5.0 (or MacOS X 10.2 w/DF)" , -6 , {{2 ,4 }, {1 ,1 }, {3 ,3 }, {1 ,1 }, {1 ,1 }, {8 ,10 }} }, - {{0 ,65535 },64 ,1 ,60 ,"FreeBSD" ,"4.7-5.0 (or MacOS X 10.2 w/DF)" , -6 , {{2 ,4 }, {1 ,1 }, {3 ,3 }, {1 ,1 }, {1 ,1 }, {8 ,10 }} }, - - {{0 ,65535 },64 ,1 ,60 ,"FreeBSD" ,"5.1" , -6 , {{2 ,4 }, {1 ,1 }, {3 ,3 , {0 ,1 }}, {1 ,1 }, {1 ,1 }, {8 ,10 }} }, - -/* ----------------- NetBSD ------------------ */ - - {{0 ,16384 },64 ,0 ,60 ,"NetBSD" ,"1.6" , -6 , {{2 ,4 }, {1 ,1 }, {3 ,3 }, {1 ,1 }, {1 ,1 }, {8 ,10 }} }, - {{0 ,16384 },64 ,1 ,60 ,"NetBSD" ,"1.6 (DF)" , -6 , {{2 ,4 }, {1 ,1 }, {3 ,3 }, {1 ,1 }, {1 ,1 }, {8 ,10 }} }, - {{0 ,16384 },64 ,0 ,60 ,"NetBSD" ,"1.3 (or OpenBSD 2.6)" , -6 , {{2 ,4 }, {1 ,1 }, {3 ,3 }, {1 ,1 }, {1 ,1 }, {8 ,10 }} }, - -/* ----------------- OpenBSD ----------------- */ - - {{0 ,16384 },64 ,1 ,64 ,"OpenBSD" ,"3.0-3.4" , -9 , {{2 ,4 }, {1 ,1 }, {1 ,1 }, {4 ,2 }, {1 ,1 }, {3 ,3 }, {1 ,1 }, {1 ,1 }, {8 ,10 }} }, - {{0 ,57344 },64 ,1 ,64 ,"OpenBSD" ,"3.3-3.4" , -9 , {{2 ,4 }, {1 ,1 }, {1 ,1 }, {4 ,2 }, {1 ,1 }, {3 ,3 }, {1 ,1 }, {1 ,1 }, {8 ,10 }} }, - {{0 ,16384 },64 ,0 ,64 ,"OpenBSD" ,"3.0-3.4 (scrub)" , -9 , {{2 ,4 }, {1 ,1 }, {1 ,1 }, {4 ,2 }, {1 ,1 }, {3 ,3 }, {1 ,1 }, {1 ,1 }, {8 ,10 }} }, - -/* Opera! */ - {{0 ,65535 },64 ,1 ,64 ,"OpenBSD" ,"3.0-3.4 (Opera)" , -9 , {{2 ,4 }, {1 ,1 }, {1 ,1 }, {4 ,2 }, {1 ,1 }, {3 ,3 }, {1 ,1 }, {1 ,1 }, {8 ,10 }} }, +#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 int match (const struct sk_buff *,const struct net_device *,const struct net_device *, +const void *,int ,const void *,u_int16_t ,int *); +static int checkentry (const char *,const struct ipt_ip *,void *, +unsigned int ,unsigned int ); - -/* ----------------- Windows ----------------- */ - -/* Windows 98 had a plenty of signatures depending on -* release, but I don't have all the data. -*/ - - {{'S' ,44 },64 ,1 ,48 ,"Windows" ,"98SE " , -4 , {{1 ,1 }, {1 ,1 }, {4 ,2 }, {2 ,4 }} }, - {{'S' ,6 },128 ,1 ,48 ,"Windows" ,"98 (no sack)" , -1 , {{2 ,4 }} }, - {{0 ,8192 },128 ,1 ,48 ,"Windows" ,"98" , -4 , {{2 ,4 }, {1 ,1 }, {1 ,1 }, {4 ,2 }} }, - {{0 ,37300 },64 ,1 ,48 ,"Windows" ,"98" , -4 , {{2 ,4 }, {1 ,1 }, {1 ,1 }, {4 ,2 }} }, - {{0 ,8192 },128 ,1 ,44 ,"Windows" ,"NT 4.0" , -1 , {{2 ,4 }} }, - - {{'%' ,8192 },128 ,1 ,48 ,"Windows" ,"XP/2000" , -4 , {{2 ,4 }, {1 ,1 }, {1 ,1 }, {4 ,2 }} }, - {{'%' ,8192 },128 ,0 ,48 ,"Windows" ,"XP/2000 (firewalled)" , -4 , {{2 ,4 }, {1 ,1 }, {1 ,1 }, {4 ,2 }} }, - {{0 ,65535 },128 ,1 ,48 ,"Windows" ,"2000 SP4" , -4 , {{2 ,4 }, {1 ,1 }, {1 ,1 }, {4 ,2 }} }, - {{0 ,65535 },128 ,0 ,48 ,"Windows" ,"2000 SP4 (firewalled)" , -4 , {{2 ,4 }, {1 ,1 }, {1 ,1 }, {4 ,2 }} }, - {{'S' ,44 },128 ,1 ,48 ,"Windows" ,"XP or 2000 SP3+ (1)" , -4 , {{2 ,4 }, {1 ,1 }, {1 ,1 }, {4 ,2 }} }, - {{'S' ,44 },128 ,0 ,48 ,"Windows" ,"XP or 2000 SP3+ (1) (firewalled)" , -4 , {{2 ,4 }, {1 ,1 }, {1 ,1 }, {4 ,2 }} }, - {{'S' ,6 },128 ,1 ,48 ,"Windows" ,"XP or 2000 SP3 (2)" , -4 , {{2 ,4 }, {1 ,1 }, {1 ,1 }, {4 ,2 }} }, - {{'S' ,6 },128 ,0 ,48 ,"Windows" ,"XP or 2000 SP3 (2) (firewalled)" , -4 , {{2 ,4 }, {1 ,1 }, {1 ,1 }, {4 ,2 }} }, - -/* This block yet to be verified, */ - {{'S' ,45 },128 ,1 ,48 ,"Windows" ,"XP (3)" , -4 , {{2 ,4 }, {1 ,1 }, {1 ,1 }, {4 ,2 }} }, - {{'S' ,45 },128 ,0 ,48 ,"Windows" ,"XP (3) (firewalled)" , -4 , {{2 ,4 }, {1 ,1 }, {1 ,1 }, {4 ,2 }} }, - {{'S' ,46 },128 ,1 ,48 ,"Windows" ,"XP (4)" , -4 , {{2 ,4 }, {1 ,1 }, {1 ,1 }, {4 ,2 }} }, - {{'S' ,46 },128 ,0 ,48 ,"Windows" ,"XP (4) (firewalled)" , -4 , {{2 ,4 }, {1 ,1 }, {1 ,1 }, {4 ,2 }} }, - {{0 ,32767 },128 ,1 ,52 ,"Windows" ,"NT4" , -6 , {{2 ,4 }, {1 ,1 }, {3 ,3 }, {1 ,1 }, {1 ,1 }, {4 ,2 }} }, - {{0 ,6144 },128 ,1 ,52 ,"Windows" ,"NT4" , -6 , {{2 ,4 }, {1 ,1 }, {3 ,3 }, {1 ,1 }, {1 ,1 }, {4 ,2 }} }, - {{'S' ,45 },128 ,1 ,52 ,"Windows" ,"NT4" , -6 , {{2 ,4 }, {1 ,1 }, {3 ,3 }, {1 ,1 }, {1 ,1 }, {4 ,2 }} }, - - {{0 ,64240 },128 ,0 ,48 ,"Windows" ,"2000/XP (NAT or snafu)" , -4 , {{2 ,4 }, {1 ,1 }, {1 ,1 }, {4 ,2 }} }, - -/* Odds, ends, mods. Advanced Networking Pack turns out to be -* responsible for enabling RFC1323, System Mechanic also messes -* with TTLs and timestamps, -*/ - - {{'*' ,0 },128 ,1 ,64 ,"Windows" ,"2000 SP4 (AdvNetPack) or PalmPC" , -9 , {{2 ,4 }, {1 ,1 }, {3 ,3 , {'W' ,2 }}, {1 ,1 }, {1 ,1 }, {8 ,10 }, {1 ,1 }, {1 ,1 }, {4 ,2 }} }, - {{'S' ,44 },128 ,1 ,64 ,"Windows" ,"XP (AdvNetPack)" , -9 , {{2 ,4 , {0 ,1460 }}, {1 ,1 }, {3 ,3 , {'W' ,0 }}, {1 ,1 }, {1 ,1 }, {8 ,10 }, {1 ,1 }, {1 ,1 }, {4 ,2 }} }, - {{0 ,58944 },64 ,1 ,52 ,"Windows" ,"XP (System Mechanic tuned)" , -6 , {{2 ,4 }, {1 ,1 }, {3 ,3 , {'W' ,2 }}, {1 ,1 }, {1 ,1 }, {4 ,2 }} }, +static struct ipt_match osf_match = +{ + {NULL ,NULL }, +"osf" , + &match, + &checkentry, +NULL , +THIS_MODULE }; static int
@@ -239,10 +97,12 @@struct ipt_osf_info *info = (struct ipt_osf_info *)matchinfo;struct iphdr *ip = skb->nh.iph;struct tcphdr *tcp; -int fsize =sizeof (fingers)/sizeof (struct osf_finger ), i, fmatch =FMATCH_WRONG ; +int fmatch =FMATCH_WRONG ;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;if (!ip || !info)return 0 ;
@@ -267,16 +127,19 @@* only in appropriate part, but here is initial variant, * so will use slow path. */ -for (i=0 ; i<fsize; ++i) +read_lock (&osf_lock); +list_for_each (ent, &finger_list) { -if (strcmp (info->genre, fingers[i].genre)) + f = list_entry(ent, struct osf_finger, flist); + +if (strcmp (info->genre, f->genre))continue ; optp = _optp; -if ( ip->ttl == fingers[i].ttl && - totlen == fingers[i].ss && - df == fingers[i].df) +if ( ip->ttl == f->ttl && + totlen == f->ss && + df == f->df) {unsigned long foptsize;int optnum;
@@ -284,14 +147,14 @@ check_WSS =0 ; -switch (fingers[i].wss.wc) +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 :log ("Wrong fingerprint wss.wc=%c, string=%d\n" , - fingers[i].wss.wc, i); +default :log ("Wrong fingerprint wss.wc=%d, %s - %s\n" , + f->wss.wc, f->genre, f->details); check_WSS =4 ;break ; }
@@ -301,8 +164,8 @@/* Check options */ foptsize =0 ; -for (optnum=0 ; optnum<fingers[i].opt_num; ++optnum) - foptsize += fingers[i].opt[optnum].length; +for (optnum=0 ; optnum<f->opt_num; ++optnum) + foptsize += f->opt[optnum].length;if (foptsize >MAX_IPOPTLEN || optsize >MAX_IPOPTLEN || optsize != foptsize)
@@ -316,16 +179,16 @@ } -for (optnum=0 ; optnum<fingers[i].opt_num; ++optnum) +for (optnum=0 ; optnum<f->opt_num; ++optnum) { -if (fingers[i].opt[optnum].kind == (*optp)) +if (f->opt[optnum].kind == (*optp)) { -unsigned char len = fingers[i].opt[optnum].length; +unsigned char len = f->opt[optnum].length;unsigned char *optend = optp + len; fmatch =FMATCH_OK ; -if (*optp ==2 )/* MSS */ +if (*optp ==OSFOPT_MSS )/* MSS */ mss =ntohs (*(unsigned short *)(optp+2 ));if (len !=1 )
@@ -333,17 +196,17 @@/* Skip kind and length fields*/ optp +=2 ; -if (fingers[i].opt[optnum].wc.wc !=0 ) +if (f->opt[optnum].wc.wc !=0 ) {unsigned long tmp =0 ;/* Hmmm... It looks a bit ugly. :) */ -memcpy (&tmp, &fingers[i].opt[optnum].wc.val, +memcpy (&tmp, &f->opt[optnum].wc.val, (len >sizeof (unsigned long )?sizeof (unsigned long ):len)); tmp =ntohl (tmp); -if (tmp != fingers[i].opt[optnum].wc.val) +if (tmp != f->opt[optnum].wc.val) fmatch =FMATCH_OPT_WRONG ; } }
@@ -364,19 +227,19 @@switch (check_WSS) {case 0 : -if (window == fingers[i].wss.val) +if (window == f->wss.val) fmatch =FMATCH_OK ;break ;case 1 :/* MSS */ -if (window == fingers[i].wss.val*mss) +if (window == f->wss.val*mss) fmatch =FMATCH_OK ;break ;case 2 :/* MTU */ -if (window == fingers[i].wss.val*(mss+40 )) +if (window == f->wss.val*(mss+40 )) fmatch =FMATCH_OK ;break ;case 3 :/* MOD */ -if (window % fingers[i].wss.val ==0 ) +if (window % f->wss.val ==0 ) fmatch =FMATCH_OK ;break ; }
@@ -386,15 +249,16 @@if (fmatch ==FMATCH_OK ) { -log ("genre %s[%25s][%d]: ttl=%d, size=%lu, df=%d, " +log ("genre %s[%25s]: ttl=%d, size=%lu, df=%d, " "check_WSS=%d, win=%lu, optsize=%lu:\n" , - fingers[i].genre, fingers[i].details, i, + f->genre, f->details, ip->ttl, totlen, df, check_WSS, window, optsize);break ; } } } +read_unlock (&osf_lock);return (fmatch ==FMATCH_OK )?1 :0 ; }
@@ -414,25 +278,400 @@return 1 ; } -static struct ipt_match osf_match = -{ - {NULL ,NULL }, -"osf" , - &match, - &checkentry, -NULL , -THIS_MODULE -}; +static struct osf_finger *finger_alloc () +{ +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 =strchr (&obuf[i],OPTDEL ); +if (ptr) + { + *ptr ='\0' ; + ptr++; + i += (int )(ptr-&obuf[i]); + + } +else + i++; +break ; +case 'S' : + op =OSFOPT_SACKP ; + ptr =strchr (&obuf[i],OPTDEL ); +if (ptr) + { + *ptr ='\0' ; + ptr++; + i += (int )(ptr-&obuf[i]); + + } +else + i++; +break ; +case 'T' : + op =OSFOPT_TS ; + ptr =strchr (&obuf[i],OPTDEL ); +if (ptr) + { + *ptr ='\0' ; + ptr++; + i += (int )(ptr-&obuf[i]); + + } +else + i++; +break ; +case 'W' : + op =OSFOPT_WSO ; + ptr =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 =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 =strchr (&obuf[i],OPTDEL ); +if (ptr) + { + *ptr ='\0' ; + ptr++; + i += (int )(ptr-&obuf[i]); + + } +else + i++; +break ; +default : + ptr =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; + +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)++; + } +} + +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: 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); + + count +=sprintf (buf+count,"%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); + +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 quirks[MAXOPTSTRLEN ], 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 ; +list_for_each_safe (ent, n, &finger_list) + { + i++; + finger = list_entry(ent, struct osf_finger, flist); +list_del (&finger->flist); +finger_free (finger); + } + +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 !=7 || i != count) + { +log ("Wrong input line cnt=%d[7], len=%lu[%lu]\n" , + cnt, i, count); +return count; + } + + +memset (quirks,0 ,sizeof (quirks)); +memset (obuf,0 ,sizeof (obuf)); + + finger =finger_alloc (); +if (!finger) + { +log ("Failed to allocate new fingerprint entry.\n" ); +return -ENOMEM ; + } + + pbeg = (char *)buffer; + pend =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 =strchr (pbeg,OSFPDEL ); +if (pend) + { + *pend ='\0' ; + finger->ttl =simple_strtoul (pbeg,NULL ,10 ); + pbeg = pend+1 ; + } + pend =strchr (pbeg,OSFPDEL ); +if (pend) + { + *pend ='\0' ; + finger->df =simple_strtoul (pbeg,NULL ,10 ); + pbeg = pend+1 ; + } + pend =strchr (pbeg,OSFPDEL ); +if (pend) + { + *pend ='\0' ; + finger->ss =simple_strtoul (pbeg,NULL ,10 ); + pbeg = pend+1 ; + } + + pend =strchr (pbeg,OSFPDEL ); +if (pend) + { + *pend ='\0' ; + cnt =snprintf (obuf,sizeof (obuf),"%s" , pbeg); + pbeg = pend+1 ; + } + + pend =strchr (pbeg,OSFPDEL ); +if (pend) + { + *pend ='\0' ; + cnt =snprintf (quirks,sizeof (quirks),"%s" , pbeg); + pbeg = pend+1 ; + } + + pend =strchr (pbeg,OSFPDEL ); +if (pend) + { + *pend ='\0' ; +if (pbeg[0 ] =='@' || pbeg[0 ] =='*' ) + cnt =snprintf (finger->genre, + ((count-(pbeg+1 -buffer)+1 ) >MAXGENRELEN )?MAXGENRELEN :(count-(pbeg+1 -buffer)+1 ), +"%s" , pbeg+1 ); +else + cnt =snprintf (finger->genre, + ((count-(pbeg-buffer)+1 ) >MAXGENRELEN )?MAXGENRELEN :(count-(pbeg-buffer)+1 ), +"%s" , pbeg); + pbeg = pend+1 ; + } + + cnt =snprintf (finger->details, + ((count - (pbeg - buffer)+1 ) >MAXDETLEN )?MAXDETLEN :(count - (pbeg - buffer)+1 ), +"%s" , pbeg); + +log ("%s - %s. ttl=%d, df=%d, size=%lu, wss=[%d, %lu]\n" , + finger->genre, finger->details, + finger->ttl, finger->df, finger->ss, + finger->wss.wc, finger->wss.val); + +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 matching module.\n" ); -return ipt_register_match (&osf_match); + +INIT_LIST_HEAD (&finger_list); + + err =ipt_register_match (&osf_match); +if (err) + { +log ("Failed to register OS fingerprint matching module.\n" ); +return -ENXIO ; + } + + p =create_proc_entry ("sys/net/ipv4/osf" ,S_IFREG |0644 ,NULL ); +if (!p) + { +ipt_unregister_match (&osf_match); +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_match (&osf_match); + +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 matching module finished.\n" ); }
Index: ipt_osf.h
===================================================================
RCS file: /usr/local/cvsroot/osf/ipt_osf.h,v
retrieving revision 1.1.1.1
ipt_osf.h +55 -2
81 lines not on this page · raw message
Index: libipt_osf.c
===================================================================
RCS file: /usr/local/cvsroot/osf/libipt_osf.c,v
retrieving revision 1.1.1.1
libipt_osf.c +18 -13
@@ -33,12 +33,12 @@#include <iptables.h> #include "ipt_osf.h" -#define IPTABLES_VERSION "1.2.8" +#define IPTABLES_VERSION "1.2.8"/* 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" ,IPTABLES_VERSION ); }
@@ -57,7 +57,6 @@static void parse_string (const unsigned char *s,struct ipt_osf_info *info) { -printf ("parse_string: s=%s\n" , s);if (strlen (s) <MAXGENRELEN )strcpy (info->genre, s);else
@@ -71,16 +70,22 @@ struct ipt_entry_match **match) {struct ipt_osf_info *info = (struct ipt_osf_info *)(*match)->data; - -if (*flags) -exit_error (PARAMETER_PROBLEM ,"Can't specify multiple strings" ); - -check_inverse (optarg, &invert, &optind,0 ); -parse_string (optarg, info); -if (invert) - info->invert =1 ; - info->len=strlen ((char *)info->genre); - *flags =1 ; + +switch (c) + { +case '1' : +if (*flags) +exit_error (PARAMETER_PROBLEM ,"Can't specify multiple strings" ); +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 ; +break ; +default : +return 0 ; + }return 1 ; }
Quoted 3 lines
All rules are added to linked list(with proper locking) without any check, if this rule already exists.
Attached patch fixes some locking problem when flushing rules. Please apply on top of previous.
Quoted 3 lines
Any feedback is allways appreciated.
Yep.
Evgeniy Polyakov
Index: ipt_osf.c
===================================================================
RCS file: /usr/local/cvsroot/osf/ipt_osf.c,v
retrieving revision 1.2
ipt_osf.c +2 -0
@@ -486,6 +486,7 @@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++;
@@ -493,6 +494,7 @@list_del (&finger->flist);finger_free (finger); } +write_unlock_bh (&osf_lock);log ("Flushed %d entries.\n" , i);
Quoted 6 lines · Evgeniy Polyakov
Quoted 3 lines
All rules are added to linked list(with proper locking) without any check, if this rule already exists.
Attached patch fixes some locking problem when flushing rules. Please apply on top of previous.
can you please send patches against patch-o-matic? (i.e. patches against patches) Otherwise it is very difficult for me to integrate your changes.
Quoted 2 lines
Yep.
Evgeniy Polyakov
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
Quoted 3 lines
can you please send patches against patch-o-matic? (i.e. patches against patches) Otherwise it is very difficult for me to integrate your changes.
This is a patch against libipt_osf.c file in userspace/extensions, so I guess you meant: against CVS.
Here it is. Funny thing is that, when I converted that module to netfilter, I rewrote the code as Evgeniy now suggests to patch, but decided not to, as I was not sure about the level of intrusion to his code. It appears I had a good hunch.
BTW. I belive that Evgeniy patch was broken anyway.
Regards,
Maciej
Index: userspace/extensions/libipt_osf.c
===================================================================
RCS file: /cvspublic/netfilter/userspace/extensions/libipt_osf.c,v retrieving revision 1.1
extensions/libipt_osf.c +14 -9
@@ -71,15 +71,20 @@ {struct ipt_osf_info *info = (struct ipt_osf_info *)(*match)->data; -if (*flags) -exit_error (PARAMETER_PROBLEM ,"Can't specify multiple strings" ); - -check_inverse (optarg, &invert, &optind,0 ); -parse_string (optarg, info); -if (invert) - info->invert =1 ; - info->len=strlen ((char *)info->genre); - *flags =1 ; +switch (c) { +case '1' : +if (*flags) +exit_error (PARAMETER_PROBLEM ,"Can't specify multiple strings" ); +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 ; +break ; +default : +return 0 ; + }return 1 ; }
Index: userspace/extensions/libipt_osf.c
===================================================================
RCS file: /cvspublic/netfilter/userspace/extensions/libipt_osf.c,v retrieving revision 1.1
extensions/libipt_osf.c +14 -9
@@ -71,15 +71,20 @@ {struct ipt_osf_info *info = (struct ipt_osf_info *)(*match)->data; -if (*flags) -exit_error (PARAMETER_PROBLEM ,"Can't specify multiple strings" ); - -check_inverse (optarg, &invert, &optind,0 ); -parse_string (optarg, info); -if (invert) - info->invert =1 ; - info->len=strlen ((char *)info->genre); - *flags =1 ; +switch (c) { +case '1' : +if (*flags) +exit_error (PARAMETER_PROBLEM ,"Can't specify multiple strings" ); +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 ; +break ; +default : +return 0 ; + }return 1 ; }
Quoted 3 lines · On Mon, 22 Sep 2003 15:51:51 +0200 Harald Welte <[email protected]> wrote:
can you please send patches against patch-o-matic? (i.e. patches against patches) Otherwise it is very difficult for me to integrate your changes.
Not so easy :)
Please recheck, comment and apply.
extension.diff is patch for libipt_osf.c( it is not patch-patch, but normal diff) with cleanups and fixed changes from
Piotr Gasid'o<[email protected]>.
pom.diff is a patch against current cvs patch-o-matic osf.patch.
I'm planning to send a bit of documentation(from the first e-mail) in form of patch-o-matic later today.
Thanks.
Quoted 4 lines
Signature · 3 lines
-- - Harald Welte <[email protected]> http://www.netfilter.org/
Evgeniy Polyakov
extensions/libipt_osf.c renamed from extensions/libipt_osf.c.orig +17 -13
@@ -36,9 +36,7 @@static void help (void ) {printf ("OS fingerprint match v%s options:\n" -" --genre [!] string Match a OS genre bypassive fingerprinting.\n" -" Genres: Linux, FreeBSD, NetBSD, OpenBSD,\n" -" Windows\n" , +" --genre [!] string Match a OS genre bypassive fingerprinting.\n" ,IPTABLES_VERSION ); }
@@ -70,16 +68,22 @@ struct ipt_entry_match **match) {struct ipt_osf_info *info = (struct ipt_osf_info *)(*match)->data; - -if (*flags) -exit_error (PARAMETER_PROBLEM ,"Can't specify multiple strings" ); - -check_inverse (optarg, &invert, &optind,0 ); -parse_string (optarg, info); -if (invert) - info->invert =1 ; - info->len=strlen ((char *)info->genre); - *flags =1 ; + +switch (c) + { +case '1' : +if (*flags) +exit_error (PARAMETER_PROBLEM ,"Can't specify multiple strings" ); +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 ; +break ; +default : +return 0 ; + }return 1 ; }
patch-o-matic/base/osf.patch renamed from patch-o-matic/base/osf.patch.orig +576 -284
994 lines not on this page · raw message
Quoted 1 line · Evgeniy Polyakov
Please recheck, comment and apply.
looks fine to me, I'va applied both patches.
Quoted 4 lines
I'm planning to send a bit of documentation(from the first e-mail) in form of patch-o-matic later today.
Thanks.
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
Quoted 2 lines · On Mon, 22 Sep 2003 19:03:25 +0400 Evgeniy Polyakov <[email protected]> wrote:
I'm planning to send a bit of documentation(from the first e-mail) in form of patch-o-matic later today.
Attached patch contains bits of documentation for passive OS fingerprint matching module.
Patch is against CVS-patch-o-matic
osf.patch.configure.help and osf.patch.help.
Please apply.
Evgeniy Polyakov
Quoted 7 lines · On Tue, 23 Sep 2003 11:21:31 +0400 Evgeniy Polyakov <[email protected]> wrote:
Attached patch contains bits of documentation for passive OS fingerprint matching module.
Patch is against CVS-patch-o-matic osf.patch.configure.help and osf.patch.help.Please apply.
Forgot attach.
Evgeniy Polyakov
base/osf.patch.help renamed from base/osf.patch.help.orig +15 -1
@@ -23,7 +23,21 @@ NOTE: -p tcp is obviously required as it is a TCP match. - The available genres are: Linux, FreeBSD, NetBSD, OpenBSD, Windows + It is possible to dynamically load/flush fingerprints through /proc fs. + For complete list of supported fingerprints please visit + http://www.openbsd.org/cgi-bin/cvsweb/src/etc/pf.os and + http://lcamtuf.coredump.cx/p0f.shtml. + + Examples: + loading new rule: + echo "16384:64:0:44:M512:.:AIX:4.3.2 and earlier">/proc/sys/net/ipv4/osf + + reading loaded rules( + not in loading format, but for info about genries/details only): + cat /proc/sys/net/ipv4/osf + + dropping whole fingerprint table with the following command: + echo -en FLUSH > /proc/sys/net/ipv4/osf If you say Y here, try iptables -m osf --help for more information.
base/osf.patch.configure.help renamed from base/osf.patch.configure.help.orig +3 -1
@@ -15,6 +15,8 @@ bit set) with hardcoded in fingers[] table ones. If you say Y here, try iptables -m osf --help for more information. - + + You need to enable procfs for correct loading/flushing fingerprints. + If you want to compile it as a module, say M here and read Documentation/modules.txt. If unsure, say `N'.
Quoted 4 lines · On Mon, 22 Sep 2003 17:19:21 +0400 Evgeniy Polyakov <[email protected]> wrote:
This patch also adds possibility to dynamically load fingerprints(for complete list of supported fingerprints please see
http://www.openbsd.org/cgi-bin/cvsweb/src/etc/pf.os and
http://lcamtuf.coredump.cx/p0f.shtml) through /proc interface.
Btw, Linux rule parsing code is not compatible with OpenBSD one, since they use fields "version" and "subversion", but one can easily remove two ":" symbols between them( and details field) and successfully load new rule.
Quoted 4 lines
Examples:
loading new rule:
echo "16384:64:0:44:M512:.:AIX:4.3.2 and
earlier">/proc/sys/net/ipv4/osf
So, in OpenBSD we have:
16384:64:0:44:M512: AIX:4.3:2-3:AIX 4.3.2 and earlier
^^^^^^^^
If someone like to use this notation, i can create a patch.
Evgeniy Polyakov
Quoted 11 lines · Evgeniy Polyakov
Quoted 5 lines
Examples:
loading new rule:
echo "16384:64:0:44:M512:.:AIX:4.3.2 and
earlier">/proc/sys/net/ipv4/osfSo, in OpenBSD we have:
16384:64:0:44:M512: AIX:4.3:2-3:AIX 4.3.2 and earlier^^^^^^^^If someone like to use this notation, i can create a patch.
Well, the osf match is pretty much your child... so it's up to you.
I personally would like to see compatibility... since this means that the fingerprint database has only to be kept in one format.
Quoted 1 line
Evgeniy Polyakov
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
Quoted 10 lines · On Tue, 23 Sep 2003 14:57:46 +0200 Harald Welte <[email protected]> wrote:
Quoted 9 lines
Quoted 4 lines
Examples:
loading new rule:
echo "16384:64:0:44:M512:.:AIX:4.3.2 and
earlier">/proc/sys/net/ipv4/osfSo, in OpenBSD we have:
16384:64:0:44:M512: AIX:4.3:2-3:AIX 4.3.2 and earlier^^^^^^If someone like to use this notation, i can create a patch.
Quoted 4 lines
Well, the osf match is pretty much your child... so it's up to you.
I personally would like to see compatibility... since this means that the fingerprint database has only to be kept in one format.
Ok, here is the patch.
Now we are compatible with OpenBSD, but not with Michal Zalewski :)
P.S. Harald, is it convenient for you to use -p0 when patching or is -p1 better?
Quoted 4 lines
Signature · 3 lines
-- - Harald Welte <[email protected]> http://www.netfilter.org/
Evgeniy Polyakov
base/osf.patch +53 -38
@@ -48,12 +48,12 @@ + +#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_ERR "ipt_osf: " x) ++#define log(x...) printk(KERN_INFO "ipt_osf: " x) +#define loga(x...) printk(x) +#else +#define log(x...) do {} while(0)
@@ -281,6 +281,18 @@ + return 1; +} + ++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() +{ + struct osf_finger *f;
@@ -316,7 +328,7 @@ + { + case 'N': + op = OSFOPT_NOP; -+ ptr = strchr(&obuf[i], OPTDEL); ++ ptr = osf_strchr(&obuf[i], OPTDEL); + if (ptr) + { + *ptr = '\0';
@@ -329,7 +341,7 @@ + break; + case 'S': + op = OSFOPT_SACKP; -+ ptr = strchr(&obuf[i], OPTDEL); ++ ptr = osf_strchr(&obuf[i], OPTDEL); + if (ptr) + { + *ptr = '\0';
@@ -342,7 +354,7 @@ + break; + case 'T': + op = OSFOPT_TS; -+ ptr = strchr(&obuf[i], OPTDEL); ++ ptr = osf_strchr(&obuf[i], OPTDEL); + if (ptr) + { + *ptr = '\0';
@@ -355,7 +367,7 @@ + break; + case 'W': + op = OSFOPT_WSO; -+ ptr = strchr(&obuf[i], OPTDEL); ++ ptr = osf_strchr(&obuf[i], OPTDEL); + if (ptr) + { + switch (obuf[i+1])
@@ -380,7 +392,7 @@ + break; + case 'M': + op = OSFOPT_MSS; -+ ptr = strchr(&obuf[i], OPTDEL); ++ ptr = osf_strchr(&obuf[i], OPTDEL); + if (ptr) + { + if (obuf[i+1] == '%')
@@ -399,7 +411,7 @@ + break; + case 'E': + op = OSFOPT_EOL; -+ ptr = strchr(&obuf[i], OPTDEL); ++ ptr = osf_strchr(&obuf[i], OPTDEL); + if (ptr) + { + *ptr = '\0';
@@ -411,7 +423,7 @@ + i++; + break; + default: -+ ptr = strchr(&obuf[i], OPTDEL); ++ ptr = osf_strchr(&obuf[i], OPTDEL); + if (ptr) + { + ptr++;
@@ -453,8 +465,9 @@ + 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); + -+ count += sprintf(buf+count, "%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); ++ count += sprintf(buf+count, "%s - %s[%s] : %s", ++ f->genre, f->version, ++ f->subtype, f->details); + + if (f->opt_num) + {
@@ -480,7 +493,7 @@ +{ + int cnt; + unsigned long i; -+ char quirks[MAXOPTSTRLEN], obuf[MAXOPTSTRLEN]; ++ char obuf[MAXOPTSTRLEN]; + struct osf_finger *finger; + struct list_head *ent, *n; +
@@ -510,15 +523,13 @@ + if (buffer[i] == ':') + cnt++; + -+ if (cnt != 7 || i != count) ++ if (cnt != 8 || i != count) + { -+ log("Wrong input line cnt=%d[7], len=%lu[%lu]\n", ++ log("Wrong input line cnt=%d[8], len=%lu[%lu]\n", + cnt, i, count); + return count; + } + -+ -+ memset(quirks, 0, sizeof(quirks)); + memset(obuf, 0, sizeof(obuf)); + + finger = finger_alloc();
@@ -529,7 +540,7 @@ + } + + pbeg = (char *)buffer; -+ pend = strchr(pbeg, OSFPDEL); ++ pend = osf_strchr(pbeg, OSFPDEL); + if (pend) + { + *pend = '\0';
@@ -561,21 +572,21 @@ + + pbeg = pend+1; + } -+ pend = strchr(pbeg, OSFPDEL); ++ pend = osf_strchr(pbeg, OSFPDEL); + if (pend) + { + *pend = '\0'; + finger->ttl = simple_strtoul(pbeg, NULL, 10); + pbeg = pend+1; + } -+ pend = strchr(pbeg, OSFPDEL); ++ pend = osf_strchr(pbeg, OSFPDEL); + if (pend) + { + *pend = '\0'; + finger->df = simple_strtoul(pbeg, NULL, 10); + pbeg = pend+1; + } -+ pend = strchr(pbeg, OSFPDEL); ++ pend = osf_strchr(pbeg, OSFPDEL); + if (pend) + { + *pend = '\0';
@@ -583,34 +594,38 @@ + pbeg = pend+1; + } + -+ pend = strchr(pbeg, OSFPDEL); ++ 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 = strchr(pbeg, OSFPDEL); ++ pend = osf_strchr(pbeg, OSFPDEL); + if (pend) + { + *pend = '\0'; -+ cnt = snprintf(quirks, sizeof(quirks), "%s", pbeg); ++ cnt = snprintf(finger->version, sizeof(finger->version), "%s", pbeg); + pbeg = pend+1; + } -+ -+ pend = strchr(pbeg, OSFPDEL); ++ ++ pend = osf_strchr(pbeg, OSFPDEL); + if (pend) + { + *pend = '\0'; -+ if (pbeg[0] == '@' || pbeg[0] == '*') -+ cnt = snprintf(finger->genre, -+ ((count-(pbeg+1-buffer)+1) > MAXGENRELEN)?MAXGENRELEN:(count-(pbeg+1-buffer)+1), -+ "%s", pbeg+1); -+ else -+ cnt = snprintf(finger->genre, -+ ((count-(pbeg-buffer)+1) > MAXGENRELEN)?MAXGENRELEN:(count-(pbeg-buffer)+1), -+ "%s", pbeg); ++ cnt = snprintf(finger->subtype, sizeof(finger->subtype), "%s", pbeg); + pbeg = pend+1; + } +
@@ -618,10 +633,9 @@ + ((count - (pbeg - buffer)+1) > MAXDETLEN)?MAXDETLEN:(count - (pbeg - buffer)+1), + "%s", pbeg); + -+ log("%s - %s. ttl=%d, df=%d, size=%lu, wss=[%d, %lu]\n", -+ finger->genre, finger->details, -+ finger->ttl, finger->df, finger->ss, -+ finger->wss.wc, finger->wss.val); ++ 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)); +
@@ -751,6 +765,7 @@ + unsigned char df; + unsigned long ss; + char genre[MAXGENRELEN]; ++ char version[MAXGENRELEN], subtype[MAXGENRELEN]; + + /* Not needed, but for consistency with original table from Michal Zalewski */ + char details[MAXDETLEN];
Quoted 2 lines · Evgeniy Polyakov
Ok, here is the patch.
Now we are compatible with OpenBSD, but not with Michal Zalewski :)
Well, I have to admit that I'm not really involved in the 'os fingerprinting community', so I don't know what might be the better format (or the more commonly used one).
Quoted 2 lines
P.S. Harald, is it convenient for you to use -p0 when patching or is -p1 better?
I'd prefer -p1, but I don't really care anyway.
Thanks.
Quoted 1 line
Evgeniy Polyakov
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