星期六, 12月 31, 2011

安裝 DenyHosts 防止 SSH 暴力破解

實在是受不了大量外部 IP 狂駭你的 SSH 嘛?

請服用 DenyHosts ~

FreeBSD 請用 ports 安裝: /usr/ports/security/denyhosts/
Linux 請到 http://denyhosts.sourceforge.net 下載安裝

官方安裝說明:

To run denyhosts from startup, add denyhosts_enable="YES" in your /etc/rc.conf.
Configiration options can be found in /usr/local/etc/denyhosts.conf
-------------------------------------------------------------------------------
In order to proper working of denyhosts
1. edit your /etc/hosts.allow file and add:
sshd : /etc/hosts.deniedssh : deny
sshd : ALL : allow
2. issue the following command if /etc/hosts.deniedssh does not exist yet
touch /etc/hosts.deniedssh
-------------------------------------------------------------------------------

/usr/local/etc/denyhosts.conf 基本設定完成後,/usr/local/etc/rc.d/denyhosts start 即可~

如需允許特定 IP 避免被鎖住,請在 DenyHosts WORK_DIR 目錄中新增一個 allow_hosts 每行一個IP,重啓 denyhosts 後即可排除特定 IP ~

星期日, 10月 02, 2011

Postfix + SASL2 + TLS + dovecot + RoundCube webmail

以下為採用 本機 passwd 認證,非虛擬帳號方式

重要 conf 設定如下:

Postfix ~ Mailbox 配合 dovecot 採用 Maildir 設定

==============================================

myhostname = HOST+DomainName
mydomain = DomainName
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
local_recipient_maps = unix:passwd.byname $alias_maps
mynetworks_style = host
mynetworks = 192.168.0.0/24, 127.0.0.0/8, WanFixIP
relay_domains = $mydestination
home_mailbox = Maildir/
mail_spool_directory = /var/mail
smtpd_banner = $myhostname ESMTP

# SASL 2
broken_sasl_auth_clients = yes
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $mydomain
smtpd_recipient_restrictions = permit_mynetworks permit_sasl_authenticated reject_unauth_destination

# TLS
smtp_use_tls = yes
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_key_file = /usr/local/etc/postfix/CA/server.key
smtpd_tls_cert_file = /usr/local/etc/postfix/CA/server.crt
smtpd_tls_CAfile = /usr/local/etc/postfix/CA/ca.crt
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom

# All mail will bcc to SomeAccount for backup
always_bcc = mailbak
==============================================

smtps inet n - n - - smtpd
-o smtpd_tls_wrappermode=yes
-o smtpd_sasl_auth_enable=yes
==============================================


SASL2 ~ 需自行新增 smtpd.conf 於 /usr/local/lib/sasl2/ 下

==============================================
[/usr/local/lib/sasl2/smtpd.conf]

pwcheck_method: saslauthd
mechlist: plain login crammd5 digestmd5
==============================================


dovecot ~ IMAP, IMAPs, POP3, POP3s 可執行 doveconf 參考基本設定來產生 dovecot.conf

==============================================
[dovecot.conf]

auth_default_realm =
auth_mechanisms = plain login
auth_username_format = %n
disable_plaintext_auth = no
protocols = imap pop3
ssl_cert = server.crt
ssl_key = server.key
userdb {
driver = passwd
}
passdb {
driver = passwd
}
ssl = yes
mail_location = maildir:~/Maildir
mail_privileged_group = mail
==============================================


Roundcube Webmail ~ 請先於 MySQL 建立相對的資料庫及權限,用 Broswer 開啓 installer 目錄進行安裝設定,便可產生 main.inc.php & db.inc.php

==============================================
[main.inc.php]

$rcmail_config['db_dsnw'] = 'mysql://user:password@host/database';

//其他依預設值即可

==============================================
[db.inc.php]

// IMAP
$rcmail_config['default_host'] = 'DomainName';
$rcmail_config['default_port'] = 143;
$rcmail_config['imap_auth_type'] = '';

// SMTP
$rcmail_config['smtp_server'] = 'localhost';
$rcmail_config['smtp_port'] = 25;
$rcmail_config['smtp_auth_type'] = 'LOGIN, PLAIN';

// USER INTERFACE
$rcmail_config['junk_mbox'] = 'Spam';
$rcmail_config['default_imap_folders'] = array('INBOX', 'Drafts', 'Sent', 'Spam', 'Trash');
$rcmail_config['create_default_folders'] = true;

// USER PREFERENCES
$rcmail_config['default_charset'] = 'UTF-8';

//其他依預設值即可

==============================================


/etc/rc.conf 需添加的設置如下
==============================================
# Postfix
postfix_enable="YES"

# dovecot
dovecot_enable="YES"

# Sendmail
sendmail_enable="NONE"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"

# SASL2
saslauthd_enable="YES"

==============================================

星期三, 9月 14, 2011

Postfix + MySQL + ExtMail郵件伺服器

[轉載] http://www.bsdlover.cn/html/51/n-2951.html

一、安装

先把相应的软件安装上,最后再来分别配置。安装之前最好先用“portsnap fetch update”更新ports
[1]. 安装cyrus-sasl2
cyrus-sasl2是为标准的SASL实现库,可以支持Courier authlib。
[root@bsd01 ~]#cd /usr/ports/security/cyrus-sasl2
[root@bsd01 cyrus-sasl2]#make install clean

然后会出现“make config”的界面,选择需要的支持即可,但是我现在是以mysql做数据库支持,所以一定要需mysql:
Options for cyrus-sasl 2.1.22_2
----------------------------------------------------------------------------
[ ] BDB Use Berkeley DB
[X] MYSQL Use MySQL
[ ] PGSQL Use PostgreSQL
[ ] SQLITE Use SQLite
[ ] DEV_URANDOM Use /dev/urandom
[ ] ALWAYSTRUE Enable the alwaystrue password verifier
[ ] KEEP_DB_OPEN Keep handle to Berkeley DB open
[X] AUTHDAEMOND Enable use of authdaemon
[X] LOGIN Enable LOGIN authentication
[X] PLAIN Enable PLAIN authentication
[X] CRAM Enable CRAM-MD5 authentication
[X] DIGEST Enable DIGEST-MD5 authentication
[X] OTP Enable OTP authentication
[X] NTLM Enable NTLM authentication


[2]. 安装courier-imap
Courier-IMAP是一个提供POP3、IMAP服务的程序,能够很方便的配置使其支持加密协议POP3s、IMAPs。并良好的支持Maildir。
[root@bsd01 cyrus-sasl2]#cd /usr/ports/mail/courier-imap
[root@bsd01 courier-imap]#make install clean

然后会出现“make config”的界面,选择需要的支持即可:
Options for courier-imap 4.4.1,2
-------------------------------------------------------------------------------
[ ] FAM Build in fam support for IDLE command
[ ] TRASHQUOTA Include deleted mails in the quota
[ ] GDBM Use gdbm db instead of system bdb
[ ] IPV6 Build with IPv6 support
[ ] AUTH_LDAP LDAP support
[X] AUTH_MYSQL MySQL support
[ ] AUTH_PGSQL PostgreSQL support
[ ] AUTH_USERDB Userdb support
[ ] AUTH_VCHKPW Vpopmail/vchkpw support


[3]. 安装postfix
postfix是一个优秀的MTA(mail transfer agent,邮件传输代理),相比sendmail在性能还是配置简便都好一些,它本身就是用来替代sendmail的,所以兼容性也很不错,大部分的sendmail的脚本都可以使用在postfix上。
[root@bsd01 courier-imap]#cd /usr/ports/mail/postfix
[root@bsd01 postfix]#make install clean

然后会出现“make config”的界面,选择我们需要的组件就可以了:
Options for postfix 2.5.5,1
--------------------------------------------------------------------------------------
[X] PCRE Perl Compatible Regular Expressions
[X] SASL2 Cyrus SASLv2 (Simple Auth. and Sec. Layer)
[ ] DOVECOT Dovecot SASL authentication method
[ ] SASLKRB If your SASL req. Kerberos select this option
[ ] SASLKRB5 If your SASL req. Kerberos5 select this option
[ ] SASLKMIT If your SASL req. MIT Kerberos5 select this option
[X] TLS Enable SSL and TLS support
[ ] BDB Berkeley DB (choose version with WITH_BDB_VER)
[X] MYSQL MySQL maps (choose version with WITH_MYSQL_VER)
[ ] PGSQL PostgreSQL maps (choose with DEFAULT_PGSQL_VER)
[ ] OPENLDAP OpenLDAP maps (choose ver. with WITH_OPENLDAP_VER)
[ ] CDB CDB maps lookups
[ ] NIS NIS maps lookups
[X] VDA VDA (Virtual Delivery Agent)
[X] TEST SMTP/LMTP test server and generator

安装过程会出现1个问题,一般默认就可以了:
Would you like me to add it [y]?y
Would you like to activate Postfix in /etc/mail/mailer.conf [n]?n

安装完之后,会提示你把启动下下面文字加入/etc/rc.conf文件
postfix_enable="YES"
#If you not need sendmail anymore, please add in your rc.conf:
sendmail_enable="NO"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"

然后把下面的加入到/etc/periodic.conf,但是我服务器上根本没有/etc/periodic.conf文件,所以就不用管它:
#And you can disable some sendmail specific daily maintenance routines in your /etc/periodic.conf file:
daily_clean_hoststat_enable="NO"
daily_status_mail_rejects_enable="NO"
daily_status_include_submit_mailq="NO"
daily_submit_queuerun="NO"

[4]. 安装extman和extmail
其实这个去http://www.extmail.org/cgi-bin/download.cgi下载也可以。
1). 安装extman 0.2.5
[root@bsd01 postfix]#cd /usr/ports/mail/extman
[root@bsd01 extman]#make install clean

然后会弹出“make config”的选项,选择我们需要的mysql就可以了:
Options for extman 0.2.5
------------------------------------------------------------
[X] MySQL Use MySQL support
[ ] LDAP Use LDAP support

extman安装好之后,网页及配置文件位于/usr/local/www/extman目录。它还会编译其他比如p5-MIME,p5-GD,p5-DBD-mysql,gd,p5-DBI,p5-Storable这些支持组件。这就是ports的强大之处。

2). 安装extmail 1.0.5
[root@bsd01 extman]#cd ../extmail
[root@bsd01 extmail]#make install clean

这里也会弹出“make config”的选项,跟extman的一样,但是由于前面extman已经选择了支持,所以这里可以把mysql和ldap的支持去掉了。
extmail安装好之后,网页及配置文件位于/usr/local/www/extmail,另外他还会把p5-Unix-Syslog这个组件安装上。

现在我们就可以来配置了。

二、配置篇
[1]. 先来做几个基本的动作
[root@bsd02 ~]#mv /usr/sbin/sendmail /usr/sbin/sendmail.old
[root@bsd01 ~]#ln -s /usr/local/sbin/sendmail /usr/sbin
[root@bsd01 ~]#echo 'postfix: root' >> /etc/aliases
[root@bsd01 ~]#/usr/local/bin/newaliases
[root@bsd01 ~]#chown postfix:postfix /etc/opiekeys

[2]. 现在来配置courier-imap
▼先复制下配置文件:
[root@bsd01 ~]#cd /usr/local/etc/courier-imap
[root@bsd01 courier-imap]#cp imapd.cnf.dist imapd.cnf
[root@bsd01 courier-imap]#cp pop3d.cnf.dist pop3d.cnf
[root@bsd01 courier-imap]#chmod a+x /var/run/authdaemond

▼然后把courier-imap的启动加到/etc/rc.conf文件:
courier_authdaemond_enable="YES"
courier_imap_pop3d_enable="YES"
courier_imap_imapd_enable="YES"

▼启动认证服务:
[root@bsd01 courier-imap]#/usr/local/etc/rc.d/courier-authdaemond start

星期三, 5月 11, 2011

MySQL root 密碼忘記 !? (Windows系列)

如果你的SERVER是 Windows XP/2000/2003/NT 應該都可以使用這個方法來重置 MySQL root 的密碼

1. 停止 MySQL 服務,執行 CMD,輸入 net stop mysql

2. 進入 MySQL 安裝目錄,ex: C:\Program files\mysql\bin\

3. 進入 mysql 安全模式,也就是 mysql start 後,不需輸入密碼就能進入 mysql! 指令如下:
mysqld -nt --skip-grant-tables
4. 再另外執行一個CMD命令窗口,輸入 mysql -u root -p,使用無密碼的方式登入 MySQL(不用輸入密碼,直接按 Enter)

5. 輸入以下指令開始修改 root 的密碼
mysql> UPDATE mysql.user SET password=PASSWORD('新密碼') WHERE User='root';
6. 重新載入 mysql 權限表
mysql> flush privileges;
7. 大功告成!
mysql> quit

如此一來,MySQL root 密碼已經重置,
MySQL 重新啟動後,就可以用新密碼登入了!

星期六, 7月 10, 2010

iPhone 3GS 誤升 iOS 4.0 成功降回 3.1.3 ( 解決 error 1015 )

同事的 iPhone 3GS 在一時手賤下,誤升級上了 iOS 4.0

在不確定是否有備份 SHSH 的情況下,只好死馬當活馬醫了...

降韌體前,須先修改 hosts 將 Apple 官方連線檢查更新SERVER 轉向至 Sauriks Server

Windows
找到 C:/Windows / System32 / drivers / etc / hosts 開啟編輯
在最下方加入下列一行:
74.208.10.249  gs.apple.com

MAC OS X
點選 Finder, 執行 Go to Folder... 輸入 /etc 後點選 Go
一樣在最下方加入一行:
74.208.10.249  gs.apple.com
此時因為權限問題,無法直接存檔,請先選擇 另存新檔 至桌面
注意! 不要勾選 [ If no extension is provide, use .txt ]
然後再到桌面,把剛剛另存的 hosts 拖拉回 /etc 目錄中,按照指示輸入權限密碼置換檔案即可!


接下來就是進行降韌體重刷工作,以下建議採用 MAC OS X 較容易成功!

  • 取得 iPhone OS 3.1.3 firmware (Click here!)
  • 取得 RecBoot (Mac App)
  • 進入 DFU 模式,直接重刷 3.1.3

進入 iPhone DFU (Device Firmware Upgrade) 模式
  1. 接上 iPod / iPhone 連接線
  2. 開啟 iTunes
  3. 同時按住 Lock(開關) 鍵與 Home 鍵不放
  4. 10 秒後放開 Lock 鍵,確實保持 Home 鍵按住不放
  5. 10 秒後 iTunes 跳出訊息,表示巳進入 recovery mode (回復模式),按 OK
  6. 在 iTunes 裡,按住 option(Shift) 同時點擊 restore(回復) 按鈕
  7. 此時跳出視窗,請指定 iPhone OS 3.1.3 ipsw 所在位置,按下 OK 開始 restore 程序

用 RecBoot 解決 error 1015 狀況

Restore 程序跑完之後,iTunes 將顯示 error 1015 訊息,立即執行 RecBoot (請執行 RecBoot Exit Only.app),按下 Exit Recovery Mode 按鈕,iPhone 將自行重新開機,完成 OS restore,接下來就可以進行 Spirit !!!


Regards, Rayback Liu.

星期二, 6月 15, 2010

「顯示桌面」不見了!怎辦?

CASE A:

請將下面虛線內的文字複製下來,不含虛線。
---------------------------------------
[Shell]
Command=2
IconFile=explorer.exe,3
[Taskbar]
Command=ToggleDesktop
---------------------------------------
將其貼到記事本上,儲存檔案為「顯示桌面.scf」
然後把這個檔案放到「C:\Documents and Settings\使用者名稱\Application Data\Microsoft\Internet Explorer\Quick Launch」即可。


CASE B:

開始 → 執行 → 輸入[regsvr32 /n /i:u shell32] → 確定

星期六, 5月 29, 2010

Cydia AptBackup 備份 & 回復

如何用 AptBackup 來備份、回復從 Cydia 安裝的 App 步驟

1. 先從 Cydia 要裝 AptBackup,在 Search 中輸入 AptBackup 就可找到

2. 完成安裝之後,執行 AptBackup,按「Backup」

3. 之後就會見到正在Backup的畫面

4. 完成 Backup 之後,與iTunes同步一次(一次就好了!),那剛剛所做的 Backup 就會備份到你的電腦中,不過緊記不要再做第二次的同步!因為這樣就會失去了剛才的備份!

5. 之後就可以 restore / 升級你的 iPhone

6. 完成 restore / 升級你的 iPhone 之後,不要將你的 iPhone 與 iTunes 同步,先(破解後)到 Cydia 安裝 AptBackup

7. 安裝 AptBackup 後,就可以將你的 iPhone 與你的 iTunes 同步了

8. 同步完成後,什麼要別做!立即執行 AptBackup

9. 在 AptBackup 後,按「Restore」

10. 這時,AptBackup 就會根據先前備份的記錄,替你重新下載、安裝一次先前你已從 Cydia 安裝的 App,完成後,你的 iPhone 會重新啟動!!

ps. AptBackup 只會記錄你從 Cydia 安裝過的 App,並幫你重新安裝,而不會替你備份其中的使用記錄 (例如遊戲進度)

星期日, 3月 07, 2010

動態磁碟轉換成基本磁碟

動態磁碟 轉換成 基本磁碟 又想保留資料的做法如下:

1. 利用任何附有 spfdisk 程式的開機片開機,然後執行 spfdisk

2. 選定要修正的硬碟之後,將它的系統ID改為 07 (原本動態磁碟 SFS 系統ID為 42)

3. 離開 spfdisk 然後重開機即可!!

星期二, 7月 01, 2008

FreeBSD sudo 用法

pkg 安裝:
pkg_add -vr sudo

ports 安裝:
cd /usr/ports/security/sudo
make install clean
rehash

設定檔:
/usr/local/etc/sudoers

與 root 同權限:
YOURACCOUNT ALL=(ALL) ALL

USER登入後,欲切換為 root 時請執行:
sudo su -

password 輸入個人密碼即可!

PostgreSQL 初始化步驟

PostgreSQL 安裝完成後,如未初始化,請先執行

initdb -D /usr/local/pgsql

初始化完成,把 PostgreSQL run 起來...

接著就可以新增一個USER

登入
su – postgres

切換至 template1
psql template1

建立USER
create user 帳號 with password '密碼' createdb createuser;

如此就已新增一個USER並擁有新增DB及USER的權限...

如需修改USER密碼的話:
alter user 使用者 with password '密碼';



phpPgAdmin 預設是不允許 postgres Login ...
所以最好先 create 一個 user 再 Login,方式請參考以上

如想要允許使用 postgres Login,務必先修改 postgres 的密碼 ( postgres 密碼不得為空 )

再修改
vi phpPgAdmin/conf/config.inc.php

Find...
$conf['extra_login_security'] = true;

Edit...
$conf['extra_login_security'] = false;

如此便可用 postgres Login !!!



如需匯入資料請用下列指令

登入
su – postgres

如無DB,請先新增DB以便匯入
createdb SOMENEWDB

匯入格式
psql -h {connected-server} -U {Username} -W -e {DB_Name} < {DB_dump_file}

EX:
psql –U admin –e SOMENEWDB <>

請先將 xxx.sql 複製到 PostgreSQL 所在目錄下 (/usr/local/pgsql),以便快速讀取
輸入以上指令後,便可將資料匯入指定的DB中...



如欲使用 pgAdmin III 工具連線,請修改

/usr/local/pgsql/postgresql.conf

tcpip_socket=false 設成 true