/** * Invoked at the end of every transaction. * * @param connp */ int callback_response(htp_connp_t *connp) { stream_data *sd = (stream_data *)htp_connp_get_user_data(connp); char *x = bstr_util_strdup_to_c(connp->out_tx->request_line); fprintf(stdout, "[#%d/%d] %s\n", sd->id, sd->req_count, x); free(x); sd->req_count++; }
/** * Invoked every time LibHTP wants to log. * * @param log */ int callback_log(htp_log_t *log) { stream_data *sd = (stream_data *)htp_connp_get_user_data(log->connp); if ((sd->log_level == -1)||(sd->log_level > log->level)) { sd->log_level = log->level; } if (log->code != 0) { fprintf(stderr, "[#%d/%d][%d][code %d][file %s][line %d] %s\n", sd->id, sd->req_count, log->level, log->code, log->file, log->line, log->msg); } else { fprintf(stderr, "[#%d/%d][%d][file %s][line %d] %s\n", sd->id, sd->req_count, log->level, log->file, log->line, log->msg); } // If this is the first time a log message was generated for this connection, // start writing the entire thing to a file on disk. if (sd->fd == -1) { char filename[256]; chunk_t *chunk; // TODO Use IP addresses and ports in filename snprintf(filename, 255, "conn-%d.t", sd->id); sd->fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR); if (sd->fd == -1) { fprintf(stderr, "Failed to create file %s: %s\n", filename, strerror(errno)); exit(1); } // Write to disk the data we have in memory list_iterator_reset(sd->chunks); while((chunk = list_iterator_next(sd->chunks)) != NULL) { if (sd->chunk_counter != 0) { write(sd->fd, "\r\n", 2); } if (sd->direction == chunk->direction) { write(sd->fd, ">>>\r\n", 5); } else { write(sd->fd, "<<<\r\n", 5); } write(sd->fd, chunk->data, chunk->len); sd->chunk_counter++; } } }
int htpy_log_callback(htp_log_t *log) { PyObject *obj = (PyObject *) htp_connp_get_user_data(log->connp); PyObject *arglist = NULL; PyObject *res; long i; if (((htpy_connp *) obj)->obj_store) arglist = Py_BuildValue("(OsiO)", (htpy_connp *) obj, log->msg, log->level, ((htpy_connp *) obj)->obj_store); else arglist = Py_BuildValue("(Osi)", (htpy_connp *) obj, log->msg, log->level); if (!arglist) return HTP_ERROR; res = PyObject_CallObject(((htpy_connp *) obj)->log_callback, arglist); Py_DECREF(arglist); if (PyErr_Occurred() != NULL) { PyErr_PrintEx(0); return HTP_ERROR; } i = PyInt_AsLong(res); Py_DECREF(res); return((int) i); }
// File data is a tx, file information, and file data. The callback thus // takes those three as arguments. int rbhtp_config_callback_request_file_data( htp_file_data_t* filedata ) { htp_connp_t* connp = filedata->tx->connp; VALUE userdata = (VALUE)htp_connp_get_user_data( connp ); VALUE config = rb_iv_get( userdata, "@cfg" ); VALUE proc = rb_iv_get( config, "@request_file_data_proc" ); if ( proc != Qnil ) { VALUE data = Qnil; if ( filedata->data ) data = rb_str_new( (char*)filedata->data, filedata->len ); return INT2FIX( rb_funcall( proc, rb_intern( "call" ), 2, rb_funcall( cTx, rb_intern( "new" ), 1, Data_Wrap_Struct( rb_cObject, 0, 0, filedata->tx ) ), rb_funcall( cFile, rb_intern( "new" ), 1, Data_Wrap_Struct( rb_cObject, 0, 0, filedata->file ) ), data ) ); } return 1; }