tcp_wrappers의 설정
<p>
<span class="ct"><b>|</b></span> <br /> <a href="/post/postList.jsp?blogId=deepinheart&categoryNo=10"><span class="ct">Security</span><a /></td>
<p>
</p>
<td align="right" class="eng" style="padding: 0 10 0 0">
2004/02/16 17:34
</td>
<p>
</tr>
<p>
</p>
<tr>
<td colspan="2" background="http://blogimgs.naver.com/imgs/bg_dot.gif" height="1">
</td>
</tr>
<p>
</p>
<tr>
</p>
<td style="padding: 0 10 0 0" align="right" colspan="2" height="20">
<a href="http://blog.naver.com/deepinheart/20000904743" target="_parent"><span class="eng_gray">http://blog.naver.com/deepinheart/20000904743</span></a>
</td>
<p>
</tr>
<p>
</p>
<tr>
<td align="right" colspan="2" style="padding: 0 10 0 0" >
</td>
</tr>
<p>
</p>
<tr>
<td style='padding: 15 10 35 10' colspan='2' width='572' class='view'>
<P>
<B><FONT color=blue><tcp_wrappers의 설정></FONT></B>
</P>
<br />
<P>
<FONT face=굴림 size=2><B>1. hosts.allow 파일의 생성</B></FONT>
</P>
<br />
<P>
<FONT face=굴림 size=2>이제는 각 서비스 별로 서비스를 열고 닫을 호스트를 정해준다. 이는 hosts.allow hosts.deny를 수정하면 된다. 파일을 수정하는 방법은 다음과 같다. <BR /></FONT>
</P>
<br /> <TABLE cellSpacing=0 cellPadding=0 bgColor=silver><br /> <br />
<TR>
<br /> <TD width=718><br />
<P>
<SPAN style="FONT-SIZE: 12pt"><FONT face=굴림 color=blue size=2>shell> vi hosts.allow</FONT></SPAN><FONT face=굴림 size=2> <BR /></FONT>
</P></TD>
</TR></TABLE>
<br />
<P>
<FONT face=굴림 size=2>/etc/inetd.conf에서 현재 시스템에서 작동 중인 인터넷 서비스를 확인하고 그 데 몬의 이름을 확인한다. 시스템에서 사용하지 않은 데몬이 있을 경우는 hosts.allow 파일에 # 를 붙인다.그리고, 각 데몬의 이름을 /etc/inetd.conf에서 확인하여 정확히 바꾸어 준다. 다음은 서비스별로 deny 할 호스트를 지정한다. 기본적으로 ALL 로서 allow하고, deny 할 호스트를 EXPECT 다음에 지정한다. 이 때, DNS name보다는 ip address를 사용하기 권장한다. <BR /></FONT>
</P>
<br />
<P>
<FONT face=굴림 size=2>예) </FONT>
</P>
<br />
<P>
<FONT face=굴림 size=2>rlogind: ALL \ <BR />EXCEPT 147.46.67. \ <BR />147.46.10.10 \ <BR />147.46.82.242 \ <BR />147.46.80.220 <BR /><BR /></FONT>
</P>
<br />
<P>
<FONT face=굴림 size=2>다음은 hosts.allow의 예제이니 참고하시기 바랍니다. <BR /></FONT>
</P>
<br />
<P>
<FONT face=굴림 size=2>(예1) gaya라는 시스템을 제외하고 hannam.ac.kr도메인안에 있는 모든 시스템들이 모든 서비 스(telnet,ftp, rlogin등등)사용할 수 있도록 설정. <BR /></FONT>
</P>
<br /> <TABLE cellSpacing=0 borderColorDark=white borderColorLight=black border=1><br /> <br />
<TR>
<br /> <TD width=718><br />
<P>
<FONT face=굴림 size=2>ALL: .hannam.ac.kr EXCEPT gaya.hannam.ac.kr <BR /></FONT>
</P></TD>
</TR></TABLE>
<br />
<P>
<FONT face=굴림 size=2>(예2) 143.248.21.25 시스템에서 요청하는 모든 서비스를 제공하도록 설정. <BR /></FONT>
</P>
<br /> <TABLE cellSpacing=0 borderColorDark=white borderColorLight=black border=1><br /> <br />
<TR>
<br /> <TD width=718><br />
<P>
<FONT face=굴림 size=2>ALL: 143.248.21.25 <BR /></FONT>
</P></TD>
</TR></TABLE>
<br />
<P>
<FONT face=굴림 size=2>(예3) 143.248.10.23, 143.248.30.33에서 요청하는 모든 서비스를 제공하도록 설정. </FONT>
</P>
<br /> <TABLE cellSpacing=0 borderColorDark=white borderColorLight=black border=1><br /> <br />
<TR>
<br /> <TD width=718><br />
<P>
<FONT face=굴림 size=2>ALL: 143.248.10.23, 143.248.30.33 </FONT>
</P>
<br />
<P>
<FONT face=굴림 size=2>혹은 </FONT>
</P>
<br />
<P>
<FONT face=굴림 size=2>ALL: 143.248.10.23 <BR />ALL: 143.248.30.33 </FONT>
</P></TD>
</TR></TABLE>
<br />
<P>
<FONT face=굴림 size=2>(예4) 서브넷 143.248.70.X의 모든 시스템들의 접근 허용 설정 </FONT>
</P>
<br /> <TABLE cellSpacing=0 borderColorDark=white borderColorLight=black border=1><br /> <br />
<TR>
<br /> <TD width=718><br />
<P>
<FONT face=굴림 size=2>ALL: 143.248.70. <BR /></FONT>
</P></TD>
</TR></TABLE>
<br />
<P>
<FONT face=굴림 size=2>hosts.allow의 수정이 끝나면, hosts.deny를 수정하는데, hosts.allow에서 EXCEPT 통해 지정했으므로 다음과 같이 설정한다. </FONT>
</P>
<br />
<P>
</P>
<br />
<P>
<FONT face=굴림 size=2><B>2. hosts.deny 파일의 생성</B></FONT>
</P>
<br /> <TABLE cellSpacing=0 cellPadding=0 bgColor=silver><br /> <br />
<TR>
<br /> <TD width=718><br />
<P>
<SPAN style="FONT-SIZE: 12pt"><FONT face=굴림 color=blue size=2>shell> vi hosts.deny</FONT></SPAN><FONT face=굴림 size=2> </FONT>
</P></TD>
</TR></TABLE>
<br />
<P>
</P>
<br /> <TABLE cellSpacing=0 borderColorDark=white borderColorLight=black border=1><br /> <br />
<TR>
<br /> <TD width=718><br />
<P>
<FONT face=굴림 size=2>ALL: ALL <BR /></FONT>
</P></TD>
</TR></TABLE>
<br />
<P>
<FONT face=굴림 size=2>hosts.deny파일은 tcp wrapper 가 설치되어있는 호스트에 hosts.allow에 설정되어있는 시스템을 제외하고는 거부하도록 위와 같이 설정하시면 됩니다. <BR /></FONT>
</P>
<br />
<P>
<FONT face=굴림 size=2><B>3. hosts.allow와 hosts.deny의 수정이 끝났으면 /etc 디렉토리에 복사</B></FONT>
</P>
<br /> <TABLE bgColor=silver border=0><br /> <br />
<TR>
<br /> <TD width=718><br />
<P>
<FONT face=굴림 color=blue size=2>shell> cp hosts.allow /etc <BR />shell> cp hosts.deny /etc </FONT>
</P></TD>
</TR></TABLE>
<br />
<P>
<FONT face=굴림 size=2><B>4. safe_finger의 복사 <BR /></B></FONT>
</P>
<br />
<P>
<FONT face=굴림 size=2>safe_finger는 deny 된 host 접근을 Log하기 위한 shell script이다. 파일은 /usr/local/bin에 복사하도록한다. 그리고 실행 가능하도록 권한을 수정한다. <BR /><BR /></FONT>
</P>
<br /> <TABLE bgColor=silver border=0><br /> <br />
<TR>
<br /> <TD width=718><br />
<P>
<FONT face=굴림 size=2></FONT><FONT face=굴림 color=blue size=2>shell> cp safe_finger /usr/local/bin<BR />shell> chmod a+x /usr/local/bin/safe_finger <BR /></FONT>
</P></TD>
</TR></TABLE>
<br />
<P>
<FONT face=굴림 color=black size=2><B>5. inetd.conf의 수정</B></FONT><FONT face=굴림 color=black size=2><B> <BR /></B></FONT>
</P>
<br /> <TABLE cellSpacing=0 cellPadding=0 bgColor=silver><br /> <br />
<TR>
<br /> <TD width=718><br />
<P>
<FONT face=굴림 color=blue size=2>shell> cp /etc/inetd.conf /etc/indetd.conf.org # /etc/inetd.conf 백업<BR />shell> vi /etc/inetd.conf # /etc/inetd.conf 수정</FONT>
</P></TD>
</TR></TABLE>
<br />
<P>
<SPAN style="FONT-SIZE: 12pt"><FONT face=굴림 color=green size=2>Wrapper를 통한 서비스만을 수정하는데, 원래의 설정을 그대로 복사한 후, #기호를 붙이고 /usr/sbin/ftpd 등의 각 서비스를 /usr/sbin/tcpd -디렉토리는 해당 디렉토리-로 바꾼다. 그리고, 마지막에 그 전에 있던 서비스를 기입한다. 아래 예를 잘 참고하자. </FONT></SPAN><FONT face=굴림 size=2><BR /><BR /></FONT>
</P>
<br /> <TABLE cellSpacing=0 borderColorDark=white borderColorLight=black border=1><br /> <br />
<TR>
<br /> <TD width=718><br />
<P>
<FONT face=굴림 size=2>##############<BR />#TCP Wrapper <BR /># <BR />#ftp stream tcp nowait root /usr/sbin/ftpd ftpd </FONT>
</P>
<br />
<P>
<FONT face=굴림 size=2>#telnet stream tcp nowait root /usr/sbin/telnetd telnetd <BR />#shell stream tcp nowait root /usr/sbin/rshd rshd <BR />#login stream tcp nowait root /usr/sbin/rlogind rlogind <BR />#exec stream tcp nowait root /usr/sbin/rexecd rexecd <BR /># </FONT>
</P>
<br />
<P>
<FONT face=굴림 size=2>ftp stream tcp nowait root /usr/sbin/tcpd /usr/sbin/ftpd <BR />telnet stream tcp nowait root /usr/sbin/tcpd /usr/sbin/telnetd <BR />shell stream tcp nowait root /usr/sbin/tcpd /usr/sbin/rshd <BR />login stream tcp nowait root /usr/sbin/tcpd /usr/sbin/rlogind <BR />exec stream tcp nowait root /usr/sbin/tcpd /usr/sbin/rexecd <BR /></FONT>
</P>
<br />
<P>
<FONT face=굴림 size=2>.. <이하생략></FONT>
</P></TD>
</TR></TABLE>
<br />
<P>
<FONT face=굴림 size=2><BR /><BR /></FONT>
</P>
<br />
<P>
<FONT face=굴림 size=2><B>6. tcpdchk를 이용한 configuration 확인 <BR /></B></FONT>
</P>
<br /> <TABLE cellSpacing=0 cellPadding=0 bgColor=silver><br /> <br />
<TR>
<br /> <TD width=718><br />
<P>
<FONT face=굴림 color=blue size=2>shell> tcpdchk</FONT><FONT face=굴림 color=blue size=2> <BR /></FONT>
</P></TD>
</TR></TABLE>
<br />
<P>
<FONT face=굴림 size=2>이 때 에러가 나오면 해당 configuration를 수정한다. <BR /></FONT>
</P>
<br />
<P>
<FONT face=굴림 size=2><B>7. tcpdmatch를 통해 configuration확인 </B></FONT>
</P>
<br />
<P>
<FONT face=굴림 size=2>설정이 제대로 되었으면 tcpdmatch 를 통해 설정한 호스트에서 들어 왔을 때 deny 되는지 allow 되는지 여부를 확인한다. <BR /></FONT>
</P>
<br /> <TABLE cellSpacing=0 borderColorDark=white borderColorLight=black border=1><br /> <br />
<TR>
<br /> <TD width=718><br />
<P>
<FONT face=굴림 size=2>usage: tcpdmatch [-d] [-i inet_conf] daemon[@host] [user@]host </FONT>
</P>
<br />
<P>
<FONT face=굴림 size=2> -d: use allow/deny files in current directory <BR /> -i: location of inetd.conf file <BR /></FONT>
</P></TD>
</TR></TABLE>
<br />
<P>
</P>
<br /> <TABLE cellSpacing=0 borderColorDark=white borderColorLight=black border=1><br /> <br />
<TR>
<br /> <TD width=718><br />
<P>
<FONT size=2>[</FONT><FONT color=blue size=2>root@gaya /root]# tcpdmatch ftpd bomun</FONT><FONT size=2><BR />warning: ftpd: no such process name in /etc/inetd.conf<BR />warning: bomun: hostname alias<BR />warning: (official name: bomun.kaist.ac.kr)<BR />client: hostname bomun.kaist.ac.kr<BR />client: address 143.248.1.102<BR />server: process ftpd<BR />matched: /etc/hosts.deny line 9<BR />access: denied<BR />[root@gaya /root]#</FONT>
</P></TD>
</TR></TABLE>
<br /> <TABLE cellSpacing=0 borderColorDark=white borderColorLight=black border=1><br /> <br />
<TR>
<br /> <TD width=718><br />
<P>
<FONT color=blue size=2>[root@gaya /root]# tcpdmatch telnetd yskim.kaist.ac.kr</FONT><FONT size=2><BR />warning: telnetd: no such process name in /etc/inetd.conf<BR />client: hostname yskim.kaist.ac.kr<BR />client: address 143.248.1.24<BR />server: process telnetd<BR />matched: /etc/hosts.allow line 9<BR />access: granted<BR />[root@gaya /root]#</FONT>
</P></TD>
</TR></TABLE>
<br />
<P>
</P>
<br />
<P>
<FONT face=굴림 size=2><B>8. inetd의 재시동 <BR /></B></FONT>
</P>
<br />
<P>
<FONT face=굴림 size=2>여기까지 이상이 없이 되었으면 이제는 inetd를 재시동하여 wrapper가 작동하도록 한다. 우선 ps 명령으로 pid를 찾아낸다. <BR /></FONT>
</P>
<br /> <TABLE cellSpacing=0 borderColorDark=white cellPadding=0 bgColor=silver borderColorLight=black><br /> <br />
<TR>
<br /> <TD width=718><br />
<P>
<FONT face=굴림 color=blue size=2>shell> ps -eaf | grep inetd </FONT>
</P>
<br />
<P>
<FONT face=굴림 size=2> root </FONT><FONT face=굴림 color=green size=2>152</FONT><FONT face=굴림 size=2> 1 0 8월 08 ? 2:18 /usr/sbin/inetd -s </FONT>
</P></TD>
</TR></TABLE>
<br />
<P>
<SPAN style="FONT-SIZE: 12pt"><FONT face=굴림 color=red size=2>(주의!!) PID는 시스템마다 다르므로 필히 확인하십시요.</FONT></SPAN><FONT face=굴림 size=2> <BR /></FONT>
</P>
<br />
<P>
<FONT face=굴림 size=2>그리고 HUP를 통해 작동시킨다. <BR /></FONT>
</P>
<br /> <TABLE cellSpacing=0 cellPadding=0 bgColor=silver><br /> <br />
<TR>
<br /> <TD width=718><br />
<P>
<FONT face=굴림 color=blue size=2>shell> kill -HUP 152 <BR /></FONT>
</P></TD>
</TR></TABLE>
<br />
<P>
<FONT face=굴림 size=2><BR /></FONT>
</P>
<br />
<P>
<FONT size=2><B>9. 설치재확인</B></FONT>
</P>
<br />
<P>
<FONT face=굴림 size=2>실험실내의 deny된 다른 호스트에서 접근 했을 때, deny가 되는지 확인한다. </FONT>
</P>
<br /> <TABLE cellSpacing=0 borderColorDark=white borderColorLight=black border=1><br /> <br />
<TR>
<br /> <TD width=718><br />
<P>
<FONT face=굴림 size=2>shell> telnet taeback.kaist.ac.kr <BR />Trying 143.248.210.5… <BR />Connected to taeback.kaist.ac.kr. <BR />Escape character is ‘^]’. <BR />Connection closed by foreign host. <BR /></FONT>
</P></TD>
</TR></TABLE></p>
| |