Red Hat Enterprise Linux Network Services and Security Administrator Unit 1 - System Performance and Security

 學習目標


1. 安全警語:不忽略小地方
2. debug 時先 try 簡單的

System Resources as Services
主從架構,「主」是Client,「從」是Server,是4先有Client需求再設計Server
同一台機器可同時擁有Server與Client角色

Security in Principle 安全層次
Physical 實體的安全,機房、螢幕、鍵盤
Local 本地端網路,Local Lan 範圍內的安全
Remote,遠端網路安全
Personnel,User 個人使用者安全
 
Security Policy: the People 管理人需要考慮的地方
1.以規章制度規範使用者行為
2.誰是使用者的最高負責人?
3.誰是發生問題的決策者?
4.什麼時候問題會提昇到法律層面?

Security Policy: the System
1.查看log監看系統的狀態
2.監看頻寬,何時高峰值?何時低峰值?
3.資料備份

Response Strategies
遭到入侵時,不要相信這台機器
1.不要run本機程式
2.使用救援CD開機進入
3.比對本機與遠端log
4.使用read-only的rpm資料庫比對rpm的資料正確性

Fault Analysis: Gathering
# strace command,可以找系統調用的呼叫
# ltrace /path/command,可以找系統調用哪些函式庫
# ldd /bin/ls,查看用到哪些函式庫
# tail -f logfile,一直hold在log的最新一行, ex. # tail -f /var/log/messages
善用 *.debug in syslog
/etc/syslog.conf
*.debug   /var/log/debug  ← debug 的 log 成長很快
也可使用 --debug option in application

Benifits of System Monitoring

Network Monitoring Utilities 網路監控工具
本機查看網路
# ip addr ifconfig 好用
# netstat -lt 
Port scanners 從別台機器掃port,-sS → SYN, -sU → UDP, -sR → RPC, -P0 → 關掉ping, -A 得到系統版本資訊, -v 得到更多資訊,不可隨便掃其他機器,若有必要要告知該系統管理員,否則會被當成駭客擋下列入黑名單,圖形介面的 nmap: nmapfe
# nmap -sS -sU -sR -P0 -A -v 192.168.1.1
Packety sniffers 抓封包軟體
tcpdump、wireshark、ethereal

File System Analysis
查看硬碟容量: # df -h
查看某目錄使用量: # du -sh /root/ or # du -sh /usr/*

Typical Problematic Permissions
駭客有可能侵入系統安裝了額外軟體,所以下面指令可以找出檔案完全不屬於 /etc/passwd 任何人的檔案
# find / \( -nouser -o -nogroup \)
查看 other 可以寫的檔案
# find / -type f -perm -002
查看 other 可以寫的目錄
# find / -type d -perm -2

Monitoring Processes
# top,可以看哪個行程最耗CPU,按 k 可以 kill 行程,按 r 可以 renice 改變行程的優先權
# gnome-system-monitor,圖形介面
# sar,可以統計負載量
其他類似功能的工具:xloadxosview

System Activity Reporting
如果有安裝 sysstat RPM,/etc/cron.d/sysstat 這個排程 sa1 每10分鐘統計一次,sa2 每天統計一次,資料寫進 /var/log/sa 裡,可以使用 sar 指令查看訊息
# iostat,統計對於 IO 的存取
# mpstat,統計CPU運作情況
# vmstat,記憶體、CPU...等等
以上指令可以配合 watch 指令讓畫面hold住不停統計更新,ex. # watch iostat

Managing Processes by Account
PAM 可以控管行程
pam_access.so 可以限制行程可以存取範圍以及帳號,/etc/security/access.conf
pam_time.so,可以限制某個行程可以作用的時間,/etc/security/time.conf
pam_limits.so,可以限制行程對CPU,檔案,記憶體可以取用的資源,/etc/security/limits.conf

System Log Files
Logging Services: syslogd
與 kernel 相關的 log: klogd,會再交給 syslogd
Logging Services:

/var/log/message,系統經常性的 log檔
/var/log/audit/audit.log,SELinux message
/var/log/secure,認證登入log,以及 xinetd services
/var/log/xferlog,FTP(vsftpd) 的 transactions log
/var/log/maillog,mail transactions


Log File Analysis
logwatch,分析 log 的套件,每天會寄報表到 root 信箱



Lab 1 重點

如何得知目前IP? # ip addr or # ifconfnig
設定IP位址的設定檔? /etc/sysconfig/network-scripts/ifcfg-eth0
如何得知目前的 runlevel? # runlevel ,第一個數字是上一次runlevel,第二個數字是目前runlevel
runlevel 的設定位置? /etc/inittab
目前有跑起來的服務? # service --status-all
開機會跑起來的服務? # chkconfig --list
有多少一般User使用者? # getent passwd | awk -F: '$3 >= 500'
如何得知目前登入的使用者是誰? # whoami
目前有什麼人 log in 在系統中? # last

# netstat -ltpn,查看網路狀態
# nmap 192.168.1.99 | grep tcp,掃目前所開的 port
# nmap -sP 192.168.1.0/24,掃整段網路有哪些機器是開著的
# LANG=en ; chkconfig --list | grep $(runlevel | cut -d" " -f2):on,找出目前runlevel一開機會跑的服務
在 /etc/init.d/* 裡面的檔案找一開機會跑起來的服務,開頭為#,空白,接著chkconfig:,空白,接著至少有一個數字(+為至少有一個數字)
#  grep '^#[[:space:]]chkconfig:[[:space:]][[:digit:]]\+' /etc/init.d/*
在 /etc/init.d/* 裡找一開機不會跑起來的服務
#  grep '^#[[:space:]]chkconfig:[[:space:]]-' /etc/init.d/*


讓這台機器可以接收別台機器丟過來的log
# vi /etc/sysconfig/syslog
SYSLOGD_OPTIONS="-r -m 0"
# service syslog restart
接收log機器防火牆要開 514/udp port

把本機log丟到192.168.0.1
# vi /etc/syslog.conf
user.*        @192.168.0.1
# restorecon -R /etc/,重設SELinux資料type
# service syslog restart
# logger -i -t Smallken "this is a test message.",丟log到192.168.0.1












By SmallKen