linux下tcpwraper訪問控制以及xinetd超級守護進程詳解

2017年2月25日21:29:29 發表評論 4,845 ℃

tcpwraper概念:不同于iptables防火墻網絡訪問控制,iptables可對于tcp/ip進行所有訪問控制并且工作在內核中,而tcpwraper只對部分具有tcp協議的服務進行網絡訪問控制,方便那些對iptables不熟悉的人使用,也就是說,只有那些鏈接libwraper.so庫文件的服務,才受tcpwraper控制。

tcp_wraper

ldd命令查詢服務是否加載動態libwrap.so庫文件,如果加載,則受tcpwraper控制,否則不受控制。

ldd `which app` | grep libwrap

/etc/hosts.allow 白名單

/etc/hosts.deny 黑名單

daemon_list:

sshd:192.168.0.

vsftpd,sshd,in.telnetd:

ALL(所有接受tcp訪問控制的服務)

daemon@host

vsftpd@192.168.0.186

 client_list[:options]

ip

network address

network/mask:只能使用長度格式,10.0.0.0/255.0.0.0

172.16.

HOSTNAME

fqdn

.a.org

MACRO

ALL

LOCAL,KNOWN,UNKNOWN,PARANOID

EXCEPT

sshd僅允許172.16.0.0/16網段訪問:

方法:

1、/etc/hosts.allow

sshd:172.16.

2、/etc/hosts.deny

sshd:ALL

telnet服務不允許172.16.0.0/16 ,但允許172.16.100.200訪問:其客戶端不做控制

方法1:

1、/etc/hosts.allow

in.telnetd: 172.16.100.200

2、/etc/hosts.deny

in.telnetd:172.16.

方法2:

/etc/hosts.deny

in.telnetd:172.16. EXCEPT 172.16.100.200

方法3:

/etc/hosts.allow

in.telnetd:ALL EXCEPT 172.16. EXCEPT 172.16.100.200

/etc/hosts.deny

in.telnetd : ALL

/etc/hosts.allow 

in.telnetd:172.16. :DENY 允許里面可以設置禁止

tcp wrapper macro:  #man 5 hosts_access

%c:client infomation (user@host) 客戶端信息

%s:service info(server@host) 訪問的服務

%h : client hostname 

%p : server pid

in.telnetd:114.80.215.  :spawn echo "`date` ,Login attempt from %c to %s" >> /var/log/tcpwrapper.log

xinetd:超級守護進程

xinetd --> (n個非獨立進程)

/etc/xinetd.conf

配置文件主要有兩部分:

1、全局配置(服務的默認配置)

2、服務配置

service <service_name>

{<attribute>  <assign_op> <value>

...

}

/etc/xinetd.d/*

syslog:專門用于記錄日志的服務(syslogd,klogd)

logtype   FILE /var/log/xinetd.log

訪問控制:

only_from=

IP: 172.16.100.2

NETWORK: 172.16.0.0/16, 172.16.0.0 /255.255.0.0

HOSTNAME: FQDN

DOAMIN: .test.com

no_access= 不允許訪問

時間控制:

access_times=hh:mm-hh:mm

監聽的地址(提供服務的地址)

bind= IP

interface

資源訪問控制:

cps=

控制每秒鐘入站連接的個數

兩個參數:

每秒入站連接數的最大值

臨時禁用的時長

per_source = 每個IP最大請求數

instances= 最大同時連接數

向啟動的server傳遞參數

server_args =

banner=/etc/telent.banner 定義提示信息

port = 端口

練習:設定本地的rsync服務(非獨立守護進程),滿足如下需求:

1、僅監聽在本地172.16.x.1的地址上提供服務

2、僅允許172.16.0.0/16網絡內的主機訪問,但不允許172.16.0.1訪問

3、僅允許同時允許最多3個實例,而且每個IP最多只運行發起兩個鏈接請求

service rsync

{

        disable = no

        flags           = IPv6

        socket_type     = stream

        wait            = no

        user            = root

        server          = /usr/bin/rsync

        server_args     = --daemon

        log_on_failure  += USERID

        only_from      = 172.16.0.0/16

        no_access      = 172.16.0.1

        bind               = 172.16.100.1

        instances       = 3

        per_source     =  2

}

nss

/etc/nsswitch.conf

passwd: nis[NOTFOUND=return] file

SUCCESS

NOTFOUND

UNAVAIL

TRYAGAIN

hostname: file dns

getent命令:獲取庫條目

getent passwd

getent hosts

名稱解析

libnss

PAM

認證

認證本身也可以不用借助名稱解析服務去查找用戶原來存放的密碼

md5:/etc/shadow

mysql

ldap

nis

Kerberos

庫文件路徑/lib[lib64]/security/

/etc/pam.d/service

type control module-path [module-arguments]

service 必須小寫

control

required  [success=ok new_authtok_reqd=ok ignore=ignore defaul=bad]

requisite [success=ok new_authtok_reqd=ok ignore=ignore defaul=die]

sufficient  [success=done new_authtok_reqd=done  defaul=ignore]

optional   [success=ok new_authtok_reqd=ok defaul=ignore]

include

substack

/etc/security/limits.conf 

<item> can be one of the following:

- nofile - max number of open files 能打開的最大文件個數

 - rss - max resident set size (KB) 能使用的最大實際內存集

- as - address space limit (KB) 地址空間限制

- cpu - max CPU time (MIN) 能使用cpu的時間

- nproc - max number of processes 用戶能運行的進程個數

【騰訊云】云服務器、云數據庫、COS、CDN、短信等云產品特惠熱賣中

發表評論

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: