mod_security ¼³Ä¡ ÈÄ ÆÄÀÏ ¾÷·Îµå°¡ ¾ÈµÇ´Â »óȲÀÔ´Ï´Ù.

dragoune   
   Á¶È¸ 344   Ãßõ 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>


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

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

ªÀº±Û Àϼö·Ï ½ÅÁßÇÏ°Ô.
ê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 Á¤µµ ¼³Á¤ÇÏ¸é ¹®Á¦°¡ ¾øÀ»°Å¶ó »ý°¢Çߴµ¥ °³¼±µÇÁö ¾Ê°í ÀÖ½À´Ï´Ù. ¤Ì_¤Ì
À½.. Àú´Â modsecurity 2.9.7 ·Î Å×½ºÆ® ÁßÀä. OWASP Modsecurity Core Rule Set ¼®´ÞÁ¤µµ Àü¿¡ ¼³Ä¡ÇÑ ·ê¼Â¿¡
À§ ¼³Á¤À¸·Î ·Îµå¸¦ ÇÏ°í °£´ÜÇÑ ¾÷·Îµå ÆäÀÌÁö ÀÛ¼ºÇؼ­ Å×½ºÆ®¸¦ Çغôµ¥, ¼³Á¤¿¡´Â º° ¹®Á¦ ¾øÀÌ ¾÷·Îµå´Â µÇ³×¿ä..

´Ù¸¸ Å×½ºÆ®¸¦ À§Çؼ­SecRequestBodyLimit  ¿É¼Ç°ªÀ» 13107 ·Î ÁÙÀÌ°í ÀÛÀº À̹ÌÁö ÆÄÀϵîÀ» ¾÷·Îµå ÇßÀ»¶§
±âÁ¸ ¼³Á¤À¸·Î´Â Àß ¿Ã¶ó°¬´Âµ¥ ¹ÝÇØ Á¦ÇÑÀÌ °É¸° °æ¿ì ¾Æ·¡¿Í °°Àº ·Î±×·Î Â÷´ÜµÇ±ä Çß½À´Ï´Ù. Âü°í°¡ µÉÁö ¸ð¸£°Ú½À´Ï´Ù.

[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À¸·Î ¸¸µé±â¸¸ÇÏ´Ùº¸´Ï
ÀÌ·± ÀÏÀÌ ´Ù »ý±â³×¿ä ¤»¤»¤»
          
¿Ê.. ÃàÇϵ帳´Ï´Ù. ´ÙÇàÀ̳׿ä.. °í»ýÇϼ̽À´Ï´Ù.
Àúµµ °æÇè ÇÑ ÀûÀÌ ÀÖ¾ú´Âµ¥..

1. TempÆú´õ (Upload folder) ÁöÁ¤.
2. Æú´õ ±ÇÇÑ ¼³Á¤ chmod 777 /Upload folder

ÀÌ·¸°Ô Ç®Àº ÀûÀÌ ÀÖ½À´Ï´Ù. ¿¹Àü ÀÏÀÌÁÒ.
     
dragoune 03-18
´äº¯ °¨»çÇÕ´Ï´Ù.
À§ ¹æ¹ýÀº ÀÌ¹Ì È®ÀÎÀ» Çß¾ú´Âµ¥ ÇØ°áµÇÁö ¾Ê¾Ò¾ú½À´Ï´Ù.
¾Æ¹«·¡µµ 2.9.6 ¹öÀüÀÌ Àú¶û Ä£ÇÏ°í ½ÍÁö ¾Ê¾Ò´ø °Í °°½À´Ï´Ù. ¤Ì_¤Ì


QnA
Á¦¸ñPage 6/5590
2015-12   1032157   ¹é¸Þ°¡
2014-05   4480522   Á¤ÀºÁØ1
04-18   364   JJAMTIGER
04-17   596   ºý½Ã´Ù
04-17   429   ´Ã¸¼À½
04-17   374   ±¸Â÷´Ï
04-17   362   chotws
04-17   450   2CPUÃÖÁÖÈñ
04-17   376   Á¦°¥±âõ
04-17   330   ¾î¼®
04-17   280   ¶Ñ¶Ñ±è´ë¿ø
04-17   292   ¹Ì´ã
04-17   313   ¹Î°æ¿­
04-17   530   zhyoon
04-17   377   Rich
04-16   492   PC¹è¿ì¹Ì
04-16   465   ¶Ñ¾Ó
04-16   394   Sakura24
04-16   447   dragoune
04-16   471   fLog
04-16   509   sasaz
04-16   348   ȸ¿ø