ȸ¿ø°¡ÀԡžÆÀ̵ð/ºñ¹øã±â
ȨÀ¸·Î


±×´©º¸µå¿¡¼­ »ç¿ëµÈ XSS (Cross Site Script) ¸·±â
10³â Àü

function conv_content($content)

{




        // Å×À̺í ű×ÀÇ °¹¼ö¸¦ ¼¼¾î Å×À̺íÀÌ ±úÁöÁö ¾Êµµ·Ï ÇÑ´Ù.

        $table_begin_count = substr_count(strtolower($content), "<table");

        $table_end_count = substr_count(strtolower($content), "</table");

        for ($i=$table_end_count; $i<$table_begin_count; $i++)

        {

            $content .= "</table>";

        }




        $content = preg_replace_callback("/<([^>]+)>/s", 'bad130128', $content);




        $content = preg_replace($source, $target, $content);




        // XSS (Cross Site Script) ¸·±â

        // ¿Ïº®ÇÑ XSS ¹æÁö´Â ¾ø´Ù.

        

        // ÀÌ·± °æ¿ì¸¦ ¹æÁöÇÔ <IMG STYLE="__XSS__expression(alert('XSS'))">

        //$content = preg_replace("#\/\*.*\*\/#iU", "", $content);

        // À§ÀÇ Á¤±Ô½ÄÀÌ ¾Æ·¡¿Í °°Àº ³»¿ëÀ» Åë°ú½ÃÅ°¹Ç·Î not greedy(ºñŽ¿å¼ö·®ÀÚ?) ¿É¼ÇÀ» Á¦°ÅÇÔ. ignore case ¿É¼Çµµ ÇÊ¿ä ¾øÀ¸¹Ç·Î Á¦°Å

        // <IMG STYLE="__XSS__ex/pression(alert('XSS'))"></IMG>

        $content = preg_replace("#\/\*.*\*\/#", "", $content);




        // object, embed ű׿¡¼­ javascript ÄÚµå ¸·±â

        $content = preg_replace_callback("#<(object|embed)([^>]+)>#i", "bad120422", $content);




        $content = preg_replace("/(on)([a-z]+)([^a-z]*)(\=)/i", "on$2$3$4", $content);

        $content = preg_replace("/(dy)(nsrc)/i", "dy$2", $content);

        $content = preg_replace("/(lo)(wsrc)/i", "lo$2", $content);

        //$content = preg_replace("/(sc)(ript)/i", "sc$2", $content);

        $content = preg_replace_callback("#<([^>]+)#", create_function('$m', 'return "<".str_replace("<", "<", $m[1]);'), $content);

        //$content = preg_replace("/\<(\w|\s|\?)*(xml)/i", "", $content);

        $content = preg_replace("/\<(\w|\s|\?)*(xml)/i", "_$1$2_", $content);




        // Ç÷¡½ÃÀÇ ¾×¼Ç½ºÅ©¸³Æ®¿Í ÀÚ¹Ù½ºÅ©¸³Æ®ÀÇ ¿¬µ¿À» Â÷´ÜÇÏ¿© ¾ÇÀÇÀûÀÎ »çÀÌÆ®·ÎÀÇ À̵¿À» ¸·´Â´Ù.

        // value="always" ¸¦ value="never" ·Î, allowScriptaccess="always" ¸¦ allowScriptaccess="never" ·Î º¯È¯Çϴµ¥ ¸ñÀûÀÌ ÀÖ´Ù.

        //$content = preg_replace("/((?<=\<param|\<embed)[^>]+)(\s*=\s*[\'\"]?)always([\'\"]?)([^>]+(?=\>))/i", "$1$2never$3$4", $content);

        // allowscript ¼Ó¼ºÀÇ param ű׸¦ »èÁ¦ÇÑ´Ù.

        $content = preg_replace("#(<param.*?allowscript[^>]+>)(<\/param>)?#i", "", $content);

        // embed ű×ÀÇ allowscript ¼Ó¼ºÀ» »èÁ¦ÇÑ´Ù.

        $content = preg_replace("#(<embed.*?)(allowscriptaccess[^\s\>]+)#i", "$1", $content);

        // object ű׿¡ allowscript ÀÇ °ªÀ» never ·Î ÇÏ¿© ű׸¦ Ãß°¡ÇÑ´Ù.

        $content = preg_replace("#(<object[^>]+>)#i", "$1<param name=\"allowscriptaccess\" value=\"never\">", $content);

        // embed ű׿¡ allowscrpt °ªÀ» never ·Î ÇÏ¿© ¼Ó¼ºÀ» Ãß°¡ÇÑ´Ù.

        $content = preg_replace("#(<embed[^>]+)#i", "$1 allowscriptaccess=\"never\"", $content);




        // À̹ÌÁö ű×ÀÇ src ¼Ó¼º¿¡ »èÁ¦µîÀÇ ¸µÅ©°¡ ÀÖ´Â °æ¿ì °Ô½Ã¹°À» È®ÀÎÇÏ´Â °Í¸¸À¸·Îµµ µ¥ÀÌÅÍÀÇ À§º¯Á¶°¡ °¡´ÉÇϹǷΠÀÌ°ÍÀ» ¸·À½

        $content = preg_replace("/<(img[^>]+delete\.php[^>]+bo_table[^>]+)/i", "*** CSRF °¨Áö : <$1", $content);

        $content = preg_replace("/<(img[^>]+delete_comment\.php[^>]+bo_table[^>]+)/i", "*** CSRF °¨Áö : <$1", $content);

        $content = preg_replace("/<(img[^>]+logout\.php[^>]+)/i", "*** CSRF °¨Áö : <$1", $content);

        $content = preg_replace("/<(img[^>]+download\.php[^>]+bo_table[^>]+)/i", "*** CSRF °¨Áö : <$1", $content);




        $content = preg_replace_callback("#style\s*=\s*[\"\']?[^\"\']+[\"\']?#i",

                    create_function('$matches', 'return str_replace("\\\\", "", stripslashes($matches[0]));'), $content);




        $pattern = "";

        $pattern .= "(e|&#(x65|101);?)";

        $pattern .= "(x|&#(x78|120);?)";

        $pattern .= "(p|&#(x70|112);?)";

        $pattern .= "(r|&#(x72|114);?)";

        $pattern .= "(e|&#(x65|101);?)";

        $pattern .= "(s|&#(x73|115);?)";

        $pattern .= "(s|&#(x73|115);?)";

        //$pattern .= "(i|&#(x6a|105);?)";

        $pattern .= "(i|&#(x69|105);?)";

        $pattern .= "(o|&#(x6f|111);?)";

        $pattern .= "(n|&#(x6e|110);?)";

        //$content = preg_replace("/".$pattern."/i", "__EXPRESSION__", $content);

        $content = preg_replace("/<[^>]*".$pattern."/i", "__EXPRESSION__", $content);

        // <IMG STYLE="__XSS__expression(alert('XSS'))"></IMG> ¿Í °°Àº Äڵ忡 Ãë¾àÁ¡ÀÌ ÀÖ¾î ¼öÁ¤ÇÔ. 121213

        $content = preg_replace("/(?<=style)(\s*=\s*[\"\']?xss\:)/i", '="__XSS__', $content);

        $content = bad_tag_convert($content);

        return $content;

}








// OBJECT ű×ÀÇ XSS ¸·±â

function bad120422($matches)

{

    $tag  = $matches[1];

    $code = $matches[2];

    if (preg_match("#\bscript\b#i", $code)) {

        return "$tag ű׿¡ ½ºÅ©¸³Æ®´Â »ç¿ë ºÒ°¡ÇÕ´Ï´Ù.";

    } else if (preg_match("#\bbase64\b#i", $code)) {

        return "$tag ű׿¡ BASE64´Â »ç¿ë ºÒ°¡ÇÕ´Ï´Ù.";

    }

    return $matches[0];

}




// tag ³»ÀÇ ÁÖ¼®¹® ¹«È¿È­ Çϱâ

function bad130128($matches)

{

    $str = $matches[2];

    return '<'.$matches[1].preg_replace('#(\/\*|\*\/)#', '', $str).'>';

}








// ¾Ç¼ºÅÂ±× º¯È¯

function bad_tag_convert($code)

{

    global $view;

    global $member, $is_admin;




    if ($is_admin && $member[mb_id] != $view[mb_id]) {

        //$code = preg_replace_callback("#(\<(embed|object)[^\>]*)\>(\<\/(embed|object)\>)?#i",

        // embed ¶Ç´Â object ű׸¦ ¸·Áö ¾Ê´Â °æ¿ì ÇÊÅ͸µÀÌ µÇµµ·Ï ¼öÁ¤

        $code = preg_replace_callback("#(\<(embed|object)[^\>]*)\>?(\<\/(embed|object)\>)?#i",

                    create_function('$matches', 'return "<div class=\"embedx\">º¸¾È¹®Á¦·Î ÀÎÇÏ¿© °ü¸®ÀÚ ¾ÆÀ̵ð·Î´Â embed ¶Ç´Â object ű׸¦ º¼ ¼ö ¾ø½À´Ï´Ù. È®ÀÎÇϽ÷Á¸é °ü¸®±ÇÇÑÀÌ ¾ø´Â ´Ù¸¥ ¾ÆÀ̵ð·Î Á¢¼ÓÇϼ¼¿ä.</div>";'),

                    $code);

    }




    //return preg_replace("/\<([\/]?)(script|iframe)([^\>]*)\>/i", "<$1$2$3>", $code);

    // script ³ª iframe ű׸¦ ¸·Áö ¾Ê´Â °æ¿ì ÇÊÅ͸µÀÌ µÇµµ·Ï ¼öÁ¤

    return preg_replace("/\<([\/]?)(script|iframe|form)([^\>]*)\>?/i", "<$1$2$3>", $code);

}
ÃßõÃßõ : 410 Ãßõ ¸ñ·Ï
¹øÈ£ Á¦¸ñ
223
Á¤±Ô½Ä ÆÁ
±×´©º¸µå¿¡¼­ »ç¿ëµÈ XSS (Cross Site Script) ¸·±â
221
À¯Åõºê µ¿¿µÀå ÁÖ¼Ò ÃßÃâ PHP Á¤±Ô½Ä ¿¹ 2 (parse_str ¹æ½Ä)
220
À¯Åõºê µ¿¿µÀå ÁÖ¼Ò ÃßÃâ Á¤±Ô½Ä ¿¹ 1
219
YouTube shortcode fix for a blog imported from WordPress.com
218
PHP < ![CDATA[ 2 ]]> Á¦°Å Á¤±Ô½Ä
217
span, font ű׸¦ Á¦°ÅÇÏ´Â Á¤±Ô½Ä
216
º»¹®¿¡¼­ À̹ÌÁö ÃßÃâ, À̹ÌÁö Á¦°Å Á¤±Ô½Ä
215
¿©·¯°³ÀÇ ºóÄ­ , ÁÙÀ» °ø¹éÀ¸·Î º¯°æÇϱâ
214
URL ó¸® °ü·Ã Á¤±Ô½Ä
213
PHP Á¤±Ô½Ä À¯È¿¼º°Ë»ç ¿¹Á¦ (IDüũ, À̸ÞÀÏüũµî)
212
PHP¿¡¼­ Ư¼ö¹®ÀÚ ¾ø¾Ö´Â Á¤±ÔÇ¥Çö½Ä
211
php ¹®ÀÚ¿­ ÀÚ¸£±â, ºñ±³, ã±â ÇÔ¼ö, str_replace, substr ,strpos, explode µîµî Á¤¸®
210
¼¼¼Ç ¹× ÄíÅ°ÀÇ Á¤º¸¸¦ ¾ÏȣȭÇϱâ
209
GetImageSize À̹ÌÁöÆÄÀÏÀÇ »çÀÌÁ ¾Ë¾Æ³»´Â ÇÔ¼ö
208
¹®ÀÚ¿­ÀÇ °ø¹éÀ» À߶󳻴 chop, trim, ltrim ÇÔ¼ö
207
µÎ°³ÀÇ º¯¼ö¸¦ ºñ±³ÇÏ´Â strcmp ÇÔ¼ö
206
ű׸¦ ¾ø¾Ö°í Ãâ·ÂÇÏ´Â strip_tags ÇÔ¼ö
205
ű׸¦ ±×´ë·Î Ãâ·ÂÇÏ´Â htmlspecialchars ÇÔ¼ö
204
º¯¼ö³»¿¡ ¿ª½½·¡½Ã ³Ö±â¿Í »©±â
203
Á¦¾î ±¸Á¶ÀÇ ´ëü ¹®¹ý
202
elseif/else if
201
if..endif ±¸¹®
200
POST, GETÀ¸·Î º¯¼ö°ªÀÌ ³Ñ¾î°¡Áö ¾Ê´Â °æ¿ì - register_globals
199
PHP ÆÄÀÏ°ü·Ã ÇÔ¼ö
198
¿ø°ÝÁö ÆÄÀÏÀÇ Á¸Àç ¿©ºÎ¸¦ üũ »ç¿ëÀÚ ÇÔ¼ö
197
PHP ÆÄÀÏ ´Ù·ç±â
196
[PHP] ÆÄÀÏ ÇÔ¼ö
195
ÆÄÀÏ »ý¼º, ±â·Ï, Àбâ
194
´Ù¸¥ ¼­¹ö·Î °ªÀ» Àü¼ÛÈÄ °á°ú°ªÀ» ¹Þ´Â ¹æ¹ý
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æħ
Copyright ¨Ï musictrot All rights reserved.