Very first commit: libmodsecurity

Check the README.md file for further information about the libmodsecurity.
This commit is contained in:
Felipe Zimmerle 2015-06-26 14:35:15 -03:00
parent 33cbe0452a
commit 95cb4c56ab
153 changed files with 12862 additions and 0 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "test/test-cases/secrules-language-tests"]
path = test/test-cases/secrules-language-tests
url = https://github.com/SpiderLabs/secrules-language-tests

3
AUTHORS Normal file
View File

@ -0,0 +1,3 @@
zimmerle = Felipe Zimmerle <felipe@zimmerle.org>
rbarnett = Ryan C. Barnett <rcbarnett@gmail.com>
csanders-git = Chaim Sanders <chaim@chaimsanders.com>

201
LICENSE Normal file
View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
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
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

33
Makefile.am Normal file
View File

@ -0,0 +1,33 @@
ACLOCAL_AMFLAGS = -I build
SUBDIRS = \
src \
test \
doc \
examples
# make clean
CLEANFILES =
# make maintainer-clean
MAINTAINERCLEANFILES = \
Makefile.in \
aclocal.m4 \
ar-lib \
build/libtool.m4 \
build/ltoptions.m4 \
build/ltsugar.m4 \
build/ltversion.m4 \
build/lt~obsolete.m4 \
compile \
config.guess \
config.sub \
configure \
install-sh \
ltmain.sh \
ylwrap \
missing \
depcomp

271
README.md Normal file
View File

@ -0,0 +1,271 @@
# Introduction
libmodsecurity is a library which provides the functionalities of ModSecurity
to be used on your application. It is capable to load/interpret rules on the
ModSecurity SecRules format and apply them on the HTTP content informed by your
application.
Currently the libmodsecurity is used by the ModSecurity nginx connector
(ModSecurity-nginx).
Notice: This project is under development and it is not ready to be placed in
production yet. It is not supporting all the operators and/or actions of the
SecRules languages yet.
### What is the difference between this project and the old ModSecurity (v2.x.x)?
* All Apache dependences were removed
* Higher performance
* New features
ModSecurity project started as just an Apache module, and as the project had
been extending to be used by other platforms (nginx, IIS and others) it became
necessary to remove the Apache dependencies, making the project more platform
independent.
libmodsecurity is no longer dependent on the Apache web server (both
compilation and runtime), and it also performs a way better. This project adds
also some new features, for instance, further it will be expended to support
audit logs into a JSON format.
### It is no longer an Apache module.
This branch does not contain the ModSecurity module for Apache, nginx or IIS,
instead it contains a library which can be consumed by connectors that can
interface with your web server, for instance the ModSecurity-nginx
(https://github.com/SpiderLabs/ModSecurity-nginx) project.
The connectors are separated projects with different release cycles, issues and
development trees.
# Compilation
Before starting the compilation process, make sure that you have all the
dependencies in place. Read the subsection “Dependencies” for further
information.
After the compilation make sure that there are no issues on your
build/platform. We strongly recommend the utilization of the unit tests and
regression tests. The test utilities are located under the subfolder tests.
As a dynamic library, dont forget that it has to be installed in a folder
where your O.S. will look for dynamic libraries in it.
### Unix (Linux, MacOS, FreeBSD, …)
On unix the project uses autotools to help the compilation process.
```shell
$ ./build.sh
$ ./configure
$ make
$ sudo make install
```
### Windows
Windows build is not ready yet.
## Dependencies
This library is written in C++ using the C++11 standards. It also uses the Flex
and Yacc to produce the “Sec Rules Language” parser. Another dependency that is
mandatory is the YAJL, as ModSecurity uses JSON for logging, and testing
framework.
Others dependencies are operators related and may not be mandatory. For
instance: libinjection is needed for the operator @detectXSS, also curl is
needed for the SecRemoteRules. If those libraries are missing ModSecurity will
be compiled without the support for the operator @detectXSS and the
configuration directive SecRemoteRules.
# Library documentation
The library documentation is written within the code in Doxygen format. Use
doxygen utility with the configuration file “doxygen.cfg” inside the "doc/"
subfolder to generate HTML output of the documentation, including examples.
# Library utilization
The library provides a C++ and C interface. Some resources are currently only
available to the C++, for instance: the capability to create custom logging
mechanism (see the regression test to check how those logging mechanism works).
The objective is to have both APIs (C, C++) providing the same functionalities,
if you are missing something, please report.
Inside the subfolder examples, there are simple examples on how to use the API.
Below some are illustrated:
### Simple example using C++
```c++
using ModSecurity::ModSecurity;
using ModSecurity::Rules;
using ModSecurity::Assay;
ModSecurity *modsec;
ModSecurity::Rules *rules;
modsec = new ModSecurity();
rules = new Rules();
rules->loadFromUri(rules_file);
Assay *modsecAssay = new Assay(modsec, rules);
modsecAssay->processConnection("127.0.0.1");
if (modsecAssay->intervention()) {
std::cout << "There is an intervention" << std::endl;
}
```
### Simple example using C
```c
#include "modsecurity/modsecurity.h"
#include "modsecurity/assay.h"
char main_rule_uri[] = "basic_rules.conf";
int main (int argc, char **argv)
{
ModSecurity *modsec = NULL;
Assay *assay = NULL;
Rules *rules = NULL;
modsec = msc_init();
rules = msc_create_rules_set();
msc_rules_add_file(rules, main_rule_uri);
assay = msc_new_assay(modsec, rules);
msc_process_connection(assay, "127.0.0.1");
msc_process_uri(assay, "http://www.modsecurity.org/test?key1=value1&key2=value2&key3=value3&test=args&test=test");
msc_process_request_headers(assay);
msc_process_request_body(assay);
msc_process_response_headers(assay);
msc_process_response_body(assay);
return 0;
}
```
# Contributing
You are more than welcome to contribute with the growth of our community. New
functionalities, fixes, bug report, support beginners users, anything that you
are willing to help.
## Providing patches
We prefer to have your patch within the GtiHub infrastructure to facilitate our
review work, and our Q.A. integration. GitHub provides an excellent
documentation on how to perform “Pull Requests”, more information available
here: https://help.github.com/articles/using-pull-requests/
Please respect the coding style. Pull requests can include various commits, so
provide one fix or one functionality per commit. Do not change anything outside
the scope of our target work (e.g. coding style in a function that you have
passed by). For further information about the coding style used in this
project, please check: https://www.chromium.org/blink/coding-style
Provides explanative commit messages. First line gives the highlight of your
patch, 3rd and on give a more detailed explanation/technical details about your
patch. Patch explanation is valuable during the review process.
### Dont know where to start?
Within our code there are various items marked as TODO or FIXME that may need
your attention. Check the list of items by performing a grep:
```
$ cd /path/to/modsecurity-nginx
$ egrep -Rin "TODO|FIXME" -R *
```
A TODO list is also available as part of the Doxygen documentation.
### Testing your patch
Along with the manual testing, we strongly recommend you to use the our
regression tests and unit tests. If you have implemented an operator, dont
forget to create unit tests for it. Anything else, it is recommended to have a
regression test for it.
The regression test and unit test utilities are native and do not demand any
external tool or script, although you need to fetch the test cases from other
repositories as they are shared with other versions of ModSecurity, those
others repositories git submodules. To fetch the submodules repository and run
the utilities, follow the commands listed below:
```shell
$ cd /path/to/your/ModSecurity
$ git submodule foreach git pull
$ cd tests
$ ./regression-tests
$ ./unit-tests
```
### Debugging
Before start the debugging process, make sure where your bug is. The problem
could be on your connector or in libmodsecurity. In order to identify where the
bug is, it is recommended the creation of a regression test that mimic the
scenario where the bug is happening. If the bug is reproducible with the
regression-test utility, then it will be a way simple to debug. On Linux it is
recommended the utilization of gdb and/or valgrind.
During the configuration/compilation time, you may want to disable the compiler
optimization making your “back traces” populated with readable data. Use the
CFLAGS to disable the compilation optimization parameters:
```shell
$ export CFLAGS=”-g -02”
$ ./build.sh
$ ./configure
$ make
$ sudo make install
```
## Reporting Issues
If you are facing a configuration issue or something is not working as you
expected to be, please use ModSecurity users mailing list. Issues on GitHub
are also welcomed, but prefer to have user questions on the mailing list first,
where you can reach an entire community. Also dont forget to look for an
existent issue before open a new one.
If you are willing to open an issue on GitHub, dont forget to tell us the
version of your libmodsecurity and the version of a specific connector if there
is one.
### Security issue
Please do not make public any security issue. Contact us at:
security@modsecurity.org reporting the issue. Once the problem is fixed your
credits will be given.
## Feature request
It will be a pleasure to discuss any feature request with the community, also,
feel free to open GitHub issues requesting for new features. Before opening a
new issue, please check if there is one already opened with the same subject.
## Packing
Having our packages in distros on time is a desire that we have, so let us know
if there is anything we can do to facilitate your work as a packager.

13
build.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/sh
rm -rf autom4te.cache
rm -f aclocal.m4
case `uname` in Darwin*) glibtoolize --force --copy ;;
*) libtoolize --force --copy ;; esac
autoreconf --install
autoheader
automake --add-missing --foreign --copy --force-missing
autoconf --force
rm -rf autom4te.cache

0
build/.empty Normal file
View File

533
build/ax_prog_doxygen.m4 Normal file
View File

@ -0,0 +1,533 @@
# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_prog_doxygen.html
# ===========================================================================
#
# SYNOPSIS
#
# DX_INIT_DOXYGEN(PROJECT-NAME, DOXYFILE-PATH, [OUTPUT-DIR])
# DX_DOXYGEN_FEATURE(ON|OFF)
# DX_DOT_FEATURE(ON|OFF)
# DX_HTML_FEATURE(ON|OFF)
# DX_CHM_FEATURE(ON|OFF)
# DX_CHI_FEATURE(ON|OFF)
# DX_MAN_FEATURE(ON|OFF)
# DX_RTF_FEATURE(ON|OFF)
# DX_XML_FEATURE(ON|OFF)
# DX_PDF_FEATURE(ON|OFF)
# DX_PS_FEATURE(ON|OFF)
#
# DESCRIPTION
#
# The DX_*_FEATURE macros control the default setting for the given
# Doxygen feature. Supported features are 'DOXYGEN' itself, 'DOT' for
# generating graphics, 'HTML' for plain HTML, 'CHM' for compressed HTML
# help (for MS users), 'CHI' for generating a seperate .chi file by the
# .chm file, and 'MAN', 'RTF', 'XML', 'PDF' and 'PS' for the appropriate
# output formats. The environment variable DOXYGEN_PAPER_SIZE may be
# specified to override the default 'a4wide' paper size.
#
# By default, HTML, PDF and PS documentation is generated as this seems to
# be the most popular and portable combination. MAN pages created by
# Doxygen are usually problematic, though by picking an appropriate subset
# and doing some massaging they might be better than nothing. CHM and RTF
# are specific for MS (note that you can't generate both HTML and CHM at
# the same time). The XML is rather useless unless you apply specialized
# post-processing to it.
#
# The macros mainly control the default state of the feature. The use can
# override the default by specifying --enable or --disable. The macros
# ensure that contradictory flags are not given (e.g.,
# --enable-doxygen-html and --enable-doxygen-chm,
# --enable-doxygen-anything with --disable-doxygen, etc.) Finally, each
# feature will be automatically disabled (with a warning) if the required
# programs are missing.
#
# Once all the feature defaults have been specified, call DX_INIT_DOXYGEN
# with the following parameters: a one-word name for the project for use
# as a filename base etc., an optional configuration file name (the
# default is 'Doxyfile', the same as Doxygen's default), and an optional
# output directory name (the default is 'doxygen-doc').
#
# Automake Support
#
# The following is a template aminclude.am file for use with Automake.
# Make targets and variables values are controlled by the various
# DX_COND_* conditionals set by autoconf.
#
# The provided targets are:
#
# doxygen-doc: Generate all doxygen documentation.
#
# doxygen-run: Run doxygen, which will generate some of the
# documentation (HTML, CHM, CHI, MAN, RTF, XML)
# but will not do the post processing required
# for the rest of it (PS, PDF, and some MAN).
#
# doxygen-man: Rename some doxygen generated man pages.
#
# doxygen-ps: Generate doxygen PostScript documentation.
#
# doxygen-pdf: Generate doxygen PDF documentation.
#
# Note that by default these are not integrated into the automake targets.
# If doxygen is used to generate man pages, you can achieve this
# integration by setting man3_MANS to the list of man pages generated and
# then adding the dependency:
#
# $(man3_MANS): doxygen-doc
#
# This will cause make to run doxygen and generate all the documentation.
#
# The following variable is intended for use in Makefile.am:
#
# DX_CLEANFILES = everything to clean.
#
# Then add this variable to MOSTLYCLEANFILES.
#
# ----- begin aminclude.am -------------------------------------
#
# ## --------------------------------- ##
# ## Format-independent Doxygen rules. ##
# ## --------------------------------- ##
#
# if DX_COND_doc
#
# ## ------------------------------- ##
# ## Rules specific for HTML output. ##
# ## ------------------------------- ##
#
# if DX_COND_html
#
# DX_CLEAN_HTML = @DX_DOCDIR@/html
#
# endif DX_COND_html
#
# ## ------------------------------ ##
# ## Rules specific for CHM output. ##
# ## ------------------------------ ##
#
# if DX_COND_chm
#
# DX_CLEAN_CHM = @DX_DOCDIR@/chm
#
# if DX_COND_chi
#
# DX_CLEAN_CHI = @DX_DOCDIR@/@PACKAGE@.chi
#
# endif DX_COND_chi
#
# endif DX_COND_chm
#
# ## ------------------------------ ##
# ## Rules specific for MAN output. ##
# ## ------------------------------ ##
#
# if DX_COND_man
#
# DX_CLEAN_MAN = @DX_DOCDIR@/man
#
# endif DX_COND_man
#
# ## ------------------------------ ##
# ## Rules specific for RTF output. ##
# ## ------------------------------ ##
#
# if DX_COND_rtf
#
# DX_CLEAN_RTF = @DX_DOCDIR@/rtf
#
# endif DX_COND_rtf
#
# ## ------------------------------ ##
# ## Rules specific for XML output. ##
# ## ------------------------------ ##
#
# if DX_COND_xml
#
# DX_CLEAN_XML = @DX_DOCDIR@/xml
#
# endif DX_COND_xml
#
# ## ----------------------------- ##
# ## Rules specific for PS output. ##
# ## ----------------------------- ##
#
# if DX_COND_ps
#
# DX_CLEAN_PS = @DX_DOCDIR@/@PACKAGE@.ps
#
# DX_PS_GOAL = doxygen-ps
#
# doxygen-ps: @DX_DOCDIR@/@PACKAGE@.ps
#
# @DX_DOCDIR@/@PACKAGE@.ps: @DX_DOCDIR@/@PACKAGE@.tag
# cd @DX_DOCDIR@/latex; \
# rm -f *.aux *.toc *.idx *.ind *.ilg *.log *.out; \
# $(DX_LATEX) refman.tex; \
# $(MAKEINDEX_PATH) refman.idx; \
# $(DX_LATEX) refman.tex; \
# countdown=5; \
# while $(DX_EGREP) 'Rerun (LaTeX|to get cross-references right)' \
# refman.log > /dev/null 2>&1 \
# && test $$countdown -gt 0; do \
# $(DX_LATEX) refman.tex; \
# countdown=`expr $$countdown - 1`; \
# done; \
# $(DX_DVIPS) -o ../@PACKAGE@.ps refman.dvi
#
# endif DX_COND_ps
#
# ## ------------------------------ ##
# ## Rules specific for PDF output. ##
# ## ------------------------------ ##
#
# if DX_COND_pdf
#
# DX_CLEAN_PDF = @DX_DOCDIR@/@PACKAGE@.pdf
#
# DX_PDF_GOAL = doxygen-pdf
#
# doxygen-pdf: @DX_DOCDIR@/@PACKAGE@.pdf
#
# @DX_DOCDIR@/@PACKAGE@.pdf: @DX_DOCDIR@/@PACKAGE@.tag
# cd @DX_DOCDIR@/latex; \
# rm -f *.aux *.toc *.idx *.ind *.ilg *.log *.out; \
# $(DX_PDFLATEX) refman.tex; \
# $(DX_MAKEINDEX) refman.idx; \
# $(DX_PDFLATEX) refman.tex; \
# countdown=5; \
# while $(DX_EGREP) 'Rerun (LaTeX|to get cross-references right)' \
# refman.log > /dev/null 2>&1 \
# && test $$countdown -gt 0; do \
# $(DX_PDFLATEX) refman.tex; \
# countdown=`expr $$countdown - 1`; \
# done; \
# mv refman.pdf ../@PACKAGE@.pdf
#
# endif DX_COND_pdf
#
# ## ------------------------------------------------- ##
# ## Rules specific for LaTeX (shared for PS and PDF). ##
# ## ------------------------------------------------- ##
#
# if DX_COND_latex
#
# DX_CLEAN_LATEX = @DX_DOCDIR@/latex
#
# endif DX_COND_latex
#
# .PHONY: doxygen-run doxygen-doc $(DX_PS_GOAL) $(DX_PDF_GOAL)
#
# .INTERMEDIATE: doxygen-run $(DX_PS_GOAL) $(DX_PDF_GOAL)
#
# doxygen-run: @DX_DOCDIR@/@PACKAGE@.tag
#
# doxygen-doc: doxygen-run $(DX_PS_GOAL) $(DX_PDF_GOAL)
#
# @DX_DOCDIR@/@PACKAGE@.tag: $(DX_CONFIG) $(pkginclude_HEADERS)
# rm -rf @DX_DOCDIR@
# $(DX_ENV) $(DX_DOXYGEN) $(srcdir)/$(DX_CONFIG)
# echo Timestamp >$@
#
# DX_CLEANFILES = \
# @DX_DOCDIR@/@PACKAGE@.tag \
# -r \
# $(DX_CLEAN_HTML) \
# $(DX_CLEAN_CHM) \
# $(DX_CLEAN_CHI) \
# $(DX_CLEAN_MAN) \
# $(DX_CLEAN_RTF) \
# $(DX_CLEAN_XML) \
# $(DX_CLEAN_PS) \
# $(DX_CLEAN_PDF) \
# $(DX_CLEAN_LATEX)
#
# endif DX_COND_doc
#
# ----- end aminclude.am ---------------------------------------
#
# LICENSE
#
# Copyright (c) 2009 Oren Ben-Kiki <oren@ben-kiki.org>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 13
## ----------##
## Defaults. ##
## ----------##
DX_ENV=""
AC_DEFUN([DX_FEATURE_doc], ON)
AC_DEFUN([DX_FEATURE_dot], OFF)
AC_DEFUN([DX_FEATURE_man], OFF)
AC_DEFUN([DX_FEATURE_html], ON)
AC_DEFUN([DX_FEATURE_chm], OFF)
AC_DEFUN([DX_FEATURE_chi], OFF)
AC_DEFUN([DX_FEATURE_rtf], OFF)
AC_DEFUN([DX_FEATURE_xml], OFF)
AC_DEFUN([DX_FEATURE_pdf], ON)
AC_DEFUN([DX_FEATURE_ps], ON)
## --------------- ##
## Private macros. ##
## --------------- ##
# DX_ENV_APPEND(VARIABLE, VALUE)
# ------------------------------
# Append VARIABLE="VALUE" to DX_ENV for invoking doxygen.
AC_DEFUN([DX_ENV_APPEND], [AC_SUBST([DX_ENV], ["$DX_ENV $1='$2'"])])
# DX_DIRNAME_EXPR
# ---------------
# Expand into a shell expression prints the directory part of a path.
AC_DEFUN([DX_DIRNAME_EXPR],
[[expr ".$1" : '\(\.\)[^/]*$' \| "x$1" : 'x\(.*\)/[^/]*$']])
# DX_IF_FEATURE(FEATURE, IF-ON, IF-OFF)
# -------------------------------------
# Expands according to the M4 (static) status of the feature.
AC_DEFUN([DX_IF_FEATURE], [ifelse(DX_FEATURE_$1, ON, [$2], [$3])])
# DX_REQUIRE_PROG(VARIABLE, PROGRAM)
# ----------------------------------
# Require the specified program to be found for the DX_CURRENT_FEATURE to work.
AC_DEFUN([DX_REQUIRE_PROG], [
AC_PATH_TOOL([$1], [$2])
if test "$DX_FLAG_[]DX_CURRENT_FEATURE$$1" = 1; then
AC_MSG_WARN([$2 not found - will not DX_CURRENT_DESCRIPTION])
AC_SUBST(DX_FLAG_[]DX_CURRENT_FEATURE, 0)
fi
])
# DX_TEST_FEATURE(FEATURE)
# ------------------------
# Expand to a shell expression testing whether the feature is active.
AC_DEFUN([DX_TEST_FEATURE], [test "$DX_FLAG_$1" = 1])
# DX_CHECK_DEPEND(REQUIRED_FEATURE, REQUIRED_STATE)
# -------------------------------------------------
# Verify that a required features has the right state before trying to turn on
# the DX_CURRENT_FEATURE.
AC_DEFUN([DX_CHECK_DEPEND], [
test "$DX_FLAG_$1" = "$2" \
|| AC_MSG_ERROR([doxygen-DX_CURRENT_FEATURE ifelse([$2], 1,
requires, contradicts) doxygen-DX_CURRENT_FEATURE])
])
# DX_CLEAR_DEPEND(FEATURE, REQUIRED_FEATURE, REQUIRED_STATE)
# ----------------------------------------------------------
# Turn off the DX_CURRENT_FEATURE if the required feature is off.
AC_DEFUN([DX_CLEAR_DEPEND], [
test "$DX_FLAG_$1" = "$2" || AC_SUBST(DX_FLAG_[]DX_CURRENT_FEATURE, 0)
])
# DX_FEATURE_ARG(FEATURE, DESCRIPTION,
# CHECK_DEPEND, CLEAR_DEPEND,
# REQUIRE, DO-IF-ON, DO-IF-OFF)
# --------------------------------------------
# Parse the command-line option controlling a feature. CHECK_DEPEND is called
# if the user explicitly turns the feature on (and invokes DX_CHECK_DEPEND),
# otherwise CLEAR_DEPEND is called to turn off the default state if a required
# feature is disabled (using DX_CLEAR_DEPEND). REQUIRE performs additional
# requirement tests (DX_REQUIRE_PROG). Finally, an automake flag is set and
# DO-IF-ON or DO-IF-OFF are called according to the final state of the feature.
AC_DEFUN([DX_ARG_ABLE], [
AC_DEFUN([DX_CURRENT_FEATURE], [$1])
AC_DEFUN([DX_CURRENT_DESCRIPTION], [$2])
AC_ARG_ENABLE(doxygen-$1,
[AS_HELP_STRING(DX_IF_FEATURE([$1], [--disable-doxygen-$1],
[--enable-doxygen-$1]),
DX_IF_FEATURE([$1], [don't $2], [$2]))],
[
case "$enableval" in
#(
y|Y|yes|Yes|YES)
AC_SUBST([DX_FLAG_$1], 1)
$3
;; #(
n|N|no|No|NO)
AC_SUBST([DX_FLAG_$1], 0)
;; #(
*)
AC_MSG_ERROR([invalid value '$enableval' given to doxygen-$1])
;;
esac
], [
AC_SUBST([DX_FLAG_$1], [DX_IF_FEATURE([$1], 1, 0)])
$4
])
if DX_TEST_FEATURE([$1]); then
$5
:
fi
AM_CONDITIONAL(DX_COND_$1, DX_TEST_FEATURE([$1]))
if DX_TEST_FEATURE([$1]); then
$6
:
else
$7
:
fi
])
## -------------- ##
## Public macros. ##
## -------------- ##
# DX_XXX_FEATURE(DEFAULT_STATE)
# -----------------------------
AC_DEFUN([DX_DOXYGEN_FEATURE], [AC_DEFUN([DX_FEATURE_doc], [$1])])
AC_DEFUN([DX_DOT_FEATURE], [AC_DEFUN([DX_FEATURE_dot], [$1])])
AC_DEFUN([DX_MAN_FEATURE], [AC_DEFUN([DX_FEATURE_man], [$1])])
AC_DEFUN([DX_HTML_FEATURE], [AC_DEFUN([DX_FEATURE_html], [$1])])
AC_DEFUN([DX_CHM_FEATURE], [AC_DEFUN([DX_FEATURE_chm], [$1])])
AC_DEFUN([DX_CHI_FEATURE], [AC_DEFUN([DX_FEATURE_chi], [$1])])
AC_DEFUN([DX_RTF_FEATURE], [AC_DEFUN([DX_FEATURE_rtf], [$1])])
AC_DEFUN([DX_XML_FEATURE], [AC_DEFUN([DX_FEATURE_xml], [$1])])
AC_DEFUN([DX_XML_FEATURE], [AC_DEFUN([DX_FEATURE_xml], [$1])])
AC_DEFUN([DX_PDF_FEATURE], [AC_DEFUN([DX_FEATURE_pdf], [$1])])
AC_DEFUN([DX_PS_FEATURE], [AC_DEFUN([DX_FEATURE_ps], [$1])])
# DX_INIT_DOXYGEN(PROJECT, [CONFIG-FILE], [OUTPUT-DOC-DIR])
# ---------------------------------------------------------
# PROJECT also serves as the base name for the documentation files.
# The default CONFIG-FILE is "Doxyfile" and OUTPUT-DOC-DIR is "doxygen-doc".
AC_DEFUN([DX_INIT_DOXYGEN], [
# Files:
AC_SUBST([DX_PROJECT], [$1])
AC_SUBST([DX_CONFIG], [ifelse([$2], [], Doxyfile, [$2])])
AC_SUBST([DX_DOCDIR], [ifelse([$3], [], doxygen-doc, [$3])])
# Environment variables used inside doxygen.cfg:
DX_ENV_APPEND(SRCDIR, $srcdir)
DX_ENV_APPEND(PROJECT, $DX_PROJECT)
DX_ENV_APPEND(DOCDIR, $DX_DOCDIR)
DX_ENV_APPEND(VERSION, $PACKAGE_VERSION)
# Doxygen itself:
DX_ARG_ABLE(doc, [generate any doxygen documentation],
[],
[],
[DX_REQUIRE_PROG([DX_DOXYGEN], doxygen)
DX_REQUIRE_PROG([DX_PERL], perl)],
[DX_ENV_APPEND(PERL_PATH, $DX_PERL)])
# Dot for graphics:
DX_ARG_ABLE(dot, [generate graphics for doxygen documentation],
[DX_CHECK_DEPEND(doc, 1)],
[DX_CLEAR_DEPEND(doc, 1)],
[DX_REQUIRE_PROG([DX_DOT], dot)],
[DX_ENV_APPEND(HAVE_DOT, YES)
DX_ENV_APPEND(DOT_PATH, [`DX_DIRNAME_EXPR($DX_DOT)`])],
[DX_ENV_APPEND(HAVE_DOT, NO)])
# Man pages generation:
DX_ARG_ABLE(man, [generate doxygen manual pages],
[DX_CHECK_DEPEND(doc, 1)],
[DX_CLEAR_DEPEND(doc, 1)],
[],
[DX_ENV_APPEND(GENERATE_MAN, YES)],
[DX_ENV_APPEND(GENERATE_MAN, NO)])
# RTF file generation:
DX_ARG_ABLE(rtf, [generate doxygen RTF documentation],
[DX_CHECK_DEPEND(doc, 1)],
[DX_CLEAR_DEPEND(doc, 1)],
[],
[DX_ENV_APPEND(GENERATE_RTF, YES)],
[DX_ENV_APPEND(GENERATE_RTF, NO)])
# XML file generation:
DX_ARG_ABLE(xml, [generate doxygen XML documentation],
[DX_CHECK_DEPEND(doc, 1)],
[DX_CLEAR_DEPEND(doc, 1)],
[],
[DX_ENV_APPEND(GENERATE_XML, YES)],
[DX_ENV_APPEND(GENERATE_XML, NO)])
# (Compressed) HTML help generation:
DX_ARG_ABLE(chm, [generate doxygen compressed HTML help documentation],
[DX_CHECK_DEPEND(doc, 1)],
[DX_CLEAR_DEPEND(doc, 1)],
[DX_REQUIRE_PROG([DX_HHC], hhc)],
[DX_ENV_APPEND(HHC_PATH, $DX_HHC)
DX_ENV_APPEND(GENERATE_HTML, YES)
DX_ENV_APPEND(GENERATE_HTMLHELP, YES)],
[DX_ENV_APPEND(GENERATE_HTMLHELP, NO)])
# Seperate CHI file generation.
DX_ARG_ABLE(chi, [generate doxygen seperate compressed HTML help index file],
[DX_CHECK_DEPEND(chm, 1)],
[DX_CLEAR_DEPEND(chm, 1)],
[],
[DX_ENV_APPEND(GENERATE_CHI, YES)],
[DX_ENV_APPEND(GENERATE_CHI, NO)])
# Plain HTML pages generation:
DX_ARG_ABLE(html, [generate doxygen plain HTML documentation],
[DX_CHECK_DEPEND(doc, 1) DX_CHECK_DEPEND(chm, 0)],
[DX_CLEAR_DEPEND(doc, 1) DX_CLEAR_DEPEND(chm, 0)],
[],
[DX_ENV_APPEND(GENERATE_HTML, YES)],
[DX_TEST_FEATURE(chm) || DX_ENV_APPEND(GENERATE_HTML, NO)])
# PostScript file generation:
DX_ARG_ABLE(ps, [generate doxygen PostScript documentation],
[DX_CHECK_DEPEND(doc, 1)],
[DX_CLEAR_DEPEND(doc, 1)],
[DX_REQUIRE_PROG([DX_LATEX], latex)
DX_REQUIRE_PROG([DX_MAKEINDEX], makeindex)
DX_REQUIRE_PROG([DX_DVIPS], dvips)
DX_REQUIRE_PROG([DX_EGREP], egrep)])
# PDF file generation:
DX_ARG_ABLE(pdf, [generate doxygen PDF documentation],
[DX_CHECK_DEPEND(doc, 1)],
[DX_CLEAR_DEPEND(doc, 1)],
[DX_REQUIRE_PROG([DX_PDFLATEX], pdflatex)
DX_REQUIRE_PROG([DX_MAKEINDEX], makeindex)
DX_REQUIRE_PROG([DX_EGREP], egrep)])
# LaTeX generation for PS and/or PDF:
AM_CONDITIONAL(DX_COND_latex, DX_TEST_FEATURE(ps) || DX_TEST_FEATURE(pdf))
if DX_TEST_FEATURE(ps) || DX_TEST_FEATURE(pdf); then
DX_ENV_APPEND(GENERATE_LATEX, YES)
else
DX_ENV_APPEND(GENERATE_LATEX, NO)
fi
# Paper size for PS and/or PDF:
AC_ARG_VAR(DOXYGEN_PAPER_SIZE,
[a4wide (default), a4, letter, legal or executive])
case "$DOXYGEN_PAPER_SIZE" in
#(
"")
AC_SUBST(DOXYGEN_PAPER_SIZE, "")
;; #(
a4wide|a4|letter|legal|executive)
DX_ENV_APPEND(PAPER_SIZE, $DOXYGEN_PAPER_SIZE)
;; #(
*)
AC_MSG_ERROR([unknown DOXYGEN_PAPER_SIZE='$DOXYGEN_PAPER_SIZE'])
;;
esac
#For debugging:
#echo DX_FLAG_doc=$DX_FLAG_doc
#echo DX_FLAG_dot=$DX_FLAG_dot
#echo DX_FLAG_man=$DX_FLAG_man
#echo DX_FLAG_html=$DX_FLAG_html
#echo DX_FLAG_chm=$DX_FLAG_chm
#echo DX_FLAG_chi=$DX_FLAG_chi
#echo DX_FLAG_rtf=$DX_FLAG_rtf
#echo DX_FLAG_xml=$DX_FLAG_xml
#echo DX_FLAG_pdf=$DX_FLAG_pdf
#echo DX_FLAG_ps=$DX_FLAG_ps
#echo DX_ENV=$DX_ENV
])

155
build/yajl.m4 Normal file
View File

@ -0,0 +1,155 @@
dnl Check for YAJL Libraries
dnl CHECK_YAJL(ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND])
dnl Sets:
dnl YAJL_CFLAGS
dnl YAJL_LDADD
dnl YAJL_LDFLAGS
dnl YAJL_LIBS
dnl YAJL_VERSION
AC_DEFUN([PROG_YAJL],
[dnl
AC_REQUIRE([PKG_PROG_PKG_CONFIG])
YAJL_CONFIG=""
YAJL_VERSION=""
YAJL_CFLAGS=""
YAJL_CPPFLAGS=""
YAJL_LDADD=""
YAJL_LDFLAGS=""
YAJL_CONFIG=${PKG_CONFIG}
YAJL_PKGNAMES="yajl2 yajl"
YAJL_SONAMES="so la sl dll dylib"
AC_ARG_WITH(
yajl,
[AC_HELP_STRING([--with-yajl=PATH],[Path to yajl prefix or config script])]
,, with_yajl=yes)
AS_CASE(["${with_yajl}"],
[no], [test_paths=],
[yes], [test_paths="/usr/local/libyajl /usr/local/yajl /usr/local /opt/libyajl /opt/yajl /opt /usr"],
[test_paths="${with_yajl}"])
AS_IF([test "x${test_paths}" != "x"], [
AC_MSG_CHECKING([for libyajl config script])
for x in ${test_paths}; do
dnl # Determine if the script was specified and use it directly
if test ! -d "$x" -a -e "$x"; then
YAJL_CONFIG=$x
break
fi
dnl # Try known config script names/locations
for y in $YAJL_CONFIG; do
if test -e "${x}/bin/${y}"; then
YAJL_CONFIG="${x}/bin/${y}"
yajl_config="${YAJL_CONFIG}"
break
elif test -e "${x}/${y}"; then
YAJL_CONFIG="${x}/${y}"
yajl_config="${YAJL_CONFIG}"
break
fi
done
if test -n "${yajl_config}"; then
break
fi
done
dnl # Try known package names
if test -n "${YAJL_CONFIG}"; then
YAJL_PKGNAME=""
for x in ${YAJL_PKGNAMES}; do
if ${YAJL_CONFIG} --exists ${x}; then
YAJL_PKGNAME="$x"
break
fi
done
fi
if test -n "${YAJL_PKGNAME}"; then
AC_MSG_RESULT([${YAJL_CONFIG}])
YAJL_VERSION="`${YAJL_CONFIG} ${YAJL_PKGNAME} --modversion`"
if test "$verbose_output" -eq 1; then AC_MSG_NOTICE(yajl VERSION: $YAJL_VERSION); fi
YAJL_CFLAGS="`${YAJL_CONFIG} ${YAJL_PKGNAME} --cflags`"
if test "$verbose_output" -eq 1; then AC_MSG_NOTICE(yajl CFLAGS: $YAJL_CFLAGS); fi
YAJL_LDADD="`${YAJL_CONFIG} ${YAJL_PKGNAME} --libs-only-l`"
if test "$verbose_output" -eq 1; then AC_MSG_NOTICE(yajl LDADD: $YAJL_LDADD); fi
YAJL_LDFLAGS="`${YAJL_CONFIG} ${YAJL_PKGNAME} --libs-only-L --libs-only-other`"
if test "$verbose_output" -eq 1; then AC_MSG_NOTICE(yajl LDFLAGS: $YAJL_LDFLAGS); fi
else
AC_MSG_RESULT([no])
dnl Hack to just try to find the lib and include
AC_MSG_CHECKING([for yajl install])
for x in ${test_paths}; do
for y in ${YAJL_SONAMES}; do
if test -e "${x}/libyajl.${y}"; then
yajl_lib_path="${x}/"
yajl_lib_name="yajl"
break
else
yajl_lib_path=""
yajl_lib_name=""
fi
done
if test -n "$yajl_lib_path"; then
break
fi
done
for x in ${test_paths}; do
if test -e "${x}/include/yajl_parse.h"; then
yajl_inc_path="${x}/include"
break
elif test -e "${x}/yajl_parse.h"; then
yajl_inc_path="${x}"
break
fi
dnl # Check some sub-paths as well
for yajl_pkg_name in ${yajl_lib_name} ${YAJL_PKGNAMES}; do
if test -e "${x}/include/${yajl_pkg_name}/yajl_parse.h"; then
yajl_inc_path="${x}/include"
break
elif test -e "${x}/${yajl_pkg_name}/yajl_parse.h"; then
yajl_inc_path="${x}"
break
else
yajl_inc_path=""
fi
done
if test -n "$yajl_inc_path"; then
break
fi
done
if test -n "${yajl_lib_path}" -a -n "${yajl_inc_path}"; then
YAJL_CONFIG=""
AC_MSG_RESULT([${yajl_lib_path} ${yajl_inc_path}])
YAJL_VERSION="2"
YAJL_CFLAGS="-I${yajl_inc_path}"
YAJL_LDADD="-l${yajl_lib_name}"
YAJL_LDFLAGS="-L${yajl_lib_path}"
else
YAJL_VERSION=""
AC_MSG_RESULT([no])
fi
fi
])
YAJL_LIBS=${YAJL_LDADD}
AC_SUBST(YAJL_CFLAGS)
AC_SUBST(YAJL_VERSION)
AC_SUBST(YAJL_LDADD)
AC_SUBST(YAJL_LIBS)
AC_SUBST(YAJL_LDFLAGS)
if test -z "${YAJL_VERSION}"; then
ifelse([$2], , AC_MSG_NOTICE([optional yajl library not found]), $2)
else
AC_MSG_NOTICE([using yajl v${YAJL_VERSION}])
YAJL_CFLAGS="-DWITH_YAJL ${YAJL_CFLAGS}"
ifelse([$1], , , $1)
fi
])

91
configure.ac Normal file
View File

@ -0,0 +1,91 @@
# ModSecurity configure.ac
# Version definition to be further used by AC_INIT and
# .so file naming.
m4_define([msc_version_major], [3])
m4_define([msc_version_minor], [0])
m4_define([msc_version_patchlevel], [0])
m4_define([msc_version],
[msc_version_major.msc_version_minor])
m4_define([msc_version_info],
[msc_version_major:msc_version_minor:msc_version_patchlevel])
# Project Information
AC_INIT([modsecurity], [msc_version], [security@modsecurity.org])
# General definitions
AC_CONFIG_MACRO_DIR([build])
AC_PREFIX_DEFAULT([/usr/local/modsecurity])
# General automake options.
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects])
# Check for dependencies (C++, AR, Lex, Yacc and Make)
AC_PROG_CXX
AM_PROG_AR
AC_PROG_YACC
AC_PROG_LEX
AC_PROG_MAKE_SET
# Check for yajl
PROG_YAJL
AM_CONDITIONAL([YAJL_VERSION], [test "$YAJL_VERSION" != ""])
# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([string])
AC_CHECK_HEADERS([iostream])
# ??
LT_INIT([dlopen])
# Variables to be used inside the Makefile.am files.
MSC_BASE_DIR=`pwd`
AC_SUBST([MSC_BASE_DIR])
MSC_VERSION_INFO=msc_version_info
AC_SUBST([MSC_VERSION_INFO])
# Files to be generated via autotools.
AC_CONFIG_FILES([\
Makefile \
doc/Makefile \
src/Makefile \
test/Makefile \
test/benchmark/Makefile \
examples/Makefile \
examples/simple_example_using_c/Makefile \
])
AC_CONFIG_HEADERS([src/config.h])
# Doxygen support
DX_HTML_FEATURE(ON)
DX_CHM_FEATURE(OFF)
DX_CHI_FEATURE(OFF)
DX_MAN_FEATURE(OFF)
DX_RTF_FEATURE(OFF)
DX_XML_FEATURE(OFF)
DX_PDF_FEATURE(OFF)
DX_PS_FEATURE(OFF)
DX_INIT_DOXYGEN([ModSecurity],[doc/doxygen.cfg])
# Generate the files.
AC_OUTPUT

0
doc/.empty Normal file
View File

17
doc/Makefile.am Normal file
View File

@ -0,0 +1,17 @@
ACLOCAL_AMFLAGS = -I build
# Doxygen support
# include $(top_srcdir)/build/ax_prog_doxygen.m4
# distribution of the Doxygen configuration file
EXTRA_DIST = \
doxygen.cfg
MAINTAINERCLEANFILES = \
Makefile.in \
doxygen_sqlite3.db \
html \
latex

2403
doc/doxygen.cfg Normal file

File diff suppressed because it is too large Load Diff

BIN
doc/ms-doxygen-logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

14
examples/Makefile.am Normal file
View File

@ -0,0 +1,14 @@
ACLOCAL_AMFLAGS = -I build
SUBDIRS = \
simple_example_using_c
# make clean
CLEANFILES =
# make maintainer-clean
MAINTAINERCLEANFILES = \
Makefile.in

View File

@ -0,0 +1,18 @@
bin_PROGRAMS = test
test_SOURCES = \
test.c
test_LDADD = \
-L$(top_builddir)/src/.libs/ -lmodsecurity
test_CFLAGS = \
-I$(top_builddir)/headers \
-I$(top_builddir)
MAINTAINERCLEANFILES = \
Makefile.in

View File

@ -0,0 +1,3 @@
SecRule ARGS:test "@detectSQLi" "allow"
SecRule ARGS|ARGS:test "!@contains asdfsafdt" "allow"
SecRule ARGS "@detectSQLi" "allow"

View File

@ -0,0 +1,48 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "modsecurity/modsecurity.h"
#include "modsecurity/assay.h"
char main_rule_uri[] = "basic_rules.conf";
int main (int argc, char **argv)
{
ModSecurity *modsec = NULL;
Assay *assay = NULL;
Rules *rules = NULL;
modsec = msc_init();
rules = msc_create_rules_set();
msc_rules_add_file(rules, main_rule_uri);
assay = msc_new_assay(modsec, rules);
msc_process_connection(assay, "127.0.0.1");
msc_process_uri(assay, "http://www.modsecurity.org/test?key1=value1&key2=value2&key3=value3&test=args&test=test");
msc_process_request_headers(assay);
msc_process_request_body(assay);
msc_process_response_headers(assay);
msc_process_response_body(assay);
return 0;
}

208
headers/modsecurity/assay.h Normal file
View File

@ -0,0 +1,208 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifdef __cplusplus
#include <ctime>
#include <iostream>
#include <list>
#include <iomanip>
#include <string>
#include <sstream>
#include <unordered_map>
#include <fstream>
#include <vector>
#endif
#include <stdlib.h>
#include <stddef.h>
#ifndef HEADERS_MODSECURITY_ASSAY_H_
#define HEADERS_MODSECURITY_ASSAY_H_
#ifndef __cplusplus
typedef struct Assay_t Assay;
typedef struct Rules_t Rules;
#endif
#include "modsecurity/intervention.h"
#ifdef __cplusplus
namespace ModSecurity {
class ModSecurity;
class Assay;
class Rules;
namespace actions {
class Action;
}
namespace operators {
class Operator;
}
class ModSecurityHeader {
public:
ModSecurityHeader(char *key, char *value)
: _key(key),
_value(value)
{ }
char *_key;
char *_value;
};
class ModSecurityCollectionsVariables :
public std::unordered_map<std::string,
std::unordered_map<std::string, std::string>> {
public:
};
class ModSecurityStringVariables :
public std::unordered_map<std::string, std::string> {
public:
};
/** @ingroup ModSecurity_CPP_API */
class Assay {
public:
Assay(ModSecurity *assay, Rules *rules);
~Assay();
/** TODO: Should be an structure that fits an IP address */
int processConnection(char *ip);
int processURI(char *uri);
int processRequestHeaders();
int addRequestHeader(const std::string& key, const std::string& value);
int addRequestHeader(const unsigned char *key, const unsigned char *value);
int addRequestHeader(const unsigned char *key, size_t len_key,
const unsigned char *value, size_t len_value);
int processRequestBody();
int appendRequestBody(const unsigned char *body, size_t size);
int processResponseHeaders();
int addResponseHeader(const std::string& key, const std::string& value);
int addResponseHeader(const unsigned char *key, const unsigned char *value);
int addResponseHeader(const unsigned char *key, size_t len_key,
const unsigned char *value, size_t len_value);
int processResponseBody();
int appendResponseBody(const unsigned char *body, size_t size);
int processLogging();
ModSecurityIntervention *intervention();
void cleanup();
const char *getResponseBody();
int getResponseBodyLenth();
std::string resolve_variable(std::string);
void store_variable(std::string, std::string);
void store_variable(std::string,
std::unordered_map<std::string, std::string>);
ModSecurityStringVariables m_variables_strings;
void debug(int, std::string);
std::vector<actions::Action *> actions;
private:
std::ofstream myfile;
Rules *m_rules;
char *m_ipAddress;
char *m_uri;
std::ostringstream m_requestBody;
std::ostringstream m_responseBody;
ModSecurityCollectionsVariables m_variables_collections;
};
#endif
#ifdef __cplusplus
extern "C" {
#endif
/** @ingroup ModSecurity_C_API */
Assay *msc_new_assay(ModSecurity *ms, Rules *rules);
/** @ingroup ModSecurity_C_API */
int msc_process_connection(Assay *assay, char *ip);
/** @ingroup ModSecurity_C_API */
int msc_process_request_headers(Assay *assay);
/** @ingroup ModSecurity_C_API */
int msc_add_request_header(Assay *assay, const unsigned char *key,
const unsigned char *value);
/** @ingroup ModSecurity_C_API */
int msc_add_n_request_header(Assay *assay, const unsigned char *key,
size_t len_key, const unsigned char *value, size_t len_value);
/** @ingroup ModSecurity_C_API */
int msc_process_request_body(Assay *assay);
/** @ingroup ModSecurity_C_API */
int msc_append_request_body(Assay *assay,
const unsigned char *body, size_t size);
/** @ingroup ModSecurity_C_API */
int msc_process_response_headers(Assay *assay);
/** @ingroup ModSecurity_C_API */
int msc_add_response_header(Assay *assay, const unsigned char *key,
const unsigned char *value);
/** @ingroup ModSecurity_C_API */
int msc_add_n_response_header(Assay *assay, const unsigned char *key,
size_t len_key, const unsigned char *value, size_t len_value);
/** @ingroup ModSecurity_C_API */
int msc_process_response_body(Assay *assay);
/** @ingroup ModSecurity_C_API */
int msc_append_response_body(Assay *assay,
const unsigned char *body, size_t size);
/** @ingroup ModSecurity_C_API */
int msc_process_uri(Assay *assay, char *uri);
/** @ingroup ModSecurity_C_API */
const char *msc_get_response_body(Assay *assay);
/** @ingroup ModSecurity_C_API */
int msc_get_response_body_length(Assay *assay);
/** @ingroup ModSecurity_C_API */
void msc_assay_cleanup(Assay *assay);
/** @ingroup ModSecurity_C_API */
ModSecurityIntervention *msc_intervention(Assay *assay);
/** @ingroup ModSecurity_C_API */
int msc_process_logging(Assay *assay);
#ifdef __cplusplus
}
} // namespace ModSecurity
#endif
#endif // HEADERS_MODSECURITY_ASSAY_H_

View File

@ -0,0 +1,68 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifdef __cplusplus
#include <iostream>
#include <fstream>
#include <string>
#endif
#ifndef HEADERS_MODSECURITY_DEBUG_LOG_H_
#define HEADERS_MODSECURITY_DEBUG_LOG_H_
#ifndef __cplusplus
typedef struct DebugLog_t DebugLog;
#endif
#ifdef __cplusplus
namespace ModSecurity {
/** @ingroup ModSecurity_CPP_API */
class DebugLog : public std::ofstream {
public:
/*
static ModSecurityDebugLog& instance() {
static ModSecurityDebugLog i;
return i;
}
*/
DebugLog()
: m_is_configured(false),
m_debug_level(0) { }
bool setOutputFile(const std::string& file);
virtual bool write_log(int level, const std::string& data);
bool setDebugLevel(int level);
bool isConfigured();
virtual DebugLog *new_instance();
private:
/*
ModSecurityDebugLog(ModSecurityDebugLog const&);
void operator=(ModSecurityDebugLog const&);
*/
int m_debug_level;
bool m_is_configured;
};
} // namespace ModSecurity
#endif
#endif // HEADERS_MODSECURITY_DEBUG_LOG_H_

View File

@ -0,0 +1,34 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef HEADERS_MODSECURITY_INTERVENTION_H_
#define HEADERS_MODSECURITY_INTERVENTION_H_
#ifdef __cplusplus
namespace ModSecurity {
#endif
typedef struct ModSecurityIntervention_t {
int status;
int pause;
char *url;
char *log;
} ModSecurityIntervention;
#ifdef __cplusplus
} // namespace ModSecurity
#endif
#endif // HEADERS_MODSECURITY_INTERVENTION_H_

View File

@ -0,0 +1,219 @@
/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
/** @file modsecurity.h Main ModSecurity header file */
/** @mainpage ModSecurity - open source, cross platform web application firewall
*
* Example Usage:
* @code
*
* using ModSecurity::ModSecurity;
* using ModSecurity::Rules;
* using ModSecurity::Assay;
*
* ModSecurity *modsec;
* ModSecurity::Rules *rules;
*
* modsec = new ModSecurity();
* rules = new Rules();
* rules->loadFromUri(rules_file);
*
* Assay *modsecAssay = new Assay(modsec, rules);
* modsecAssay->processConnection("127.0.0.1");
*
* if (modsecAssay->intervention()) {
* std::cout << "There is an intervention" << std::endl;
* }
*
* ...
*
* @endcode
*
*/
/**
* @defgroup ModSecurity_C_API ModSecurity C API
*
* This is the ModSecurity C API description
*
* At this page you can get information on how the extend your C
* application, by embedding ModSecurity.
*
*/
/**
* @defgroup ModSecurity_CPP_API ModSecurity CPP API
*
* This is the ModSecurity CPP API description.
*
* At this page you can get information on how the extend your CPP
* application, by embedding ModSecurity.
*
*/
/**
* @defgroup ModSecurity_Operator ModSecurity Operators
*
* SecLanguage operator
*/
#ifdef __cplusplus
#include <ctime>
#include <iostream>
#endif
#ifndef HEADERS_MODSECURITY_MODSECURITY_H_
#define HEADERS_MODSECURITY_MODSECURITY_H_
#ifndef __cplusplus
typedef struct ModSecurity_t ModSecurity;
#endif
#include "modsecurity/intervention.h"
#include "modsecurity/assay.h"
#include "modsecurity/debug_log.h"
#include "modsecurity/rules.h"
#define MODSECURITY_MAJOR "3"
#define MODSECURITY_MINOR "0"
#define MODSECURITY_PATCHLEVEL "0"
#define MODSECURITY_VERSION MODSECURITY_MAJOR "." \
MODSECURITY_MINOR "." MODSECURITY_PATCHLEVEL
#ifdef __cplusplus
namespace ModSecurity {
/* few forwarded declarations */
namespace actions {
class Action;
}
namespace operators {
class Operators;
}
class Rule;
/** @ingroup ModSecurity_CPP_API */
class ModSecurity {
public:
ModSecurity();
~ModSecurity() { }
/**
*
* The Phases enumerator consists in mapping the different stages of a
* given request. ModSecurity is expected to inspect data based on those
* "phases". If your module/application use this in a different order, it
* will lead ModSecurity to act in an unexpected behavior.
*
* It is mandatory to call all the phases, even if you don't have this
* phases segmented in your end.
*
*/
enum Phases {
/**
*
* The connection is the very first information that ModSecurity can
* inspect. It is expected to happens before the virtual host name be
* resolved. This phase is expected to happen immediately after a
* connection is established.
*
*/
ConnectionPhase,
/**
*
* The "URI" phase happens just after the web server (or any other
* application that you may use with ModSecurity) have the acknowledgement
* of the full request URI.
*
*/
UriPhase,
/**
*
* The "RequestHeaders" phase happens when the server has all the
* information about the headers. Notice however, that it is expected to
* happen prior to the reception of the request body (if any).
*
*/
RequestHeadersPhase,
/**
*
* At the "RequestHeaders" phase, ModSecurity is expected to inspect the
* content of a request body, that does not happens when the server has all
* the content but prior to that, when the body transmission started.
* ModSecurity can ask the webserver to block (or make any other disruptive
* action) while the client is still transmitting the data.
*
*/
RequestBodyPhase,
/**
*
* The "ResponseHeaders" happens just before all the response headers are
* ready to be delivery to the client.
*
*/
ResponseHeadersPhase,
/**
*
* Same as "RequestBody" the "ResponseBody" phase perform a stream
* inspection which may result in a disruptive action.
*
*/
ResponseBodyPhase,
/**
*
* The last phase is the logging phase. At this phase ModSecurity will
* generate the internal logs, there is no need to hold the request at
* this point as this phase does not produce any kind of action.
*
*/
LoggingPhase,
/**
* Just a marking for the expected number of phases.
*
*/
NUMBER_OF_PHASES,
};
};
#endif
#ifdef __cplusplus
extern "C" {
#endif
/** @ingroup ModSecurity_C_API */
ModSecurity *msc_init();
#ifdef __cplusplus
}
} // namespace ModSecurity
#endif
#endif // HEADERS_MODSECURITY_MODSECURITY_H_

110
headers/modsecurity/rules.h Normal file
View File

@ -0,0 +1,110 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifdef __cplusplus
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
#endif
#ifndef HEADERS_MODSECURITY_RULES_H_
#define HEADERS_MODSECURITY_RULES_H_
#ifndef __cplusplus
typedef struct Rules_t Rules;
typedef struct Assay_t Assay;
#endif
#include "modsecurity/modsecurity.h"
#include "modsecurity/assay.h"
#include "modsecurity/debug_log.h"
#ifdef __cplusplus
class Driver;
namespace ModSecurity {
class Rule;
/** @ingroup ModSecurity_CPP_API */
class Rules {
public:
Rules()
: m_referenceCount(0),
m_custom_debug_log(NULL) { }
explicit Rules(DebugLog *custom_log)
: m_referenceCount(0),
m_custom_debug_log(custom_log) { }
~Rules() { }
void incrementReferenceCount(void);
void decrementReferenceCount(void);
/**
* FIXME:
*
* names should follow a patterner
*
*/
int loadFromUri(char *uri);
int loadRemote(char *key, char *uri);
int load(char *rules);
int merge(Driver *driver);
int merge(Rules *rules);
int evaluate(int phase, Assay *assay);
std::vector<Rule *> rules[7]; // Number of Phases.
int sec_rule_engine;
int sec_audit_type;
bool sec_audit_engine;
bool sec_request_body_access;
bool sec_response_body_access;
std::string audit_log_path;
std::string audit_log_parts;
std::string debug_log_path;
int debug_level;
DebugLog *debug_log;
void debug(int level, std::string message);
private:
int m_referenceCount;
DebugLog *m_custom_debug_log;
};
#endif
#ifdef __cplusplus
extern "C" {
#endif
Rules *msc_create_rules_set();
int msc_rules_merge(Rules *rules_dst, Rules *rules_from);
int msc_rules_add_remote(Rules *rules, char *key, char *uri);
int msc_rules_add_file(Rules *rules, char *file);
int msc_rules_add(Rules *rules, char *plain_rules);
#ifdef __cplusplus
}
} // namespace ModSecurity
#endif
#endif // HEADERS_MODSECURITY_RULES_H_

108
src/Makefile.am Normal file
View File

@ -0,0 +1,108 @@
libmodsecuritydir = $(prefix)/lib
libmodsecurity_LTLIBRARIES = libmodsecurity.la
libmodsecurity_ladir = $(prefix)/include
CLEANFILES = \
location.hh \
position.hh \
parser/seclang-parser.cc \
parser/seclang-parser.hh \
parser/seclang-scanner.cc \
stack.hh
MAINTAINERCLEANFILES = \
Makefile.in \
config.h.in \
config.h.in~
pkginclude_HEADERS = \
../headers/modsecurity/modsecurity.h \
../headers/modsecurity/assay.h \
../headers/modsecurity/rules.h \
../headers/modsecurity/debug_log.h \
../headers/modsecurity/intervention.h
libmodsecurity_la_SOURCES = \
parser/seclang-parser.yy \
parser/seclang-scanner.ll \
parser/driver.cc \
assay.cc \
modsecurity.cc \
rules.cc \
utils.cc \
debug_log.cc \
rule.cc \
variable.cc \
operators/operator.cc \
operators/detect_sqli.cc \
operators/detect_xss.cc \
operators/inspect_file.cc \
operators/fuzzy_hash.cc \
operators/validate_byte_range.cc \
operators/validate_dtd.cc \
operators/validate_hash.cc \
operators/validate_schema.cc \
operators/validate_url_encoding.cc \
operators/validate_utf8_encoding.cc \
operators/verify_cc.cc \
operators/verify_cpf.cc \
operators/verify_ssn.cc \
operators/geolookup.cc \
operators/gsblookup.cc \
operators/rsub.cc \
operators/within.cc \
operators/contains_word.cc \
operators/contains.cc \
operators/ends_with.cc \
operators/eq.cc \
operators/ge.cc \
operators/gt.cc \
operators/ip_match_f.cc \
operators/ip_match.cc \
operators/ip_match_from_file.cc \
operators/le.cc \
operators/lt.cc \
operators/pm_f.cc \
operators/pm.cc \
operators/pm_from_file.cc \
operators/rbl.cc \
operators/rx.cc \
operators/str_eq.cc \
operators/str_match.cc \
operators/begins_with.cc \
actions/rule_id.cc \
actions/phase.cc \
actions/action.cc \
actions/block.cc \
actions/redirect.cc \
actions/status.cc \
actions/transformations/transformation.cc \
actions/transformations/trim.cc \
actions/transformations/lowercase.cc
libmodsecurity_la_CFLAGS =
libmodsecurity_la_CPPFLAGS = \
-std=c++11 \
-I.. \
-g \
-O0 \
-I ../headers
libmodsecurity_la_LIBADD = \
@LEXLIB@
libmodsecurity_la_LDFLAGS = \
-version-info @MSC_VERSION_INFO@

78
src/actions/action.cc Normal file
View File

@ -0,0 +1,78 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "actions/action.h"
#include <iostream>
#include <string>
#include "modsecurity/assay.h"
#include "actions/block.h"
#include "actions/redirect.h"
#include "actions/status.h"
#include "actions/rule_id.h"
#include "actions/phase.h"
namespace ModSecurity {
namespace actions {
std::string & Action::evaluate(std::string value,
Assay *assay) {
return value;
}
bool Action::evaluate(Assay *assay) {
return true;
}
bool Action::evaluate(Rule *rule) {
return true;
}
void Action::fill_intervention(ModSecurityIntervention *i) {
}
Action *Action::instantiate(std::string name) {
std::string status("status:");
std::string redirect("redirect:");
std::string block("block");
std::string phase("phase:");
std::string rule_id("id:");
if (name.compare(0, status.length(), status) == 0) {
return new Status(name);
}
if (name.compare(0, redirect.length(), redirect) == 0) {
return new Redirect(name);
}
if (name.compare(0, block.length(), block) == 0) {
return new Block(name);
}
if (name.compare(0, phase.length(), phase) == 0) {
return new Phase(name);
}
if (name.compare(0, rule_id.length(), rule_id) == 0) {
return new RuleId(name);
}
return new Action(name);
}
} // namespace actions
} // namespace ModSecurity

90
src/actions/action.h Normal file
View File

@ -0,0 +1,90 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 <string>
#include "modsecurity/intervention.h"
#ifndef SRC_ACTIONS_ACTION_H_
#define SRC_ACTIONS_ACTION_H_
#ifdef __cplusplus
namespace ModSecurity {
class Assay;
class Rule;
namespace actions {
class Action {
public:
explicit Action(std::string _action)
: action_kind(2),
action(_action) { }
/**
*
* Define the action kind regarding to the execution time.
*
*
*/
enum Kind {
/**
*
* Action that are executed while loading the configuration. For instance
* the rule ID or the rule phase.
*
*/
ConfigurationKind,
/**
*
* Those are actions that demands to be executed before call the operator.
* For instance the tranformations.
*
*
*/
RunTimeBeforeMatchAttemptKind,
/**
*
* Actions that are executed after the execution of the operator, only if
* the operator returned Match (or True). For instance the disruptive
* actions.
*
*/
RunTimeOnlyIfMatchKind,
};
std::string action;
int action_kind;
std::string name;
virtual std::string& evaluate(std::string exp,
Assay *assay);
virtual bool evaluate(Assay *assay);
virtual bool evaluate(Rule *rule);
static Action *instantiate(std::string action);
virtual void fill_intervention(ModSecurityIntervention *intervention);
};
} // namespace actions
} // namespace ModSecurity
#endif
#endif // SRC_ACTIONS_ACTION_H_

44
src/actions/block.cc Normal file
View File

@ -0,0 +1,44 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "actions/block.h"
#include <iostream>
#include <string>
#include "modsecurity/assay.h"
namespace ModSecurity {
namespace actions {
Block::Block(std::string action)
: Action(action) {
this->action = action;
this->action_kind = 2;
}
bool Block::evaluate(Assay *assay) {
assay->actions.push_back(this);
return true;
}
void Block::fill_intervention(ModSecurityIntervention *i) {
i->status = 403;
i->log = "Blocked request!";
}
} // namespace actions
} // namespace ModSecurity

44
src/actions/block.h Normal file
View File

@ -0,0 +1,44 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 <string>
#include "actions/action.h"
#ifndef SRC_ACTIONS_BLOCK_H_
#define SRC_ACTIONS_BLOCK_H_
#ifdef __cplusplus
class Assay;
namespace ModSecurity {
class Assay;
namespace actions {
class Block : public Action {
public:
explicit Block(std::string action);
bool evaluate(Assay *assay) override;
void fill_intervention(ModSecurityIntervention *i) override;
};
} // namespace actions
} // namespace ModSecurity
#endif
#endif // SRC_ACTIONS_BLOCK_H_

50
src/actions/phase.cc Normal file
View File

@ -0,0 +1,50 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "actions/phase.h"
#include <iostream>
#include <string>
#include "modsecurity/assay.h"
#include "src/rule.h"
#include "modsecurity/modsecurity.h"
namespace ModSecurity {
namespace actions {
Phase::Phase(std::string action)
: Action(action) {
this->action_kind = ConfigurationKind;
std::string a = action;
a.erase(0, 6);
this->phase = std::stoi(a);
if (this->phase == 0) {
/* Phase 0 is something new, we want to use as ConnectionPhase */
this->phase = ModSecurity::Phases::ConnectionPhase;
} else {
/* Otherwise we want to shift the rule to the correct phase */
this->phase = phase + ModSecurity::Phases::RequestHeadersPhase - 1;
}
}
bool Phase::evaluate(Rule *rule) {
rule->phase = this->phase;
return true;
}
} // namespace actions
} // namespace ModSecurity

45
src/actions/phase.h Normal file
View File

@ -0,0 +1,45 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 <string>
#include "actions/action.h"
#ifndef SRC_ACTIONS_PHASE_H_
#define SRC_ACTIONS_PHASE_H_
#ifdef __cplusplus
class Assay;
namespace ModSecurity {
class Assay;
class Rule;
namespace actions {
class Phase : public Action {
public:
explicit Phase(std::string action);
bool evaluate(Rule *rule) override;
int phase;
};
} // namespace actions
} // namespace ModSecurity
#endif
#endif // SRC_ACTIONS_PHASE_H_

52
src/actions/redirect.cc Normal file
View File

@ -0,0 +1,52 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "actions/redirect.h"
#include <iostream>
#include <string>
#include "modsecurity/assay.h"
namespace ModSecurity {
namespace actions {
Redirect::Redirect(std::string action)
: Action(action) {
this->url = action;
this->url.erase(0, 9);
this->action = action;
this->action_kind = 2;
this->status = 302;
}
bool Redirect::evaluate(Assay *assay) {
assay->actions.push_back(this);
return true;
}
void Redirect::fill_intervention(ModSecurityIntervention *i) {
/* if it was changed before, lets keep it. */
if (i->status == 200) {
i->status = this->status;
}
// reinterpret_cast<char *>
i->url = (char *) this->url.c_str(); //** TODO: wheee */
i->log = "Redirecting";
}
} // namespace actions
} // namespace ModSecurity

45
src/actions/redirect.h Normal file
View File

@ -0,0 +1,45 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 <string>
#include "actions/action.h"
#ifndef SRC_ACTIONS_REDIRECT_H_
#define SRC_ACTIONS_REDIRECT_H_
#ifdef __cplusplus
class Assay;
namespace ModSecurity {
class Assay;
namespace actions {
class Redirect : public Action {
public:
explicit Redirect(std::string action);
bool evaluate(Assay *assay) override;
int status;
std::string url;
void fill_intervention(ModSecurityIntervention *i) override;
};
} // namespace actions
} // namespace ModSecurity
#endif
#endif // SRC_ACTIONS_REDIRECT_H_

42
src/actions/rule_id.cc Normal file
View File

@ -0,0 +1,42 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "actions/rule_id.h"
#include <iostream>
#include <string>
#include "modsecurity/assay.h"
#include "src/rule.h"
namespace ModSecurity {
namespace actions {
RuleId::RuleId(std::string action)
: Action(action) {
this->action_kind = ConfigurationKind;
std::string a = action;
a.erase(0, 3);
this->rule_id = std::stod(a);
}
bool RuleId::evaluate(Rule *rule) {
rule->rule_id = this->rule_id;
return true;
}
} // namespace actions
} // namespace ModSecurity

45
src/actions/rule_id.h Normal file
View File

@ -0,0 +1,45 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 <string>
#include "actions/action.h"
#ifndef SRC_ACTIONS_RULE_ID_H_
#define SRC_ACTIONS_RULE_ID_H_
#ifdef __cplusplus
class Assay;
namespace ModSecurity {
class Assay;
class Rule;
namespace actions {
class RuleId : public Action {
public:
explicit RuleId(std::string action);
bool evaluate(Rule *rule) override;
double rule_id;
};
} // namespace actions
} // namespace ModSecurity
#endif
#endif // SRC_ACTIONS_RULE_ID_H_

48
src/actions/status.cc Normal file
View File

@ -0,0 +1,48 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "actions/status.h"
#include <iostream>
#include <string>
#include "modsecurity/assay.h"
namespace ModSecurity {
namespace actions {
Status::Status(std::string action)
: Action(action) {
std::string a = action;
a.erase(0, 7);
this->action = action;
this->action_kind = 2;
this->status = stoi(a);
}
bool Status::evaluate(Assay *assay) {
assay->actions.push_back(this);
return true;
}
void Status::fill_intervention(ModSecurityIntervention *i) {
i->status = this->status;
i->log = "Status";
}
} // namespace actions
} // namespace ModSecurity

43
src/actions/status.h Normal file
View File

@ -0,0 +1,43 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 <string>
#include "actions/action.h"
#ifndef SRC_ACTIONS_STATUS_H_
#define SRC_ACTIONS_STATUS_H_
#ifdef __cplusplus
class Assay;
namespace ModSecurity {
class Assay;
namespace actions {
class Status : public Action {
public:
explicit Status(std::string actions);
bool evaluate(Assay *assay) override;
void fill_intervention(ModSecurityIntervention *i) override;
int status;
};
} // namespace actions
} // namespace ModSecurity
#endif
#endif // SRC_ACTIONS_STATUS_H_

View File

@ -0,0 +1,47 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "actions/transformations/lowercase.h"
#include <algorithm>
#include <string>
#include "modsecurity/assay.h"
#include "actions/transformations/transformation.h"
#include "actions/action.h"
namespace ModSecurity {
namespace actions {
namespace transformations {
LowerCase::LowerCase(std::string a)
: Transformation(a) {
}
std::string & LowerCase::evaluate(std::string value,
Assay *assay) {
std::locale loc;
for (std::string::size_type i=0; i < value.length(); ++i) {
value[i] = std::tolower(value[i], loc);
}
return value;
}
} // namespace transformations
} // namespace actions
} // namespace ModSecurity

View File

@ -0,0 +1,45 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 <string>
#include "actions/action.h"
#include "actions/transformations/transformation.h"
#ifndef SRC_ACTIONS_TRANSFORMATIONS_LOWERCASE_H_
#define SRC_ACTIONS_TRANSFORMATIONS_LOWERCASE_H_
#ifdef __cplusplus
namespace ModSecurity {
class Assay;
namespace actions {
namespace transformations {
class LowerCase : public Transformation {
public:
explicit LowerCase(std::string action);
std::string& evaluate(std::string exp,
Assay *assay) override;
};
} // namespace transformations
} // namespace actions
} // namespace ModSecurity
#endif
#endif // SRC_ACTIONS_TRANSFORMATIONS_LOWERCASE_H_

View File

@ -0,0 +1,55 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "actions/transformations/transformation.h"
#include <iostream>
#include <string>
#include "modsecurity/assay.h"
#include "actions/transformations/trim.h"
#include "actions/transformations/lowercase.h"
#include "actions/action.h"
namespace ModSecurity {
namespace actions {
namespace transformations {
Transformation::Transformation(std::string action)
: Action(action) {
this->name = this->action;
this->name.erase(0, 2);
this->action_kind = 1;
}
std::string &Transformation::evaluate(std::string value,
Assay *assay) {
return value;
}
Transformation* Transformation::instantiate(std::string a) {
if (a == "t:trim") {
return new transformations::Trim(a);
}
if (a == "t:lowercase") {
return new LowerCase(a);
}
return new Transformation(a);
}
} // namespace transformations
} // namespace actions
} // namespace ModSecurity

View File

@ -0,0 +1,46 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 <string>
#include "actions/action.h"
#ifndef SRC_ACTIONS_TRANSFORMATIONS_TRANSFORMATION_H_
#define SRC_ACTIONS_TRANSFORMATIONS_TRANSFORMATION_H_
#ifdef __cplusplus
namespace ModSecurity {
class Assay;
namespace actions {
namespace transformations {
class Transformation : public Action {
public:
explicit Transformation(std::string action);
static Transformation* instantiate(std::string);
std::string& evaluate(std::string exp,
Assay *assay) override;
};
} // namespace transformations
} // namespace actions
} // namespace ModSecurity
#endif
#endif // SRC_ACTIONS_TRANSFORMATIONS_TRANSFORMATION_H_

View File

@ -0,0 +1,61 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "actions/transformations/trim.h"
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <cctype>
#include <locale>
#include "modsecurity/assay.h"
#include "actions/transformations/transformation.h"
#include "actions/action.h"
namespace ModSecurity {
namespace actions {
namespace transformations {
static inline std::string *ltrim(std::string *s) {
s->erase(s->begin(), std::find_if(s->begin(), s->end(),
std::not1(std::ptr_fun<int, int>(std::isspace))));
return s;
}
static inline std::string *rtrim(std::string *s) {
s->erase(std::find_if(s->rbegin(), s->rend(),
std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s->end());
return s;
}
static inline std::string *trim(std::string *s) {
return ltrim(rtrim(s));
}
Trim::Trim(std::string action)
: Transformation(action) {
this->action_kind = 1;
}
std::string & Trim::evaluate(std::string value,
Assay *assay) {
return *trim(&value);
}
} // namespace transformations
} // namespace actions
} // namespace ModSecurity

View File

@ -0,0 +1,44 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 <string>
#include "actions/action.h"
#include "actions/transformations/transformation.h"
#ifndef SRC_ACTIONS_TRANSFORMATIONS_TRIM_H_
#define SRC_ACTIONS_TRANSFORMATIONS_TRIM_H_
#ifdef __cplusplus
namespace ModSecurity {
class Assay;
namespace actions {
namespace transformations {
class Trim : public Transformation {
public:
explicit Trim(std::string action);
std::string& evaluate(std::string exp,
Assay *assay) override;
};
} // namespace transformations
} // namespace actions
} // namespace ModSecurity
#endif
#endif // SRC_ACTIONS_TRANSFORMATIONS_TRIM_H_

1086
src/assay.cc Normal file

File diff suppressed because it is too large Load Diff

126
src/debug_log.cc Normal file
View File

@ -0,0 +1,126 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "modsecurity/debug_log.h"
#include <stddef.h>
#include <fstream>
namespace ModSecurity {
/**
* @name new_instance
* @brief Create a new instance of the DebugLog.
*
* @return Debug log pointer
* @retval >0 Debug log structure was initialized correctly
* @retval NULL Debug log could not be initialized.
*
*/
DebugLog *DebugLog::new_instance() {
return new DebugLog();
}
/**
* @name setOutputFile
* @brief Set an output file where the log will be saved
*
* @param file_path Path to the log file.
*
* @return If the operation successful or not.
* @retval true Operation was successful.
* @retval false Operation failed.
*
*/
bool DebugLog::setOutputFile(const std::string& file_path) {
if (is_open()) {
close();
}
open(file_path, std::fstream::out | std::fstream::app);
if (!is_open()) {
return false;
}
return true;
}
/**
* @name write_log
* @brief Write a message into the debug log.
*
* @param debug_level Debug level of the given message.
* @param text Message to be written.
*
* @return If the operation successful or not.
* @retval true Operation was successful.
* @retval false Operation failed.
*
*/
bool DebugLog::write_log(int debug_level, const std::string &text) {
if (!is_open()) {
return false;
}
if (debug_level <= m_debug_level) {
*this << "[" << debug_level << "] " << text << std::endl;
}
return true;
}
/**
* @name setDebugLevel
* @brief Changes the default debug level.
*
* @param level Debug level.
*
* @return If the operation successful or not.
* @retval true Operation was successful.
* @retval false Operation failed.
*
*/
bool DebugLog::setDebugLevel(int level) {
if (level < 0 || level > 9) {
return false;
}
m_debug_level = level;
return true;
}
/**
* @name isConfigured
* @brief Returns if debug log is configured or not.
*
* @return If the debug log is configured or not
* @retval true It is configured.
* @retval false It is not configured.
*
*/
bool DebugLog::isConfigured() {
return m_is_configured;
}
} // namespace ModSecurity

68
src/modsecurity.cc Normal file
View File

@ -0,0 +1,68 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 <ctime>
#include <iostream>
#include "modsecurity/modsecurity.h"
#include "src/utils.h"
namespace ModSecurity {
/**
* @name ModSecurity
* @brief Initilizes ModSecurity CPP API
*
* ModSecurity initializer. Although it is not really doing anything
* in this version, further versions of this API may demands this to
* be executed.
*
* Example Usage:
* @code
*
* using ModSecurity::ModSecurity;
*
* ModSecurity *msc = new ModSecurity();
*
* @endcode
*/
ModSecurity::ModSecurity() {
}
/**
* @name msc_init
* @brief Initilizes ModSecurity C API
*
* ModSecurity initializer. Although it is not really doing anything
* in this version, further versions of this API may demands this to
* be executed.
*
* Example Usage:
* @code
*
* ModSecurity msc = msc_init();
*
* @endcode
*/
extern "C" ModSecurity *msc_init() {
ModSecurity *modsec = new ModSecurity();
return modsec;
}
} // namespace ModSecurity

6
src/operators/.directory Normal file
View File

@ -0,0 +1,6 @@
[Dolphin]
SortRole=type
Timestamp=2015,6,11,13,57,39
Version=3
ViewMode=1
VisibleRoles=Details_text,Details_size,Details_date,Details_type,CustomizedDetails

View File

@ -0,0 +1,44 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/begins_with.h"
#include <string>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool BeginsWith::evaluate(Assay *assay) {
/**
* @todo Implement the operator BeginsWith.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#beginswith
*/
return true;
}
BeginsWith::BeginsWith(std::string op, std::string param,
bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

View File

@ -0,0 +1,39 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_BEGINS_WITH_H_
#define SRC_OPERATORS_BEGINS_WITH_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class BeginsWith : public Operator {
public:
/** @ingroup ModSecurity_Operator */
BeginsWith(std::string o, std::string p, bool i);
bool evaluate(Assay *assay);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_BEGINS_WITH_H_

35
src/operators/contains.cc Normal file
View File

@ -0,0 +1,35 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/contains.h"
#include <string>
namespace ModSecurity {
namespace operators {
bool Contains::evaluate(Assay *assay, const std::string &input) {
return input.find(this->param) != std::string::npos;
}
Contains::Contains(std::string _op, std::string _param,
bool negation)
: Operator() {
this->op = _op;
this->param = _param;
}
} // namespace operators
} // namespace ModSecurity

40
src/operators/contains.h Normal file
View File

@ -0,0 +1,40 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_CONTAINS_H_
#define SRC_OPERATORS_CONTAINS_H_
#include <string>
#include "modsecurity/assay.h"
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class Contains : public Operator {
public:
/** @ingroup ModSecurity_Operator */
Contains(std::string o, std::string p, bool i);
bool evaluate(Assay *assay, const std::string &exp) override;
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_CONTAINS_H_

View File

@ -0,0 +1,65 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/contains_word.h"
#include <string>
#include <regex>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool ContainsWord::evaluate(Assay *assay,
std::string input) {
/**
* @todo Implement the operator ContainsWord in a performative way.
*/
// FIXME: This is odd logic and should be removed in a future version
if (this->param == "") {
return 1;
}
// If our length is too long we will never match
if (this->param.length() > input.length()) {
return 0;
}
// If they are exact matches shortcut
if (this->param == input) {
return 1;
}
std::regex r("\\b" + this->param + "\\b");
std::smatch m;
if (std::regex_search(input, m, r)) {
// this won't find anything because 'spoons' is not
// the word you're searching for
return 1;
}
return 0;
}
ContainsWord::ContainsWord(std::string op,
std::string param, bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

View File

@ -0,0 +1,40 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_CONTAINS_WORD_H_
#define SRC_OPERATORS_CONTAINS_WORD_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class ContainsWord : public Operator {
public:
/** @ingroup ModSecurity_Operator */
ContainsWord(std::string o, std::string p, bool i);
bool evaluate(Assay *assay, std::string exp);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_CONTAINS_WORD_H_

View File

@ -0,0 +1,43 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/detect_sqli.h"
#include <string>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool DetectSQLi::evaluate(Assay *assay) {
/**
* @todo Implement the operator BeginsWith.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#detectsqli
*/
return true;
}
DetectSQLi::DetectSQLi(std::string op, std::string param,
bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

View File

@ -0,0 +1,39 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_DETECT_SQLI_H_
#define SRC_OPERATORS_DETECT_SQLI_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class DetectSQLi : public Operator {
public:
/** @ingroup ModSecurity_Operator */
DetectSQLi(std::string o, std::string p, bool i);
bool evaluate(Assay *assay);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_DETECT_SQLI_H_

View File

@ -0,0 +1,42 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/detect_xss.h"
#include <string>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool DetectXSS::evaluate(Assay *assay) {
/**
* @todo Implement the operator DetectXSS.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#detectxss
*/
return true;
}
DetectXSS::DetectXSS(std::string op, std::string param, bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

View File

@ -0,0 +1,39 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_DETECT_XSS_H_
#define SRC_OPERATORS_DETECT_XSS_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class DetectXSS : public Operator {
public:
/** @ingroup ModSecurity_Operator */
DetectXSS(std::string o, std::string p, bool i);
bool evaluate(Assay *assay);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_DETECT_XSS_H_

View File

@ -0,0 +1,58 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/ends_with.h"
#include <string>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool EndsWith::evaluate(Assay *assay,
std::string input) {
// Check that the param is not longer than the input
if (this->param.length() > input.length()) {
return 0;
}
// Check that the input != the param
if (this->param == input) {
return 1;
}
// Start at the end of the input minus the size of the input
std::string endString = input.substr(input.length() - \
(this->param.length()), (this->param.length()));
// FIXME: We can make this smalle
if (endString == this->param) {
return 1;
}
return 0;
}
EndsWith::EndsWith(std::string op, std::string param,
bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

40
src/operators/ends_with.h Normal file
View File

@ -0,0 +1,40 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_ENDS_WITH_H_
#define SRC_OPERATORS_ENDS_WITH_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class EndsWith : public Operator {
public:
/** @ingroup ModSecurity_Operator */
EndsWith(std::string o, std::string p, bool i);
bool evaluate(Assay *assay, std::string exp);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_ENDS_WITH_H_

42
src/operators/eq.cc Normal file
View File

@ -0,0 +1,42 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/eq.h"
#include <string>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool Eq::evaluate(Assay *assay) {
/**
* @todo Implement the operator Eq.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#eq
*/
return true;
}
Eq::Eq(std::string op, std::string param,
bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

39
src/operators/eq.h Normal file
View File

@ -0,0 +1,39 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_EQ_H_
#define SRC_OPERATORS_EQ_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class Eq : public Operator {
public:
/** @ingroup ModSecurity_Operator */
Eq(std::string o, std::string p, bool i);
bool evaluate(Assay *assay);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_EQ_H_

View File

@ -0,0 +1,41 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/fuzzy_hash.h"
#include <string>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool FuzzyHash::evaluate(Assay *assay) {
/**
* @todo Implement the operator FuzzyHash.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#fuzzyhash
*/
return true;
}
FuzzyHash::FuzzyHash(std::string op, std::string param,
bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

View File

@ -0,0 +1,40 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_FUZZY_HASH_H_
#define SRC_OPERATORS_FUZZY_HASH_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class FuzzyHash : public Operator {
public:
/** @ingroup ModSecurity_Operator */
FuzzyHash(std::string o, std::string p, bool i);
bool evaluate(Assay *assay);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_FUZZY_HASH_H_

43
src/operators/ge.cc Normal file
View File

@ -0,0 +1,43 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/ge.h"
#include <string>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool Ge::evaluate(Assay *assay) {
/**
* @todo Implement the operator Ge.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#ge
*/
return true;
}
Ge::Ge(std::string op, std::string param,
bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

39
src/operators/ge.h Normal file
View File

@ -0,0 +1,39 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_GE_H_
#define SRC_OPERATORS_GE_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class Ge : public Operator {
public:
/** @ingroup ModSecurity_Operator */
Ge(std::string o, std::string p, bool i);
bool evaluate(Assay *assay);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_GE_H_

View File

@ -0,0 +1,41 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/geolookup.h"
#include <string>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool GeoLookup::evaluate(Assay *assay) {
/**
* @todo Implement the operator GeoLookup.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#geolookup
*/
return true;
}
GeoLookup::GeoLookup(std::string op, std::string param,
bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

39
src/operators/geolookup.h Normal file
View File

@ -0,0 +1,39 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_GEOLOOKUP_H_
#define SRC_OPERATORS_GEOLOOKUP_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class GeoLookup : public Operator {
public:
/** @ingroup ModSecurity_Operator */
GeoLookup(std::string o, std::string p, bool i);
bool evaluate(Assay *assay);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_GEOLOOKUP_H_

View File

@ -0,0 +1,42 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/gsblookup.h"
#include <string>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool GsbLookup::evaluate(Assay *assay) {
/**
* @todo Implement the operator GeoLookup.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#gsblookup
*/
return true;
}
GsbLookup::GsbLookup(std::string op, std::string param,
bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

40
src/operators/gsblookup.h Normal file
View File

@ -0,0 +1,40 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_GSBLOOKUP_H_
#define SRC_OPERATORS_GSBLOOKUP_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class GsbLookup : public Operator {
public:
/** @ingroup ModSecurity_Operator */
GsbLookup(std::string o, std::string p, bool i);
bool evaluate(Assay *assay);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_GSBLOOKUP_H_

42
src/operators/gt.cc Normal file
View File

@ -0,0 +1,42 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/gt.h"
#include <string>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool Gt::evaluate(Assay *assay) {
/**
* @todo Implement the operator Gt.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#gt
*/
return true;
}
Gt::Gt(std::string op, std::string param,
bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

38
src/operators/gt.h Normal file
View File

@ -0,0 +1,38 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_GT_H_
#define SRC_OPERATORS_GT_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class Gt : public Operator {
public:
/** @ingroup ModSecurity_Operator */
Gt(std::string o, std::string p, bool i);
bool evaluate(Assay *assay);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_GT_H_

View File

@ -0,0 +1,42 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/inspect_file.h"
#include <string>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool InspectFile::evaluate(Assay *assay) {
/**
* @todo Implement the operator InspectFile.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#inspectfile
*/
return true;
}
InspectFile::InspectFile(std::string op, std::string param,
bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

View File

@ -0,0 +1,39 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_INSPECT_FILE_H_
#define SRC_OPERATORS_INSPECT_FILE_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class InspectFile : public Operator {
public:
/** @ingroup ModSecurity_Operator */
InspectFile(std::string o, std::string p, bool i);
bool evaluate(Assay *assay);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_INSPECT_FILE_H_

43
src/operators/ip_match.cc Normal file
View File

@ -0,0 +1,43 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/ip_match.h"
#include <string>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool IpMatch::evaluate(Assay *assay) {
/**
* @todo Implement the operator IpMatch.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#ipmatch
*/
return true;
}
IpMatch::IpMatch(std::string op, std::string param,
bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

39
src/operators/ip_match.h Normal file
View File

@ -0,0 +1,39 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_IP_MATCH_H_
#define SRC_OPERATORS_IP_MATCH_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class IpMatch : public Operator {
public:
/** @ingroup ModSecurity_Operator */
IpMatch(std::string o, std::string p, bool i);
bool evaluate(Assay *assay);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_IP_MATCH_H_

View File

@ -0,0 +1,42 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/ip_match_f.h"
#include <string>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool IpMatchF::evaluate(Assay *assay) {
/**
* @todo Implement the operator IpMatchF.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#ipmatchf
*/
return true;
}
IpMatchF::IpMatchF(std::string op, std::string param,
bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

View File

@ -0,0 +1,39 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_IP_MATCH_F_H_
#define SRC_OPERATORS_IP_MATCH_F_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class IpMatchF : public Operator {
public:
/** @ingroup ModSecurity_Operator */
IpMatchF(std::string p, std::string o, bool i);
bool evaluate(Assay *assay);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_IP_MATCH_F_H_

View File

@ -0,0 +1,42 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/ip_match_from_file.h"
#include <string>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool IpMatchFromFile::evaluate(Assay *assay) {
/**
* @todo Implement the operator IpMatchFromFile.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#ipmatchfromfile
*/
return true;
}
IpMatchFromFile::IpMatchFromFile(std::string op, std::string param,
bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

View File

@ -0,0 +1,38 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_IP_MATCH_FROM_FILE_H_
#define SRC_OPERATORS_IP_MATCH_FROM_FILE_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class IpMatchFromFile : public Operator {
public:
/** @ingroup ModSecurity_Operator */
IpMatchFromFile(std::string o, std::string p, bool i);
bool evaluate(Assay *assay);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_IP_MATCH_FROM_FILE_H_

41
src/operators/le.cc Normal file
View File

@ -0,0 +1,41 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/le.h"
#include <string>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool Le::evaluate(Assay *assay) {
/**
* @todo Implement the operator Le.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#le
*/
return true;
}
Le::Le(std::string op, std::string param, bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

41
src/operators/le.h Normal file
View File

@ -0,0 +1,41 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_LE_H_
#define SRC_OPERATORS_LE_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class Le : public Operator {
public:
/** @ingroup ModSecurity_Operator */
Le(std::string o, std::string p, bool i);
bool evaluate(Assay *assay);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_LE_H_

41
src/operators/lt.cc Normal file
View File

@ -0,0 +1,41 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/lt.h"
#include <string>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool Lt::evaluate(Assay *assay) {
/**
* @todo Implement the operator Lt.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#lt
*/
return true;
}
Lt::Lt(std::string op, std::string param, bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

40
src/operators/lt.h Normal file
View File

@ -0,0 +1,40 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_LT_H_
#define SRC_OPERATORS_LT_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class Lt : public Operator {
public:
/** @ingroup ModSecurity_Operator */
Lt(std::string o, std::string p, bool i);
bool evaluate(Assay *assay);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_LT_H_

177
src/operators/operator.cc Normal file
View File

@ -0,0 +1,177 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/operator.h"
#include <cstring>
#include <string>
#include "modsecurity/assay.h"
#include "operators/detect_sqli.h"
#include "operators/detect_xss.h"
#include "operators/inspect_file.h"
#include "operators/fuzzy_hash.h"
#include "operators/validate_byte_range.h"
#include "operators/validate_dtd.h"
#include "operators/validate_hash.h"
#include "operators/validate_schema.h"
#include "operators/validate_url_encoding.h"
#include "operators/validate_utf8_encoding.h"
#include "operators/verify_cc.h"
#include "operators/verify_cpf.h"
#include "operators/verify_ssn.h"
#include "operators/geolookup.h"
#include "operators/gsblookup.h"
#include "operators/rsub.h"
#include "operators/within.h"
#include "operators/contains_word.h"
#include "operators/contains.h"
#include "operators/ends_with.h"
#include "operators/eq.h"
#include "operators/ge.h"
#include "operators/gt.h"
#include "operators/ip_match_f.h"
#include "operators/ip_match.h"
#include "operators/ip_match_from_file.h"
#include "operators/le.h"
#include "operators/lt.h"
#include "operators/pm_f.h"
#include "operators/pm.h"
#include "operators/pm_from_file.h"
#include "operators/rbl.h"
#include "operators/rx.h"
#include "operators/str_eq.h"
#include "operators/str_match.h"
#include "operators/begins_with.h"
#define IF_MATCH(a) \
if (op.compare(1, std::strlen(#a), #a) == 0)
namespace ModSecurity {
namespace operators {
Operator::Operator() {
}
Operator::Operator(std::string op, std::string param, bool negation) {
this->op = op;
this->param = param;
}
bool Operator::evaluate(Assay *assay) {
if (assay) {
assay->debug(2, "Operator: " + this->op + \
" is not implemented or malfunctioning.");
}
return true;
}
bool Operator::evaluate(Assay *assay, const std::string& a) {
if (assay) {
assay->debug(2, "Operator: " + this->op + \
" is not implemented or malfunctioning.");
}
return true;
}
Operator *Operator::instantiate(std::string op_string) {
// Sanity check.
if (op_string.size() <= 2) {
return NULL;
}
std::string op = op_string;
op = op.substr(1, op_string.size() - 2);
// We assume no negation by default
bool negation = false;
// If there is a '!' in front substring and assign negation
if (op.at(0) == '!') {
op = op.substr(1, op.size() - 1);
negation = true;
}
// Check to see if there is a parameter, if not param is an empty string
std::string param = "";
if (op.find(" ") != std::string::npos) {
param = op;
param.erase(0, op_string.find(" "));
op.erase(op_string.find(" "),
op_string.length() - op_string.find(" "));
}
for (std::basic_string<char>::iterator p = op.begin();
p != op.end(); ++p) {
*p = tolower(*p);
}
IF_MATCH(beginswith) { return new BeginsWith(op, param, negation); }
IF_MATCH(contains) { return new Contains(op, param, negation); }
IF_MATCH(containsword) { return new ContainsWord(op, param, negation); }
IF_MATCH(detectsqli) { return new DetectSQLi(op, param, negation); }
IF_MATCH(detectxss) { return new DetectXSS(op, param, negation); }
IF_MATCH(endswith) { return new EndsWith(op, param, negation); }
IF_MATCH(eq) { return new Eq(op, param, negation); }
IF_MATCH(fuzzyhash) { return new FuzzyHash(op, param, negation); }
IF_MATCH(geolookup) { return new GeoLookup(op, param, negation); }
IF_MATCH(ge) { return new Ge(op, param, negation); }
IF_MATCH(gsblookup) { return new GsbLookup(op, param, negation); }
IF_MATCH(gt) { return new Gt(op, param, negation); }
IF_MATCH(inspectfile) { return new InspectFile(op, param, negation); }
IF_MATCH(ipmatchf) { return new IpMatchF(op, param, negation); }
IF_MATCH(ipmatchfromfile) {
return new IpMatchFromFile(op, param, negation);
}
IF_MATCH(ipmatch) { return new IpMatch(op, param, negation); }
IF_MATCH(le) { return new Le(op, param, negation); }
IF_MATCH(lt) { return new Lt(op, param, negation); }
IF_MATCH(pmf) { return new PmF(op, param, negation); }
IF_MATCH(pmfromfile) { return new PmFromFile(op, param, negation); }
IF_MATCH(pm) { return new Pm(op, param, negation); }
IF_MATCH(rbl) { return new Rbl(op, param, negation); }
IF_MATCH(rsub) { return new Rsub(op, param, negation); }
IF_MATCH(rx) { return new Rx(op, param, negation); }
IF_MATCH(streq) { return new StrEq(op, param, negation); }
IF_MATCH(strmatch) { return new StrMatch(op, param, negation); }
IF_MATCH(validatebyterange) {
return new ValidateByteRange(op, param, negation);
}
IF_MATCH(validatedtd) { return new ValidateDTD(op, param, negation); }
IF_MATCH(validatehash) { return new ValidateHash(op, param, negation); }
IF_MATCH(validateschema) { return new ValidateSchema(op, param, negation); }
IF_MATCH(validateurlencoding) {
return new ValidateUrlEncoding(op, param, negation);
}
IF_MATCH(validateutf8encoding) {
return new ValidateUtf8Encoding(op, param, negation);
}
IF_MATCH(verifycc) { return new VerifyCC(op, param, negation); }
IF_MATCH(verifycpf) { return new VerifyCPF(op, param, negation); }
IF_MATCH(verifyssn) { return new VerifySSN(op, param, negation); }
IF_MATCH(within) { return new Within(op, param, negation); }
return new Operator(op, param, negation);
}
} // namespace operators
} // namespace ModSecurity

49
src/operators/operator.h Normal file
View File

@ -0,0 +1,49 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifdef __cplusplus
#include <string>
#endif
#ifndef SRC_OPERATORS_OPERATOR_H__
#define SRC_OPERATORS_OPERATOR_H__
#include "modsecurity/assay.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class Operator {
public:
/** @ingroup ModSecurity_Operator */
Operator();
Operator(std::string po, std::string param, bool invert);
std::string op;
std::string param;
virtual bool evaluate(Assay *assay);
virtual bool evaluate(Assay *assay, const std::string &str);
static Operator *instantiate(std::string op);
protected:
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_OPERATOR_H__

41
src/operators/pm.cc Normal file
View File

@ -0,0 +1,41 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/pm.h"
#include <string>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool Pm::evaluate(Assay *assay) {
/**
* @todo Implement the operator Pm.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#pm
*/
return true;
}
Pm::Pm(std::string op, std::string param, bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

39
src/operators/pm.h Normal file
View File

@ -0,0 +1,39 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_PM_H_
#define SRC_OPERATORS_PM_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class Pm : public Operator {
public:
/** @ingroup ModSecurity_Operator */
Pm(std::string o, std::string p, bool i);
bool evaluate(Assay *assay);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_PM_H_

41
src/operators/pm_f.cc Normal file
View File

@ -0,0 +1,41 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/pm_f.h"
#include <string>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool PmF::evaluate(Assay *assay) {
/**
* @todo Implement the operator PmF.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#pmf
*/
return true;
}
PmF::PmF(std::string op, std::string param, bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

39
src/operators/pm_f.h Normal file
View File

@ -0,0 +1,39 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_PM_F_H_
#define SRC_OPERATORS_PM_F_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class PmF : public Operator {
public:
/** @ingroup ModSecurity_Operator */
PmF(std::string o, std::string p, bool i);
bool evaluate(Assay *assay);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_PM_F_H_

View File

@ -0,0 +1,41 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/pm_from_file.h"
#include <string>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool PmFromFile::evaluate(Assay *assay) {
/**
* @todo Implement the operator PmFromFile.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#pmfromfile
*/
return true;
}
PmFromFile::PmFromFile(std::string op, std::string param, bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

View File

@ -0,0 +1,40 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_PM_FROM_FILE_H_
#define SRC_OPERATORS_PM_FROM_FILE_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class PmFromFile : public Operator {
public:
/** @ingroup ModSecurity_Operator */
PmFromFile(std::string o, std::string p, bool i);
bool evaluate(Assay *assay);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_PM_FROM_FILE_H_

41
src/operators/rbl.cc Normal file
View File

@ -0,0 +1,41 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/rbl.h"
#include <string>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool Rbl::evaluate(Assay *assay) {
/**
* @todo Implement the operator Rbl.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#rbl
*/
return true;
}
Rbl::Rbl(std::string op, std::string param, bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

40
src/operators/rbl.h Normal file
View File

@ -0,0 +1,40 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_RBL_H_
#define SRC_OPERATORS_RBL_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class Rbl : public Operator {
public:
/** @ingroup ModSecurity_Operator */
Rbl(std::string o, std::string p, bool i);
bool evaluate(Assay *assay);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_RBL_H_

41
src/operators/rsub.cc Normal file
View File

@ -0,0 +1,41 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/rsub.h"
#include <string>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool Rsub::evaluate(Assay *assay) {
/**
* @todo Implement the operator Rsub.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#rsub
*/
return true;
}
Rsub::Rsub(std::string op, std::string param, bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

38
src/operators/rsub.h Normal file
View File

@ -0,0 +1,38 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_RSUB_H_
#define SRC_OPERATORS_RSUB_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class Rsub : public Operator {
public:
/** @ingroup ModSecurity_Operator */
Rsub(std::string o, std::string p, bool i);
bool evaluate(Assay *assay);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_RSUB_H_

41
src/operators/rx.cc Normal file
View File

@ -0,0 +1,41 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/rx.h"
#include <string>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool Rx::evaluate(Assay *assay) {
/**
* @todo Implement the operator Rx.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#rx
*/
return true;
}
Rx::Rx(std::string op, std::string param, bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

39
src/operators/rx.h Normal file
View File

@ -0,0 +1,39 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_RX_H_
#define SRC_OPERATORS_RX_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class Rx : public Operator {
public:
/** @ingroup ModSecurity_Operator */
Rx(std::string o, std::string p, bool i);
bool evaluate(Assay *assay);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_RX_H_

39
src/operators/str_eq.cc Normal file
View File

@ -0,0 +1,39 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/str_eq.h"
#include <string>
namespace ModSecurity {
namespace operators {
bool StrEq::evaluate(Assay *assay, const std::string &str) {
/**
* @todo Implement the operator StrEq.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#streq
*/
return !this->param.compare(str);
}
StrEq::StrEq(std::string op, std::string param, bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

43
src/operators/str_eq.h Normal file
View File

@ -0,0 +1,43 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 <string>
#include "modsecurity/assay.h"
#include "operators/operator.h"
#ifndef SRC_OPERATORS_STR_EQ_H_
#define SRC_OPERATORS_STR_EQ_H_
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class StrEq : public Operator {
public:
/** @ingroup ModSecurity_Operator */
StrEq(std::string o, std::string p, bool i);
bool evaluate(Assay *assay, const std::string &str) override;
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_STR_EQ_H_

View File

@ -0,0 +1,41 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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 "operators/str_match.h"
#include <string>
#include "operators/operator.h"
namespace ModSecurity {
namespace operators {
bool StrMatch::evaluate(Assay *assay) {
/**
* @todo Implement the operator StrMatch.
* Reference: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#strmatch
*/
return true;
}
StrMatch::StrMatch(std::string op, std::string param, bool negation)
: Operator() {
this->op = op;
this->param = param;
}
} // namespace operators
} // namespace ModSecurity

39
src/operators/str_match.h Normal file
View File

@ -0,0 +1,39 @@
/**
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 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.
*
*/
#ifndef SRC_OPERATORS_STR_MATCH_H_
#define SRC_OPERATORS_STR_MATCH_H_
#include <string>
#include "operators/operator.h"
#ifdef __cplusplus
namespace ModSecurity {
namespace operators {
class StrMatch : public Operator {
public:
/** @ingroup ModSecurity_Operator */
StrMatch(std::string o, std::string p, bool i);
bool evaluate(Assay *assay);
};
} // namespace operators
} // namespace ModSecurity
#endif
#endif // SRC_OPERATORS_STR_MATCH_H_

Some files were not shown because too many files have changed in this diff Show More