/* by hkpco(ChanAm Park) hkpco@korea.com http://hkpco.kr/ cut off the MSN messenger using by netfilter module */ #include #include #include #include #include #include #include #include #define MSG_CHK(x, y) ((x[y +0] == 'M') && (x[y +1] == 'S') && (x[y +2] == 'G')) #define MSNP_CHK(x, y) ((x[y +0] == 'M') && (x[y +1] == 'S') && (x[y +2] == 'N') && (x[y +3] == 'P')) unsigned int msn_cutting( unsigned int hook_no, struct sk_buff **pp_skb, const struct net_device *dev_in, const struct net_device *dev_out, int (*handler)(struct sk_buff *) ) { int pk_len, cnt = 0; unsigned char *pk_sig; struct iphdr *ip_h = (struct iphdr *)((*pp_skb)->data); struct tcphdr *tcp_h = (struct tcphdr *)((*pp_skb)->data + sizeof(struct iphdr)); pk_len = (*pp_skb)->len - ((ip_h->ihl * 4) + (tcp_h->doff * 4)); pk_sig = (unsigned char *)(tcp_h + tcp_h->doff * 4); if( pk_len >= 3 ) { do { if(MSG_CHK(pk_sig, cnt)) { printk( KERN_ALERT "MSN Detected - \"MSG\" string found\n" ); return NF_DROP; } } while( (++cnt) <= (pk_len -3) ); cnt = 0; if( pk_len >= 4 ) { do { if(MSNP_CHK(pk_sig, cnt)) { printk( KERN_ALERT "MSN Detected - \"MSNP\" string found\n" ); return NF_DROP; } } while( (++cnt) <= (pk_len -4) ); } } return NF_ACCEPT; } static struct nf_hook_ops netfilter = { .hook = msn_cutting, .owner = THIS_MODULE, .pf = PF_INET, .hooknum = NF_IP_LOCAL_IN, .priority = NF_IP_PRI_FIRST }; int __init hk_init( void ) { nf_register_hook( &netfilter ); printk( KERN_ALERT "[MSN Cutting Module] Loaded\n" ); return 0; } void __exit hk_exit( void ) { nf_unregister_hook( &netfilter ); printk( KERN_ALERT "[MSN Cutting Module] Exit\n" ); } module_init( hk_init ); module_exit( hk_exit ); MODULE_LICENSE( "GPL" ); MODULE_AUTHOR( "hkpco " );