Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

sp_bait_and_switch.c

Go to the documentation of this file.
00001 /* $Id: sp_template.c,v 1.5 2004/02/13 16:19:03 roesch Exp $ */
00002 /* Snort Detection Plugin Source File Template */
00003 
00004 /* sp_template 
00005  * 
00006  * Purpose:
00007  *
00008  * Detection engine plugins test an aspect of the current packet and report
00009  * their findings.  The function may be called many times per packet with 
00010  * different arguments.  These functions are acccessed from the rules file
00011  * as standard rule options.  When adding a plugin to the system, be sure to 
00012  * add the "Setup" function to the InitPlugins() function call in 
00013  * plugbase.c!
00014  *
00015  * Arguments:
00016  *   
00017  * This is the type of arguements that the detection plugin can take when
00018  * referenced as a rule option
00019  *
00020  * Effect:
00021  *
00022  * What the plugin does.  
00023  *
00024  * Comments:
00025  *
00026  * Any comments?
00027  *
00028  */
00029 
00030 
00031 /* stickydrop is only used in inline mode */
00032 #ifdef GIDS
00033 #ifndef IPFW
00034 
00035 #include <sys/types.h>
00036 #include <stdlib.h>
00037 #include <ctype.h>
00038 
00039 #include "rules.h"
00040 #include "decode.h"
00041 #include "plugbase.h"
00042 #include "parser.h"
00043 #include "debug.h"
00044 #include "util.h"
00045 #include "mstring.h"
00046 #include "plugin_enum.h"
00047 #include "spp_bait_and_switch.h"
00048 #include "sp_bait_and_switch.h"
00049 #include <sys/socket.h>
00050 #include <netinet/in.h>
00051 #include <arpa/inet.h>
00052 
00053 /* 
00054  * don't forget to include the name of this file in plugbase.c! 
00055  */
00056 
00057 /* 
00058  * setup any data structs here 
00059  */
00060 
00061 /* function prototypes go here */
00062 void BandSpInit(char *, OptTreeNode *, int);
00063 static void BandSpRuleParseFunction(char *, OptTreeNode *, BandSp *);
00064 static int BandSpFunction(Packet *, struct _OptTreeNode *, 
00065         OptFpList *);
00066 
00067 /*
00068  * 
00069  * Function: SetupTemplate()
00070  *
00071  * Purpose: Generic detection engine plugin template.  Registers the
00072  *          configuration function and links it to a rule keyword.  This is
00073  *          the function that gets called from InitPlugins in plugbase.c.
00074  *
00075  * Arguments: None.
00076  *
00077  * Returns: void function
00078  *
00079  */
00080 void SetupBandSp()
00081 {
00082     /* map the keyword to an initialization/processing function */
00083     RegisterPlugin("bait-and-switch", BandSpInit);
00084 
00085     DEBUG_WRAP(DebugMessage(DEBUG_PLUGIN,"Plugin: BandSp Setup\n"););
00086 }
00087 
00088 
00089 /*
00090  * 
00091  * Function: TemplateInit(char *, OptTreeNode *)
00092  *
00093  * Purpose: Generic rule configuration function.  Handles parsing the rule 
00094  *          information and attaching the associated detection function to
00095  *          the OTN.
00096  *
00097  * Arguments: data => rule arguments/data
00098  *            otn => pointer to the current rule option list node
00099  *
00100  * Returns: void function
00101  *
00102  */
00103 void BandSpInit(char *data, OptTreeNode *otn, int protocol)
00104 {
00105     BandSp *bandsp_d;
00106     OptFpList *ofl;
00107 
00108     if(!BaitAndSwitchIsRunning())
00109     {
00110         FatalError("dude, you can't have a bait-and-switch plugin without the bait-and-switch preproc\n");
00111     }
00112     bandsp_d = (BandSp *) SnortAlloc(sizeof(BandSp));
00113     BandSpRuleParseFunction(data, otn, bandsp_d);
00114 
00115     ofl = AddOptFuncToList(BandSpFunction, otn);
00116     ofl->context = (void *) bandsp_d;
00117     otn->ds_list[PLUGIN_BANDSP]=(BandSp *)bandsp_d;
00118 }
00119 
00120 
00121 
00122 /*
00123  * 
00124  * Function: TemplateRuleParseFunction(char *, OptTreeNode *)
00125  *
00126  * Purpose: This is the function that is used to process the option keyword's
00127  *          arguments and attach them to the rule's data structures.
00128  *
00129  * Arguments: data => argument data
00130  *            otn => pointer to the current rule's OTN
00131  *            td => pointer to the configuration storage struct
00132  *
00133  * Returns: void function
00134  *
00135  */
00136 static void BandSpRuleParseFunction(char *data, OptTreeNode *otn, BandSp *bs) 
00137 {
00138    char **toks;
00139    int numToks;
00140    char *direction;
00141 //   u_int32_t tmpaton;
00142    toks = mSplit(data, ",", 3, &numToks, 0);
00143 
00144       if(numToks > 3)
00145          FatalError("ERROR %s (%d): Bad arguments to bait-and-switch: %s\n", file_name,
00146                  file_line, data);
00147           
00148            if(isdigit((char)toks[0][1]))
00149            {
00150                bs->bands_timeout = atoi(toks[0]);
00151            }
00152            else
00153            {
00154                FatalError("ERROR %s (%d): Bad arguments to bait-and-switch: %s\n", file_name,
00155                      file_line, data);
00156            }
00157 
00158         
00159       if(numToks > 2)
00160       {
00161           direction = toks[1];
00162 
00163           while(isspace((int)*direction)) {direction++;}
00164 
00165           if(!strcasecmp(direction, "src"))
00166           {           
00167               bs->bands_direction = 0;
00168           }         
00169           else if(!strcasecmp(direction, "dst"))
00170           {                
00171               bs->bands_direction = 1;
00172           }
00173           else
00174           {
00175    
00176                FatalError("%s(%d):we need a direction either src or dst%s\n",file_name,file_line,toks[1]);
00177           }
00178       }
00179       if(numToks > 1)
00180       {
00181          
00182             bs->hpotaddr = (u_int32_t)(inet_addr(toks[2])); 
00183          
00184       }
00185       else
00186       {
00187 
00188           FatalError("%s(%d):we need a direction either src or dst%s\n",file_name,file_line,toks[1]);
00189       }
00190 
00191        mSplitFree(&toks, numToks);
00192 }
00193 
00194 
00195 /*
00196  * 
00197  * Function: TemplateDetectorFunction(char *, OptTreeNode *, OptFpList *)
00198  *
00199  * Purpose: Use this function to perform the particular detection routine
00200  *          that this rule keyword is supposed to encompass.
00201  *
00202  * Arguments: data => argument data
00203  *            otn => pointer to the current rule's OTN
00204  *            fp_list => pointer to the function pointer list current node
00205  *
00206  * Returns: If the detection test fails, this function *must* return a zero!
00207  *          On success, it calls the next function in the detection list 
00208  *
00209  */
00210 static int BandSpFunction(Packet *p, struct _OptTreeNode *otn, OptFpList *fp_list)
00211 {
00212     /* not really sure how we could fail here return 1 always */
00213     return 1;
00214 }
00215 
00216 #endif /* IPFW */
00217 #endif /* GIDS */

Generated on Sun May 14 14:51:12 2006 by  doxygen 1.4.2