Django framework exceptions

Detects suspicious Django web application framework exceptions that could indicate exploitation attempts

Rule Content

- title: Django framework exceptions
  id: fd435618-981e-4a7c-81f8-f78ce480d616
  description: Detects suspicious Django web application framework exceptions that
    could indicate exploitation attempts
  author: Thomas Patzke
  references:
  - https://docs.djangoproject.com/en/1.11/ref/exceptions/
  - https://docs.djangoproject.com/en/1.11/topics/logging/#django-security
  logsource:
    category: application
    product: django
    service: null
  detection:
    keywords:
    - SuspiciousOperation
    - DisallowedHost
    - DisallowedModelAdminLookup
    - DisallowedModelAdminToField
    - DisallowedRedirect
    - InvalidSessionKey
    - RequestDataTooBig
    - SuspiciousFileOperation
    - SuspiciousMultipartForm
    - SuspiciousSession
    - TooManyFieldsSent
    - PermissionDenied
    condition: keywords
  falsepositives:
  - Application bugs
  - Penetration testing
  level: medium

Querying Elasticsearch

Import Libraries


In [ ]:
from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search
import pandas as pd

Initialize Elasticsearch client


In [ ]:
es = Elasticsearch(['http://helk-elasticsearch:9200'])
searchContext = Search(using=es, index='logs-*', doc_type='doc')

Run Elasticsearch Query


In [ ]:
s = searchContext.query('query_string', query='\*.keyword:(*SuspiciousOperation* OR *DisallowedHost* OR *DisallowedModelAdminLookup* OR *DisallowedModelAdminToField* OR *DisallowedRedirect* OR *InvalidSessionKey* OR *RequestDataTooBig* OR *SuspiciousFileOperation* OR *SuspiciousMultipartForm* OR *SuspiciousSession* OR *TooManyFieldsSent* OR *PermissionDenied*)')
response = s.execute()
if response.success():
    df = pd.DataFrame((d.to_dict() for d in s.scan()))

Show Results


In [ ]:
df.head()