码迷,mamicode.com
首页 > 其他好文 > 详细

马哥第七次作业

时间:2017-04-16 23:14:27      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:作业


系统的INPUT和OUTPUT默认策略为DROP,请完成以下关于iptables的题目;

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


答:


iptables -A INPUT -d 192.168.2.35 -p tcp --dport 80 -m time --weekdays Mon -m limit --limit 100/second -m string --algo kmp --string "admin" -j DROP


iptables -A OUTPUT -m state --state ESTABLISED -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 time --timestart 08:30 --timestop 18:00 --weekdays Mon,Tue,Wed,Thu,Fri -m limit --limit 5/minute -j ACCEPT

# iptables -A OUTPUT -d 172.16.0.0/16 -p tcp --sport 20 -j ACCEPT

# iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT



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


答:


# iptables -A INPUT -d 172.16.6.10 -p tcp --dport 22 -m iprange --src-range 172.16.6.1-192.168.6.100 -m limit --limit 2/min -j ACCEPT 

# iptables -A OUTPUT -s 172.16.6.10 -p tcp --sport 22 -m iprange --dst-range 172.16.6.1-192.168.6.100 -m state --state ESTABLISHED -j ACCEPT



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


答:


#iptables -A INPUT -d 192.168.2.35 -p tcp --tcp-flags ALL ALL -j DROP

#iptables -A INPUT -d 192.168.2.35 -p tcp --tcp-flags ALL NONE -j DROP



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


答:


#iptables -A OUTPUT -s 192.168.2.35 -p icmp --icmp-type 8 -j ACCEPT

#iptables -A INPUT -d 192.168.2.35 -p icmp --icmp-type 0 -j DROP


6、判断下述规则的意义:


答:


# iptables -N clean_in

创建自定义链 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报文中syn标志不为1,链接状态为新建链接的包

# 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

在结束clean_in链过滤后回到主链


# iptables -A INPUT -d 172.16.100.7 -j clean_in

目标为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接口进入,目标端口为:53,113,135,137,139,445的TCP报文

# iptables -A INPUT  -i eth0 -m multiport -p udp --dports 53,113,135,137,139,445 -j DROP

丢弃从eth0接口进入,目标端口为:53,113,135,137,139,445的UDP报文

# iptables -A INPUT  -i eth0 -p udp --dport 1026 -j DROP

丢弃从eth0接口进入,目标端口为1026的UDP报文

# iptables -A INPUT  -i eth0 -m multiport -p tcp --dports 1433,4899 -j DROP

丢弃从eth0接口进入,目标端口为:1433,4899的TCP报文

# iptables -A INPUT  -p icmp -m limit --limit 10/second -j ACCEPT

限定ping速率为每秒10次



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


答:


[root@ns1 ~]# vim /etc/hosts.allow 

vsftpd:172.16.0.0/255.255.0.0 EXCEPT 172.16.100.3


[root@ns1 ~]# vim /etc/hosts.deny 

vsftpd:ALL :spawn /bin/echo `date` login attempt from %c to %s, %d >> /var/log/tcp_wrapper.log



8、删除/boot/grub/grub.conf文件中所有行的行首的空白字符;


答:

查看文件内容:


[root@www grub]# cat grub.conf 

# grub.conf generated by anaconda

#

# Note that you do not have to rerun grub after making changes to this file

# NOTICE:  You have a /boot partition.  This means that

#          all kernel and initrd paths are relative to /boot/, eg.

#          root (hd0,0)

#          kernel /vmlinuz-version ro root=/dev/sda2

#          initrd /initrd-[generic-]version.img

#boot=/dev/sda

default=0

timeout=5

splashimage=(hd0,0)/grub/splash.xpm.gz

hiddenmenu

title CentOS 6 (2.6.32-642.el6.x86_64)

root (hd0,0)

kernel /vmlinuz-2.6.32-642.el6.x86_64 ro root=UUID=a55b9a39-c9a3-4908-aaed-2b930a8344cc rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet

initrd /initramfs-2.6.32-642.el6.x86_64.img



使用sed命令删除grub.conf文件中所有行的行首的空白字符(使用 -i选项可直接修原文件,此处只作演示。)


[root@www grub]# sed  ‘s@^[[:space:]]\+@@‘ grub.conf 

# grub.conf generated by anaconda

#

# Note that you do not have to rerun grub after making changes to this file

# NOTICE:  You have a /boot partition.  This means that

#          all kernel and initrd paths are relative to /boot/, eg.

#          root (hd0,0)

#          kernel /vmlinuz-version ro root=/dev/sda2

#          initrd /initrd-[generic-]version.img

#boot=/dev/sda

default=0

timeout=5

splashimage=(hd0,0)/grub/splash.xpm.gz

hiddenmenu

title CentOS 6 (2.6.32-642.el6.x86_64)

root (hd0,0)

kernel /vmlinuz-2.6.32-642.el6.x86_64 ro root=UUID=a55b9a39-c9a3-4908-aaed-2b930a8344cc rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet

initrd /initramfs-2.6.32-642.el6.x86_64.img


9、删除/etc/fstab文件中所有以#开头,后跟至少一个空白字符的行的行首的#和空白字符;


答:

查看文件内容:


[root@www etc]# cat fstab 


#

# /etc/fstab

# Created by anaconda on Tue Mar 28 19:48:55 2017

#

# Accessible filesystems, by reference, are maintained under ‘/dev/disk‘

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

UUID=a55b9a39-c9a3-4908-aaed-2b930a8344cc /                       ext4    defaults        1 1

UUID=53a40663-7787-4f8d-8aea-424359f4267e /boot                   ext4    defaults        1 2

UUID=5e15512e-d152-4e2e-ba1a-8f1235466b70 swap                    swap    defaults        0 0

tmpfs                   /dev/shm                tmpfs   defaults        0 0

devpts                  /dev/pts                devpts  gid=5,mode=620  0 0

sysfs                   /sys                    sysfs   defaults        0 0

proc                    /proc                   proc    defaults        0 0


使用sed命令删除:


[root@www etc]# sed  ‘s@^#[[:space:]]\+@@‘ fstab 


#

/etc/fstab

Created by anaconda on Tue Mar 28 19:48:55 2017

#

Accessible filesystems, by reference, are maintained under ‘/dev/disk‘

See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

UUID=a55b9a39-c9a3-4908-aaed-2b930a8344cc /                       ext4    defaults        1 1

UUID=53a40663-7787-4f8d-8aea-424359f4267e /boot                   ext4    defaults        1 2

UUID=5e15512e-d152-4e2e-ba1a-8f1235466b70 swap                    swap    defaults        0 0

tmpfs                   /dev/shm                tmpfs   defaults        0 0

devpts                  /dev/pts                devpts  gid=5,mode=620  0 0

sysfs                   /sys                    sysfs   defaults        0 0

proc                    /proc                   proc    defaults        0 0


10、把/etc/fstab文件的奇数行另存为/tmp/fstab.3;


答:


[root@www etc]# sed ‘n;d‘ fstab > /tmp/fstab.3

[root@www etc]# cat /tmp/fstab.3 


# /etc/fstab

#

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

UUID=a55b9a39-c9a3-4908-aaed-2b930a8344cc /                       ext4    defaults        1 1

UUID=5e15512e-d152-4e2e-ba1a-8f1235466b70 swap                    swap    defaults        0 0

devpts                  /dev/pts                devpts  gid=5,mode=620  0 0

proc                    /proc                   proc    defaults        0 0


11、echo一个文件路径给sed命令,取出其基名;进一步地,取出其路径名;


答:


取出其基名:

[root@www ~]# echo "/usr/local/sbin" | sed ‘s#/.*/##‘

sbin


取出其路径名:

[root@www ~]# echo "/usr/local/sbin" | sed ‘s#[^/]\+/\?$##‘

/usr/local/



12、统计当前系统上所有tcp连接的各种状态的个数;


答:


[root@www ~]# netstat -nat | awk ‘FNR>2{print $NF}‘ | sort | uniq -c

      3 ESTABLISHED

     10 LISTEN



13、统计指定的web访问日志中各ip的资源访问次数:

答:


[root@localhost ~]# cat /var/log/httpd/www2.access | cut -d‘ ‘ -f1 | sort | uniq -c

    119 192.168.1.102

      2 192.168.1.106


14、授权centos用户可以运行fdisk命令完成磁盘管理,以及使用mkfs或mke2fs实现文件系统管理;


答:


[root@www etc]# visudo 

centos ALL=(root) /sbin/fdisk, /sbin/mke2fs



15、授权gentoo用户可以运行逻辑卷管理的相关命令;


答:

[root@www etc]# visudo 

gentoo ALL=(root) /sbin/lvm


16、基于pam_time.so模块,限制用户通过sshd服务远程登录只能在工作时间进行;


答:


[root@www ~]# vim /etc/pam.d/sshd

在account required pam_nologin.so上插入一行:


account required pam_time.so


[root@www ~]# vim /etc/security/time.conf

*;*;*;MoTuWeThFr0800-1700


17、基于pam_listfile.so模块,定义仅某些用户,或某些组内的用户可登录系统;



答:



[root@www ~]# vim /etc/AllowedUser

[root@www ~]# chmod 600 /etc/AllowedUser 


再编辑/etc/pam.d/sshd文件,加入以下一行内容:

auth       required     pam_listfile.so item=user sense=allow file=/etc/AllowedUser onerr=succeed


马哥第七次作业

标签:作业

原文地址:http://2834473.blog.51cto.com/2824473/1916476

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!