OpenSSH 安全性漏洞 CVE-2016-0777 and CVE-2016-0778

openssh

OpenSSH 今日公佈 Client Bug 漏洞 CVE-2016-0777 and CVE-2016-0778,發生原因是 SSH Clinet 跟 Server 溝通時,新功能 roaming 造成傳輸過程被惡意程式破解,影響的 OpenSSH 版本為 5.4 - 7.1. 大家快看看自己是否為這版本區間。此問題會發生在 SSH Client 而不是 Server 端,所以 Linux FreeBSDMacOS 都需要升級 OpenSSH,如果你是在 Windows 用 Putty 則不受影響。

[Read More]

安裝 XCache 加速 PHP 執行速度

php-logo

前言

最近 FreeBSD 系統常常會當機,加上 Varnish cache + APC 一直給我出包,所以這次就換了一套加速 PHP 執行的套件 XCache,這是一套由華人所開發的加速器,可以參考篇台灣PHP聯盟論壇所發表 PHP 加速器 - xcache,裡面可以看到這篇裡面就有中文的對話,非常好玩,這次也順便把 PHP 升級到 5.3.8 版本,還有 Varnish 一次升級到 3.0.1 版本。

各家 PHP 加速器

大家都知道目前網路上知名的 PHP 加速器 apc, eaccelerator, phpa, truck-mmcache,這幾套網路上資料很多,大家都可以試著玩看看,尤其是前面兩套 APC 及 eaccelerator,phpa 目前已經不再維護了,truck-mmcache 版本好像也沒啥在更新,距離上次更新是 2009-07-17,Xcache 作者研究 truck-mmcache 跟 APC 已經很長的時間,他發現 APC 的程式碼比起 truck-mmcache 還要簡單更容易瞭解,所以大家也可以研究 APC 相關程式碼。

[Read More]

好用 PHP debug extension Xdebug on FreeBSD 安裝

xdebug-logo
之前介紹

FirePHP 這套好用的 PHP Debug 工具,也寫了一篇針對 CodeIgniter 的安裝方式,請參考: [PHP] 好用 Debug PHP 工具 FirePHP for FireFox on CodeIgniter,今天要介紹一套好用的 PHP debug Extension: Xdebug 的安裝方式,作者環境是在 FreeBSD 上,Windows 安裝方式就到官方網站下載對應的 PHP Windows binaries,目前在 FreeBSD ports 上面的版本是 2.1.0,但是 Xdebug 作者已經更新到 2.1.1,自己就順手發了一個 patch 157677 給 FreeBSD 官方 ports 去 update。

FreeBSD 安裝步驟

# cd /usr/ports/devel/php-xdebug
# make install clean
設定

/usr/local/etc/php/extensions.ini 檔案後面加入

extension=xdebug.so
設定

/usr/local/etc/php/php.ini 檔案後面加入

[Read More]

[FreeBSD] 利用 fsck 指令修復不正常斷電關機

由於人不在機器前面,所以都請學弟妹幫忙直接拔電在插電,現在問題出來了,完全不能開機了,現在就只能進去單人模式修復,其實修復也非常容易,進入開機選單,選擇 Single user mode 模式,進入之後會直接看到底下訊息提示:

enter full pathname of shell or return for :/bin/sh:
沒意外就直接按下 Enter 鍵就可以了,由於 fsck 指令在修復過程不可以先 mount 磁區,所以先利用 mount -a 來掛上所有磁區
# 掛上所有磁區
mount -a
# 顯示硬碟磁區
df -h
Console 會看到
Filesystem                                    Size    Used   Avail Capacity  Mounted on
/dev/da0s1a                                   496M    341M    115M    75%    /
devfs                                         1.0K    1.0K      0B   100%    /dev
/dev/da0s1e                                   496M     16M    440M     4%    /tmp
/dev/da0s1f                                    24G     15G    6.4G    71%    /usr
/dev/da1s1d                                    33G     22G    8.4G    73%    /usr/home
/dev/da0s1d                                   4.7G    2.5G    1.8G    58%    /var
如果針對 /dev/da1s1d 做修復,請下底下指令
umont /usr/home
fsck -y /dev/da1s1d
fsck 修復完成會出現底下訊息
** /dev/da1s1d
** Last Mounted on
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
** Phase 5 - Check Cyl groups
2 files, 2 used, 506337 free (25 frags, 63289 blocks, 0.0% fragmentation)
如果中間有錯誤訊息,就繼續 fsck 步驟,直到修復完成,完成之後下 reboot 重新開機,就可以看到 login as: 可以在 rc.conf 裡面加入兩行設定
fsck_y_enable="YES"
background_fsck="YES"

[整理] 文件系統修復 【FreeBSD】系統異常關機修複方式 FSCK [FreeBSD] 請教: FreeBSD斷電後fsck後能不能自動reboot

ProFTPD UseEncoding 繁體中文亂碼解決 Localization

Proftpd ProFTPD 一直都是我最喜歡使用的 FTP 伺服器,設定方式簡單淺顯易懂,最近在用 PSPad 寫程式,發現使用內建 FTP 功能時候,連不上 FreeBSD 架設的 ProFTPD,連線過程出現許多亂碼,所以造成 PSPad 斷線出現錯誤,解決方式就是利用 mod_lang 模組,設定 UseEncoding 讓系統可以顯示 Big5 中文編碼,FreeBSD Ports 請勾選

[X] NLSUOTA Use nls (builds mod_lang)
自行編譯請按照底下步驟
./configure --enable-nls
make
make install 

UseEncoding 設定

Syntax: UseEncoding on|off|local-charset client-charset
Default: None
Context: "server config", , 
Module: mod_lang
Compatibility: 1.3.2rc1
在 1.3.2rc1 版本之後才有支援,請複製底下設定,貼到 proftpd.conf
# 简体中文環境
UseEncoding UTF-8 GBK
# 繁体中文環境
UseEncoding UTF-8 Big5
Reference:

ProFTPD module mod_lang centos上解決proftp中文亂碼問題

[FreeBSD] update apache -> 2.2.15, PHP -> 5.3.2, and MySQL downgrade to 5.1.9

昨天升級了 FreeBSD 的 Apache, PHP, and MySQL,遇到很多地雷阿,最多的就是 PHP 的部份,因為本來自己使用 5.2.11 版本,但是在 commit port 的時候發生去裝 5.3.2 版本,所以就直接砍掉全部重練,先是遇到 MySQL 問題,原先在 database/mysql60-server 已經被 FreeBSD 移除,任何關於 mysql60 的相關 port 都被 remove 掉了,只好 downgrade 到 mysql 5.1.48 版本,移除同時順手把 apache PHP 相關都拿掉了。

移除 apache mysql php 相關 ports -rf 依序找尋相關 Mysql ports 移除

pkg_deinstall -rf mysql60-server
接下來安裝 MySQL 5.1.48 Server and Client,可以找到在

databases/mysql51-server and databases/mysql51-client,直接安裝即可

cd /usr/ports/databases/mysql51-server && make install
安裝 Apache 2.2.15
cd /usr/ports/www/apache22 && make WITH_MPM=worker install
安裝 PHP 5.3.2,FreeBSD 把 5.2.X 跟 5.3.X 分開不同資料夾

lang/php5, lang/php52,extension 也是分成兩個,所以要安裝 5.2 版本也是可以的

[Read More]

Apache 取得透過 Reverse Proxy (Varnish) 的 Client 真正 IP (mod_rpaf)

feather 之前介紹 [FreeBSD]high performance caching reverse proxy: Varnish (安裝架設篇) 來當 Web 前端 Reverse Proxy,也有 load balance 的功能,不過碰到這樣的環境,後端 Apache Server 只會抓到 Reverse Proxy IP 來當作 log 紀錄,而無法正確取得 Client 端 IP,Varnish 官網 FAQ 有提到 log 檔案得的解決方法,不過在程式方面,要大量的修改,假設今天 Apache 跑10個 Virtual Host ,不就要去改10個網站程式,背後或許是一些大型 open source 的 Project,改起來相當不容易,也很費工夫。Darkhero 提供了 reverse proxy add forward module for Apache (mod_rpaf) 模組,只要裝上這模組,Apache 就不必動到其它設定就可以正確紀錄 log 檔案,且程式都不必修改,就可以得到正確 IP 了。 FreeBSD Ports 安裝方式:

cd /usr/ports/www/mod_rpaf2/
make install clean
修改 httpd.conf (FreeBSD: /usr/local/etc/apache22/httpd.conf)
LoadModule rpaf_module        libexec/apache22/mod_rpaf.so
將上面 unmask,最後面加上:
RPAFenable On
RPAFsethostname On
RPAFproxy_ips xxx.xxx.xxx.xxx 127.0.0.1
RPAFheader X-Forwarded-For

[Vim] 想套用 *.php syntax 顏色於 *.ros

vim_header Vim 是一套強大的編輯器,它分佈於各大 UNIX systems,安裝好一套 UNIX 系統,預設就是 Vi 編輯器(FreeBSD 預設是 ee),相當好用,他也支援各種語言的 syntax,讓您在編輯檔案能夠看到各種不同顏色,在 FreeBSD 底下可以去看 /usr/local/share/vim/vim64/syntax/ 該資料夾支援各種語言,例如 PHP、Ruby、css、html、java、C/C++…等,假設今天我們想要 .ros 的副檔名需要用 php.vim syntax 來開啟,就必須做底下設定: 執行底下:

mkdri ~/.vim
vi ~/.vim/filetype.vim 
寫入 filetype.vim 資訊 if version < 600 syntax clear elseif exists("b:current_syntax") finish endif augroup filetypedetect au! BufRead,BufNewFile *.ros setfiletype php augroup END[/code] ps. on freebsd 7.1-RELEASE-p11 vim version 6.4.9 reference:

Vim 套用 Markdown syntax vi 設定

[FreeBSD] DenyHosts 設定在 hosts.allow 注意事項

denyhosts DenyHosts 是一套用 Python 跟 shell script 寫出來的 open source base on Linux or FreeBSD (/var/log/secure on Redhat, /var/log/auth.log on Mandrake, FreeBSD, etc…),用來阻擋 SSH Server 被攻擊,之前寫一篇 FreeBSD 安裝設定教學,有一點沒有注意到,就是打開 /etc/hosts.allow,注意要把 ALL : ALL : allow 放到最後一行,跟 iptables 設定原理是一樣的,會從第一條規則開始比對,如果比對成功,下面的 rule 就會略過比對了,參考英文說明:

Start by allowing everything (this prevents the rest of the file from working, so remove it when you need protection). The rules here work on a “First match wins” basis. /etc/hosts.deny 已經被 FreeBSD 棄用,所以必須把 allow 跟 deny 的 rule 都寫到 hosts.allow 檔案裡面才是正確的

[Read More]

[FreeBSD] Fanout and Fanterm Tool to run commands on multiple machines

在 Linux 或 FreeBSD 系統底下,如何下達 command 來達到多方控管機器,在網路上找到 Fanout and fanterm 這兩套軟體,可以實現我想要的目的,在 FreeBSD 有把 sysutils/fanout 進到 ports 裡面,安裝方式很簡單,就直接 make install clean 就可以了,用法也很簡易:

Usage:
  /usr/local/bin/fanout "MACHINES" "commands and parameters to run on each machine"
  /usr/local/bin/fanout -h      #Show this help
  /usr/local/bin/fanout --noping        # Do not ping before running command
當然事情沒有這麼簡單,因為是透過 SSH 方式去對其他機器下 command,所以作者都把預設 port 設定成 22,沒有完整考慮到其他環境,管理重要的 Server 怎麼會設定 22 阿,一定會改掉的阿,後來檢查一下 /usr/local/bin/fanout 這隻程式,並非編譯過的 binary 檔案,所以打開來看,就是利用 bash shell script 所寫的程式,網路上 Google 也找到一篇

Does anyone know how to specify a ssh port number with fanout? 文章,但是最後我是自己把 bash 改成支援可調整 port,也就是 MACHINES 可以放入:ip:portt or hostname:port patch 檔案:需要的就拿去 patch 就可以用了

[Read More]