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

±×´©º¸µå¿¡¼­ »ç¿ëµÈ 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);

}
ÃßõÃßõ : 404 Ãßõ ¸ñ·Ï
¹øÈ£ Á¦¸ñ
2,885
input ÀÔ·Â ÇÊµå ¾ÕµÚ °ø¹é ½Ç½Ã°£ Á¦°Å
2,884
Placeholder Æ÷Ä¿½º½Ã °¨Ãß±â
2,883
MySQL Áߺ¹µÈ µ¥ÀÌÅ͸¦ »èÁ¦
2,882
MySQL Áߺ¹ µ¥ÀÌÅÍ È®ÀÎ
2,881
sessionStorage.getItem ¿Í sessionStorage.setItem
2,880
Á¦ÀÌÄõ¸® ·£´ýÀ¸·Î ¹è°æ»ö º¯°æ
2,879
preg match¿¡ °üÇÑ Á¤±Ô½Ä
2,878
Stream an audio file with MediaPlayer ¿Àµð¿À ÆÄÀÏ ½ºÆ®¸®¹Ö Çϱâ
2,877
Audio Streaming PHP Code
2,876
PHP $ SERVER ȯ°æ º¯¼ö Á¤¸®
2,875
Vimeo (ºñ¸Þ¿À) API ¸¦ »ç¿ëÇÏ¿© Ç÷¹À̾î ÄÁÆ®·ÑÇϱâ
2,874
iframe »ç¿ë½Ã ÇÏ´Ü¿¡ ¹ß»ýÇÏ´Â °ø¹é Á¦°Å¹æ¹ý
2,873
¾ÆÀÌÇÁ·¹ÀÓ(iframe) Àüüȭ¸é °¡´ÉÇÏ°Ô Çϱâ
2,872
ºÎÆ®½ºÆ®·¦(bootstrapk)¿¡¼­ »ç¿ëÇÏ´Â class¸í Á¤¸®
2,871
ºÎÆ®½ºÆ®·¦ CSS
2,870
Å©·Ò¿¡¼­ ¸¶Áø Á¶Àý
2,869
PHP ÇöÀç ÆäÀÌÁöÀÇ µµ¸ÞÀθíÀ̳ª urlµîÀÇ Á¤º¸ ¾Ë¾Æ¿À±â
2,868
PHP preg match all()
2,867
PHP ·Î À¥ÆäÀÌÁö ±Ü¾î¿À±â ¸ðµç ¹æ¹ý ÃÑÁ¤¸®!
2,866
[PHP] ¿ø°ÝÁö ÆÄÀÏ ÁÖ¼Ò ³ëÃâ ¾ÈÇÏ°í curl·Î ´Ù¿î·Îµå ¹Þ±â
2,865
PHP ÇÔ¼ö Á¤¸®
2,864
¾ÆÀÌÇÁ·¹ÀÓ(iframe) ºñÀ² À¯ÁöÇϸ鼭 Å©±â Á¶ÀýÇÏ´Â ¹æ¹ý
2,863
PHP ¹è¿­¿¡¼­ ¹«ÀÛÀ§·Î Çϳª »Ì¾ÆÁÖ´Â array rand() ÇÔ¼ö
2,862
PHP Á¤±Ô½Ä Á¤¸®
2,861
PHP Á¤±Ô½ÄÀ» È°¿ëÇÑ ÅÂ±× ¹× ƯÁ¤ ¹®ÀÚ¿­ Á¦°Å ¹× ÃßÃâ ¹æ¹ý
2,860
php Å©·Ñ¸µ ¶Ç´Â ÆÄ½Ì ÇÔ¼ö, Á¤±Ô½Ä ¸ðÀ½
2,859
Á¦ÀÌÄõ¸® ±âº» ¸í·É¾î
2,858
À¥ÆäÀÌÁö °¡·Î ¸ðµå¼¼·Î ¸ðµå ÀνÄÇϱâ
2,857
¸ð¹ÙÀÏ À¥ È­¸é °­Á¦ ȸÀü(°¡·Î¸ðµå °íÁ¤)
2,856
[HTML5]¿¡¼­ frameset ´ëü ¹æ¹ý°ú iframe ¼Ó¼º
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æħ
Copyright ¨Ï musictrot All rights reserved.