N22-第十四周作业

系统的INPUT和OUTPUT默认策略为DROP;

~]# iptables -P INPUT DROP
~]# iptables -P OUTPUT DROP

1、限制本地主机的web服务器在周一不允许访问;新请求的速率不能超过100个每秒;web服务器包含了admin字符串的页面不允许访问;web服务器仅允许响应报文离开本机;

~]# iptables -A INPUT  -s 0/0 -p tcp --dport 80 -m time --weekdays 1 -j DROP
~]# iptables -A INPUT  -s 0/0 -p tcp --dport 80 -m string --algo bm --string "admin" -j DROP
~]# iptables -A INPUT  -s 0/0 -p tcp --dport 80 -m limit --limit 100/second  -j ACCEPT
~]# iptables -A OUTPUT  -d 0/0 -p tcp --sport 80  -j ACCEPT

2、在工作时间,即周一到周五的8:30-18:00,开放本机的ftp服务给172.16.0.0网络中的主机访问;数据下载请求的次数每分钟不得超过5个;

~]# iptables -A INPUT -s 172.16.0.0/16 -p tcp --dport 21 -m limit --limit 5/minute -m time --timestart 08:30:00 --timestop 18:00:00 --weekdays 1,2,3,4,5 -j ACCEPT ;放行符合要求的请求报文
~]# iptables -A OUTPUT -d 172.16.0.0/16 -p tcp --sport 21 -j ACCEPT ;放行响应报文

3、开放本机的ssh服务给172.16.x.1-172.16.x.100中的主机,x为你的座位号,新请求建立的速率一分钟不得超过2个;仅允许响应报文通过其服务端口离开本机;

~]# iptables -A INPUT -s 172.16.10.1/16,172.16.10.100/16 -p tcp --dport 22 -m limit --limit 2/minute -j ACCEPT
~]# iptables -A OUTPUT  -d 172.16.10.1/16,172.16.10.100/16 -p tcp --sport 22 -j ACCEPT

4、拒绝TCP标志位全部为1及全部为0的报文访问本机;

~]# iptables -A INPUT -s 0/0 -d localhost -p tcp --tcp-flags ALL ALL -j DROP
~]# iptables -A INPUT -s 0/0 -d localhost -p tcp --tcp-flags ALL NONE -j DROP

5、允许本机ping别的主机;但不开放别的主机ping本机;

~]# iptables -A OUTPUT -s localhost -d 0/0 -p icmp --icmp-type 8 -j ACCEPT ;允许本机向外发送ping请求
~]# iptables -A INPUT -s 0/0 -d localhost -p icmp --icmp-type 0 -j ACCEPT ;放行对方的ping回应报文
或者用 :
~]# iptables -A INPUT -s 0/0 -d localhost -p icmp -m state  --state ESTABLISHED -j ACCEPT ;放行对方的ping回应报文

6、判断下述规则的意义:
  # iptables -N clean_in
在filter表上新建一个自定义链 clean_in
  # iptables -A clean_in -d 255.255.255.255 -p icmp -j DROP
所有发往本地网段的协议类型为icmp协议的报文都会被丢弃
  # iptables -A clean_in -d 172.16.255.255 -p icmp -j DROP
所有发往172.16.0.0/16网段的协议类型为icmp协议的报文都会被丢弃

  # iptables -A clean_in -p tcp ! –syn -m state –state NEW -j DROP
非tcp连接三次握手中第一次连接的报文且状态为NEW的报文都丢弃
  # iptables -A clean_in -p tcp –tcp-flags ALL ALL -j DROP
tcp连接中,传输报文中所有标志位都为1的报文丢弃
  # iptables -A clean_in -p tcp –tcp-flags ALL NONE -j DROP
tcp连接中,传输报文中所有标志位都为0的报文丢弃
  # iptables -A clean_in -d 172.16.100.7 -j RETURN
当报文的目标地址为172.16.110.7时,结束clean_in链上的规则检查,返回调用它的主链

  # iptables -A INPUT -d 172.16.100.7 -j clean_in
INPUT链上引用一条自定义链,当报文目标地址为172.16.100.7时,调用clean_in
  # iptables -A INPUT  -i lo -j ACCEPT
放行从本地回环接口流入的报文
  # iptables -A OUTPUT -o lo -j ACCEPT
放行从本地回环接口流出的报文

  # iptables -A INPUT  -i eth0 -m multiport -p tcp –dports 53,113,135,137,139,445 -j DROP
丢弃从本机eth0网卡流入的报文且目标端口为本机TCP的53,113,135,137,139,445端口
  # iptables -A INPUT  -i eth0 -m multiport -p udp –dports 53,113,135,137,139,445 -j DROP
丢弃从本机eth0网卡流入的报文且目标端口为本机UDP的53,113,135,137,139,445端口
  # iptables -A INPUT  -i eth0 -p udp –dport 1026 -j DROP
丢弃从本机eth0网卡流入的报文且目标端口为本机UDP的1026端口
  # iptables -A INPUT  -i eth0 -m multiport -p tcp –dports 1433,4899 -j DROP
丢弃从本机eth0网卡流入的报文且目标端口为本机TCP的1433,4899端口

  # iptables -A INPUT  -p icmp -m limit –limit 10/second -j ACCEPT
本机1秒内最多允许10次的icmp请求进入

7、通过tcp_wrapper控制vsftpd仅允许192.168.1.0/255.255.255.0网络中的主机访问,但192.168.1.57除外;对所被被拒绝的访问尝试都记录在/var/log/tcp_wrapper.log日志文件中;

  先编辑/etc/hosts.allow编辑允许访问FTP服务的白名单:
           

[root@CentOS7 ~]# tail -n 1 /etc/hosts.allow
               vsftpd: 192.168.1. EXCEPT 192.168.1.57

  再编辑/etc/hosts.deny编辑黑名单为除白名单外的所有人,并记录访问拒绝日志:
       

[root@CentOS7 ~]# tail -n 1 /etc/hosts.deny
          vsftpd: ALL :spawn echo `date` login attempt denied from %c to %s. >> /var/log/tcp_wrapper.log

 

  FTP服务器地址192.168.1.67 ,分别以客户端192.168.1.57和192.168.1.58尝试访问:
       

~]# ifconfig 
          eth0      Link encap:Ethernet  HWaddr 00:0C:29:69:9A:88  
          inet addr:192.168.1.57  Bcast:192.168.1.255  Mask:255.255.255.0
  [root@CentOS6 ~]# ftp 192.168.1.67
Connected to 192.168.1.67 (192.168.1.67).
421 Service not available.
ftp> ls
Not connected.
ftp> exit

~]# ifconfig 
          eth0      Link encap:Ethernet  HWaddr 00:0C:29:69:9A:88  
          inet addr:192.168.1.58  Bcast:192.168.1.255  Mask:255.255.255.0
~]# ftp 192.168.1.67
Connected to 192.168.1.67 (192.168.1.67).
220 (vsFTPd 3.0.2)
Name (192.168.1.67:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (192,168,1,67,64,8).
150 Here comes the directory listing.
drwxr-xr-x    2 0        0              21 Nov 09 07:56 pub
drwxr-xr-x    2 14       0               6 Nov 09 09:46 upload
226 Directory send OK.
ftp> cd pub
250-you can download company information from here !
250 Directory successfully changed.
ftp> exit
221 Goodbye.

查看tcp_wrapper日志文件:

~]# cat /var/log/tcp_wrapper.log
2016年 11月 21日 星期一 09:09:41 CST login attempt denied from 192.168.1.57 to vsftpd@192.168.1.67.

原创文章,作者:上海-brown,如若转载,请注明出处:http://www.178linux.com/67083

(0)
上海-brown上海-brown
上一篇 2017-03-15 19:09
下一篇 2017-03-15 19:09

相关推荐

  • 网络基础

    什么是计算机网络? 是指将地理位置不同的具有独立功能的多台计算机及外部设备,借助于某种网络介质连接起来,实现资源共享和信息传递的计算机系统 计算机网络的特点? 1、能实现数据信息的快速传输和集中处理 2、可共享计算机系统资源 3、提高了计算机的可靠性及可用性 4、能均衡负载互相协作 常见的网络应用程序 Web 浏览器(Chrome、IE、Firef…

    Linux干货 2016-09-09
  • SElinux

    selinux  配置文件 修改   就要重启 targeted:用来保护常见的网路服务,仅有限进程受到selinux控制,只监控容易被入侵的进程。 targeted  慢慢完善的法律 系统默认使用   targeted     CENTOS6 CENTOS7 ZAI &nbsp…

    Linux干货 2016-09-14
  • 了解 linux

    计算机组成     CPU  ——> central processing unit, 运算器&控制器             主要工作管理和运算;   &…

    Linux干货 2016-09-17
  • 文本处理工具练习题(包含正则)

    正则练习题(包含文本处理练习题) 问题 找出ifconfig命令结果中本机的所有IPv4地址  查出分区空间使用率的最大百分比值 查出用户UID最大值的用户名、UID及shell类型 查出/tmp的权限,以数字方式显示 统计当前连接本机的每个远程主机IP的连接数,并按从大 到小排序 答; ifconfig | grep -o '[0-9]\…

    Linux干货 2016-08-08
  • 处理交换文件和分区

    处理交换文件和分区 交换分区是系统RAM的补充   基本设置包括:  1 创建交换分区或者文件  2 使用mkswap写入特殊签名  3 在/etc/fstab文件中添加适当的条目  4 使用swapon -a 激活交换空间 挂载交换分区  启用:swapon swapon [OPTION]……

    Linux干货 2016-09-01
  • 基于nginx实现7层http的负载均衡

    一、实验环境实验环境为三台服务器:1. nginx负载均衡器1. 内网ip:192.168.11.1002. 外网ip:172.16.251.892. 提供网页服务的RS-1服务器:192.168.11.2013. 提供网页服务的RS-2服务器:192.168.11.2024. 拓扑如下:二、实验配置后台服务器配置:1. 后台提供网页服务的两台服务器配置:y…

    Linux干货 2017-06-29