3535#include "fuzzy.h"
3636#endif
3737
38- #include "libinjection/libinjection.h"
38+ #include "others/libinjection/src/libinjection.h"
39+ #include "others/libinjection/src/libinjection_error.h"
3940
4041#ifdef WITH_PCRE_STUDY
4142#ifdef WITH_PCRE_JIT
@@ -2279,6 +2280,14 @@ static int msre_op_contains_execute(modsec_rec *msr, msre_rule *rule, msre_var *
22792280 return 0 ;
22802281}
22812282
2283+ /** libinjection evaluate
2284+ * evaluates the result of a libinjection function
2285+ * based on injection_result_t enum values
2286+ */
2287+ static int libinjection_evaluate (injection_result_t result ) {
2288+ return (result != LIBINJECTION_RESULT_FALSE );
2289+ }
2290+
22822291/** libinjection detectSQLi
22832292 * links against files in libinjection directory
22842293 * See www.client9.com/libinjection for details
@@ -2292,21 +2301,41 @@ static int msre_op_detectSQLi_execute(modsec_rec *msr, msre_rule *rule, msre_var
22922301 assert (var != NULL );
22932302 assert (error_msg != NULL );
22942303 char fingerprint [8 ];
2295- int issqli ;
2304+ injection_result_t issqli ;
22962305 int capture ;
22972306
22982307 issqli = libinjection_sqli (var -> value , var -> value_len , fingerprint );
22992308 capture = apr_table_get (rule -> actionset -> actions , "capture" ) ? 1 : 0 ;
23002309
2301- if (issqli ) {
2302- set_match_to_tx (msr , capture , fingerprint , 0 );
2303-
2304- * error_msg = apr_psprintf (msr -> mp , "detected SQLi using libinjection with fingerprint '%s'" ,
2305- fingerprint );
2306- if (msr -> txcfg -> debuglog_level >= 9 ) {
2307- msr_log (msr , 9 , "ISSQL: libinjection fingerprint '%s' matched input '%s'" ,
2308- fingerprint ,
2309- log_escape_ex (msr -> mp , var -> value , var -> value_len ));
2310+ if (libinjection_evaluate (issqli )) {
2311+ switch (issqli ) {
2312+ case LIBINJECTION_RESULT_TRUE :
2313+ set_match_to_tx (msr , capture , fingerprint , 0 );
2314+ * error_msg = apr_psprintf (msr -> mp , "detected SQLi using libinjection with fingerprint '%s'" ,
2315+ fingerprint );
2316+ if (msr -> txcfg -> debuglog_level >= 9 ) {
2317+ msr_log (msr , 9 , "ISSQL: libinjection fingerprint '%s' matched input '%s'" ,
2318+ fingerprint ,
2319+ log_escape_ex (msr -> mp , var -> value , var -> value_len ));
2320+ }
2321+ break ;
2322+ case LIBINJECTION_RESULT_ERROR :
2323+ set_match_to_tx_safe (msr , capture , var -> value , var -> value_len , 0 );
2324+ * error_msg = apr_psprintf (msr -> mp , "libinjection parser error" );
2325+ if (msr -> txcfg -> debuglog_level >= 9 ) {
2326+ msr_log (msr , 9 , "ISSQL: libinjection's input '%s' caused a parser error" ,
2327+ log_escape_ex (msr -> mp , var -> value , var -> value_len ));
2328+ }
2329+ break ;
2330+ default :
2331+ set_match_to_tx_safe (msr , capture , var -> value , var -> value_len , 0 );
2332+ * error_msg = apr_psprintf (msr -> mp , "unexpected libinjection result: (%d)" , issqli );
2333+ if (msr -> txcfg -> debuglog_level >= 9 ) {
2334+ msr_log (msr , 9 , "ISSQL: libinjection's input '%s' caused an unexpected result: (%d)" ,
2335+ log_escape_ex (msr -> mp , var -> value , var -> value_len ),
2336+ issqli );
2337+ }
2338+ break ;
23102339 }
23112340 } else {
23122341 if (msr -> txcfg -> debuglog_level >= 9 ) {
@@ -2315,7 +2344,7 @@ static int msre_op_detectSQLi_execute(modsec_rec *msr, msre_rule *rule, msre_var
23152344 }
23162345 }
23172346
2318- return issqli ;
2347+ return libinjection_evaluate ( issqli ) ;
23192348}
23202349
23212350/** libinjection detectXSS
@@ -2329,25 +2358,44 @@ static int msre_op_detectXSS_execute(modsec_rec *msr, msre_rule *rule, msre_var
23292358 assert (var != NULL );
23302359 assert (error_msg != NULL );
23312360 int capture ;
2332- int is_xss ;
2361+ injection_result_t is_xss ;
23332362
23342363 is_xss = libinjection_xss (var -> value , var -> value_len );
23352364 capture = apr_table_get (rule -> actionset -> actions , "capture" ) ? 1 : 0 ;
23362365
2337- if (is_xss ) {
2338- set_match_to_tx (msr , capture , var -> value , 0 );
2339- * error_msg = apr_psprintf (msr -> mp , "detected XSS using libinjection." );
2340-
2341- if (msr -> txcfg -> debuglog_level >= 9 ) {
2342- msr_log (msr , 9 , "IS_XSS: libinjection detected XSS." );
2366+ if (libinjection_evaluate (is_xss )) {
2367+ set_match_to_tx_safe (msr , capture , var -> value , var -> value_len , 0 );
2368+ switch (is_xss ) {
2369+ case LIBINJECTION_RESULT_TRUE :
2370+ * error_msg = apr_psprintf (msr -> mp , "detected XSS using libinjection." );
2371+ if (msr -> txcfg -> debuglog_level >= 9 ) {
2372+ msr_log (msr , 9 , "IS_XSS: libinjection detected XSS in input '%s'" ,
2373+ log_escape_ex (msr -> mp , var -> value , var -> value_len ));
2374+ }
2375+ break ;
2376+ case LIBINJECTION_RESULT_ERROR :
2377+ * error_msg = apr_psprintf (msr -> mp , "libinjection parser error" );
2378+ if (msr -> txcfg -> debuglog_level >= 9 ) {
2379+ msr_log (msr , 9 , "IS_XSS: libinjection's input '%s' caused a parser error" ,
2380+ log_escape_ex (msr -> mp , var -> value , var -> value_len ));
2381+ }
2382+ break ;
2383+ default :
2384+ * error_msg = apr_psprintf (msr -> mp , "unexpected libinjection result: (%d)" , is_xss );
2385+ if (msr -> txcfg -> debuglog_level >= 9 ) {
2386+ msr_log (msr , 9 , "IS_XSS: libinjection's input '%s' caused an unexpected result: (%d)" ,
2387+ log_escape_ex (msr -> mp , var -> value , var -> value_len ),
2388+ is_xss );
2389+ }
2390+ break ;
23432391 }
23442392 } else {
23452393 if (msr -> txcfg -> debuglog_level >= 9 ) {
23462394 msr_log (msr , 9 , "IS_XSS: not XSS, libinjection was not able to find any XSS." );
23472395 }
23482396 }
23492397
2350- return is_xss ;
2398+ return libinjection_evaluate ( is_xss ) ;
23512399}
23522400
23532401
0 commit comments