ModSecurity¸¦ ÀÌ¿ëÇÑ ¾ÆÆÄÄ¡ À¥¼º¸ º¸¾È ±¸Ãà Mod Security´Â Apache À¥ ¼¹ö¸¦ À§ÇÑ ¿ÀÇ ¼Ò½º À¥ ¹æȺ®ÀÔ´Ï´Ù.
ÁÖ¿ä±â´É
- ¿äû(request) ÇÊÅ͸µ Ŭ¶óÀ̾ðÆ®·ÎºÎÅÍ À¥¿äûÀÌ µé¾î¿Ã ¶§ À¥¼¹ö ¶Ç´Â ´Ù¸¥ ¸ðµâµéÀÌ Ã³¸®Çϱâ Àü¿¡ ModSecurity°¡ ¿äû ³»¿ëÀ» ºÐ¼®ÇÏ¿© »çÀü¿¡ ÇÊÅ͸µÇÕ´Ï´Ù.
- ¿ìȸ ¹æÁö ±â¼ú °æ·Î¿Í ÆĶó¹ÌÅ͸¦ ºÐ¼®Çϱâ Àü¿¡ Á¤±ÔȽÃÄÑ ¿ìȸ °ø°ÝÀ» Â÷´ÜÇÕ´Ï´Ù. Áï, ¡°//¡±, ¡°\/¡±, ¡°.¡±, ¡°%00¡± µî ¿ìȸ °ø°Ý¿ë ½ºÆ®¸µÀ» Á¦°ÅÇÏ°í, ÀÎÄÚµùµÈ URLÀ» µðÄÚµùÇÕ´Ï´Ù.
- HTTP ÇÁ·ÎÅäÄÝ ÀÌÇØ ¿£ÁøÀÌHTTP ÇÁ·ÎÅäÄÝÀ» ÀÌÇØÇϱ⠶§¹®¿¡ ¾ÆÁÖ Àü¹®ÀûÀÌ°í ¹Ì¼¼ÇÑ ÇÊÅ͸µÀ» ¼öÇàÇÒ ¼ö ÀÖ½À´Ï´Ù.
- POST ÆäÀ̷εå(payload) ºÐ¼® GET ¹æ½Ä »Ó¸¸ ¾Æ´Ï¶ó POST ¸Þ¼Òµå¸¦ »ç¿ëÇؼ Àü¼ÛµÇ´Â ÄÁÅÙÃ÷µµ °¡·Îä¾î ºÐ¼®ÇÒ ¼ö ÀÖ½À´Ï´Ù.
- °¨»ç ·Î±ë POST¸¦ Æ÷ÇÔÇÏ¿© ¸ðµç ¿äûÀÇ ¸ðµç »ó¼¼ÇÑ ºÎºÐµé±îÁö ÃßÈÄ ºÐ¼®À» À§Çؼ ·Î±ëµÉ ¼ö ÀÖ½À´Ï´Ù. ModSecurity¿¡¼ Â÷´Ü±â´ÉÀ» ºñÈ°¼ºÈ½ÃŲ ÈÄ, °·ÂÇÑ ·Î±ë ±â´É¸¸À¸·Î ħÀÔŽÁö ½Ã½ºÅÛ ¿ªÇÒÀ» ¼öÇàÇÒ ¼ö ÀÖµµ·Ï ÇÕ´Ï´Ù.
- HTTPS ÇÊÅ͸µ ¿£ÁøÀº À¥¼¹ö¿¡ ÀÓº£µðµåµÇ¾î Àֱ⠶§¹®¿¡ º¹È£È ÇÑ ÈÄ¿¡ ¿äû µ¥ÀÌÅÍ¿¡ Á¢±ÙÇÏ¿©HTTPS ¸¦ ÅëÇÑ °ø°Ýµµ ÇÊÅ͸µÇÒ ¼ö ÀÖ½À´Ï´Ù. ModSecurity DSO ¹× ¼Ò½º¼³Ä¡ Çϱ⠾ÆÆÄÄ¡ ¼³Ä¡ ¹æ½Ä¿¡´Â ¸ðµâ ÀûÀç¹æ½Ä¿¡ µû¶óDSO, Static ¹æ½ÄÀÌ ÀÖ½À´Ï´Ù. DSO´Â ¾ÆÆÄÄ¡¿¡ ¼³Ä¡µÈ ¸ðµâÀÌ ÇÊ¿äÇÒ ¶§¸¸ ½Ã½ºÅÛ¿¡ ÀûÀçÇÏ´Â ¹æ½ÄÀ¸·Î ½Ã½ºÅÛÀÇ ¸®¼Ò½º(¸Þ¸ð¸®, CPU)µéÀ» ÀûÀýÇÏ°Ô È¿À²ÀûÀ¸·Î »ç¿ëÇÑ´Ù°í º¼ ¼ö ÀÖÀ¸¸ç ¸ðµâÀ» Ãß°¡·Î ¼³Ä¡ÇÒ ¶§¿¡ ¾ÆÆÄÄ¡¸¦ Àç ÄÄÆÄÀÏ ÇÏÁö ¾Ê°í ¸ðµâÀ» ÀûÀçÇÒ ¼ö ÀÖ´Â ¹æ½ÄÀÔ´Ï´Ù. Static´Â ¾ÆÆÄÄ¡ °¡µ¿½Ã ¸ðµç ¸ðµâÀ» ÇÔ²² ÀûÀçÇÏ´Â ¹æ½ÄÀ¸·Î ¸ðµâÀ» Ãß°¡·Î ¼³Ä¡ÇÒ ¶§¿¡ ¾ÆÆÄÄ¡¸¦ Àç ÄÄÆÄÀÏ ÇØ¾ß ÇÏ´Â ¹æ½ÄÀÔ´Ï´Ù. Apache ¼³Ä¡À¯Çü È®ÀÎÇϱâ [root@systemen httpd-2.0.55]# httpd –l mod_so.c À§mod_so ¸ðµâÀÌ ÀûÀçµÇ¾î ÀÖÀ¸¸é DSO ¹æ½ÄÀ¸·Î ¼³Ä¡µÈ °ÍÀ̸ç mod_so ¸ðµâÀÌ ÀûÀçµÇÁö ¾ÊÀº »óÅÂÀ̸é Static·Î ¼³Ä¡µÈ °ÍÀÔ´Ï´Ù.
( 1 ) Apache_1.x ´ë ModSecurity DSO ¹æ½Ä ¼³Ä¡Çϱâ
modsecurity-apache_1.9.5.tar.gz ¹öÀüÀ» ´Ù¿î·Îµå ÇϽøé Apache_1.x, Apache_2.x ¹öÀü¿¡ ¸ðµÎ Àû¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù. ¨ç modsecurity-apache_1.9.5.tar.gz ´Ù¿î·Îµå http://www.modsecurity.org/download wgetÀº À¥¿¡¼ ÀÚµ¿ÀûÀ¸·Î ÆÄÀÏÀ» ¹Þ¾Æ¿À´Âµ¥ »ç¿ëµÇ´Â À¯Æ¿¸®Æ¼À̸ç HTTP, HTTPS, FTP ÇÁ·ÎÅäÄÝÀ» Áö¿øÇÕ´Ï´Ù. [root@nextline ~]# wget http://www.modsecurity.org/download/modsecurity-apache_1.9.5.tar.gz
¨è ¾ÐÃàÇØÁ¦ [tar ¸í·É¾î ¿É¼Ç] tar ¸í·É¾î´Â ÆÄÀÏÀ» ¹°Å³ª Ç® ¶§ »ç¿ëµÇ´Â ¸®´ª½º ¸í·É¾î ÀÔ´Ï´Ù. c : tar ÆÄÀÏÀ» »ý¼ºÇÒ ¶§(¿©·¯ °³ÀÇ ÆÄÀÏÀ» ÇϳªÀÇ ÆÄÀÏ·Î ¹À» ¶§) v : ¹À» ¶§³ª Ç®¾îÁÙ ¶§ ÆÄÀϵéÀÇ ³»¿ëÀ» ÀÚ¼¼ÇÏ°Ô º¸·Á°í ÇÒ ¶§. z : gzip°ú °ü·ÃÇÏ¿© ¾ÐÃàÀ̳ª ÇØÁ¦¸¦ ÇѲ¨¹ø¿¡ ÇÏ·Á°í ÇÒ ¶§ »ç¿ë. x : ÁÖ¾îÁø À̸§ÀÇ ÆÄÀÏ¿¡ ´ëÇÏ¿© ÃßÃâ »ç¿ë¹ý: tar [¿É¼Ç] ÆÄÀϸí [root@nextline ~]# tar zxf modsecurity-apache_1.9.5.tar.gz ¾ÐÃàÇØÁ¦µÈ modsecurity-apache_1.9.5 µð·ºÅ丮·Î À̵¿ÇÕ´Ï´Ù. [root@nextline ~]# cd modsecurity-apache_1.9.5 Apache_1.x ¹öÀü¿¡ Àû¿ëÇϱâ À§Çؼ´Â apache1 µð·ºÅ丮·Î À̵¿ÇÏ¿© ÄÄÆÄÀÏÀ» ÇÕ´Ï´Ù. [root@nextline modsecurity-apache_1.9.5]#cd apache1 [root@nextline apache1]# ls makefile.win mod_security.c ¨émod_security.c ÄÄÆÄÀÏ apxs´Â ¾ÆÆÄÄ¡ ¼¹öÀÇ È®Àå ¸ðµâÀ» ÄÄÆÄÀÏÇÏ°í ¼³Ä¡ÇÏ´Â µµ±¸ÀÔ´Ï´Ù. ¿É¼Ç ¼³¸í -i : ¶óÀ̺귯¸® µð·ºÅ丮¿¡ so ÆÄÀÏ º¹»çÇ϶ó´Â ¿É¼Ç -a : httpd.conf ÆÄÀÏ¿¡ LoadModule ¼³Á¤À» Ç϶ó´Â ¿É¼Ç -c : ÄÄÆÄÀÏ Ç϶ó´Â ¿É¼Ç [root@nextline apache1]# /usr/local/apache/bin/apxs -i -a -c mod_security.c ¨ê ¸ðµâÀûÀç È®ÀÎ ÄÄÆÄÀÏ ¿Ï·á ÈÄ/usr/local/apache/libexec µð·ºÅ丮¿¡ mod_security.so ÆÄÀÏÀÌ »ý¼ºµË´Ï´Ù. [root@nextline apache1]# ls /usr/local/apache/libexec Httpd.exe libphp4.so mod_security.so
[vi ¿¡µðÅÍ »ç¿ë¹ý] »ç¿ëÇü½Ä: vi [¿É¼Ç] [»ý¼ºÇÒ ÆÄÀϸí/ÆíÁýÇÒ ÆÄÀϸí] vi ¿¡µðÅÍ´Â ÀԷ¸ðµå, ¸í·É¸ðµå, ½ÇÇà¸ðµå·Î ±¸ºÐµË´Ï´Ù. ÀԷ¸ðµå: vi ÆíÁýȸ鿡¼ ¹®ÀÚ¸¦ ÀÔ·ÂÇÒ ¼ö ÀÖ´Â ¸ðµå·Î¼ ÀԷ¸ðµå·Î ÁøÀÔÇϱâ À§Çؼ´Â i, a, o, I, A, O, RµîÀÌ ÀÖ½À´Ï´Ù. Áï Ãʱâ vi ÆíÁý±â ¸ðµå´Â ¸í·É¾î ¸ðµå·Î ÁøÀÔÀ» Çϱ⶧¹®¿¡ ¹®ÀÚ¸¦ ÀÔ·ÂÇϱâ Àü¿¡ ¾ÕÀÇ ´ÜÃàÅ°Áß Çϳª¸¦ ¸ÕÀú ÀÔ·ÂÇØ¾ß ¿øÇÏ´Â ¹®ÀÚ¸¦ ÀÔ·ÂÇÒ ¼ö ÀÖ½À´Ï´Ù. ¸í·É¸ðµå: Ä¿¼À̵¿/¹®ÀÚ»èÁ¦/¹®ÀÚ(¿)±³Ã¼/¹®ÀÚ¿°Ë»ö µîÀ» ÇÒ¼ö ÀÖ´Â ¸ðµå·Î¼ ÀԷ¸ðµå¿¡¼ ÆíÁýÀÌ ¿Ï·áµÇ¸é EscÅ°¸¦ ´·¯ ¸í·É¸ðµå·Î ÁøÀÔÇÏ¸é µË´Ï´Ù. ½ÇÇà¸ðµå: Ưº°ÇÑ ¸í·É¾î¸¦ ½ÇÇàÇÏ´Â ¸ðµå·Î¼ ¸í·É¾î¸ðµå¿¡¼ ":"(ÄÝ·Ð)¸¦ ´©¸£¸é vi ȸé ÇÏ´Ü ÁÂÃø¿¡ vi Ư¼ö¸í·É¾î¸¦ ÀÔ·ÂÇÒ ¼ö ÀÖ½À´Ï´Ù. [½ÇÇà¸ðµåÀÇ ÀϹÝÀûÀ¸·Î ¾²À̴ Ư¼ö ¸í·É¾î] q : ¼öÁ¤ ÀÛ¾÷ÀÌ ÀÌ·ç¾îÁöÁö ¾ÊÀº »óÅ¿¡¼ vi ÆíÁý±â¿¡¼ ºüÁ®³ª¿É´Ï´Ù. q! : ¼öÁ¤ ÀÛ¾÷ÀÌ ÀÌ·ç¾îÁø ºÎºÐÀ» Àû¿ë½ÃÅ°Áö ¾Ê°í vi ÆíÁý±â¸¦ °Á¦·Î ºüÁ®³ª¿É´Ï´Ù. w : ¼öÁ¤µÈ ÀÛ¾÷À» ÀúÀåÇÕ´Ï´Ù. wq : ¼öÁ¤µÈ ÀÛ¾÷À» ÀúÀåÇÏ°í vi ÆíÁý±â¿¡¼ ºüÁ®³ª¿É´Ï´Ù. Ãʱ⠸í·É¾î¸ðµå-> ÀԷ¸ðµåÁøÀÔ -> ÆíÁý -> ¸í·É¾î¸ðµå -> ½ÇÇà¸ðµå -> Á¾·á ÄÄÆÄÀÏ ÀÛ¾÷À¸·Îhttpd.confÆÄÀÏ¿¡ ¸ðµâÀÌ µî·ÏµÇ¾ú´ÂÁö È®ÀÎÇÕ´Ï´Ù. [root@nextline mod_throttle-3.1.2]# vi /usr/local/apache/conf/httpd.conf LoadModule security_module libexec/mod_security.so
¨ëphpinfoÀ» ÀÌ¿ëÇÑ ¸ðµâÀûÀç È®ÀÎ php Á¤º¸¸¦ È®ÀÎÇϱâ À§ÇÏ¿© vi ¿¡µðÅ͸¦ ÀÌ¿ëÇÏ¿© php_test.php ÆÄÀÏÀ» »ý¼ºÇÕ´Ï´Ù. [root@nextline ~]# vi /usr/local/apache/htdocs/php_test.php
<? phpinfo(); ?> ¹®À» Ãß°¡ÇÕ´Ï´Ù.
¨ì http://ÇØ´çip/php_test.php È®ÀÎȸé
( 2 ) Apache_2.x ´ë ModSecurity DSO ¹æ½Ä ¼³Ä¡Çϱâ
Apache_1.x ´ë ¹öÀü°ú µ¿ÀÏÇÑ ¼³Ä¡ ¹æ½ÄÀÌ Àû¿ëµÇ¸ç modsecurity-apache_1.9.5 ÇÏÀ§µð·ºÅ丮¿¡¼ apache2 µð·ºÅ丮¿¡ ÀÖ´Â mod_security.c ÆÄÀÏ·Î ÄÄÆÄÀÏ ÇÑ´Ù´Â Â÷ÀÌÁ¡ÀÌ ÀÖ½À´Ï´Ù.
¨ç ¾ÐÃàÇØÁ¦µÈ modsecurity-apache_1.9.5 µð·ºÅ丮·Î À̵¿ÇÕ´Ï´Ù. [root@nextline ~]# cd modsecurity-apache_1.9.5 ¨è Apache_2.x ¹öÀü¿¡ Àû¿ëÇϱâ À§Çؼ´Â apache2 µð·ºÅ丮·Î À̵¿ÇÏ¿© ÄÄÆÄÀÏÀ» ÇÕ´Ï´Ù. [root@nextline modsecurity-apache_1.9.5]#cd apache2 [root@nextline apache1]# ls Makefile.in config.m4 makefile.win mod_security.c ¨émod_security.c ÄÄÆÄÀÏ [root@nextline apache2]# /usr/local/apache/bin/apxs -i -a -c mod_security.c
¨ê ¸ðµâÀûÀç È®ÀÎ [root@nextline apache2]# ls /usr/local/apache/modules/ httpd.exp libphp4.so mod_security.so
¨ë ÄÄÆÄÀÏ ÀÛ¾÷À¸·Îhttpd.confÆÄÀÏ¿¡ ¸ðµâÀÌ µî·ÏµÇ¾ú´ÂÁö È®ÀÎÇÕ´Ï´Ù. [root@nextline mod_throttle-3.1.2]# vi /usr/local/apache/conf/httpd.conf LoadModule security_module libexec/mod_security.so
¨ìphpinfoÀ» ÅëÇÑ ¸ðµâÀûÀç È®ÀÎ http://ÇØ´çip/php_test.php È®ÀÎȸé
( 3 ) ModSecurity ·ê ¼³Á¤
¨çhttpd.conf ¼³Á¤ÆÄÀÏ ÆíÁý
¨èmodsecurity ´Â Rule º¯°æÀÌ Áö¼ÓÀûÀ¸·Î ÇÊ¿äÇϹǷΠº°µµÀÇ ÆÄÀÏÀ» ÀÌ¿ëÇϱâ À§ÇØ Include Áö½ÃÀÚ¸¦ ÀÌ¿ëÇØ conf/modsecurity.conf ¿¡ ·ê ¼³Á¤ÆÄÀÏÀ» º°µµ·Î »ý¼ºÇÕ´Ï´Ù.
¨é modsecurity ÀÛµ¿Å×½ºÆ® modsecurity.conf ÆÄÀÏ¿¡ ¾Æ·¡ ¶óÀÎÀ» Ãß°¡ ÈÄ Rule ¼³Á¤ÀÌ Àû¿ëµÇ´ÂÁö È®ÀÎÇÕ´Ï´Ù. Rule Àû¿ë Àü HEAD °ª ¹× Server ¸í ³ëÃâ ȸéÀÔ´Ï´Ù.
¨ëRule ÆÄÀÏ »ý¼º [root@nextline ~]# vi /usr/local/apache/conf/modsecurity.conf
¨ìRule ¼³Á¤ ¾Æ·¡ÀÇ ¶óÀÎÀ» modsecurity.conf ¿¡ Ãß°¡ÇÕ´Ï´Ù. #Server ¸í º¯°æ ¼³Á¤ SecServerSignature ¡°Microsoft-IIS/5.0¡± #°ø°Ý°¡´É¼ºÀÌ ³ôÀº GET, HEAD ¿äûÂ÷´Ü ¼³Á¤ SecFilterSelective REQUEST_METHOD "^(GET|HEAD)$" chain SecFilterSelective HTTP_Content-Length "!^$" SecFilterSelective SERVER_PROTOCOL "!^HTTP/(0\.9|1\.0|1\.1)$"
¨ì ¼³Á¤ Àû¿ëÀ» À§ÇØ ¾ÆÆÄÄ¡¸¦ Àç°¡µ¿ ÇÕ´Ï´Ù. [root@nextline conf]# apachectl restart
curlÀ» ÅëÇØ head°ªÀ» ¿äûÇÏ¸é ¾Æ·¡¿Í °°ÀÌ Rule ¼³Á¤´ë·Î Àû¿ëÇÑ Server ¸íÀ¸·Î Ç¥½ÃµÇ¸ç HEAD°ªÀÌ ³ëÃâµÇÁö ¾ÊÀ½À» È®ÀÎÇÒ ¼ö ÀÖ½À´Ï´Ù.
À§¿Í°°ÀÌRule ¼³Á¤ÀÌ Àû¿ëµÇ¸é ModSecurity°¡ Á¤»óÀûÀ¸·Î ¼³Ä¡µÈ °ÍÀÔ´Ï´Ù. ¨ímodsecurity.conf ¿¡ ·Î±× ±â·Ï ¼³Á¤ ½Ã ȸé°ú °°ÀÌ modsecurity ·Î±×°¡ ±â·ÏµË´Ï´Ù.
¨îRule Àû¿ë¼³¸í SecFilterEngine On mod_securityÀÇ ±â´ÉÀ» »ç¿ëÇÒ °ÍÀÎÁö ¿©ºÎ¸¦ Á¤ÀÇÇϸç OnÀº ¸ðµç ¿äû¿¡ ´ëÇØ ºÐ¼®ÇÏ°í Off´Â ºÐ¼®ÇÏÁö ¾Ê´Â ¼³Á¤ÀÔ´Ï´Ù. SecFilterEngine On POST ¸Þ¼Òµå·Î Àü´ÞµÇ´Â playoad¸¦ üũ ÇÒ °ÍÀÎÁö ¿©ºÎ¸¦ ÁöÁ¤ÇÕ´Ï´Ù. SecFilterScanPost On GET»Ó¸¸ ¾Æ´Ï¶ó POST·Î ³Ñ¾î¿À´Â ¸Þ½ÃÁö±îÁö ÇÊÅ͸µ ÇÒ°ÍÀÎÁö¸¦ °áÁ¤ÇÏ´Â ¿É¼ÇÀÔ´Ï´Ù. SecFilterCheckURLEncoding On URL·Î Àü´ÞµÇ±â Àü¿¡ Ư¼ö¹®ÀÚ´Â encodingµÉ ÇÊ¿ä°¡ Àִµ¥, encodingµÈ ¹®ÀÚ°¡ À¯È¿ÇÑÁö¸¦ üũÇÒ Áö ¿©ºÎ¸¦ ÁöÁ¤ÇÕ´Ï´Ù. SecFilterScanOutput On SecFilterOutputMimeTypes "(null) text/html text/plain" ¾ÆÆÄÄ¡2¿¡¼ ModSecurity´Â Ãâ·Â ÇÊÅ͸¦ Áö¿øÇÕ´Ï´Ù. µðÆúÆ®·Î ÀÌ ±â´ÉÀº ºñÈ°¼ºÈµÇ¾î ÀÖÀ¸¹Ç·Î À§¿Í °°ÀÌ È°¼ºÈ½ÃÄÑ ÁÖ¾î¾ß ÇÕ´Ï´Ù. ±âÁ¸ÀÇ ÀÔ·Â ÇÊÅÍ´Â À¥¿äûÀÌ ¾ÆÆÄÄ¡¿¡ ÀÇÇØ Ã³¸®µÇ±â ÀÌÀü¿¡ ½ÇÇàµÇÁö¸¸ Ãâ·Â ÇÊÅÍ´Â ¾ÆÆÄÄ¡¿¡ ÀÇÇØ À¥¿äûÀÌ Ã³¸® ¿Ï·áµÈ ÀÌÈÄ¿¡ ½ÇÇàµË´Ï´Ù. À§¿Í °°ÀÌ Ãâ·Â ÇÊÅ͸¦ ¼³Á¤ÇÑ ÈÄ¿¡ ´ÙÀ½°ú °°ÀÌ ¡°OUTPUT" ÆĶó¸ÞÅ͸¦ »ç¿ëÇÏ¿© ƯÁ¤ Å°¿öµå¸¦ °¡Áø Ãâ·Â¿¡ ´ëÇØ ÇÊÅ͸µÀ» ÇÒ ¼ö ÀÖ½À´Ï´Ù. SecFilterSelective OUTPUT "Fatal error:" deny,status:500 ErrorDocument 500 /php-fatal-error.html ÀÌ¿Í °°ÀÌ °ø°ÝÀÚ°¡ °ø°Ý Á¤º¸·Î ÀÌ¿ëµÉ ¼ö ÀÖ´Â Á¤º¸³ª ƯÁ¤ ¸í·É¾î ½ÇÇà °á°ú µîCriticalÇÑ °á°ú°¡ ½ÇÇàµÇ¾î °ø°ÝÀÚ¿¡°Ô °á°ú°¡ Àü´ÞµÇ´Â °ÍÀ» Â÷´ÜÇÒ ¼ö ÀÖ½À´Ï´Ù. Ãâ·Â ÇÊÅÍ´Â ÀÏ¹Ý Æò¹®text¿Í HTML Ãâ·Â¿¡ ´ëÇؼ¸¸ À¯¿ëÇϸç, À̹ÌÁö¿Í °°Àº ¹ÙÀ̳ʸ® ÄÁÅÙÃ÷¿¡ ´ëÇØ Á¤±Ô½ÄÀ» Àû¿ëÇÑ´Ù¸é ¼¹ö°¡ ´À·ÁÁú ¼ö ÀÖ½À´Ï´Ù. µðÆúÆ®·Î ModSecurity´Â ÄÁÅÙÃ÷ ŸÀÔÀ» °¡Áö°í ÀÖÁö ¾Ê°Å³ª ¡°text/plan" ¶Ç´Â ¡±text/html"À» ÄÁÅÙÃ÷ ŸÀÔÀ¸·Î °¡Áø Ãâ·Â¿¡ ´ëÇؼ¸¸ ½ºÄµÇÏ¸ç ½ºÄµÇÏ°íÀÚ ÇÏ´Â ÄÁÅÙÃ÷ ŸÀÔÀ» ¹Ù²Ù°íÀÚ ÇÒ °æ¿ì¿¡´Â ¡°SecFilterOutputMimeTypes¡± Áö½ÃÀÚ¸¦ ÀÌ¿ëÇÕ´Ï´Ù. SecFilterOutputMimeTypes "(null) text/html text/plain" À§ÀÇ ¼³Á¤ÀºModSecurity°¡ Æò¹® text ÆÄÀÏ, HTML ÆÄÀÏ ±×¸®°í MIME ŸÀÔÀÌ Á¤ÀǵÇÁö ¾ÊÀº ÆÄÀϵ鿡 ´ëÇØ Ãâ·Â ÇÊÅ͸¦ Àû¿ëÇÏ°Ô ÇÕ´Ï´Ù. Ãâ·Â ÇÊÅÍ´Â À¯¿ëÇÑ ±â´ÉÀ̶ó°í ÇÒ ¼ö ÀÖÁö¸¸ ¿Ïº®ÇÏÁö´Â ¸øÇÕ´Ï´Ù. °ø°ÝÀÚ°¡ ¸ð´ÏÅ͸µÇÏ°í ÀÖÁö ¾Ê´Â ÄÁÅÙÃ÷ ŸÀÔÀ¸·Î ¹Ù²Û´ÙµçÁö Ãâ·ÂÀ» ÀÎÄÚµùÇÏ´Â ¹æ¹ýÀ¸·Î ÇÊÅ͸¦ ¿ìȸÇÒ °¡´É¼ºÀÌ Á¸ÀçÇÕ´Ï´Ù. SecServerSignature "Microsoft-IIS/5.0" ¼¹ö³ª ¹öÀü µîÀÇ Á¤º¸¸¦ ÀÓÀÇ·Î º¯°æÇÒ ¼ö ÀÖ´Â ·êÀÔ´Ï´Ù. SecFilterCheckURLEncoding On URL·Î Àü´ÞµÇ±â Àü¿¡ Ư¼ö¹®ÀÚ´Â encodingµÉ ÇÊ¿ä°¡ Àִµ¥, encodingµÈ ¹®ÀÚ°¡ À¯È¿ÇÑÁö¸¦ üũÇÒÁö ¿©ºÎ¸¦ °áÁ¤ÇÕ´Ï´Ù. SecUploadDir /tmp ¼¹ö¸¦ ÅëÇØ ¾÷·ÎµåµÇ´Â ÆÄÀÏ¿¡ ´ëÇØ Àӽ÷ΠÀúÀåÇÒ °æ·Î¸¦ ÁöÁ¤Çϸç ÃÖ±Ù¿¡´Â À¥½© µîÀ» ¾÷·ÎµåÇÏ´Â °æ¿ì°¡ ¸¹ÀÌ ÀÖÀ¸¹Ç·Î ¾î¶² ÆÄÀÏÀÌ ¼¹ö·Î ¾÷·ÎµåµÇ´ÂÁö ¸ð´ÏÅ͸µÇÏ°íÀÚ ÇÒ ¶§ À¯¿ëÇÕ´Ï´Ù. SecUploadKeepFiles Off ¼¹ö¸¦ ÅëÇØ ¾÷·ÎµåµÇ´Â ÆÄÀÏÀ» º°µµ·Î º¹»çÇØ ÀúÀåÇÒ °ÍÀÎÁö ¿©ºÎ¸¦ ÁöÁ¤ÇÑ´Ù. SecFilterForceByteRange 1 255 Stack Overflow °ø°ÝÀ» Â÷´ÜÇϱâ À§ÇØ RequestÀÇ byte¸¦ Á¦ÇÑÇÒ ¼ö ÀÖ´Ù. ±âº»ÀûÀ¸·Î´Â Á¦ÇÑÀÌ ¾øÁö¸¸ À§¿Í °°ÀÌ ¼³Á¤½Ã 1byteºÎÅÍ 255byte¸¸ Çã¿ëÇÕ´Ï´Ù. SecFilterDefaultAction "log,deny,status:403" ÇÊÅÍ¿¡ ¸ÅĪµÇ´Â ¿äûÀÌ ÀÖÀ»¶§ ¾î¶»°Ô ´ëÀÀÇÒ °ÍÀÎÁö¿¡ ´ëÇÑ ±âº» ¼³Á¤À¸·Î À§¿Í °°ÀÌ ¼³Á¤Çϸé ÇÊÅÍ¿¡ ¸ÅĪ µÇ¾úÀ» °æ¿ì ¿äûÀ» Â÷´Ü ÈÄ404 ¿¡·¯¸¦ ³Ñ°ÜÁÖ¼Ò ·Î±×¸¦ ³²±â°Ô µË´Ï´Ù. SecFilterDefaultActio action pass : ÇÊÅ͸µÇÏÁö ¾Ê°í Åë°úÇϵµ·Ï ÇÑ´Ù. deny : ÇÊÅ͸µ¿¡ ¸ÅĪµÉ °æ¿ì ¿äûÀ» °ÅºÎÇÑ´Ù. Ưº°ÇÑ status¸¦ ÁöÁ¤ÇÏÁö ¾ÊÀ¸¸é ±âº»ÀûÀ¸·Î 500 error·Î ÀÀ´äÇÑ´Ù. status : ¿äûÀÌ °ÅºÎµÇ¾úÀ» °æ¿ì Á¦°øµÇ´Â HTTP »óÅ Äڵ带 ÁöÁ¤ÇÑ´Ù. redirect : ÇÊÅ͸µ¿¡ ¸ÅĪµÉ °æ¿ì ƯÁ¤ URL·Î redirectÇÒ ¼ö ÀÖ´Ù exec : ÇÊÅ͸µ¿¡ ¸ÅĪµÉ °æ¿ì ÁöÁ¤ÇÑ ¸í·É¾î ¶Ç´Â cgi¸¦ ½ÇÇàÇϵµ·Ï ÇÑ´Ù. log : ÇÊÅ͸µ¿¡ ¸ÅĪµÉ °æ¿ì apacheÀÇ ¿¡·¯ ·Î±×¿¡ ³²±âµµ·Ï ÇÑ´Ù. nolog : ¿¡·¯ ·Î±×¿¡ ³²±âÁö ¾Êµµ·Ï ÇÑ´Ù. pause : ¿äû¿¡ ÀÀ´äÇϱâ Àü¿¡ ÁöÁ¤µÈ ¹Ð¸®Ãʵ¿¾È ¸ØÃßµµ·Ï ÇÑ´Ù. SecFilter "\.\./" ÀϹÝÀûÀÎ À¥ ¿äû¿¡¼ ¡°../¡±¿Í °°Àº °æ·Î´Â ÇÊ¿äÄ¡ ¾ÊÀ¸¸ç ÀÌ´Â À¥À» ÅëÇØ /etc/passwd¿Í °°ÀÌ ºñÁ¤»óÀûÀÎ À¥ ¿äûÀ» À§ÇÑ °æ¿ì°¡ ¸¹À¸¹Ç·Î Â÷´ÜÇÏ´Â °ÍÀÌ ¹Ù¶÷Á÷ÇÕ´Ï´Ù. SecFilterDebugLog logs/modsec_debug.log SecFilterDebugLevel 1 ¿äûÀÌ µé¾î¿Ã¶§ ·Î±×¸¦ ³²±æ°ÍÀÎÁö ¼³Á¤ÇÕ´Ï´Ù. 0 ³²±âÁö ¾Ê´Â °ÍÀÌ°í, 1Àº ½É°¢ÇÑ À̺¥Æ®°¡ ¹ß»ý ÇÏ¿´À»¶§, 2, 3À¸·Î °¥¼ö·Ï ÀÚ¼¼ÇÑ Á¤º¸¸¦ ³²±â°Ô µË´Ï´Ù. SecAuditEngine RelevantOnly SecAuditLog logs/modsec_audit.log ÇÊÅ͸µ¿¡ ¸ÅĪµÇ´Â ¿äû¿¡ ´ëÇؼlogs/modsec_audit.log ÆÄÀÏ¿¡ »ó¼¼ÇÑ Á¤º¸¸¦ Á¦°øÇϵµ·Ï Çϸç ÇÊÅÍ¿¡ °É¸®´Â Á¤º¸¸¸ ³²±â·Á¸é On ´ë½Å RelevantOnly¸¦ ÁöÁ¤ÇÕ´Ï´Ù. SecFilterSelective REQUEST_METHOD "^(GET|HEAD)$" chain SecFilterSelective HTTP_Content-Length "!^$" SecFilterSelective SERVER_PROTOCOL "!^HTTP/(0\.9|1\.0|1\.1)$" Body¸¦ °¡Áø GET ¶Ç´Â HEAD ¿äû Â÷´Ü(°ø°Ý °¡´É¼º ³ôÀ½) SecFilterSelective REQUEST_METHOD "^POST$" chain SecFilterSelective HTTP_Content-Length "^$" SecFilterSelective HTTP_Transfer-Encoding "!^$" Content-Length°¡ ¾ø´Â POST ¿äûÀ» Â÷´ÜÇÕ´Ï´Ù. SecFilterSelective HTTP_Host|HTTP_User-Agent|HTTP_Accept "^$" SecFilterSelective HTTP_User-Agent "(libwhisker|paros|wget|libwww|perl|curl|java)" À¥ ºê¶ó¿ìÀú°¡ ¾Æ´Ñ ¾îÇø®ÄÉÀ̼ÇÀ» ÀÌ¿ëÇÑ Á¢¼ÓÀ̳ª php µî¿¡¼ socket Åë½ÅµîÀ» »ç¿ëÇÏ´Â °æ¿ì¶ó¸é ÁÖ¼®Ã³¸® ÇØ¾ß Á¢¼ÓÀÌ °¡´ÉÇÕ´Ï´Ù. SecFilterSignatureAction "log,deny,msg:'SQL Injection attack'" SecFilterSelective ARGS "delete[[:space:]]+from" SecFilterSelective ARGS "drop[[:space:]]+database" SecFilterSelective ARGS "drop[[:space:]]+table" SecFilterSelective ARGS "drop[[:space:]]+column" SecFilterSelective ARGS "drop[[:space:]]+procedure" SecFilterSelective ARGS "create[[:space:]]+table" SecFilterSelective ARGS "update.+set.+=" SecFilterSelective ARGS "insert[[:space:]]+into.+values" SecFilterSelective ARGS "select.+from" SecFilterSelective ARGS "bulk[[:space:]]+insert" SecFilterSelective ARGS "union.+select" SecFilterSelective ARGS "or.+1[[:space:]]*=[[:space:]]1" SecFilterSelective ARGS "alter[[:space:]]+table" SecFilterSelective ARGS "or 1=1--'" SecFilterSelective ARGS "'.+--" SecFilterSelective ARGS "into[[:space:]]+outfile" SecFilterSelective ARGS "load[[:space:]]+data SecFilterSelective ARGS "/\*.+\*/" SQL Injection °ø°ÝÀ» Â÷´ÜÇÏ´Â ¼³Á¤ÀÔ´Ï´Ù. ÃÖ±Ù Áß±¹¹ß °ø°Ý µî ¸¹Àº °ø°ÝÀÌSQL Injection Ãë¾àÁ¡À» ÀÌ¿ëÇÑ °ø°ÝÀ̹ǷΠ´ÙÀ½°ú °°ÀÌ DB Query¸¦ ÅëÇØ DB¿¡ ´ëÇÑ »èÁ¦, Ãß°¡, ¿¶÷½Ãµµ µîÀ» Â÷´ÜÇÏ´Â °ÍÀÌ ¹Ù¶÷Á÷ÇÕ´Ï´Ù. phpmyadmin À» »ç¿ëÇÒ °æ¿ì ÀüºÎ ÁÖ¼®Ã³¸® ÇؾßÇϸç ÀÌÀ¯´Â phpmyadminÀÇ °æ¿ì ÆäÀÌÁö argument ·Î sql¹®À» Àü¼ÛÇϱ⠶§¹®¿¡ À̺κÐÀ» »ì·ÁµÎ¸é phpmyadminÀº »ç¿ëÀÌ ºÒ°¡´ÉÇØ Áý´Ï´Ù. SecFilterSignatureAction "log,deny,msg:'XSS attack'" SecFilterSelective ARGS "<script" SecFilterSelective ARGS "javascript:" SecFilterSelective ARGS "vbscript:" SecFilterSelective ARGS "document\.cookie" SecFilterSelective ARGS "document\.location" SecFilterSelective ARGS "document\.write" XSS´Â À¥ ÆäÀÌÁö¿¡ JavaScript¿Í °°Àº ¾Ç¼º ½ºÅ©¸³Æ®¸¦ »ðÀÔÇÏ¿© ´Ù¸¥ À¥ Á¢¼ÓÀÚ°¡ À̸¦ ½ÇÇà½ÃÅ°°ÔÇÏ´Â °ø°ÝÀÔ´Ï´Ù. ÀÌ °ø°Ý¿¡ ´ëÇÑ ¹æ¾î´Â ÆĶó¸ÞÅÍ ÇÊÅ͸µÀε¥ ´ÙÀ½°ú °°ÀÌ ¼³Á¤ÇÒ ¼ö ÀÖ½À´Ï´Ù. À§ÀÇ ¿¹´Â ÀÚ¹Ù½ºÅ©¸³Æ®, ºñÁÖ¾óº£ÀÌÁ÷ ½ºÅ©¸³Æ® µî ½ºÅ©¸³Æ® Äڵ带 Â÷´ÜÇÏ°í, ½ºÅ©¸³Æ®¿¡ ÀÇÇØ ÄíÅ° Á¤º¸°¡ ³ëÃâµÇ´Â °ÍÀ» ¹æÁöÇÏ°í ÀÖ½À´Ï´Ù. SecFilterSignatureAction "log,deny,msg:'Command execution attack'" SecFilterSelective ARGS_VALUES ";[[:space:]]*(ls|pwd|wget)" ÆĶó¸ÞÅÍ¿¡ ¡°ls", "pwd", "wget" µîÀÇ Å°¿öµå°¡ ÀÖÀ» °æ¿ì Â÷´ÜÇÕ´Ï´Ù. SecFilterSignatureAction "log,deny,msg:'PHP Injection Attacks'" SecFilterSelective ARGS_VALUES "^http:/" PHP Injection °ø°ÝÀ» Â÷´ÜÇÏ´Â ¼³Á¤À¸·Î ÆĶó¸ÞÅÍ¿¡ URLÀÌ µé¾î ÀÖ´Â ¿äûÀ» Â÷´ÜÇÕ´Ï´Ù. SecFilterSelective ARGS_NAMES "(^globals\[|^globals$)" Àü¿ªº¯¼öGLOBALS¸¦ ÀÌ¿ëÇÑ °ø°ÝÀ» ¸·±â À§Çؼ´Â ´ÙÀ½°ú °°ÀÌ ¼³Á¤ÇÕ´Ï´Ù. ¨ïModSecurity Rule ¼³Á¤ ¿¹ ##### Configuration ##### SecFilterEngine On SecFilterScanPost On SecFilterDefaultAction "deny,log,status:404" SecFilterScanOutput Off SecFilterOutputMimeTypes "(null) text/html text/plain" SecServerSignature "Microsoft-IIS/5.0" ##### Validation ##### SecFilterCheckURLEncoding On SecUploadDir /tmp SecUploadKeepFiles Off SecFilterCheckUnicodeEncoding Off SecFilterForceByteRange 1 255 SecFilterDefaultAction "log,deny,status:403" ##### Logging ##### SecFilterDebugLog logs/modsec_debug.log SecFilterDebugLevel 1 SecAuditEngine RelevantOnly SecAuditLog logs/modsec_audit.log ##### Hardening ##### # Body¢¬¦ ¡Æ¢®Á©ª GET ¢ÒÇ¢¥Â HEAD ¢¯äû ¡À¢¥Ü(¡Æ©ª¡ÆÝ ¡Æ¢®¢¥É¨ù¨¬ ©øôÀ¨ö) SecFilterSelective REQUEST_METHOD "^(GET|HEAD)$" chain SecFilterSelective HTTP_Content-Length "!^$" SecFilterSelective SERVER_PROTOCOL "!^HTTP/(0\.9|1\.0|1\.1)$" # Content-Length¡Æ¢® ¨ú©ª¢¥Â POST ¢¯äû ¡À¢¥Ü SecFilterSelective REQUEST_METHOD "^POST$" chain SecFilterSelective HTTP_Content-Length "^$" SecFilterSelective HTTP_Transfer-Encoding "!^$" ##### General ##### SecFilterSelective HTTP_Host|HTTP_User-Agent|HTTP_Accept "^$" SecFilterSelective HTTP_User-Agent "(libwhisker|paros|wget|libwww|perl|curl|java)" ##### SQL Injection Attacks ##### SecFilterSignatureAction "log,deny,msg:'SQL Injection attack'" SecFilterSelective ARGS "delete[[:space:]]+from" SecFilterSelective ARGS "drop[[:space:]]+database" SecFilterSelective ARGS "drop[[:space:]]+table" SecFilterSelective ARGS "drop[[:space:]]+column" SecFilterSelective ARGS "drop[[:space:]]+procedure" SecFilterSelective ARGS "create[[:space:]]+table" SecFilterSelective ARGS "update.+set.+=" SecFilterSelective ARGS "insert[[:space:]]+into.+values" SecFilterSelective ARGS "select.+from" SecFilterSelective ARGS "bulk[[:space:]]+insert" SecFilterSelective ARGS "union.+select" SecFilterSelective ARGS "or.+1[[:space:]]*=[[:space:]]1" SecFilterSelective ARGS "alter[[:space:]]+table" SecFilterSelective ARGS "or 1=1--'" SecFilterSelective ARGS "'.+--" SecFilterSelective ARGS "into[[:space:]]+outfile" SecFilterSelective ARGS "load[[:space:]]+data SecFilterSelective ARGS "/\*.+\*/" ##### XSS Attacks ##### SecFilterSignatureAction "log,deny,msg:'XSS attack'" SecFilterSelective ARGS "<script" SecFilterSelective ARGS "javascript:" SecFilterSelective ARGS "vbscript:" SecFilterSelective ARGS "document\.cookie" SecFilterSelective ARGS "document\.location" SecFilterSelective ARGS "document\.write" ##### Command Execution ##### SecFilterSignatureAction "log,deny,msg:'Command execution attack'" SecFilterSelective ARGS_VALUES ";[[:space:]]*(ls|id|pwd|wget)" ##### PHP Attacks ##### SecFilterSignatureAction "log,deny,msg:'PHP Injection Attacks'" SecFilterSelective ARGS_VALUES "^http:/" SecFilterSelective ARGS_NAMES "(^globals\[|^globals$)"
|
|