gpt4 book ai didi

nginx-ingress - ModSecurity(在 DetectionOnly 模式下)没有提供有用的日志/警告

转载 作者:行者123 更新时间:2023-12-05 06:04:47 34 4
gpt4 key购买 nike

我已经在 Kubernetes Nginx Controller 上配置了 modsecurity-nginx 连接器。

目前,我使用 ModSecurity WAF 的目标是在 DetectionOnly 模式下实现,因为我不想立即开始阻止所有内容。因此,为了实现这一点,我在我的 Controller ConfigMap 中使用了以下配置。

enable-modsecurity: "true"
modsecurity-snippet: |
SecRuleEngine DetectionOnly
SecAuditEngine On
SecAuditLogParts ABIJDEFHZ
SecAuditLogFormat JSON
SecAuditLogType Serial
SecAuditLog /dev/stdout

为了对此进行测试,我尝试了 SQL 注入(inject)攻击,在这种攻击中,我将来自客户端的 SQL 查询插入到我的测试应用程序中。但是 ModSecurity 没有在日志中给出任何警告或任何有用的信息,告诉应用程序中插入了 SQL 查询。以下是我分别发送和获取日志的请求:

$ curl -ks -o /dev/null -w ‘%{http_code}’ “https://test-ingress-nginx.example.com/foo?username=1'%20or%20'1'%20=%20'”

输出:404

Logs :
----
{“transaction”:{“client_ip”:“192.xxx.xxx.xx",“time_stamp”:“Tue Feb 16 07:44:10 2021",“server_id”:“995f188ad543e6fcbcdbfb4c7a2c67327xxxxx",“client_port”:59455,“host_ip”:“10.x.xxx.xxx”,“host_port”:443,“unique_id”:“161346145098.924xxx",“request”:{“method”:“GET”,“http_version”:2.0,“uri”:“/foo?username=1'%20or%20'1'%20=%20'“,”headers”:{“host”:“test-ingress-nginx.example.com”,“user-agent”:“curl/7.64.1",“accept”:“*/*“}},“response”:{“body”:“<!DOCTYPE HTML PUBLIC \“-//IETF//DTD HTML 2.0//EN\“>\n<html><head>\n<title>404 Not Found</title>\n</head><body>\n<h1>Not Found</h1>\n<p>The requested URL /foo was not found on this server.</p>\n<hr>\n<address>Apache/2.4.25 (Debian) Server at test-ingress-nginx.example.com Port 80</address>\n</body></html>\n”,“http_code”:404,“headers”:{“Server”:“”,“Server”:“”,“Date”:“Tue, 16 Feb 2021 07:44:10 GMT”,“Content-Length”:“306”,“Content-Type”:“text/html; charset=iso-8859-1”,“Connection”:“close”,“Strict-Transport-Security”:“max-age=15724800; includeSubDomains”}},“producer”:{“modsecurity”:“ModSecurity v3.0.4 (Linux)“,”connector”:“ModSecurity-nginx v1.0.1”,“secrules_engine”:“DetectionOnly”,“components”:[]},“messages”:[]}}

如果我将 SecRuleEngine DetectionOnly 更改为 SecRuleEngine On,则错误代码会更改并且日志会显示请求被阻止的原因:

$ curl -ks -o /dev/null -w ‘%{http_code}’ “https://test-ingress-nginx.example.com/foo?username=1'%20or%20'1'%20=%20'”

输出:403

Logs :
----
2021/02/16 07:35:11 [error] 8100#8100: *25411553 [client 192.xxx.xxx.xx] ModSecurity: Access denied with code 403 (phase 2). Matched “Operator `Ge’ with parameter `5' against variable `TX:ANOMALY_SCORE’ (Value: `5' ) [file “/etc/nginx/owasp-modsecurity-crs/rules/REQUEST-949-BLOCKING-EVALUATION.conf”] [line “80"] [id “949110”] [rev “”] [msg “Inbound Anomaly Score Exceeded (Total Score: 5)“] [data “”] [severity “2"] [ver “OWASP_CRS/3.3.0”] [maturity “0"] [accuracy “0”] [tag “application-multi”] [tag “language-multi”] [tag “platform-multi”] [tag “attack-generic”] [hostname “10.x.xxx.xxx"] [uri “/foo”] [unique_id “16134609114.611xxx"] [ref “”], client: 192.xxx.xx.xx, server: test-ingress-nginx.example.com, request: “GET /foo?username=1'%20or%20'1'%20=%20' HTTP/2.0", host: “test-ingress-nginx.example.com”

问题:当我在 Detection Only 模式下启用 ModSecurity 时,有什么方法可以在 ModSecurity 日志中获取一些有用的信息,以便我可以识别即将到来的请求/威胁类型我的应用程序,因此开始为他们编写阻止规则。

最佳答案

核心规则集 Dev on Duty 在这里。在您的 403 日志输出中,我看到您已使用 OWASP Core Rule Set 配置了 ModSecurity .

您的 ModSecurity 配置似乎是正确的,您配置了正确的 SecAuditLogParts

当我使用具有完全相同的 ModSecurity 配置的官方 CRS Docker 容器对此进行测试时,我得到以下输出:

{"transaction":{"client_ip":"172.x.x.x","time_stamp":"Wed Jan 19 19:51:47 2022","server_id":"364905fd334fdd694cd3e0d02976eb3eb63f3790","client_port":46202,"host_ip":"172.x.x.x","host_port":80,"unique_id":"1642621907","request":{"method":"GET","http_version":1.1,"uri":"/foo?username=1'%20or%20'1'%20=%20'","headers":{"Host":"localhost","User-Agent":"curl/7.58.0","Accept":"*/*"}},"response":{"body":"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n<title>404 Not Found</title>\n<h1>Not Found</h1>\n<p>The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.</p>\n","http_code":404,"headers":{"Server":"nginx/1.20.1","Date":"Wed, 19 Jan 2022 19:51:47 GMT","Content-Length":"233","Content-Type":"text/html","Access-Control-Allow-Origin":"*","Connection":"keep-alive","Access-Control-Allow-Credentials":"true"}},"producer":{"modsecurity":"ModSecurity v3.0.5 (Linux)","connector":"ModSecurity-nginx v1.0.2","secrules_engine":"DetectionOnly","components":["OWASP_CRS/3.4.0-dev\""]},"messages":[{"message":"","details":{"match":"detected SQLi using libinjection.","reference":"v18,13","ruleId":"942100","file":"/etc/modsecurity.d/owasp-crs/rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf","lineNumber":"46","data":"","severity":"0","ver":"OWASP_CRS/3.4.0-dev","rev":"","tags":[],"maturity":"0","accuracy":"0"}},{"message":"Inbound Anomaly Score Exceeded (Total Score: 5)","details":{"match":"Matched \"Operator `Ge' with parameter `5' against variable `TX:ANOMALY_SCORE' (Value: `5' )","reference":"","ruleId":"949110","file":"/etc/modsecurity.d/owasp-crs/rules/REQUEST-949-BLOCKING-EVALUATION.conf","lineNumber":"139","data":"","severity":"2","ver":"OWASP_CRS/3.4.0-dev","rev":"","tags":["${MODSEC_TAG}","application-multi","language-multi","platform-multi","attack-generic"],"maturity":"0","accuracy":"0"}}]}}

我的和你的输出之间的区别是:

  • 您的消息数组为空
  • 组件也是空的

在我的输出中,我看到组件:“OWASP_CRS/3.4.0-dev”messages数组包含两条消息:一条是违反CRS规则942100和阻止规则949110。

正如我们在今天的回复中看到的那样,它在 SecAuditLogFormat Native 而不是 SecAuditLogFormat JSON 中显示了 ModSecurity AuditLog,违反的规则应该在 SecAuditLogParts 中列出 部分 H

为了确认这一点,我在我的环境中对其进行了测试,我可以使用 H 部分完全关闭消息部分。

所以我进一步调查并发现了一些与您的问题相关的 ModSecurity 问题。

这些不能 1:1 解释您的问题。我看到 CRS 规则之间的区别是:由您的 curl 测试触发的 SQL 注入(inject)规则是 942100,它具有操作 block(未记录):https://github.com/coreruleset/coreruleset/blob/v3.4/dev/rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf#L46

阻止 ID 为 949110 的请求的阻止评估规则具有操作 deny:https://github.com/coreruleset/coreruleset/blob/v3.4/dev/rules/REQUEST-949-BLOCKING-EVALUATION.conf#L139 .

正如我上面所说,这并不能 1:1 解释您的问题。但是我建议你升级到最新版本再测试一下。您的帖子已有 11 个月了,问题本可以在此期间得到解决,因为我们看到了一些 ModSecurity 问题和与此问题相关的拉取请求。

关于nginx-ingress - ModSecurity(在 DetectionOnly 模式下)没有提供有用的日志/警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66222656/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com