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

相关推荐

  • 马哥教育网络班21期-第4周课程练习

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。     cp -R /etc/skel /home/tuser1     chmod g-rwx,o-r…

    Linux干货 2016-08-03
  • 浅谈linux基础知识(二)

    1、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示 文件管理工具:cp,mv,rm cp命令:copy 源文件,目标文件 单源复制:cp[OPTION]… [-T] SOURCE DEST 多源复制: cp[OPTION]… SOURCE… DIRECTORY cp[OPT…

    Linux干货 2016-10-12
  • 第七周作业

    1、创建一个10G分区,并格式为ext4文件系统; (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl; ]#mke2fs -t ext4 -b 2048 -L MYDATA -m 2 O acl /dev/sda1 (2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件…

    Linux干货 2017-03-11
  • Linux程序包管理rpm、yum、源码编译

    概述:     众所周知,Linux操作系统本身,必须要借助额外的一些软件,才能完成某些应用的,操作系统如果没有应用程序的填充,就无法创造出生产力,这样即使再完美的操作系统,也毫无用处。那么本章就简要介绍一下Linux系统上对程序包的管理,分为以下三个部分:     1、程序包的…

    Linux干货 2016-08-24
  • Linux 第四天: (07月28日) Linux文件管理

    Linux 第四天: (07月28日) Linux文件管理         rootfs 根目录文件系统 root filesystemLSB  Linux Standard BaseFHS 文件系统分层结构 Filesystem Hierarchy Standard     蓝色表示 目…

    Linux干货 2016-08-08
  • 笔记三、如何在VMWare Workstation中安装CentOS 7

    一、准备工作     1.1 安装VMWare WorkStatrion     1.2 准备好CentOS 7 镜像包     http://www.centoscn.com/CentosSoft/iso/    CenOS7下载地址 二…

    2017-02-23