From 90856f42b6bb37552ecfccb2d895bb348721dbfd Mon Sep 17 00:00:00 2001 From: Mihai Pitu Date: Wed, 18 Sep 2013 17:41:18 +0100 Subject: [PATCH] BeanShell support --- apache2/re_actions.c | 51 +++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/apache2/re_actions.c b/apache2/re_actions.c index 12505574..1bb652fc 100644 --- a/apache2/re_actions.c +++ b/apache2/re_actions.c @@ -1,4 +1,4 @@ -/* +/* * ModSecurity for Apache 2.x, http://www.modsecurity.org/ * Copyright (c) 2004-2013 Trustwave Holdings, Inc. (http://www.trustwave.com/) * @@ -2197,31 +2197,34 @@ static char *msre_action_exec_validate(msre_engine *engine, apr_pool_t *mp, msre static apr_status_t msre_action_exec_execute(modsec_rec *msr, apr_pool_t *mptmp, msre_rule *rule, msre_action *action) { -//#ifdef WITH_BEANSHELL - if (action->param != NULL) { - int lenparam = strlen(action->param); + //#ifdef WITH_BEANSHELL + int bsh = 0; + int lenparam = action->param != NULL ? strlen(action->param) : -1; + if (lenparam > 0) if ((action->param[lenparam - 4] == '.' && - action->param[lenparam - 3] == 'b' && - action->param[lenparam - 2] == 's' && - action->param[lenparam - 1] == 'h')) { - //beanshell_execute(action->param, msr, mptmp, rule); - char *script_output = NULL; - int rc; - const char *start = "java -classpath bsh*.jar bsh.Interpreter "; + action->param[lenparam - 3] == 'b' && + action->param[lenparam - 2] == 's' && + action->param[lenparam - 1] == 'h')) + bsh = 1; - char *command = (char*) apr_palloc(mptmp, strlen(start) + lenparam + 1); - msr_log(msr, 1, "Executing: %s", action->param); - strcpy(command, start); - strcat(command, action->param); - command[strlen(start) + lenparam] = '\0'; - rc = apache2_exec(msr, command, NULL, &script_output); - if (rc != 1) { - msr_log(msr, 1, "Failed to execute: %s", action->param); - return 0; - } + if (bsh) { + //beanshell_execute(action->param, msr, mptmp, rule); + char *script_output = NULL; + int rc; + const char *start = "java -classpath bsh*.jar bsh.Interpreter "; + + char *command = (char*) apr_palloc(mptmp, strlen(start) + lenparam + 1); + msr_log(msr, 1, "beanshell ftw"); + strcpy(command, start); + strcat(command, action->param); + command[strlen(start) + lenparam] = '\0'; + rc = apache2_exec(msr, command, NULL, &script_output); + if (rc != 1) { + msr_log(msr, 1, "Failed to execute: %s", action->param); + return 0; } - } -//#endif + } else + //#endif #if defined(WITH_LUA) if (action->param_data != NULL) { /* Lua */ msc_script *script = (msc_script *)action->param_data; @@ -2982,4 +2985,4 @@ void msre_engine_register_default_actions(msre_engine *engine) { NULL, msre_action_append_execute ); -} +} \ No newline at end of file