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
|
/*
============================================================================
Name : VIGILANTE
Author : SAMBIA39
Version : 0.1
Copyright : Copyright (c) 09/07/2016 SAMBIA39
Description : Ansi-style
============================================================================
*/
/*
* Constante
* utile
*/
#define MAX_TOL 3
#define MAX_SEC (MAX_TOL * MAX_TOL)+1
#define ui_int unsigned int
#define PRIVATE static
#define PTR_NULL (char)0
#define SYS_ERROR -1
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
/*
* Flag conversion
* adresse ip
*/
#define FLAG_S_ADDR_A 0x000000FF
#define FLAG_S_ADDR_B 0x0000FF00
#define FLAG_S_ADDR_C 0x00FF0000
#define FLAG_S_ADDR_D 0xFF000000
/*
* Pour l'exemple je vais
* utiliser les constantes
* suivantes.
*/
#define FLAG_PROTO_ICE 8 // ICMP_ECHO
#define FLAG_PROTO_TCP 6 // Transmission control protocol
#define FLAG_PROTO_ICMP 1 // Internet control message protocol
#define FLAG_PROTO_UDP 17 // User datagram protocol
#define FLAG_PROTO_SCTP 132 // Stream Control Transmission Protocol
/*
* En-tête
* Lunix-netfilter
* Pour l'exemple
*/
#include <linux/in.h>
#include <linux/ip.h>
#include <linux/in6.h>
#include <linux/tcp.h>
#include <linux/udp.h>
#include <linux/icmp.h>
#include <linux/igmp.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/skbuff.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
MODULE_LICENSE("Dual BSD/GPL");
/*
* Structure des protocoles
* TCP - UDP - ICMP & SCTP
*/
typedef struct s_hoock_type_arp{
struct icmphdr *ptr_Icm; // Protocol ICMP
struct udphdr *ptr_Udp; // Protocol UDP
struct tcphdr *ptr_Tcp; // Protocol TCP
struct sctphdr *ptr_Sct; // Protocol SCTP
}PROTOCOL;
/*
* Structure des DATA TRAME
*/
typedef struct s_hoock_snif{
PROTOCOL PROTO;
struct iphdr *ptr_ipHead;
struct nf_hook_ops nfhook;
struct sk_buff *ptr_socket_buff;
}DATA_SNIF_TRAME;
DATA_SNIF_TRAME TRAME;
/*
* Fonction qui se charge de
* traiter tout les paquet
* dans cette exemple il
* liste les connexions
*/
PRIVATE ui_int f_hook_snif_arp( ui_int idhook,
struct sk_buff *ptr_buff,
int (*foksnif)(struct sk_buff*),
const struct net_device *ptr_rsx_out,
const struct net_device *ptr_rsx_in ){
/*
* Règle de ban data
*/
PRIVATE int iTolerance;
PRIVATE int iSecure_drop;
/*
* Journalisation active
* Tout type de paquet même
* ceux qui ne sont pas analyser
* sont lister donc module passive
*/
TRAME.ptr_socket_buff = ptr_buff;
if( !TRAME.ptr_socket_buff )
return NF_ACCEPT;
TRAME.ptr_ipHead = (struct iphdr*)skb_network_header(
TRAME.ptr_socket_buff);
if( TRAME.ptr_ipHead ){
printk(KERN_INFO
"ARP IP \t:%d.%d.%d.%d\tINTERCEPTER\n",
(TRAME.ptr_ipHead->saddr & FLAG_S_ADDR_A),
(TRAME.ptr_ipHead->saddr & FLAG_S_ADDR_B) >> 8,
(TRAME.ptr_ipHead->saddr & FLAG_S_ADDR_C) >> 16,
(TRAME.ptr_ipHead->saddr & FLAG_S_ADDR_D) >> 24);
/*
* Traitement des datas selon le
* protocole
* TCP & UDP sont accepter
* PING-ECHO est tolérée MAX 3
* PING est tolérer MAX 10
* ( mémo code a revoir pour la gestion ping)
*/
switch( TRAME.ptr_ipHead->protocol ){
case FLAG_PROTO_TCP:
TRAME.PROTO.ptr_Tcp =
(struct tcphdr*)(
(__u32 *)TRAME.ptr_ipHead+TRAME.ptr_ipHead->ihl);
//f_printk_hack_spoof_addr( TRAME.ptr_ipHead );
printk(KERN_INFO "\t[DATA_TCP]\tSRC\t:%d\tDST\t:%d\n",
TRAME.PROTO.ptr_Tcp->source,
TRAME.PROTO.ptr_Tcp->dest );
return NF_ACCEPT;
break; // non executé
case FLAG_PROTO_UDP:
TRAME.PROTO.ptr_Udp =
(struct udphdr*)(
(__u32 *)TRAME.ptr_ipHead+TRAME.ptr_ipHead->ihl);
printk(KERN_INFO "\t[DATA_UDP]\tSRC\t:%d\tDST\t:%d\n",
TRAME.PROTO.ptr_Udp->source,
TRAME.PROTO.ptr_Udp->dest );
return NF_ACCEPT;
break; //non executé
case FLAG_PROTO_SCTP:
TRAME.PROTO.ptr_Sct =
(struct sctphdr*)(
(__u32 *)TRAME.ptr_ipHead+TRAME.ptr_ipHead->ihl);
printk(KERN_INFO "\t[DATA_SCT DETECTER]\n");
return NF_ACCEPT;
break; //non executé
case FLAG_PROTO_ICE:
TRAME.PROTO.ptr_Icm =
(struct udphdr*)(
(__u32 *)TRAME.ptr_ipHead+TRAME.ptr_ipHead->ihl);
printk(KERN_ALERT "\t[DATA_ICM PING-ECHO BANNI]\n");
return NF_DROP;
break; //non executé
case FLAG_PROTO_ICMP:
if( MAX_TOL == iTolerance ){
printk(KERN_ALERT "\t[DATA_ICM SECURITER PING DROP -> %d/%d]\n",
iTolerance, MAX_TOL );
return NF_DROP;
}
TRAME.PROTO.ptr_Icm =
(struct icmphdr*)(
(__u32 *)TRAME.ptr_ipHead+TRAME.ptr_ipHead->ihl);
printk(KERN_ALERT "\t[PING TOLERER %d/%d]\n",iTolerance, MAX_TOL);
++iTolerance;
return NF_ACCEPT;
break; //non executé
default:
if( MAX_SEC == iSecure_drop){
printk(KERN_ALERT"\t[SECURITER AUTRE PROTO BANNI-> %d/%d]\n",
iSecure_drop, MAX_SEC );
return NF_DROP;
}
printk(KERN_ALERT"\t[SECURITER AUTRE PROTO TOLERER-> %d/%d]\n",
iSecure_drop, MAX_SEC );
++iSecure_drop;
return NF_ACCEPT;
break; // non executé
}
}
return NF_ACCEPT;
}
/*
* Initialisation du module
* et chargement.
*/
static int __init f_inter_arp_init( void ){
printk( KERN_ALERT "VIGILANTE DATA ARP v0.0.1\n" );
TRAME.nfhook.hooknum = 1;
TRAME.nfhook.pf = AF_INET;
TRAME.nfhook.hook = f_hook_snif_arp;
TRAME.nfhook.priority = NF_IP_PRI_FIRST;
nf_register_hook(&TRAME.nfhook);
printk(KERN_INFO "START INTERCEPTIONS DES ARP\n" );
return EXIT_SUCCESS;
}
/*
* Décharge module (hook)
*/
static void __exit f_inter_arp_exit( void ){
nf_unregister_hook(&TRAME.nfhook);
printk(KERN_ALERT "ARRET INTERCEPTION DES ARP\n" );
}
//Appel des fonction
module_init( f_inter_arp_init );
module_exit( f_inter_arp_exit ); |
Partager