mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-30 11:44:32 +03:00
Gsb matched urls set into tx variable
This commit is contained in:
@@ -1005,6 +1005,37 @@ static int msre_op_pm_execute(modsec_rec *msr, msre_rule *rule, msre_var *var, c
|
||||
|
||||
/* gsbLookup */
|
||||
|
||||
static int set_gsb_to_tx(modsec_rec *msr, int capture, const char *match) {
|
||||
|
||||
if (capture) {
|
||||
int i;
|
||||
msc_string *s = (msc_string *)apr_pcalloc(msr->mp, sizeof(msc_string));
|
||||
|
||||
if (s == NULL) return -1;
|
||||
|
||||
s->name = "0";
|
||||
s->name_len = strlen(s->name);
|
||||
s->value = apr_pstrdup(msr->mp, match);
|
||||
if (s->value == NULL) return -1;
|
||||
s->value_len = strlen(s->value);
|
||||
apr_table_setn(msr->tx_vars, s->name, (void *)s);
|
||||
|
||||
if (msr->txcfg->debuglog_level >= 9) {
|
||||
msr_log(msr, 9, "Added phrase match to TX.0: %s",
|
||||
log_escape_nq_ex(msr->mp, s->value, s->value_len));
|
||||
}
|
||||
|
||||
/* Unset the remaining ones (from previous invocations). */
|
||||
for(i = 1; i <= 9; i++) {
|
||||
char buf[2];
|
||||
apr_snprintf(buf, sizeof(buf), "%d", i);
|
||||
apr_table_unset(msr->tx_vars, buf);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int verify_gsb(gsb_db *gsb, msre_rule *rule, const char *match, unsigned int match_length) {
|
||||
apr_md5_ctx_t ctx;
|
||||
apr_status_t rc;
|
||||
@@ -1070,6 +1101,7 @@ static int msre_op_gsbLookup_execute(modsec_rec *msr, msre_rule *rule, msre_var
|
||||
unsigned int size = var->value_len;
|
||||
char *base = NULL, *canon = NULL, *savedptr = NULL;
|
||||
char *str = NULL, *entire = NULL;
|
||||
int capture;
|
||||
|
||||
if(regex == NULL) {
|
||||
if (msr->txcfg->debuglog_level >= 8) {
|
||||
@@ -1094,6 +1126,8 @@ static int msre_op_gsbLookup_execute(modsec_rec *msr, msre_rule *rule, msre_var
|
||||
return -1;
|
||||
}
|
||||
|
||||
capture = apr_table_get(rule->actionset->actions, "capture") ? 1 : 0;
|
||||
|
||||
memcpy(data,var->value,var->value_len);
|
||||
|
||||
while (offset < size && (rv = msc_regexec_ex(regex, data, size, offset, PCRE_NOTEMPTY, ovector, 30, &my_error_msg)) >= 0)
|
||||
@@ -1122,8 +1156,10 @@ static int msre_op_gsbLookup_execute(modsec_rec *msr, msre_rule *rule, msre_var
|
||||
|
||||
ret = verify_gsb(gsb, rule, match, match_length);
|
||||
|
||||
if(ret > 0)
|
||||
if(ret > 0) {
|
||||
set_gsb_to_tx(msr, capture, match);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* append / in the end of full url */
|
||||
if ((match[match_length -1] != '/') && (strchr(match,'?') == NULL)) {
|
||||
@@ -1138,10 +1174,12 @@ static int msre_op_gsbLookup_execute(modsec_rec *msr, msre_rule *rule, msre_var
|
||||
canon_length = strlen(canon);
|
||||
ret = verify_gsb(gsb, rule, canon, canon_length);
|
||||
|
||||
if(ret > 0)
|
||||
if(ret > 0) {
|
||||
set_gsb_to_tx(msr, capture, canon);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
str = apr_pstrdup(rule->ruleset->mp,match);
|
||||
|
||||
@@ -1163,9 +1201,11 @@ static int msre_op_gsbLookup_execute(modsec_rec *msr, msre_rule *rule, msre_var
|
||||
canon_length = strlen(canon);
|
||||
ret = verify_gsb(gsb, rule, canon, canon_length);
|
||||
|
||||
if(ret > 0)
|
||||
if(ret > 0) {
|
||||
set_gsb_to_tx(msr, capture, canon);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user