Skip to content

Commit

Permalink
git - Merge pull request #303 from DinoTools/http
Browse files Browse the repository at this point in the history
Improve http service
  • Loading branch information
phibos authored Nov 12, 2020
2 parents 291f373 + d0df814 commit d0e03ae
Show file tree
Hide file tree
Showing 6 changed files with 338 additions and 94 deletions.
1 change: 0 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ extend-exclude =
modules/python/dionaea/ftp.py
modules/python/dionaea/ftp_download.py
modules/python/dionaea/hpfeeds.py
modules/python/dionaea/http.py
modules/python/dionaea/ihandlers.py
modules/python/dionaea/log_db_sql/controller.py
modules/python/dionaea/log_incident.py
Expand Down
17 changes: 17 additions & 0 deletions conf/services/http.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,38 @@

- name: http
config:
# Root directory to look for files
root: "@DIONAEA_STATEDIR@/http/root"
ports:
- 80
ssl_ports:
- 443
max_request_size: 32768 # maximum size in kbytes of the request (32MB)
# Set default Content-Type if unable to detect
# default_content_type: text/html; charset=utf-8
# Max number of fields to extract from GET request (Python >= 3.8)
# get_max_num_fields: 100
# List of default headers
# default_headers:
# - ["Content-Type", "{content_type}"]
# - ["Content-Length", "{content_length}""]
# - ["Connection", "{connection}"]
# Try to detect the Content-Type by using the filename
# detect_content_type: true
global_headers:
- ["Server", "nginx"]
# Add additional headers to the response. First match wins.
# filename_pattern - is a regex if matched the headers are set
# headers - a list of HTTP headers to set
# the order matters, use to simulate your webserver as good as possible
headers:
- filename_pattern: ".*\\.php"
headers:
- ["Content-Type", "text/html; charset=utf-8"]
- ["Content-Length", "{content_length}"]
- ["Connection", "{connection}"]
- ["X-Powered-By", "PHP/5.5.9-1ubuntu4.5"]
# If enabled, try to handle some SOAP requests
# soap_enabled: false
template:
# set to true to enable template processing
Expand Down
35 changes: 35 additions & 0 deletions doc/source/service/http.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,38 @@ Define headers to use if the filename matches a pattern.
- ["Content-Length", "{content_length}"]
- ["Connection", "{connection}"]
- ["X-Powered-By", "PHP/5.5.9-1ubuntu4.5"]
Templates
---------

It is possible to use Jinja_ templates to customise the content returned by dionaea.

Requirements:

- Jinja

Before any template is used the template processing has to be enabled in the config file.
Some global templates (e.g. for error pages) are specified in the config file.
To use the template function in a static file just place it under the content root directory and add the template file extension as specified with the ``file_extension``.

Example:

- you have a file called ``my-app.html``
- to enabled template processing rename the file to ``my-app.html.j2``
- now you can use template strings

Template values:

- ``connection`` is an instance of HTTP connection class
- ``values`` is a Dictionary of additional template values specified in the config

Demo:


Have a look at our demo template and play with it in your test lab before releasing it into the wild.

.. literalinclude:: ../../../share/python/http/template/example/form.html.j2
:language: jinja
:caption: http/root/form.html.j2

.. _Jinja: https://palletsprojects.com/p/jinja/
Loading

0 comments on commit d0e03ae

Please sign in to comment.