linux下tcpwraper訪問控制以及xinetd超級(jí)守護(hù)進(jìn)程詳解

2017年2月25日21:29:29 發(fā)表評(píng)論 4,747 ℃

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

tcp_wraper

ldd命令查詢服務(wù)是否加載動(dòng)態(tài)libwrap.so庫(kù)文件,如果加載,則受tcpwraper控制,否則不受控制。

ldd `which app` | grep libwrap

/etc/hosts.allow 白名單

/etc/hosts.deny 黑名單

daemon_list:

sshd:192.168.0.

vsftpd,sshd,in.telnetd:

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

daemon@host

vsftpd@192.168.0.186

 client_list[:options]

ip

network address

network/mask:只能使用長(zhǎng)度格式,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網(wǎng)段訪問:

方法:

1、/etc/hosts.allow

sshd:172.16.

2、/etc/hosts.deny

sshd:ALL

telnet服務(wù)不允許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 允許里面可以設(shè)置禁止

tcp wrapper macro:  #man 5 hosts_access

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

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

%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:超級(jí)守護(hù)進(jìn)程

xinetd --> (n個(gè)非獨(dú)立進(jìn)程)

/etc/xinetd.conf

配置文件主要有兩部分:

1、全局配置(服務(wù)的默認(rèn)配置)

2、服務(wù)配置

service <service_name>

{<attribute>  <assign_op> <value>

...

}

/etc/xinetd.d/*

syslog:專門用于記錄日志的服務(wù)(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= 不允許訪問

時(shí)間控制:

access_times=hh:mm-hh:mm

監(jiān)聽的地址(提供服務(wù)的地址)

bind= IP

interface

資源訪問控制:

cps=

控制每秒鐘入站連接的個(gè)數(shù)

兩個(gè)參數(shù):

每秒入站連接數(shù)的最大值

臨時(shí)禁用的時(shí)長(zhǎng)

per_source = 每個(gè)IP最大請(qǐng)求數(shù)

instances= 最大同時(shí)連接數(shù)

向啟動(dòng)的server傳遞參數(shù)

server_args =

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

port = 端口

練習(xí):設(shè)定本地的rsync服務(wù)(非獨(dú)立守護(hù)進(jìn)程),滿足如下需求:

1、僅監(jiān)聽在本地172.16.x.1的地址上提供服務(wù)

2、僅允許172.16.0.0/16網(wǎng)絡(luò)內(nèi)的主機(jī)訪問,但不允許172.16.0.1訪問

3、僅允許同時(shí)允許最多3個(gè)實(shí)例,而且每個(gè)IP最多只運(yùn)行發(fā)起兩個(gè)鏈接請(qǐng)求

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命令:獲取庫(kù)條目

getent passwd

getent hosts

名稱解析

libnss

PAM

認(rèn)證

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

md5:/etc/shadow

mysql

ldap

nis

Kerberos

庫(kù)文件路徑/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 能打開的最大文件個(gè)數(shù)

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

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

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

- nproc - max number of processes 用戶能運(yùn)行的進(jìn)程個(gè)數(shù)

【騰訊云】云服務(wù)器、云數(shù)據(jù)庫(kù)、COS、CDN、短信等云產(chǎn)品特惠熱賣中

發(fā)表評(píng)論

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