2016年3月24日 星期四

如何清除DNS快取 (Flush DNS)

有空該補一章DNS的來由會比較好理解。

這個功能一般user應該很少用到,但搞IT的人卻是必備的技能。
當client瀏覽網頁、ping domain時,client PC會先透過DNS Server解析domain-IP的對應,並把結果暫存在cache裡,因此下次再次用到這個domain時,便不需要再次找DNS Server解析,以增加連線效率。

但有時會遇到,暫存的資料實際上已經異動時,client卻不知道,因此不論怎麼連都連不到,此時有幾個辦法可以解決。
1. 重開機
2. Restart 網卡
3. 下指令強制清除cache

在Windows環境下,清除cache的指令如下:
ipconfig /flushdns

在Mac OSX環境下,清除cache的指令如下:
dscacheutil -flushcache

在Linux環境下,清除cache的指令如下:
/etc/init.d/nscd restart

CentOS 7 安裝 GitLab

網址
https://about.gitlab.com/downloads/#centos7

Step 1.環境設置
==
sudo yum install curl openssh-server
sudo systemctl enable sshd
sudo systemctl start sshd
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
sudo firewall-cmd --permanent --add-service=http
sudo systemctl reload firewalld

Step 2.下載安裝
==
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo yum install gitlab-ce



Step 3.設定對外網址
==
>vi /etc/gitlab/gitlab.rb

>external_url 'http://192.168.1.228'


Step 4.設定
==
sudo gitlab-ctl reconfigure

Step 5.網址測試
==
至此安裝完畢
進入設定對外網址或IP
輸入帳密設定

Username: root
Password: 5iveL!fe

Step 6.Server操作指令
==
gitlab-ctl reconfigure
服務
gitlab-ctl restart
gitlab-ctl stop 0

2016年3月19日 星期六

Linux CentOS/Redhat SCP

當網管在一堆SERVER之間遊走時操作時,
會有遠端COPY檔案的需求
此時便是SCP的出現


除了遠端連線(SSH)之外

也可提供檔案傳輸的指令


scp 來源 目的

將檔案從遠端傳到本機
遠端-->本機
scp username@tohostname:/remotefile /newlocalfile



將檔案從本機傳到遠端
本機 -->遠端

scp localfile username@tohostname:/newfilename

2016年3月13日 星期日

Exchange 2013 設定SPAM List


在沒有邊際傳輸伺服器(Forefront Protection)的情形下,
Exchange Mail Server的角色並無法檢視與過濾垃圾或有害郵件

但還是可以透過SPAM List 的設定來過濾與拒絕高風險伺服器發出的郵件
※當然,如果是自家內部發出的就GG了

設定方式如下:
 ※溫馨小提醒,在做任何變更前必先存檔
開啟Exchange 命令介面(別開成2012 Power Shell)

開啟連結拒絕清單
安裝TransportAgent

Install-TransportAgent -Name "Connection Filtering Agent" -TransportService FrontEnd -TransportAgentFactory "Microsoft.Exchange.Transport.Agent.ConnectionFiltering.ConnectionFilteringAgentFactory" -AssemblyPath "C:\Program Files\Microsoft\Exchange Server\V15\TransportRoles\agents\Hygiene\Microsoft.Exchange.Transport.Agent.Hygiene.dll"

開啟服務

Enable-TransportAgent -TransportService FrontEnd -Identity "Connection Filtering Agent"
重啟
Exchange Transport Service

查看狀態
Get-TransportAgent -TransportService FrontEnd


====================
加入SPAM List名稱


Add-IPBlockListProvider -Name SpamhausSBL -LookupDomain sbl.spamhaus.org -AnyMatch $true -Enabled $true -RejectionResponse "IP address is listed by Spamhaus"
Add-IPBlockListProvider -Name SpamhausXBL -LookupDomain xbl.spamhaus.org -AnyMatch $true -Enabled $true -RejectionResponse "IP address is listed by Spamhaus"
Add-IPBlockListProvider -Name SpamhausPBL -LookupDomain pbl.spamhaus.org -AnyMatch $true -Enabled $true -RejectionResponse "IP address is listed by Spamhaus"
Add-IPBlockListProvider -Name SpamhausSBL+XBL -LookupDomain sbl-xbl.spamhaus.org -AnyMatch $true -Enabled $true -RejectionResponse "IP address is listed by Spamhaus"
Add-IPBlockListProvider -Name SpamhausZEN -LookupDomain zen.spamhaus.org -AnyMatch $true -Enabled $true -RejectionResponse "IP address is listed by Spamhaus"


===
Get-IPBLOCKLISTPROVIDER
===


設定完畢 ,加入SPAM List IP
====
Set-IPBlockListProvider "SpamhausZEN" -IPAddressesMatch @{Add="127.0.0.2","127.0.0.4","127.0.0.5","127.0.0.6","127.0.0.7","127.0.0.8","127.0.0.10","127.0.0.11"}
Set-IPBlockListProvider "SpamhausSBL" -IPAddressesMatch @{Add="127.0.0.2"}
Set-IPBlockListProvider "SpamhausXBL" -IPAddressesMatch @{Add="127.0.0.4","127.0.0.5","127.0.0.6","127.0.0.7","127.0.0.8"}
Set-IPBlockListProvider "SpamhausPBL" -IPAddressesMatch @{Add="127.0.0.10","127.0.0.11"}
Set-IPBlockListProvider "SpamhausSBL+XBL" -IPAddressesMatch @{Add="127.0.0.2","127.0.0.3","127.0.0.4","127.0.0.5","127.0.0.6","127.0.0.7","127.0.0.8"}
====
完成

===
※移除 SPAM List 設定
Remove-IPBlockListProvider -Name Spamhaus -LookupDomain zen.spamhaus.org -AnyMatch $true -Enabled $true -RejectionResponse "IP address is listed by Spamhaus"


2016年3月5日 星期六

Mail Server SPAM List (SPF)

前幾天遇到遇到了件很有趣的事情,
即是有員工和MIS反映信寄不出去的問題

個人先是由Mail Server 的寄信設定開始查驗,

經過一番設定確認,才發現自家公司的郵件伺服器被第三方組織設為垃圾郵件(SPAM)
因此在公司的信一寄出便被過濾阻擋。

這是個有意思的事情,因為這是我念書知道很久(莫約N年)卻從沒遇過的事情。

首先,先須查詢郵件伺服器的IP是否在清單上

查詢網址如下:

http://mxtoolbox.com/blacklists.aspx

※由於第三方組織SPAM List不只一個,故不一一介紹

然後查看你上榜的了哪些,在一一過去查看原因,
自檢排除後並寫信或是依該網站所提供步驟要求在該黑名單中移除即可

時間還挺快的,以前念書時聽到老師或是前輩提供的經驗是一兩天不等,
現在倒是二十分鐘到兩個小時內就好了。

由於其中有要求DNS須符合SPF規範,檢查了一下外部DNS還真沒有(XD)
所以也一併設定。

而Mail Server 榜的原因則是有人以公司郵件伺服器發出含木馬與病毒的廣告信之故。

所以,之後還是得架上邊際伺服器與要求使用者安裝防毒軟體。

資安,還是有很多是要忙的

另外也得持續觀察Mail Server 的情況。

====================================================================
歸納網路上找到個解決辦法與需注意的方面:

1. 假設貴公司開放 SMTP ports 讓外部可以透過 smtp 發信
則要做好權限控管,沒有透過認證者 or IP 不再安全清單一律不許使用 SMTP 發信。
(也可考慮 VPN)

2. 定期檢查使用者是否濫用 SMTP 寄送非公司相關信件

3. 定期檢查使用者電腦是否中毒、中木馬成為發送廣告信的跳板

4. 教育使用者足夠的資訊安全概念

5. 安裝防毒軟體與郵件掃描軟體(或建構郵件邊際伺服器)

6. 定時檢察有無進入SPAM 清單 http://mxtoolbox.com/blacklists.aspx

7.考慮使用 DKIM or Domainkey 金鑰簽署郵件提高辨識性與安全性。

=====================================================================
並為了避免Mail  Server  有被冒充的風險,故於DNS設定上 SPF 

SPF 的全寫是 Sender Policy Framework,它是一個可以保障域名持有人,免被 spammers 冒充發信的一種機制。

補上DNS 的 SPF設定方是
1. 確認Mail Server 設定IP位置正確(A)
2. 確認有無設定郵件伺服器(MX)
3. 確認有無設定反解(ptr)
4. 設定(TXT)

填上 ip4:mail server ip位置

v=spf1 mx ip4:xxx.xxx.xxx.xxx -all

5.設置後於測試
http://tools.bevhost.com/spf/
輸入E-mail 與 mail server 網址查看是否符合其設置
※DNS設置並不是即時的,故需要一段時間才能更新,
較迅速的做法是將測試的DNS設為本機較方便。


以下為SPF 規格的說明:
StatementResultMeaning
+allpassAllow all mail
-allfailOnly allow mail that matches one of the parameters (IPv4, MX, etc) in the record
~allsoftfailAllow mail whether or not it matches the parameters in the record
?allneutralNo policy statement

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

SPF的詳細設定參考以下網站:

http://www.coolsun.idv.tw/modules/xhnewbb/viewtopic.php?topic_id=1423

http://blog.xuite.net/rockmansyz/twblog/115535143-%E5%A6%82%E4%BD%95%E5%9C%A8+DNS+Server+%E8%A8%AD%E5%AE%9A+SPF


http://www.openspf.org/Tools#wizard?mydomain=&x=35&y=6

http://vovo2000.com/phpbb2/viewtopic-336398.html

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

另外,補上須寫信求下榜的....英文公式 A_A


Dear Sir:
We are responsible for the management of the mail server of " XXX.XXX.XXX.XXX " ( 貴公司郵件伺服器IP ).
This server does not provide Open Relay or Open Proxy for unauthenticated users.
We had added several blocking rules for preventing spammers from making use of our server.
We also had changed some improper passwords of user accounts.
Please remove " XXX.XXX.XXX.XXX " ( 
貴公司郵件伺服器IP ) from the black list.
Thanks and best regards,
XXX



2016年2月14日 星期日

Redhat "Resource temporarily unavailable"

最近遇到的一些問題
其中一個為

"Resource temporarily unavailable"

遠端連線時出現訊息為:

利用SU切換帳號則會出現:
"cannot set user id: Resource temporarily unavailable" while trying to login or su as a local user in



"cannot set user id: Resource temporarily unavailable" while trying to login or su as a local user in


Normal user is unable to login on the system with an error "fork: Resource temporarily unavailable"



這個問題來自於用戶的執行程序數量抵達該用戶的上限所致
但,需要釐清其原因是因有需求程式還是應程式的錯誤迴圈導致其資源被用盡。
查看使用程序的數量:

 # ps -u testuser -L | wc -l
    103

將找到的程序刪除
 $  killall xxxx



過陣子再查看是否有清除期程序:

 $ ps ux | wc -l

若是需調整其資源限制則為:
/etc/security/limits.d/90-nproc.conf
增加或修改上限

查看限制
 $ ulimit -u

並可從安全紀錄查看變更記錄
/var/log/secure:



Red Hat Enterprise Linux
https://access.redhat.com/solutions/30316


2016年1月13日 星期三

Windows systeminfo (windows 安裝程式查詢)

最近在有需求要查詢公司電腦配置,
找到這之工具
便寫成bat 檔案處理,順便曬上來看看

===========================
::Systeminfo  version 4
::20151208 By Edwin.Chen


::切時間變數
For /F "tokens=1" %%i in ('DATE/T') do Set Tdate=%%i
For /F "eol=  tokens=1-3 delims=/ " %%a IN ("%Tdate%") DO (SET FDate=%%a%%b%%c)
::變數設定computername為windos內建hostname
Set txt=.csv
Set systeminfo=%FDate%_%computername%_systeminfo%txt%
Set port=%FDate%_%computername%_port%txt%
Set user_bk_u=%FDate%_%computername%_user%txt%
Set user_bk_g=%FDate%_%computername%_Group%txt%
Set Computer_product=%FDate%_%computername%_product%txt%

::利用systeminfo並將輸出格式設定為csv
mkdir C:\systeminfo\
Systeminfo >C:\systeminfo\%systeminfo% /fo csv

::利用netstat - an 查看電腦網路port使用

for /F "tokens=1-4 delims= " %%A in ('netstat -an') do echo %%A,%%B,%%C,%%D>>C:\systeminfo\%port%

::利用net user 查看電腦的使用者帳號
net user >C:\systeminfo\%user_bk_u%
net localgroup >C:\systeminfo\%user_bk_g%

::利用systeminfo的變數輸出電腦安裝的程式清單
WMIC /output:"C:\systeminfo\%Computer_product%" product get name,version /format:csv

echo Systeminfo Get Success!
PAUSE
::end
============================
用systeminfo可以看到電腦安裝的程式,但若是沒有在控制台登錄使用的程式則是無法查看的。