代码之家  ›  专栏  ›  技术社区  ›  Majid Abdolhosseini

Apache将所有post数据发送到Graylog

  •  1
  • Majid Abdolhosseini  · 技术社区  · 7 年前

    我需要实现的是,在我的graylog中记录apache请求。 我已经完成了这项任务,下面是我的apache vhost的一部分,它与这项任务有关:

    LogFormat "{ \"version\": \"1.1\", \"host\": \"%V\", \"short_message\": \"%r\", \"timestamp\": %{%s}t, \"level\": 6, \"_user_agent\": \"%{User-Agent}i\", \"_source_ip\": \"%{X-Forwarded-For}i\", \"_duration_usec\": %D, \"_duration_sec\": %T, \"_request_size_byte\": %O, \"_http_status_orig\": %s, \"_http_status\": %>s, \"_http_request_path\": \"%U\", \"_http_request\": \"%U%q\", \"_http_method\": \"%m\", \"_http_referer\": \"%{Referer}i\", \"_from_apache\": \"true\" }" graylog_access
    CustomLog "|/bin/nc -u 192.168.50.21 12201" graylog_access
    

    但我意识到我的日志中没有post-request body。 我在网上搜索,找到了安装apache mod_security的方法 把它的日志发送到我的graylog 这是我的modsecurity配置:

    SecRuleEngine Off
    
    SecRequestBodyAccess On
    
    SecRule REQUEST_HEADERS:Content-Type "(?:text|application)/xml" \
         "id:'200000',phase:1,t:none,t:lowercase,pass,nolog,ctl:requestBodyProcessor=XML"
    
    SecRule REQUEST_HEADERS:Content-Type "application/json" \
         "id:'200001',phase:1,t:none,t:lowercase,pass,nolog,ctl:requestBodyProcessor=JSON"
    
    SecRequestBodyLimit 13107200
    SecRequestBodyNoFilesLimit 131072
    
    SecRequestBodyInMemoryLimit 131072
    
    SecRequestBodyLimitAction Reject
    
    SecRule REQBODY_ERROR "!@eq 0" \
    "id:'200002', phase:2,t:none,log,deny,status:400,msg:'Failed to parse request body.',logdata:'%{reqbody_error_msg}',severity:2"
    
    SecRule MULTIPART_STRICT_ERROR "!@eq 0" \
    "id:'200003',phase:2,t:none,log,deny,status:400, \
    msg:'Multipart request body failed strict validation: \
    PE %{REQBODY_PROCESSOR_ERROR}, \
    BQ %{MULTIPART_BOUNDARY_QUOTED}, \
    BW %{MULTIPART_BOUNDARY_WHITESPACE}, \
    DB %{MULTIPART_DATA_BEFORE}, \
    DA %{MULTIPART_DATA_AFTER}, \
    HF %{MULTIPART_HEADER_FOLDING}, \
    LF %{MULTIPART_LF_LINE}, \
    SM %{MULTIPART_MISSING_SEMICOLON}, \
    IQ %{MULTIPART_INVALID_QUOTING}, \
    IP %{MULTIPART_INVALID_PART}, \
    IH %{MULTIPART_INVALID_HEADER_FOLDING}, \
    FL %{MULTIPART_FILE_LIMIT_EXCEEDED}'"
    
    SecRule MULTIPART_UNMATCHED_BOUNDARY "!@eq 0" \
    "id:'200004',phase:2,t:none,log,deny,msg:'Multipart parser detected a possible unmatched boundary.'"
    
    SecPcreMatchLimit 100000
    SecPcreMatchLimitRecursion 100000
    
    SecRule TX:/^MSC_/ "!@streq 0" \
            "id:'200005',phase:2,t:none,deny,msg:'ModSecurity internal error flagged: %{MATCHED_VAR_NAME}'"
    
    SecRule REQUEST_METHOD "POST" "id:1000,phase:2,ctl:auditEngine=On,nolog,pass"
    
    SecResponseBodyAccess On
    
    SecResponseBodyMimeType text/plain text/html text/xml
    
    SecResponseBodyLimit 524288
    
    SecResponseBodyLimitAction ProcessPartial
    
    
    SecTmpDir /tmp/
    
    SecDataDir /tmp/
    
    
    
    SecAuditEngine On
    SecAuditLogRelevantStatus "^(?:5|4(?!04))"
    
    SecAuditLogParts ABDEFHIJZ
    
    SecAuditLogType Serial
    # SecAuditLog /var/log/apache2/modsec_audit.log
    SecAuditLog "|/bin/nc -u 192.168.50.21 12201"
    
    SecArgumentSeparator &
    
    SecCookieFormat 0
    
    SecUnicodeMapFile unicode.mapping 20127
    SecStatusEngine On
    

    请帮我完成这项任务。

    你可以在这里找到更完整的apache vhost。

    <VirtualHost *:80>
        ServerAdmin test@gmail.com
        ServerName localhost
        DocumentRoot /var/www/public
    
        ErrorLog /var/log/apache2/error.log
    #    CustomLog /var/log/apache2/access.log combined
    
        LogFormat "{ \"version\": \"1.1\", \"host\": \"%V\", \"short_message\": \"%r\", \"timestamp\": %{%s}t, \"level\": 6, \"_user_agent\": \"%{User-Agent}i\", \"_source_ip\": \"%{X-Forwarded-For}i\", \"_duration_usec\": %D, \"_duration_sec\": %T, \"_request_size_byte\": %O, \"_http_status_orig\": %s, \"_http_status\": %>s, \"_http_request_path\": \"%U\", \"_http_request\": \"%U%q\", \"_http_method\": \"%m\", \"_http_referer\": \"%{Referer}i\", \"_from_apache\": \"true\" }" graylog_access
        CustomLog "|/bin/nc -u 192.168.50.21 12201" graylog_access
    
        <Directory /var/www>
            Options FollowSymLinks
            AllowOverride All
        </Directory>
    
        <Directory /var/www/public>
             Options Indexes FollowSymLinks MultiViews
             AllowOverride All
             Order allow,deny
             allow from all
        </Directory>
    
    </VirtualHost>
    
    0 回复  |  直到 7 年前