Exemple #1
0
htp_cfg_t *htp_config_create(void) {
    htp_cfg_t *cfg = calloc(1, sizeof (htp_cfg_t));
    if (cfg == NULL) return NULL;

    cfg->field_limit_hard = HTP_FIELD_LIMIT_HARD;
    cfg->field_limit_soft = HTP_FIELD_LIMIT_SOFT;
    cfg->log_level = HTP_LOG_NOTICE;
    cfg->response_decompression_enabled = 1;
    cfg->parse_request_cookies = 1;
    cfg->parse_request_auth = 1;
    cfg->extract_request_files = 0;
    cfg->extract_request_files_limit = -1; // Use the parser default.   
        
    // Default settings for URL-encoded data.

    htp_config_set_bestfit_map(cfg, HTP_DECODER_DEFAULTS, bestfit_1252);
    htp_config_set_bestfit_replacement_byte(cfg, HTP_DECODER_DEFAULTS, '?');

    htp_config_set_url_encoding_invalid_handling(cfg, HTP_DECODER_DEFAULTS, HTP_URL_DECODE_PRESERVE_PERCENT);
    htp_config_set_nul_raw_terminates(cfg, HTP_DECODER_DEFAULTS, 0);
    htp_config_set_nul_encoded_terminates(cfg, HTP_DECODER_DEFAULTS, 0);
    htp_config_set_u_encoding_decode(cfg, HTP_DECODER_DEFAULTS, 0);

    htp_config_set_server_personality(cfg, HTP_SERVER_MINIMAL);

    return cfg;
}
Exemple #2
0
VALUE rbhtp_config_set_server_personality( VALUE self, VALUE personality )
{
	Check_Type( personality, T_FIXNUM );
	
	htp_cfg_t* cfg = NULL;
	Data_Get_Struct( rb_iv_get( self, "@cfg" ), htp_cfg_t, cfg );

	return INT2FIX(
		htp_config_set_server_personality( cfg, FIX2INT( personality ) )
	);
}
Exemple #3
0
/**
 * Main entry point for this program.
 *
 * @param argc
 * @param argv
 */
int main(int argc, char *argv[]) {
    // Check parameters
    if ((argc < 2)||(argc > 4)) {
        print_usage();
        return 1;
    }

    // Configure libnids
    if (argc > 2) {
        if (strcmp(argv[1], "-r") != 0) {
            print_usage();
            return 1;
        }

        nids_params.filename = argv[2];

        if (argc == 4) {
            nids_params.pcap_filter = argv[3];
        }
    } else {
        nids_params.pcap_filter = argv[1];
    }

    // Initialize libnids
    if (!nids_init()) {
        fprintf(stderr, "libnids initialization failed: %s\n", nids_errbuf);
        return 1;
    }

    // Create LibHTP configuration
    cfg = htp_config_create();
    htp_config_set_server_personality(cfg, HTP_SERVER_APACHE_2_2);

    htp_config_register_response(cfg, callback_response);
    htp_config_register_log(cfg, callback_log);

    // Run libnids
    nids_register_tcp(tcp_callback);
    nids_run();

    // Destroy LibHTP configuration
    htp_config_destroy(cfg);

    return 0;
}
Exemple #4
0
/**
 * Creates a new configuration structure. Configuration structures created at
 * configuration time must not be changed afterwards in order to support lock-less
 * copying.
 *
 * @return New configuration structure.
 */
htp_cfg_t *htp_config_create() {
    htp_cfg_t *cfg = calloc(1, sizeof(htp_cfg_t));
    if (cfg == NULL) return NULL;

    cfg->field_limit_hard = HTP_HEADER_LIMIT_HARD;
    cfg->field_limit_soft = HTP_HEADER_LIMIT_SOFT;
    cfg->log_level = HTP_LOG_NOTICE;

    cfg->path_u_bestfit_map = bestfit_1252;
    cfg->path_replacement_char = '?';

    // No need to create hooks here; they will be created on-demand,
    // during callback registration

    // Set the default personality before we return
    htp_config_set_server_personality(cfg, HTP_SERVER_MINIMAL);

    return cfg;
}
Exemple #5
0
    virtual void SetUp() {
        home = getenv("srcdir");
        if (home == NULL) {
            fprintf(stderr, "This program needs environment variable 'srcdir' set.");
            exit(EXIT_FAILURE);
        }

        cfg = htp_config_create();
        htp_config_set_server_personality(cfg, HTP_SERVER_APACHE_2);

        connp = htp_connp_create(cfg);
        tx = htp_connp_tx_create(connp);
        htp_tx_set_user_data(tx, &output);

        decompressor = htp_gzip_decompressor_create(connp, HTP_COMPRESSION_GZIP);
        decompressor->callback = GUnzip_decompressor_callback;

        o_boxing_wizards = bstr_dup_c("The five boxing wizards jump quickly.");
        output = NULL;
    }