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


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

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);

}
ÃßõÃßõ : 519 Ãßõ ¸ñ·Ï
¹øÈ£ Á¦¸ñ
2,501
¾Èµå·ÎÀ̵å À¥ºä(Android WebView) ¿¹Á¦
2,500
¾Èµå·ÎÀÌµå ¾Û Ä¿½ºÅÒ ±Û²Ã ³Ö±â
2,499
¾Èµå·ÎÀ̵å À¥ºä ¸µÅ© »õâó¸®
2,498
PHP·Î ºê¶ó¿ìÀú ¾Ë¾Æ³»±â
2,497
Mysql DB¿¡¼­ ƯÁ¤´Ü¾îµé Àϰý ¼öÁ¤ Äõ¸®
2,496
JW Ç÷¹ÀÌ¾î ±âº»Å±×
2,495
[php] ¾Ë¾ÆµÎ¸é ÆíÇÑ Á¤±ÔÇ¥Çö½Ä
2,494
PHP Á¤±Ô½Ä À¯È¿¼º°Ë»ç ¿¹Á¦ (IDüũ, À̸ÞÀÏüũµî)
2,493
[PHP] php ¹®ÀÚ¿­ ÇÔ¼ö
2,492
¸ð¹ÙÀÏÀ¥¿¡¼­ ÀÚÁÖ ¾²´Â ¼Ó¼ºµé
2,491
±×´©º¸µå ÃÖ°í°ü¸®ÀÚ ºñ¹Ð¹øÈ£ º¯°æ¹æ¹ý
2,490
¹®ÀÚ¿­ ÆÄÀÏ Ã³¸®ÇÔ¼ö
2,489
PHP file ó¸® ÇÔ¼ö
2,488
¹®ÀÚ¿­ °ø¹éÁ¦°Å ÇÔ¼ö trim°ú preg_replace
2,487
JavaScript ÆÄÀÏ ÀÐ°í ¾²±â ¿¹Á¦
2,486
php·Î À¥»óÀÇ ÆÄÀÏ Àбâ(html ¼Ò½º Àбâ)
2,485
PHPÀÇ allow_url_fopen=offÀ϶§ URL ÁÖ¼Ò·Î ÆÄÀÏ Àоî¿À±â
2,484
Ư¼ö¹®ÀÚ ¾ø¾Ö´Â Á¤±ÔÇ¥Çö½Ä / pcre ·Î °£´ÜÈ÷ ´Ü¾î¸¸ ÃßÃâÇϱâ
2,483
http://www.gskinner.com/RegExr/ Á¤±Ô½Ä Å×½ºÆ® »çÀÌÆ®
2,482
PCRE Á¤±ÔÇ¥Çö½Ä ¿¹Á¦·Î °³³äÀâ±â.
2,481
page º¯¼ö Áߺ¹ Á¦°Å ÆäÀÌ¡ ó¸® &page= Á¦°Å
2,480
Ư¼ö¹®ÀÚ ¾ø¾Ö´Â Á¤±ÔÇ¥Çö½Ä
2,479
regex Á¤±Ô½Ä ¿¹Á¦
2,478
ereg / eregi ¿À·ù Function eregi() is deprecated in ó¸®
2,477
phpÇѱÛüũ¸¦ À§ÇÑ Á¤±ÔÇ¥Çö½Ä
2,476
Á¤±Ô½Ä ¹®ÀÚ¿­ ³» À̹ÌÁö,¸µÅ© ÃßÃâÇϱâ
2,475
Á¤±Ô½Ä ¹è¿­·Î ¿©·¯ °³ µ¿½Ã ó¸®
2,474
{include ÆÄÀϸí.php} ó¸® (ÆÄÀϸí ġȯ ó¸®)
2,473
³»¿ëÁß image ÃßÃâ ó¸®
2,472
¹øÈ£ ½ÃÀÛ 1. tets 2.tets 11.test ÃßÃâ Á¤·Ä ó¸®
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æÄ§
Copyright ¨Ï musictrot All rights reserved.