免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 4503 | 回复: 11
打印 上一主题 下一主题

[文本处理] 脚本处理inetd.conf文件 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-10-17 14:45 |只看该作者 |倒序浏览
求助:
安全加固使用脚本处理inetd.conf文件
1)除ftp、shell、login前面不加#号外,其它的都加#注释。
2)已经加#的不作处理。

论坛徽章:
0
2 [报告]
发表于 2014-10-20 15:39 |只看该作者
这答案等的好辛苦!

论坛徽章:
8
戌狗
日期:2014-09-26 16:39:44水瓶座
日期:2014-10-10 02:06:57金牛座
日期:2014-10-11 23:04:042015亚冠之首尔
日期:2015-06-23 15:37:0015-16赛季CBA联赛之天津
日期:2016-01-22 18:58:2915-16赛季CBA联赛之佛山
日期:2016-05-31 19:18:0815-16赛季CBA联赛之同曦
日期:2016-08-10 16:26:3315-16赛季CBA联赛之辽宁
日期:2018-01-10 11:47:40
3 [报告]
发表于 2014-10-20 15:53 |只看该作者
不知所云  如何回答

论坛徽章:
2
处女座
日期:2014-10-24 11:12:372015年辞旧岁徽章
日期:2015-03-03 16:54:15
4 [报告]
发表于 2014-10-20 16:40 |只看该作者
各个脚本例子,说出期望结果

论坛徽章:
3
天蝎座
日期:2013-12-10 19:37:11酉鸡
日期:2014-08-04 20:05:38双鱼座
日期:2014-08-09 21:53:54
5 [报告]
发表于 2014-10-20 16:44 |只看该作者
回复 1# manganese_zh


    inetd.conf这个文件应该在各个发行版当中未必是一样的,你只是说这个文件 还不如直接将里面的内容贴上来,然后把你期望的结果说一下, 这样大家才容易给你解决。

论坛徽章:
0
6 [报告]
发表于 2014-10-20 16:51 |只看该作者
inetd.conf这个看情况区别比较大。你发下你要的结果的详细描述。

论坛徽章:
2
2015年亚洲杯之伊拉克
日期:2015-04-13 10:55:1115-16赛季CBA联赛之山西
日期:2016-05-16 09:54:41
7 [报告]
发表于 2014-10-20 16:52 |只看该作者
manganese_zh 发表于 2014-10-17 14:45
求助:
安全加固使用脚本处理inetd.conf文件
1)除ftp、shell、login前面不加#号外,其它的都加#注释。


这个问的奇怪,是包含ftp、shell、login的是行首字母,还是文本中的单词?

论坛徽章:
0
8 [报告]
发表于 2014-10-21 09:14 |只看该作者
看到大家的回复,我很感激!论坛提问真是一门技术,可惜本人水平不高,所以直接上具体的要求。

/etc/inetd.conf
==============================================================================
## @(#)62        1.17.3.4  src/tcpip/etc/inetd.conf, tcpinet, tcpip61N, 1024A_61N 5/27/10 21:56:33
## IBM_PROLOG_BEGIN_TAG
## This is an automatically generated prolog.
##  
## tcpip61N src/tcpip/etc/inetd.conf 1.17.3.4
##  
## Licensed Materials - Property of IBM
##  
## COPYRIGHT International Business Machines Corp. 1993,2010
## All Rights Reserved
##  
## US Government Users Restricted Rights - Use, duplication or
## disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
##  
## IBM_PROLOG_END_TAG
##
## COMPONENT_NAME: TCPIP inetd.conf
##
## FUNCTIONS:
##
## ORIGINS: 26  27
##
## (C) COPYRIGHT International Business Machines Corp. 1993
## All Rights Reserved
## Licensed Materials - Property of IBM
##
## US Government Users Restricted Rights - Use, duplication or
## disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
##
#######################################################################
##
##                 Internet server configuration database
##
##        Services can be added and deleted by deleting or inserting a
##        comment character (ie. #) at the beginning of a line  If inetd
##        is running under SRC control then the "refresh -s inetd" command
##        needs to be executed for inetd to re-read the inetd.conf file.
##
##        NOTE: The TCP/IP servers do not require SRC and may be started
##        by invoking the service directly (i.e. /etc/inetd). If inetd
##        has been invoked directly, after modifying this file, send a
##        hangup signal, SIGHUP to inetd (ie. kill -1 "pid_of_inetd").
##
##        NOTE: The services with socket type of "sunrpc_tcp" and "sunrpc_udp"
##        require that the portmap daemon be running.
##        Also please use ## to designate comments in this file so that
##         the smit commands can edit this file correctly.
##
##        NOTE: When using IPv6 services, specify "tcp6" or "udp6" for the
##        protocol.  "tcp" and "udp" are interpreted as IPv4.
##
## service  socket  protocol  wait/  user    server    server program
##  name     type             nowait         program     arguments
##
ftp     stream  tcp6    nowait  root    /usr/sbin/ftpd         ftpd
#telnet  stream  tcp6    nowait  root    /usr/sbin/telnetd      telnetd -a
shell   stream  tcp6    nowait  root    /usr/sbin/rshd         rshd
#kshell  stream  tcp     nowait  root    /usr/sbin/krshd        krshd
login   stream  tcp6    nowait  root    /usr/sbin/rlogind      rlogind
#klogin  stream  tcp     nowait  root    /usr/sbin/krlogind     krlogind
exec    stream  tcp6    nowait  root    /usr/sbin/rexecd       rexecd
#comsat dgram   udp     wait    root    /usr/sbin/comsat       comsat
#uucp   stream  tcp     nowait  root    /usr/sbin/uucpd        uucpd
#bootps        dgram   udp     wait    root    /usr/sbin/bootpd       bootpd /etc/bootptab
##
## Finger, systat and netstat give out user information which may be
## valuable to potential "system crackers."  Many sites choose to disable
## some or all of these services to improve security.
##
#finger stream  tcp     nowait  nobody  /usr/sbin/fingerd     fingerd
#systat        stream        tcp        nowait        nobody        /usr/bin/ps           ps -ef
#netstat stream        tcp        nowait        nobody        /usr/bin/netstat      netstat -f inet
#
#tftp         dgram        udp6        SRC        nobody        /usr/sbin/tftpd                tftpd -n
#talk   dgram   udp     wait    root    /usr/sbin/talkd         talkd
ntalk   dgram   udp     wait    root    /usr/sbin/talkd         talkd
#
# rexd uses very minimal authentication and many sites choose to disable
# this service to improve security.
#
#rquotad  sunrpc_udp     udp     wait    root    /usr/sbin/rpc.rquotad rquotad 100011 1
#rexd         sunrpc_tcp        tcp        wait        root        /usr/sbin/rpc.rexd rexd 100017 1
#rstatd         sunrpc_udp        udp        wait        root        /usr/sbin/rpc.rstatd rstatd 100001 1-3
#rusersd sunrpc_udp        udp        wait        root        /usr/lib/netsvc/rusers/rpc.rusersd rusersd 100002 1-2
#rwalld         sunrpc_udp        udp        wait        root        /usr/lib/netsvc/rwall/rpc.rwalld rwalld 100008 1
#sprayd         sunrpc_udp        udp        wait        root        /usr/lib/netsvc/spray/rpc.sprayd sprayd 100012 1
#pcnfsd         sunrpc_udp        udp        wait         root        /usr/sbin/rpc.pcnfsd pcnfsd 150001 1-2
#echo        stream        tcp        nowait        root        internal
#discard        stream        tcp        nowait        root        internal
#chargen        stream        tcp        nowait        root        internal
daytime        stream        tcp        nowait        root        internal
time        stream        tcp        nowait        root        internal
#echo        dgram        udp        wait        root        internal
#discard        dgram        udp        wait        root        internal
#chargen        dgram        udp        wait        root        internal
daytime        dgram        udp        wait        root        internal
time        dgram        udp        wait        root        internal
## The following line is for installing over the network.
#instsrv stream        tcp        nowait        netinst        /u/netinst/bin/instsrv instsrv -r /tmp/netinstalllog /u/netinst/scripts
#imap2        stream        tcp        nowait        root        /usr/sbin/imapd imapd
#pop3        stream        tcp        nowait        root        /usr/sbin/pop3d pop3d
caa_cfg        stream        tcp6        nowait        root        /usr/sbin/clusterconf clusterconf >>/var/adm/ras/clusterconf.log 2>&1
wsmserver        stream        tcp        nowait        root        /usr/websm/bin/wsmserver wsmserver -start
xmquery        dgram        udp        wait        root        /usr/bin/xmtopas xmtopas -p3
#dtspcd        stream        tcp        nowait        root        /usr/dt/bin/dtspcd /usr/dt/bin/dtspcd
cmsd        sunrpc_udp        udp        wait        root        /usr/dt/bin/rpc.cmsd cmsd 100068 2-5
ttdbserver        sunrpc_tcp        tcp        wait        root        /usr/dt/bin/rpc.ttdbserver rpc.ttdbserver 100083 1
#godm        stream        tcp        nowait        root        /usr/es/sbin/cluster/godmd
=================================================================================

处理要求:
1)将/etc/inetd.conf中前面带#号的,不做处理。
例如:
#dtspcd        stream        tcp        nowait        root        /usr/dt/bin/dtspcd /usr/dt/bin/dtspcd
.
.
.
#godm        stream        tcp        nowait        root        /usr/es/sbin/cluster/godmd
2)如果/etc/inetd.conf中前面不带#号的,则需要加#,如
daytime        stream        tcp        nowait        root        internal
cmsd        sunrpc_udp        udp        wait        root        /usr/dt/bin/rpc.cmsd cmsd 100068 2-5
3)但是以下三条不需要加#号
ftp     stream  tcp6    nowait  root    /usr/sbin/ftpd         ftpd
shell   stream  tcp6    nowait  root    /usr/sbin/rshd         rshd
login   stream  tcp6    nowait  root    /usr/sbin/rlogind      rlogind

论坛徽章:
0
9 [报告]
发表于 2014-10-21 09:17 |只看该作者
对于本人提到的要求,前两个我已经写了如下脚本进行处理,并经过实验验证!现在把结果发出来,希望得到大侠们的提正!!
cp -p /etc/inetd.conf /etc/inetd.conf.20141020
cat /etc/inetd.conf|while read line
do
LINENUM=`echo $line|grep -v "^#"|wc -l`
if [ $LINENUM = "0" ]
   then
       echo $line >>/etc/inetd.conf.bak
   else   
       echo $line|sed 's/^/#&/g'>>/etc/inetd.conf.bak
fi
done
#cat /etc/inetd.conf|grep -v "^#"|sed 's/^/#&/g'
cp -p /etc/inetd.conf.bak /etc/inetd.conf
refresh -s inetd

论坛徽章:
24
申猴
日期:2014-10-10 15:56:39射手座
日期:2014-10-10 15:57:18黑曼巴
日期:2018-05-14 11:05:122016科比退役纪念章
日期:2018-05-14 11:05:0715-16赛季CBA联赛之北控
日期:2018-05-14 11:05:0015-16赛季CBA联赛之江苏
日期:2017-02-27 18:11:0715-16赛季CBA联赛之上海
日期:2018-08-15 09:48:5415-16赛季CBA联赛之佛山
日期:2018-07-20 17:14:2315-16赛季CBA联赛之佛山
日期:2019-09-10 18:08:4615-16赛季CBA联赛之山西
日期:2020-03-26 09:40:5115-16赛季CBA联赛之佛山
日期:2020-05-08 09:03:54
10 [报告]
发表于 2014-10-21 09:52 |只看该作者
本帖最后由 chengchow 于 2014-10-21 10:10 编辑

awk '!/^(#|ftp|shell|login)/{$0="#"$0}1' file
sed -r '/^(#|login|shell|ftp)/!s/.*/#&/' file
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP