You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/* * ModSecurity, http://www.modsecurity.org/ * Copyright (c) 2015 - 2021 Trustwave Holdings, Inc. (http://www.trustwave.com/) * * You may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * If any of the files related to licensing are missing or if you have any * other questions related to licensing please contact Trustwave Holdings, Inc. * directly using the email address security@modsecurity.org. * */#include<stdio.h>#include<stdlib.h>#include<string.h>#include"modsecurity/modsecurity.h"#include"modsecurity/rules_set.h"#include<modsecurity/transaction.h>#include<modsecurity/intervention.h>voidlog_callback(void*data, constvoid*ruleMessage) {
constModSecurityIntervention*intervention= (constModSecurityIntervention*)ruleMessage;
if (intervention->log!=NULL) {
printf("Log: %s\n", intervention->log);
}
}
charmain_rule_uri[] ="basic_rules.conf";
intmain (intargc, char**argv)
{
intret;
constchar*error=NULL;
ModSecurity*modsec;
Transaction*transaction=NULL;
RulesSet*rules;
modsec=msc_init();
msc_set_connector_info(modsec, "ModSecurity-test v0.0.1-alpha (Simple " \
"example on how to use ModSecurity API");
rules=msc_create_rules_set();
ret=msc_rules_add_file(rules, main_rule_uri, &error);
if (ret<0) {
fprintf(stderr, "Problems loading the rules --\n");
fprintf(stderr, "%s\n", error);
goto end;
}
// **Segment error**msc_set_log_cb(modsec, log_callback);
// msc_rules_dump(rules);// 打开日志文件FILE*log_file=fopen("webalert.txt", "a");
if (log_file==NULL) {
fprintf(stderr, "Failed to open log file\n");
msc_rules_cleanup(rules);
msc_cleanup(modsec);
return1;
}
transaction=msc_new_transaction(modsec, rules, NULL);
msc_process_connection(transaction, "127.0.0.1", 12345, "127.0.0.1", 80);
msc_process_uri(transaction,
"http://www.modsecurity.org/index.php?id=select../../../etc/passwd",
"GET", "1.1");
//msc_process_request_headers(transaction);// 模拟请求参数msc_add_request_header(transaction, "Host", "example.com");
msc_add_request_header(transaction, "User-Agent", "TestAgent");
msc_add_request_header(transaction, "Accept", "*/*");
msc_add_request_header(transaction, "Content-Type", "application/x-www-form-urlencoded");
// 处理请求头msc_process_request_headers(transaction);
msc_process_request_body(transaction);
msc_process_logging(transaction);
end:
if(error!=NULL)
msc_rules_error_cleanup(error);
msc_rules_cleanup(rules);
msc_cleanup(modsec);
return0;
}
The text was updated successfully, but these errors were encountered:
ModSecurityIntervention is a completely different type as the function expects there. You can consider ruleMessage there is a C string. Perhaps the segment error caused by this, but as I wrote I wasn't able to reproduce this.
The text was updated successfully, but these errors were encountered: