Skip to content

Commit

Permalink
allow filter scripts to be loaded without enabling
Browse files Browse the repository at this point in the history
By applying this patch, ettercap now can load filter scripts (-F)
without enabling the newly loaded script at once; to achieve this, the
flag ":0" is appended to the filename of the filter script, allowing
multiple scripts to be loaded and enabling them individually by using
the interactive interface.
  • Loading branch information
wertarbyte committed Nov 10, 2011
1 parent 66fe7a9 commit b3028f5
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion include/ec_filter.h
Expand Up @@ -136,7 +136,7 @@ void filter_init_mutex(void);
/* exported functions */

EC_API_EXTERN void filter_packet(struct packet_object *po);
EC_API_EXTERN int filter_load_file(char *filename, struct filter_list **list);
EC_API_EXTERN int filter_load_file(char *filename, struct filter_list **list, uint8_t enabled);
EC_API_EXTERN void filter_unload(struct filter_list **list);
EC_API_EXTERN void filter_clear(void);
EC_API_EXTERN void filter_walk_list( int(*cb)(struct filter_list*, void*), void *arg);
Expand Down
1 change: 1 addition & 0 deletions man/ettercap.8.in
Expand Up @@ -629,6 +629,7 @@ ettercap-compliant binary filter file. Read the etterfilter(8) man page for the
list of functions you can use inside a filter script.
Any number of filters can be loaded by specifying the option multiple times;
packets are passed through each filter in the order specified on the command line.
You can also load a script without enabling it by appending :0 to the filename.
.br
NOTE: these filters are different from those set with \-\-pcapfilter. An ettercap
filter is a content filter and can modify the payload of a packet before
Expand Down
8 changes: 4 additions & 4 deletions src/ec_filter.c
Expand Up @@ -43,7 +43,7 @@ static pthread_mutex_t filters_mutex;

/* protos */

int filter_load_file(char *filename, struct filter_list **list);
int filter_load_file(char *filename, struct filter_list **list, uint8_t enabled);
void filter_unload(struct filter_list **list);
static void reconstruct_strings(struct filter_env *fenv, struct filter_header *fh);
static int compile_regex(struct filter_env *fenv, struct filter_header *fh);
Expand Down Expand Up @@ -986,7 +986,7 @@ static int cmp_geq(u_int32 a, u_int32 b)
/*
* load the filter from a file
*/
int filter_load_file(char *filename, struct filter_list **list)
int filter_load_file(char *filename, struct filter_list **list, uint8_t enabled)
{
int fd;
void *file;
Expand Down Expand Up @@ -1051,8 +1051,8 @@ int filter_load_file(char *filename, struct filter_list **list)
/* save the name of the loaded filter */
(*list)->name = strdup(filename);

/* enable the filter */
(*list)->enabled = 1;
/* enable the filter if requested */
(*list)->enabled = enabled;

FILTERS_UNLOCK;

Expand Down
12 changes: 11 additions & 1 deletion src/ec_parser.c
Expand Up @@ -200,6 +200,11 @@ void parse_options(int argc, char **argv)
optind = 0;

while ((c = getopt_long (argc, argv, "A:a:B:CchDdEe:F:f:GhIi:j:k:L:l:M:m:n:oP:pQqiRr:s:Tt:UuV:vW:w:z", long_options, (int *)0)) != EOF) {
/* used for parsing arguments */
char *opt_end = optarg;
while (opt_end && *opt_end) opt_end++;
/* enable a loaded filter script? */
uint8_t f_enabled = 0;

switch (c) {

Expand Down Expand Up @@ -301,7 +306,12 @@ void parse_options(int argc, char **argv)
break;

case 'F':
if (filter_load_file(optarg, GBL_FILTERS) != ESUCCESS)
/* is there a :0 or :1 appended to the filename? */
if ( (opt_end-optarg >=2) && *(opt_end-2) == ':' ) {
*(opt_end-2) = '\0';
f_enabled = !( *(opt_end-1) == '0' );
}
if (filter_load_file(optarg, GBL_FILTERS, f_enabled) != ESUCCESS)
FATAL_ERROR("Cannot load filter file \"%s\"", optarg);
break;

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/curses/ec_curses_filters.c
Expand Up @@ -151,7 +151,7 @@ static void load_filter(char *path, char *file)
* load the filters chain.
* errors are spawned by the function itself
*/
filter_load_file(tmp, GBL_FILTERS);
filter_load_file(tmp, GBL_FILTERS, 1);

SAFE_FREE(tmp);
}
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/gtk/ec_gtk_filters.c
Expand Up @@ -61,7 +61,7 @@ void gtkui_load_filter(void)
* load the filters chain.
* errors are spawned by the function itself
*/
filter_load_file(filename, GBL_FILTERS);
filter_load_file(filename, GBL_FILTERS, 1);
}
gtk_widget_destroy (dialog);
}
Expand Down
2 changes: 1 addition & 1 deletion utils/etterfilter/ef_test.c
Expand Up @@ -57,7 +57,7 @@ void test_filter(char *filename)
/*memset(fenv, 0, sizeof(struct filter_env));*/

/* load the file */
if (filter_load_file(filename, &flist) != ESUCCESS) {
if (filter_load_file(filename, &flist, 1) != ESUCCESS) {
exit(-1);
}
fenv = &flist->env;
Expand Down

0 comments on commit b3028f5

Please sign in to comment.