tcpwrapper
這片文章介紹以下tcpwrapper(tcp的包裝器)。
tcpwrapper的作用是對基於tcp的程序進行安全控制。它通過使用/usr/sbin/tcpd這樣一個進程來代爲監聽任何一個使用了tcpwrapper的發起連接的tcp請求。假設sshd接受tcpwrapper的驗證,當有一個連接發起ssh連接時先有tcpwrapper進行身份驗證,如果通過了驗證,則將連接轉向sshd,否則直接拒絕連接。
tcpwrapper只能爲tcp的連接進行驗證。它實際是通過庫文件libwrap.so來實現控制的,並不是所有的tcp連接都接受其控制。查看的方法是:1.如果是動態鏈接的話用 ldd `which COMMAND` | grep libwrap.so 如果結果有着庫文件的話說明其接受tcpwrapper的控制;2.如果是靜態連接的方式使用命令 strings `which COMMAND` grep hosts 如果結果有hosts.allow和hosts.deny這兩個文件說明是接受其控制。當對非獨立守護進程檢查的時候需對xinetd進行檢查。
tcpwrapper工作在傳輸層。其配置文件爲/etc/hosts.allow和/etc/hosts.deny當服務發起的時候首先/etc/hosts.allowà/etc/hosts.denyà默認是allow。所以如果只想接受某個固定的訪問,首先在allow中添加用戶,在deny中拒絕所有。
配置文件的語法格式 deamon: clients:[options]
如果有兩塊網卡可以在deamon@IP 或是hostname,這樣可以實現只對一塊兒網卡的控制。切記deamon必須是可執行程序的二進制的名字,而不是進程名。如sshd是有OpenSSH提供的但定義的時候必須寫sshd,再如telnet服務在寫的時候必須寫in.telnetd等。這可以在其啓動腳本中找到。因爲它只是對二進制本身做控制
eg:[email protected]:192.168.0.172
在配置文件中有以下幾個關於clients本地宏定義:
對於deamon的宏定義只有ALL一個表示多有接受控制的
對clients的表示有
1. IP 192.168.0.172
2. NAME www.zlyblog.com
3. netmask 192.168.0.0/255.255.255.0
4. NETGROUP @notexample(通過nis域控制)
其主機名後可以加EXCEPT的選項:EXCEPT eg:sshd 10.0.0.0/255.255.0.0 EXCEPT 10.0.0.100表示允許10.0.0網段中除了10.0.0.100的主機的訪問
deny eg 在allow中in.telnetd :192.168.0.:deny表示拒絕這個網段的主機
spawn 表示當tcpwrapper檢查到一個訪問的時候,執行的一個程序。eg:記錄日誌 eg:in.telnetd:192.168.0. :spawn echo “Login attempt from %c to %s “ >> /var/log/tcpwrapper.log 表示當有一個訪問的時候記錄一下日誌
其中如上的%c %s我們可以通過man 5 hosts_access 來查看
%a (%A) The client (server) host address.
%c Client information: user@host, user@address, a host name, or just an address, depending on how much information is available.
%h (%H) The client (server) host name or address, if the host name is unavailable.
%n (%N) The client (server) host name (or "unknown" or "paranoid").
%s Server information: daemon@host, daemon@address, or just a dae- mon name, depending on how much information is available.
%u The client user name (or "unknown").