mod_security ġ ε尡 ȵǴ ȲԴϴ.

dragoune   
   ȸ 1295   õ 0    

안녕하세요 쪽팔리면 질문하지 말라고 써있는데 그래도 먹고 살려고(...) 질문 올립니다.
이틀 삽질했는데 안됐으니 고견을 여쭙고자 합니다.

질문은 아래와 같습니다.

mod_security에서 DetectionOnly ON 에서는 안걸리는데,
DetectionOnly OFF 상태에서는 블럭되는 경우 어떻게 원인이 되는 룰을 찾아야 할까요?


환경은 Rocky Linux 8.9 / apache 2.4 / php 8.4

mod_security는 dnf로 설치했으며 버전은
mod_security-2.9.6-1.el8.x86_64 입니다.


기본적으로는 CentOS7 시절에 쓰던 것들을 그대로 가져온 상태이며
mod_security 설정도 그대로 입니다.
파일 업로드를 하면 파일이 업로드 되지 않는 상황인데

SecRuleEngine DetectionOnly 옵션을 활성화 한 상태로는
당연히 파일 업로드가 되고 어떠한 에러/디버그 메시지도 나타나지 않습니다.

audit.log
modsec_audit.log
modsec_debug.log

SecRuleEngine DetectionOnly 옵션을 꺼서 실제로 블럭하게 한 상황에서는

modsec_debug.log에서
[18/Mar/2024:11:28:59] [localhost/sid#563f93697640][rid#7f103401de20][/api/front/index/][1] Multipart parsing error: Multipart: Final boundary missing.

요런게 찍히고요
apache error 로그에는

[Mon Mar 18 11:28:59] [:error] [pid 2207392:tid 139707031746304] [client ::1:57880] [client ::1] ModSecurity: Multipart parsing error: Multipart: Final boundary missing. [hostname "localhost"] [uri "/api/front/index/"] [unique_id "Zfem6yDs7FhPxjvCHrnUQgAAANM"]

[Mon Mar 18 11:28:59.738473 2024] [proxy_fcgi:error] [pid 2207392:tid 139707249825536] [client 201.xxx.xxx.174:60428] AH01071: Got error 'PHP message: PHP Warning:  file_get_contents(https://localhost/api/front/index/?lang=ja&ckey=audio&akey=add): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error\r\n in /public_html/Component/Component.php on line 118\n', referer: https://test.xxxxxxxx.com/auto/audio/add/?lang=ja


요런식으로 찍히더군요
Component.php on line 118 는 업로드한 파일을 읽어들이는 부분이라 localhost로 던졌을 때 실제 파일이 업로드되지 않아서 발생하는 것으로 추측하고 있습니다. 그렇다고 제가 마음대로 고칠 수 있는 것도 아니라...


ModSecurity: Multipart parsing error: Multipart: Final boundary missing. 

로 검색해보니 대용량 파일 업로드 시에 발생한다는 것 같은데
파일 용량이 1MB 이하의 작은 파일에서 발생하고 있습니다.

modsecurity.conf 파일 설정은 아래와 같습니다.

<IfModule mod_security2.c>
    <IfModule unique_id_module>
        SecRuleEngine On
#        SecRuleEngine DetectionOnly
        SecRequestBodyAccess On
        SecDebugLog logs/modsec_debug.log
        SecDebugLogLevel 3
        SecTmpDir /tmp/
        SecUploadDir /tmp/
        SecDataDir /tmp/
        SecAuditEngine On
        SecAuditEngine RelevantOnly
        SecAuditLogType concurrent
        SecAuditLogParts ABIDEFGHZ
        SecAuditLogStorageDir /tmp/
        SecAuditLog logs/audit_log
        SecPcreMatchLimit 100000
        SecPcreMatchLimitRecursion 100000
        SecRequestBodyLimit 13107200
        SecRequestBodyNoFilesLimit 13107200
        SecRequestBodyInMemoryLimit 13107200
        SecRequestBodyLimitAction ProcessPartial

        Include modsecurity.d/crs-setup.conf
        Include /usr/share/mod_modsecurity_crs/rules/*.conf
    </IfModule>
</IfModule>


로그레벨 올렸더니 일일히 나오긴하는데, 너무 많...

고견을 부탁드립니다. ㅜ_ㅜ

ª ϼ ϰ.
ܹl 03-18
êGPT  Ʒ µ,
 ѹ Ȯغ..

A: ־ ModSecurity "Multipart parsing error: Multipart: Final boundary missing" ذϱ ǽغ ִ ϴ:

1. SecRequestBodyLimit Ȯ: ־ û ũ Ǿ ֽϴ. û ũ⸦ ϰ ׿ ֽϴ. ׷ ʹ ۰ Ǿ ְų, ƼƮ û ũⰡ ʰϴ 쿡 ̷ ߻ ֽϴ.

2. SecRequestBodyInMemoryLimit Ȯ: û ޸𸮿 ϴ ִ ִ ޸ մϴ. ʹ ۰ Ǿ ū ƼƮ û ó ߻ ֽϴ.

3. SecRequestBodyLimitAction Ȯ: û ũ ѿ ModSecurity  ؾ ϴ մϴ. , "ProcessPartial" , û Ϻθ óϰ մϴ. ϰ Ǿ ִ Ȯؾ մϴ.

ƼƮ Ȯ: CRS (Core Rule Set) õ Ʈ ϴ Ͽ ƼƮ û óϴ ʿ Ģ ԵǾ ֽϴ. ̷ ƼƮ û ȿ ˻ϰ õ ֽϴ.

־ CRS (Core Rule Set) õ ԵǾ Ƿ, CRS ƼƮ ߰ ȣ Ȱ ֽϴ.


Q: SecRequestBodyLimit 뷮 󸶸 ǹϴ°? ްƮ..
A: SecRequestBodyLimit "13107200" Ǿ ֽϴ. Ʈ ǥõǸ, ްƮ ȯϸ ˴ϴ:

13107200 Ʈ = 13107200 / 1024 / 1024 ≈ 12.5 ްƮ

SecRequestBodyLimit 12.5 ްƮԴϴ. û ִ ũ⸦ ϴ , Ŭ̾Ʈ ִ û ִ ũ⸦ ϴ մϴ.
     
dragoune 03-18
մϴ.
crs ⺻ ϰ ִ ̰, ýۿ ۵ϰ ֽϴ.
Ѵٸ ϴ ý۰ ϰ ״ Ϸ մϴ.

SecRequestBody*Limit ʰ Ȥóؼ ־ Դϴ.
ϴ 뷮 1MB ̱ 12MB ϸ Ŷ ߴµ ʰ ֽϴ. _
ܹl 03-18
.. modsecurity 2.9.7 ׽Ʈ ε. OWASP Modsecurity Core Rule Set ġ ¿
ε带 ϰ ε ۼؼ ׽Ʈ غôµ, ε dz׿..

ٸ ׽Ʈ ؼSecRequestBodyLimit  ɼǰ 13107 ̰ ̹ ϵ ε
δ ö󰬴µ ɸ Ʒ α׷ ܵDZ ߽ϴ. 𸣰ڽϴ.

[18/Mar/2024:13:57:57.096980 +0900] [/sid#55cda7aa9d28][rid#7fb898007ac0][/up.html][2] Warning. Pattern match "^[\\d.:]+$" at REQUEST_HEADERS:Host. [file "//apache/coreruleset/rules/REQUEST-920-PROTOCOL-ENFORCEMENT.conf"] [line "736"] [id "920350"] [msg "Host header is a numeric IP address"] [data ""] [severity "WARNING"] [ver "OWASP_CRS/3.3.5"] [tag "application-multi"] [tag "language-multi"] [tag "platform-multi"] [tag "attack-protocol"] [tag "paranoia-level/1"] [tag "OWASP_CRS"] [tag "capec/1000/210/272"] [tag "PCI/6.5.10"]
[18/Mar/2024:13:58:01.649251 +0900] [/sid#55cda7aa9d28][rid#7fb898027e70][/upload.php][1] Request body (Content-Length) is larger than the configured limit (13107).
[18/Mar/2024:13:58:01.649681 +0900] [/sid#55cda7aa9d28][rid#7fb898027e70][/upload.php][1] Request body (Content-Length) is larger than the configured limit (13107).
[18/Mar/2024:13:58:01.649964 +0900] [/sid#55cda7aa9d28][rid#7fb898027e70][/upload.php][1] Multipart parsing error: Multipart: Final boundary missing.


Ʈ ѹ غô ͵  ˴ϴ.
Ʒ 丮 ҽ ġ ߾ϴ.

# ModSecurity ҽ ٿε
# git clone -b v2.9.7 --single-branch https://github.com/SpiderLabs/ModSecurity.git
     
dragoune 03-18
մϴ. غڽϴ. _
     
dragoune 03-18
մϴ.

2.9.7 ġؼ ذƽϴ.
״ ΰ
OWASP ص Ǵ±
...ҽ ġ Ⱦϴ Ƽ ø ƿ rpm ⸸ϴٺ
̷ ׿
          
ܹl 03-18
.. ϵ帳ϴ. ̳׿.. ϼ̽ϴ.
03-18
־µ..

1. Temp (Upload folder) .
2. chmod 777 /Upload folder

̷ Ǯ ֽϴ. .
     
dragoune 03-18
亯 մϴ.
̹ Ȯ ߾µ ذ ʾҾϴ.
ƹ 2.9.6 ģϰ ʾҴ ϴ. _


QnA
Page 5581/5661
2015-12   1421926   ް
2014-05   4882763   1
2023-12   1064   Caig
02-03   1064   嵿2014
04-01   1064   Software1995
03-10   1064   صĵ
2022-05   1064   Ѿź糪
01-10   1064   ĵ
2022-05   1063   ocarina
07-16   1063  
2023-06   1063   ¯
03-29   1063   Rich
2023-06   1062   ¿
01-09   1062   ̴̴
05-17   1062   ο
04-09   1062   ȸ
07-12   1062   soom
01-20   1062   ̿
2023-06   1062  
01-05   1062   inquisitive
02-16   1062   chotws
2022-04   1061   AMD