Beispiel #1
0
static void htpy_connp_dealloc(htpy_connp *self) {
	/*
	 * Decrement reference counters and free the underlying
	 * libhtp backed storage.
	 */
	Py_XDECREF(self->obj_store);
	Py_XDECREF(self->cfg);
	Py_XDECREF(self->request_start_callback);
	Py_XDECREF(self->request_line_callback);
	Py_XDECREF(self->request_uri_normalize_callback);
	Py_XDECREF(self->request_headers_callback);
	Py_XDECREF(self->request_header_data_callback);
	Py_XDECREF(self->request_body_data_callback);
	Py_XDECREF(self->request_trailer_callback);
	Py_XDECREF(self->request_trailer_data_callback);
	Py_XDECREF(self->request_complete_callback);
	Py_XDECREF(self->response_start_callback);
	Py_XDECREF(self->response_line_callback);
	Py_XDECREF(self->response_headers_callback);
	Py_XDECREF(self->response_header_data_callback);
	Py_XDECREF(self->response_body_data_callback);
	Py_XDECREF(self->response_trailer_callback);
	Py_XDECREF(self->response_trailer_data_callback);
	Py_XDECREF(self->response_complete_callback);
	Py_XDECREF(self->transaction_complete_callback);
	Py_XDECREF(self->log_callback);
	htp_connp_destroy_all(self->connp);
	self->ob_type->tp_free((PyObject *) self);
}
Beispiel #2
0
 virtual void TearDown() {
     bstr_free(output);
     bstr_free(o_boxing_wizards);
     decompressor->destroy(decompressor);
     htp_connp_destroy_all(connp);
     htp_config_destroy(cfg);
 }
Beispiel #3
0
void rbhtp_connp_free( void* p )
{
	htp_connp_t* connp = (htp_connp_t*)p;
	if ( connp )
		htp_connp_destroy_all( connp );
}
Beispiel #4
0
/**
 * Called by libnids whenever it has an event we have to handle.
 *
 * @param tcp
 * @param user_data
 */
void tcp_callback (struct tcp_stream *tcp, void **user_data) {
    stream_data *sd = *user_data;

    // New connection
    if (tcp->nids_state == NIDS_JUST_EST) {
        tcp->client.collect++;
        tcp->server.collect++;
        tcp->server.collect_urg++;
        tcp->client.collect_urg++;

        // Allocate custom per-stream data
        sd = calloc(1, sizeof(stream_data));
        sd->id = counter++;
        sd->direction = -1;
        sd->fd = -1;
        sd->log_level = -1;
        sd->chunks = list_array_create(16);
        sd->inbound_chunks = list_array_create(16);
        sd->outbound_chunks = list_array_create(16);
        sd->req_count = 1;

        // Init LibHTP parser
        sd->connp = htp_connp_create(cfg);
        if (sd->connp == NULL) {
            fprintf(stderr, "Failed to create LibHTP parser instance.\n");
            exit(1);
        }

        // Associate TCP stream information with the HTTP connection parser
        htp_connp_set_user_data(sd->connp, sd);

        // Associate TCP stream information with the libnids structures
        *user_data = sd;

        return;
    }

    // Connection close
    if (tcp->nids_state == NIDS_CLOSE) {
        if (sd == NULL) return;

        // Destroy parser
        htp_connp_destroy_all(sd->connp);

        // Free custom per-stream data
        free_stream_data(sd);

        return;
    }

    // Connection close (RST)
    if (tcp->nids_state == NIDS_RESET) {
        if (sd == NULL) return;

        // Destroy parser
        htp_connp_destroy_all(sd->connp);

        // Free custom per-stream data
        free_stream_data(sd);

        return;
    }

    if (tcp->nids_state == NIDS_DATA) {
        struct half_stream *hlf;
        int direction;

        if (tcp->client.count_new) {
            hlf = &tcp->client;
            direction = DIRECTION_SERVER;
        } else {
            hlf = &tcp->server;
            direction = DIRECTION_CLIENT;
        }

        if (sd == NULL) return;

        if (sd->direction == -1) {
            sd->direction = direction;
        }

        // Write data to disk or store for later
        if (sd->fd == -1) {
            // Store data, as we may need it later
            chunk_t *chunk = calloc(1, sizeof(chunk_t));
            // TODO
            chunk->direction = direction;
            chunk->data = malloc(hlf->count_new);
            // TODO
            chunk->len = hlf->count_new;
            memcpy(chunk->data, hlf->data, chunk->len);

            list_add(sd->chunks, chunk);
        } else {
            // No need to store, write directly to file

            if (sd->chunk_counter != 0) {
                write(sd->fd, "\r\n", 2);
            }

            if (sd->direction == direction) {
                write(sd->fd, ">>>\r\n", 5);
            } else {
                write(sd->fd, "<<<\r\n", 5);
            }

            write(sd->fd, hlf->data, hlf->count_new);

            sd->chunk_counter++;
        }

        // Process data
        process_stream_data(sd, direction, hlf);

        return;
    }
}