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 用户能运行的进程个数