2009년 10월 14일 수요일

TCPWRAPER 를 이용한 보안

작업환경 : Redhat6.2k
=========================================================================

TCPWRAPER를 이용한 간단 보안임돠.
관리자가 선택적으로 접속하는 호스트를 막는 툴이라고나 할까염?!

/etc/hosts.allow
/etc/hosts.deny
그리고, 파일하나를 작성합니다.
/etc/hosts.check

============================== START ====================================

#!/bin/sh

################################ 변수정의부문

# 메일 수신자
mailto=root

# 화면출력 여부, 메일전송 여부
dsp=$1; msg=$2

# 접속자 정보 등
a=$3; c=$4; d=$5; h=$6; n=$7; p=$8; s=$9; u=$10

# 현재 시간
time=`date`

# 접속시도자 소속 서버의 finger 정보
finger=`/usr/bin/finger -l @$h 2> /dev/null`


################################ 화면 출력부문

if [ $dsp = Y ]
then

/bin/echo "

========================================
접속이 허용되지 않습니다.
========================================

Access Time : $time
Client host address : $a
Client information : $c
Client host name(or IP) : $h
Client host name : $n
Client user name : $un

"

fi


################################ 메일 송신부문

if [ $msg = Y ]
then

/bin/echo "

========================================
접속 거부자 상세정보
========================================

Access Time : $time
Access client host address : $a
Access client information : $c
The daemon process name : $d
Access client host name(or IP) : $h
Access client host name : $n
The daemon process id : $p
Server information : $s
Access client user name : $u

--------------------------------------------------------
                              Access client finger information
--------------------------------------------------------
$finger
---------------------------------------------------------
n" |
/bin/mail -s "tcp_wrapper report [$d]" $mailto

fi

============================= STOP ======================================

/etc/hosts.check 파일을 만든뒤,

chmod a+rx /etc/host_check

이렇게 실행가능하도록 합니다.
그담은 /etc/hosts.allow 파일을 자신의 환경에 맞게 적당하게 수정합니다.

============================= START =====================================

#
# hosts.allow This file describes the names of the hosts which are
# allowed to use the local INET services, as decided
# by the '/usr/sbin/tcpd' server.
#
# 메일을 모든 사람에게 허용
# in.smtpd: ALL
# telnet과 ftp는 같은 도메인에 속한 사람과 집에 있는 본인의 호스트
# 에만 허용
# telnetd, ftpd: LOCAL, linux.klug.org
# finger를 허용하되 누가 요청했는지 기록을 남긴다.
# fingerd: ALL: (finger @%h | mail -s "finger from %h" root)
#in.telnetd: 192.168.0., LOCAL, koug.net
#in.ftpd: 192.168.0., LOCAL, koug.net
#ipop3d: 192.168.0., LOCAL, koug.net
#in.smtpd: 192.168.0.,LOCAL, koug.net
#in.telnetd: ALL
#ipop3d: ALL
#in.smtpd: ALL
in.telnetd ipop3d in.smtpd:
                127.0.0.1
                211.209.69.103
                koug.net
                192.168.0.2
                : ALLOW
in.ftpd: ALL

================================= STOP ==================================

그리고, /etc/hosts.deny 파일을 수정합니다.
크게 건드릴것은 없습니다.

================================= START =================================

#
# hosts.deny This file describes the names of the hosts which are
# *not* allowed to use the local INET services, as decided
# by the '/usr/sbin/tcpd' server.
#
# The portmap line is redundant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow. In particular
# you should know that NFS uses portmap!
#ALL : ALL

#서비스: 거부주소: 쉘명령
#in.telnetd: ALL: twist ( /etc/hosts.check Y Y %a %c %d %h %n %p %s %u )
&
#ipop3d: ALL: twist ( /etc/hosts.check Y Y %a %c %d %h %n %p %s %u ) &
ALL : ALL EXCEPT LOCAL:
                twist ( /etc/hosts.check Y Y %a %c %d %h %n %p %s %u ) &

=============================== STOP ====================================

죽 보시면 크게 어려운건 없을듯하네염. 저두하는데염.__+)
hosts.allow에는 허용할 컴의 ip내지 domain을 쓰면 됩니다.
그리고 hosts.deny는 수정할 것이 거의 없습니다.
단, 메일받는 사람의 ID는 root 로 해놓았는데 원하는 ID로 하시면 됩니다.
이것이 어떻게 작동을 하느냐하면, 일단 허용되지 않는곳의 IP에서 telnet으
로 접속을 시도합니다. 그러면 바로 hosts.check가 실행됩니다.
그리고 접속을 시도한 컴에게 finger를 시도해서 정보를 메일로 관리자에게 보
냅니다.

이런 프로그램에 관심이 있으신분들은,
http://www.rootshell.com
를 들러보십시오. 전 잘........ --ㆀ

직접 테스트한 화면을 볼까염!
=========================================================================
[root@www /etc]# telnet 211.209.69.103
Trying 211.209.69.103...
Connected to 211.209.69.103.
Escape character is '^]'.


========================================
접속이 허용되지 않습니다.
========================================

Access Time : 금 5월 11 23:22:17 KST 2001
Client host address : 211.209.69.103
Client information : 211.209.69.103
Client host name(or IP) : 211.209.69.103
Client host name : paranoid
Client user name :


Connection closed by foreign host.
=========================================================================

메일을 받을 ID로 보내진 메일을 확인해볼까염!
=========================================================================

From root Fri May 11 23:22:17 2001
Date: Fri, 11 May 2001 23:22:17 +0900
From: root <root@koug.net>
To: root@koug.net
Subject: tcp_wrapper report [in.telnetd]



========================================
접속 거부자 상세정보
========================================

Access Time : 금 5월 11 23:22:17 KST 2001
Access client host address : 211.209.69.103
Access client information : 211.209.69.103
The daemon process name : in.telnetd
Access client host name(or IP) : 211.209.69.103
Access client host name : paranoid
The daemon process id : 12378
Server information : in.telnetd@211.209.69.103
Access client user name : Y0

--------------------------------------------------------
                              Access client finger information
--------------------------------------------------------

=========================================================================

세부적인것은 나름대로 공부하시기 바랍니다.

사용할 대몬프로그램의 이름을 앞에 써주고 형식은 같으니 변형해서 사용하시
면 됩니다.

댓글 없음:

댓글 쓰기