- 論壇徽章:
- 6
|
網(wǎng)絡(luò)服務(wù)安全
摘要
samba,ftp,apache,ipchains(2002-07-19 16:18:41)
--------------------------------------------------------------------------------
By shokme
1.使用ipchains作防火墻和路由(包過濾和tcp/ip參考知識)
ipchains適用于2.2內(nèi)核和2.4內(nèi)核
1.1 與ipchains防火墻相關(guān)的內(nèi)核選項(xiàng)(2.2內(nèi)核)
CONFIG_FIREWALL
CONFIG_IP_FIREWALL 激活I(lǐng)P包過濾
CONFIG_IP_MASQUERADE 路由器 MASQ
CONFIG_IP_MASQUERADE_IMCP
CONFIG_IP_ADVANCED_ROUTER 高級路由
CONFIG_IP_TRANSPARENT_PROXY 將指向遠(yuǎn)程主機(jī)的局域網(wǎng)流量重
定向到本地端口的代理服務(wù)起
(PROXY)REDIRECT
注意:IPCHAINS規(guī)則只適用于tcp/ip,無法阻止同一個接口上基于ipx或者appletack的攻擊
1.2 理解IPCHAINS的七個對象
ACCEPT,DENY,REJECT,MASQ,RETURN(相當(dāng)于鏈的子程序調(diào)用的回歸),user chain
1.3 ipchains基本參數(shù)
-A,-D,-R,-I,-L,-F,-N,-X,-P,-C
實(shí)例 動手操作
#ipchains -A input -s 0/0 -d 192.168.0.1 -j ACCEPT
#ipchains -R input 1 -s 192.168.0.2 -d 192.168.0.1 -j DENY
#ipchains -I input 1 -s 0/0 -d 0/0 -j REJECT
如果是遠(yuǎn)程登陸,會出現(xiàn)。。。斷線的情況
#ipchains -nL
#ipchains -N mychain
#ipchains -F input
#ipchains -F
#ipchains -X
#ipchains -P input DENY
#ipchains -C input -i eth0 -s 192.168.1.2 www -d 192.168.1.1 www -p tcp
#ipchains -D input 1
1.4 ipchains基本選項(xiàng)
-p [!]protocol
-s [!]addr [[!]port]
-d [!]addr [[!]port]
-i [!]interface
-j target
-l 當(dāng)匹配時,該規(guī)則紀(jì)錄有關(guān)包的信息
[!]-y 該規(guī)則應(yīng)該僅匹配正在初始化連接的tcp包。
1.5 example
a.關(guān)于domain的設(shè)置注意tcp和udp
#ipchains -A input -p tcp -s $DNS domain -j ACCEPT
#ipchains -A input -p udp -s $DNS domain -j ACCEPT
b.設(shè)置ip masquerade時不要忘記打開ip轉(zhuǎn)發(fā)
可以在/etc/rc.d/rc.local腳本中寫入 #echo 1 >; /proc/sys/net/ipv4/ip_forward,否則重起后,ip_forward又變成0
#ipchains -A input -i eth1 -s $INT -j ACCEPT
#ipchains -A forward -s $INT -j MASQ
#ipchains -A forward -j DENY -l 禁止并紀(jì)錄其他轉(zhuǎn)發(fā)企圖
注意$INT的范圍:92.168.1.0/24 (192.168.1.1-192.168.1.254);主機(jī)為192.168.1.1、192.168.0.0/16(192.168.1.1-192.168.255.254)
c.允許內(nèi)部網(wǎng)絡(luò)訪問外部ftp服務(wù)
#ipchains -A input -p tcp -s 0/0 ftp-data -j ACCEPT
#ipchains -A input -p tcp -s 0/0 ftp -j ACCEPT
介紹:port forwarding端口轉(zhuǎn)發(fā),允許到達(dá)外部接口的網(wǎng)絡(luò)接口的數(shù)據(jù)包轉(zhuǎn)發(fā)到內(nèi)部網(wǎng)相同端口的 一種方法,
允許在防火墻后面提供網(wǎng)絡(luò)服務(wù)?梢酝ㄟ^ipchains和ipmasqadm(ip偽裝工具管理)來實(shí)現(xiàn)。
語法為:ipmasqadm portfw -a -P tcp -L $myip port -R server_ip port
具體為:#ipmasqadm portfw -a -P tcp -L $myip 80 -R 192.168.1.2 80
2.保護(hù)Apache,Ftp,Samba服務(wù)
2.1 核心配置文件的位置
/etc/httpd/conf/httpd.conf、resourceconfig、conf/srm.conf、accessconfig
conf/access.conf定義了配置文件的位置,現(xiàn)在已經(jīng)不使用了;
maxclients 100
不可以太大,也不可以太小,根據(jù)服務(wù)器配置和客戶數(shù)量綜合決定
port 80
修改為別的端口時,最好不要與/etc/services中的端口重復(fù)
user apache
group apache
指定運(yùn)行httpd進(jìn)程的用戶和組的所有權(quán),不要以root身份運(yùn)行httpd進(jìn)程
userdir public_html
userdir disabled root
如果只允許少數(shù)用戶的web空間,如下作
userdir disabled
userdir enabled kim ben jack
userdir disabled
例如如下配置:
userdir public_html
#userdir disabled
#userdir enabled ben
AllowOverride FileInfo AuthConfig Limit
Options MultiViews Indexes
SymLinksIfOwnerMatch IncludesNoExec
Order allow,deny
Allow from all
Order deny,allow
Deny from all
注意修改/home/*的目錄屬性為711
2.2 全局日志指令
好的日志對于好的安全性非常關(guān)鍵,尤其是高流量的服務(wù)器時。
ErrorLog logs/error_log
#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn
#產(chǎn)生最少的日志流量,不會錯過任何危險的情況
LogFormat "%h %l %u %t "%r" %>;s %b" common
#logformat的特殊值
# %a 遠(yuǎn)程用戶ip,
# %A 本地httpd服務(wù)器的ip,
# %f 傳送的文件名,
# %h 遠(yuǎn)程主機(jī),
# %m 請求方式
# %l identd給出的遠(yuǎn)程名,
# %p連接httpd的端口,
# %P 請求的httpd進(jìn)程,
# %t 時間,
# %T 服務(wù)請求時間
CustomLog logs/access_log combined
2.3 作用域和其他作用域
order deny,allow
deny from all
#例外如下
order allow,deny
allow from all
#例如:allow from all,
# allow from 10.0.0.0/8,
# allow from 10. ,
# allow from .china.com
# 如果把private.txt改成index.html會怎么樣?
order deny,allow
deny from all
a.4 驗(yàn)證
authtype basic
authname "private areas"
authuserfile /etc/httpd/conf/privatepasswd
require valid-user
創(chuàng)建驗(yàn)證數(shù)據(jù)庫
#htpasswd -bc /etc/httpd/conf/privatepasswd ben ben
#htpasswd -b /etc/httpd/conf/privatepasswd kim
新密碼:kim
重新輸入密碼:kim
還有一種方式創(chuàng)建.htaccess文件,使用accessfilename .htaccess選項(xiàng),格式為:
authtype basic
authname "student club"
authuserfile /etc/httpd/conf/studentclub
require valie-user
另外:用mysql+php來驗(yàn)證網(wǎng)絡(luò)服務(wù),學(xué)有余力的學(xué)員可以try
3.ftp服務(wù)屬于xinetd服務(wù)
3.1 禁止你名ftp登陸
/etc/passwd和/etc/shadow中刪除ftp
/etc/ftpusers中加入ftp或者anonymous
3.2 /etc/ftpaccess配置文件
loginfails 3
greeting brief
# 顯示簡短的消息給用戶,忽略了版本信息
# 220 liwei FTP server (Version wu-2.6.1-1 ready.
# Turn on logging to /var/log/xferlog
log transfers anonymous,guest,real inbound,outbound
# 紀(jì)錄所有種類的用戶初始化傳輸
log commands anonymous,guest,real
# 紀(jì)錄所有種類的用戶輸入的所有命令
chmod no anonymous,guest
delete no anonymous,guest
overwrite no anonymous,guest
rewrite no anonymous,guest
umask no anonymous,guest
passwd-check rfc822 enforce
# 強(qiáng)制使用合法的email賬號作為匿名ftp登陸的密碼
noretrieve /etc/ /home/*/.htaccess core
# 以下內(nèi)容為復(fù)習(xí)
class all real,guest,anonymous *
limit all 20 Any /etc/mesg
upload /var/ftp * no
upload /var/ftp /pub/imcoming yes ftp daemon 0600 dirs
alias inc /pub/incoming
email admin@localhost
restricted-uid %501-510
# 流量限制自己。。。
throughput /var/ftp * * oo - *
throughput /var/ftp /pub* * 2000 0.5 *
throughput /var/ftp /pub* readme oo - *
throughput /var/ftp /pub* * oo - *.fudan.edu.cn
cdpath /pub
# 指定優(yōu)先搜尋路經(jīng),例如cd abc,會優(yōu)先尋找/pub下的abc
cdpath /
# 然后再是/目錄下的abc
3.3命令(客戶端命令略)
ftpshut now
ftpshut 1001
ftpshut +20
ftpshut -l 30 -d 10 1700 "ftp is shutting down "
ftprestart
對/etc/shutmsg和/var/ftp/shutmsg文件刪除操作
ftpwho
ftpcount
匿名上傳目錄權(quán)限位chmod 733 incoming
4.samba的安全
不屬于xinetd服務(wù),但是samba的管理工具swat屬于xinetd服務(wù)
swat(samba web administration tool) 啟動swat不必啟動apache服務(wù)器,swat有自己的內(nèi)嵌的web服務(wù)器
因?yàn)閟amba不使用加密連接,所以不要遠(yuǎn)程使用swat工具
包過濾
#grep netbios /etc/services
允許外部某個主機(jī)訪問內(nèi)部samba服務(wù),通過ipchains建立如下規(guī)則
#ipchains -A input -p tcp -s trusted.ext.system.ip
-d myip 137:139 -j ACCEPT
#ipchains -A input -p udp -s trusted.ext.system.ip
-d myip 137:139 -j ACCEPT
#ipchains -A input -i !lo -d myip 137:139 -j DENY -l
通過iptable實(shí)現(xiàn)如下(略)
#iptables -t filter -A INPUT -p tcp -s trusted.ext.system.ip
-d myip 137:139 -j ACCEPT
#iptables -t filter -A INPUT -p udp -s trusted.ext.system.ip
-d myip 137:139 -j ACCEPT
#iptables -t filter -A INPUT -i !lo -d myip 137:139 -j DROP |
|