Exemplo n.º 1
0
/*---------------------------------------------------------------------------*
 * NAME: main
 * DESC: Main Entry Point
 *---------------------------------------------------------------------------*/
int main(int argc, char **argv) {

  config *conf;
  unsigned int first_arg;

  /* create the configuration structure */
  conf = malloc_(sizeof(config));

  /* init the configuration structure */
  init_configuration(conf);

  /* parse the arguments */
  first_arg = parsing_args(argc, argv, conf);
  conf->xml_filename = argv[first_arg];

  /* copy the name of the .ad file */
  conf->output_name = argv[first_arg+1];

  /* basic check */
  if ((conf->output_name == NULL) || (conf->xml_filename == NULL)) {
    usage(argv, conf);
  }

  /* open the output_name file */
  output_desc = fopen(conf->output_name, "w");
  if (!output_desc) {
    error_("cannot write the file: \"%s\": ", conf->output_name);
    perror("");
    error_("QUITTING!\n");
    free(conf);
    exit(-1);
  }
  

  /* xml parsing of the file */
  xml_parsing(conf);

  /* free the configuration structure */
  free(conf);
  
  return 0;
}
Exemplo n.º 2
0
/*---------------------------------------------------------------------------*
 * NAME: main
 * DESC: Main Entry Point
 *---------------------------------------------------------------------------*/
int main(int argc, char **argv) {

  config *conf;
  unsigned int first_arg;

  /* create the configuration structure */
  conf = malloc_(sizeof(config));

  /* create the adc structure */
  conf->adc = malloc_(sizeof(struct struct_adc));

  /* initialize the configuration structure */
  init_configuration(conf);

  /* parse the arguments */
  first_arg = parsing_args(argc, argv, conf);

  /* check if selected mode is well defined (dirty) */
  if (
      /* client mode -> port AND host */
      ((conf->mode == 0) && ((conf->port == 0) ||
			     (conf->host == NULL)))
      ||
      /* server mode -> port */
      ((conf->mode == 1) && (conf->port == 0))
      ||
      /* no file.ad defined */
      (argv[first_arg] == NULL)
      ||
      /* debugger and file */
      ((conf->type == 2) && (conf->dbg_mode))
      ||
      /* fuzz udp or tcp or file */
      ((conf->fuzz_file_dir != NULL) && ((conf->host != NULL) ||
					 (conf->port != 0)    ||
					 (conf->type != 2)))
      ) {
    usage(argv, conf);
  }

  /* verbose messages */

  /* autodafe's debugger */
    if (conf->dbg_mode) {
    verbose_("[*] Autodafe's debugger mode activated.\n");
  }

  /* file mode */
  if (conf->type == 2) {
    verbose_("[*] mode *file* - all fuzzed files will be in %s\n", conf->fuzz_file_dir);
  }

  /* network mode */
  else {
    if (conf->mode) {
      if (!conf->type) /* tcp */
	verbose_("[*] mode *server* - listening on port: %d (tcp)\n", conf->port);
      else /* udp */
	verbose_("[*] mode *server* - listening on port: %d (udp)\n", conf->port);
    }
    else {
      if (!conf->type) /* tcp */
	verbose_("[*] mode *client* - connection to %s on port: %d (tcp)\n", conf->host, conf->port);
      else /* udp */
	verbose_("[*] mode *client* - connection to %s on port: %d (udp)\n", conf->host, conf->port);
    }
  }
  /* read the file */
  if(read_adc_file(conf, argv[first_arg])) goto fuzzer_end;

  /* ignore the SIGPIPE signal (ie. "Connection closed by foreign host") */
  signal(SIGPIPE, sigpipe_handler);


  /* start the connection with the debugger */
  if (conf->dbg_mode)
    if (dbg_connection(conf)) goto fuzzer_end;

  /* start the fuzz engine */
  fuzz_engine(conf);


  if (conf->buf_fuzz)    free(conf->buf_fuzz);    /* free the fuzz buffer (in case of error) */
 fuzzer_end:
  if (conf->adc->buffer) free(conf->adc->buffer); /* free the memory-copy of adc file */
  if (conf->adc)         free(conf->adc);         /* free the adc structure */
  if (conf)              free(conf);              /* free the configuration structure */

  return 0;
}