Django审计

django-audit-wazuh的Python项目详细描述


Django审计Wazuh

审计应用程序,尽可能简单,有一个良好的日志记录系统的安全目的。 您将有一个json文件可以由Wazuh或OSSEC这样的SIEM处理。在

特点

  • 登录、注销和暴力尝试。在

托多

  • 其他关键django.安全消息,需要用正常的单元测试进行更多测试。在

设置

pip install django-audit
# or
pip install git+https://github.com/peppelinux/django-audit.git

配置

settings.py中:

  1. INSTALLED_APPS中添加“auditing”
  2. 添加一个中间件,如下所示(不是必需的!)在
  3. 配置日志记录如下
^{pr2}$

结果

您将得到一个文件,其中包含json格式的所有相关事件,比如

{"timestamp": "2020-04-21 13:05:01,238", "msg": "Django Login failed", "username": "dsfsdf", "url": "http://localhost:8000/gestionelogin/?next=/gestione", "data.srcip": "127.0.0.1", "path": "/gestionelogin/?next=/gestione", "Content-Length": "132", "Content-Type": "application/x-www-form-urlencoded", "Host": "localhost:8000", "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate", "Origin": "http://localhost:8000", "Connection": "keep-alive", "Referer": "http://localhost:8000/gestionelogin/?next=/gestione", "Cookie": "csrftoken=pTG3UCHtiE0q4PNectVIH4hbezbqL2O2tvWx97rY8zwOxigSzG9unl2tqELzMhpM; cookieconsent_status=dismiss", "Upgrade-Insecure-Requests": "1", "level": "WARNING",  "name": "auditing", "path": "__init__.py.login_failed_logger:23", "@source":"django-audit"}
{"timestamp": "2020-04-21 13:05:33,521", "msg": "Django Login successful", "username": "wert", "url": "http://localhost:8000/gestionelogin/?next=/gestione", "data.srcip": "127.0.0.1", "path": "/gestionelogin/?next=/gestione", "Content-Length": "131", "Content-Type": "application/x-www-form-urlencoded", "Host": "localhost:8000", "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate", "Origin": "http://localhost:8000", "Connection": "keep-alive", "Referer": "http://localhost:8000/gestionelogin/?next=/gestione", "Cookie": "csrftoken=pTG3UCHtiE0q4PNectVIH4hbezbqL2O2tvWx97rY8zwOxigSzG9unl2tqELzMhpM; cookieconsent_status=dismiss", "Upgrade-Insecure-Requests": "1", "level": "INFO",  "name": "auditing", "path": "__init__.py.login_logger:16", "@source":"django-audit"}
{"timestamp": "2020-04-21 13:05:36,582", "msg": "Django Logout successful", "username": "wert", "url": "http://localhost:8000/gestionelogout/", "data.srcip": "127.0.0.1", "path": "/gestionelogout/", "Content-Type": "text/plain", "Host": "localhost:8000", "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate", "Connection": "keep-alive", "Referer": "http://localhost:8000/gestione", "Cookie": "csrftoken=e50mIQ4NWKYjDKBKA9a1iFufQuRv2W8LKAWnIjm4meXhiCSWPHzxfkrllMeNVqDR; cookieconsent_status=dismiss; sessionid=cxu3hfono6t6p1dl70q80836pe292ri3", "Upgrade-Insecure-Requests": "1", "level": "INFO",  "name": "auditing", "path": "__init__.py.logout_logger:30", "@source":"django-audit"}

调谐

审计中间件可以记录http请求和它的后续响应之间的所有内容。 这些是可重载的设置变量

# for i in http.HTTPStatus: print(i, i.value) 
AUDIT_RESPONSE_HTTPCODES = getattr(settings,
                                   'AUDIT_RESPONSE_HTTPCODES',
                                   [i.value for i in http.HTTPStatus if i not in (200,201,202,301,302)])

# prevents to read the password in clear
AUDIT_REQUEST_POST_IGNORED = ('password', )

Wazuh配置

  1. 复制wazuh-ruleset/27081-django_decoders.xml的内容到/var/ossec/etc/decoders/local_decoder.xml

  2. 复制wazuh-ruleset/27081-django_rules.xmlwazuh-ruleset/27081-django_rules.xml的内容。在

  3. 使用/var/ossec/bin/ossec-logtest测试触发器,在stdin中复制一条日志行并查看事件。在

  4. 创建一个名为django的代理组

    /var/ossec/bin/agent_groups -a -g django
    
  5. 按此方式编辑代理组配置/var/ossec/etc/shared/django/agent.conf

    <localfile>
         <location>ABSOLUTE_PATH_TO_YOUR_DJANGO_AUDIT_LOG.json</location>
         <log_format>json</log_format>
         <label key="@source">django-audit</label>
    </localfile>
    
  6. 将代理添加到此组

    /var/ossec/bin/agent_groups -a -i 014 -g django
    
  7. 同步时控制

    /var/ossec/bin/agent_groups -S -i 014
    
  8. 重新启动Wazuh管理器以重新加载规则集service wazuh-manager restart

GeoIP公司

在wazuh管理器上,编辑/usr/share/filebeat/module/wazuh/alerts/incente/管道.json在处理器中添加新的IP字段以及其他地理位置字段:

    {
      "geoip": {
        "field": "srcip",
        "target_field": "GeoLocation",
        "properties": ["city_name", "country_name", "region_name", "location"],
        "ignore_missing": true,
        "ignore_failure": true
      }
    },

我们现在需要删除当前的管道。在Kibana中,点击扳手图标进入devtools。然后执行以下操作:

DELETE _ingest/pipeline/filebeat-7.6.2-wazuh-alerts-pipeline

我们在wazuh manager中重新启动Filebeat:

systemctl restart filebeat

许可证

阿帕奇

作者

朱塞佩·德马尔科giuseppe.demarco@unical.it

学分

Garrlab Wazuh SIEM船员

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
用于限制返回字符串大小的java<bean:write>标记   java将值传递给内部类方法?   数组无法在Java中使用for循环获取所有JSONObject   java中的StringTokenizer需要帮助   java如何在运行时在方法中自动连接类   java通过setter或构造函数分配多个字段   java JPA OneToMany ManyTone   java无法解析类org。贾布拉斯。双矩阵   java如何使用Rest-Assured从以下Json响应获取NetworkID   如果类具有“org”字段,则java@Slf4j生成“无法引用非静态变量org”   swing Java jform前景色未显示   java向kafka事件订阅rest api   java为什么我的数组会出现NullPointerException?   java通过JavaMail从Exchange server读取Zip文件后提取Zip文件的内容   Java中的字符串值舍入   java如何解析单个变量中的每个字符串   带有ListView头的java ListView   java输入流无限循环   java Grails在Spring Boot中的BootStrap#init等价物?